• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/sensor-nets/tags.h

00001 // Author: Satish Kumar, kkumar@isi.edu
00002 
00003 #ifndef tag_h_
00004 #define tag_h_
00005 
00006 #include <cstdlib>
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include <iostream>
00010 #include <iomanip.h>
00011 #include <assert.h>
00012 #include <tclcl.h>
00013 #include <trace.h>
00014 #include <rng.h>
00015 
00016 #define NUM_RECTANGLES 10 // Divide into 10 rectangles at each level
00017 #define TRUE 1
00018 #define FALSE 0
00019 
00020 
00021 // Structure used for caching at agents
00022 class TagCache {
00023 public:
00024   int obj_name_;
00025   int origin_time_;
00026   double X_;
00027   double Y_;
00028 };
00029 
00030 
00031 
00032 // Object to hold attribute value pairs
00033 class attribs {
00034   char *name;
00035   char *value;
00036   attribs *next_;
00037 };
00038 
00039 
00040 // Tag object definition
00041 class tag {
00042 public:
00043   tag() { next_ = NULL;}
00044   double x_;           // x-coordinate
00045   double y_;           // y-coordinate
00046   int obj_name_;  // Hierarchical object name
00047   attribs *attributes_; // <attribute, value> pairs
00048   tag *next_;           // Used to attach tags to a list
00049 };
00050   
00051 
00052 // List of tags in 2-dimensional space (for now)
00053 class dbase_node {
00054 public:
00055   dbase_node (double x_min, double x_max, double y_min, double y_max) {
00056     assert ((x_min <= x_max) && (y_min <= y_max));
00057     x_min_ = x_min;
00058     x_max_ = x_max;
00059     y_min_ = y_min;
00060     y_max_ = y_max;
00061     tags_list_ = NULL;
00062 
00063     for(int i = 0; i < NUM_RECTANGLES; ++i) {
00064       list_node_[i] = NULL;
00065     }
00066     
00067   };
00068   
00069   double x_min_;
00070   double x_max_;
00071   double y_min_;
00072   double y_max_;
00073 
00074   // Divide into NUM_RECTANGLES rectangles at each level
00075   dbase_node *list_node_[NUM_RECTANGLES]; 
00076 
00077   tag *tags_list_;                              
00078 };
00079 
00080 
00081 // A compressed list returned to the node. Excluded attributes for now.
00082 class compr_taglist {
00083 public:
00084   compr_taglist() { next_ = NULL;}
00085   int obj_name_;
00086   compr_taglist *next_;
00087 };
00088 
00089 
00090 
00091 class tags_database : public TclObject {
00092 public:
00093   tags_database() : tags_db_(NULL) { 
00094      num_tags_ = 0;
00095      num_sensed_tags_ = 0;
00096      sensed_tag_list_ = NULL;
00097      num_freq_qry_tags_= 0;   
00098      freq_qry_tag_list_ = NULL;
00099      rn_ = new RNG;
00100   }
00101 
00102   ~tags_database() {
00103     // Need to add deletion of tree as well
00104     delete[] sensed_tag_list_;
00105   }
00106 
00107   virtual int command(int argc, const char * const * argv);
00108 
00109   void create_tags_database(double x_min, double x_max, double y_min, double y_max, int num_tags);
00110   void Addtag(const tag *tag_);
00111   void Deletetag(const tag *tag_);
00112   compr_taglist *Gettags(double x, double y, double r); // Returns all tags 
00113                              // within a circle centered at (x,y) and radius r
00114   Trace *tracetarget_;       // Trace target
00115   void trace(char *fmt,...);                              
00116   int get_random_tag();
00117 
00118 protected:
00119   dbase_node *tags_db_;  // interior node
00120   int num_tags_;         // total number of tags in database
00121   int num_sensed_tags_;  // number of tags sensed by nodes
00122   int *sensed_tag_list_; // list of all tags sensed by nodes
00123 
00124   int num_freq_qry_tags_;   // number of frequently queried tags              
00125   int *freq_qry_tag_list_;  // tags that will be frequently queried
00126 
00127   RNG *rn_;
00128   compr_taglist *vtags_; //used to store returned tag list after search    
00129   void add_level(double x_min, double x_max, double y_min, double y_max, dbase_node *dbnode);                                  
00130   void search_tags_dbase(double x, double y, double r, dbase_node *dbnode);
00131 };
00132 
00133 
00134 
00135 #endif
00136 
00137 
00138 

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1