clmsg-discovery.h

Go to the documentation of this file.
00001 /* -*- Mode:C++ -*- */
00002 
00003 /*
00004  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00016  *    names of its contributors may be used to endorse or promote products 
00017  *    derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00021  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00022  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00023  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 
00043 #ifndef CLMSG_DISCOVERY_H
00044 #define CLMSG_DISCOVERY_H
00045 
00046 #include <clmessage.h>
00047 #include <map>
00048 #include <list>
00049 #include <set>
00050 #include <vector>
00051 #include <packet.h>
00052 #include <string>
00053 
00054 #define CLMSG_DISCOVERY_VERBOSITY 3
00055 
00056 extern ClMessage_t CLMSG_DISCOVERY;
00057 
00058 class DiscoveryData;
00059 class ClSAP;
00060 class PlugIn;
00061 
00062 // map < module_id, data_collected>
00063 typedef map<int, DiscoveryData> DBId;
00064 // lookup tables:
00065 // const plugin* --> id
00066 typedef map< const PlugIn* , int > DBPointer2Id;
00067 // layer_id , id
00068 typedef map< int , set<int> > DBLayer2Id;
00069 // miracle_tag , id
00070 typedef map< string , set<int> > DBTag2Id;
00071 // tcl_name , id
00072 typedef map< string , set<int> > DBName2Id;
00073 
00074 typedef set<int>::iterator SetIt;
00075 typedef set<int>::reverse_iterator setRit;
00076 typedef DBPointer2Id::iterator DBPointer2IdIt;
00077 typedef DBPointer2Id::reverse_iterator DBPointer2IdRit;
00078 typedef DBLayer2Id::iterator DBLayer2IdIt;
00079 typedef DBLayer2Id::reverse_iterator DBLayer2IdRit;
00080 typedef DBTag2Id::iterator DBTag2IdIt;
00081 typedef DBTag2Id::reverse_iterator DBTag2IdRit;
00082 typedef DBName2Id::iterator DBName2IdIt;
00083 typedef DBName2Id::reverse_iterator DBName2IdRit;
00084 typedef DBId::iterator DBIt;
00085 typedef DBId::reverse_iterator DBRit;
00086 
00087 typedef vector<DiscoveryData>::iterator VDDIt;
00088 typedef vector<DiscoveryData>::reverse_iterator VDDRit;
00089 
00090 class DiscoveryData {
00091 
00092 public:
00093 
00094   DiscoveryData(const PlugIn* pointer, int layer_id, int id, const char* tcl_name, const char* miracle_tag);
00095   DiscoveryData();
00096   DiscoveryData(const DiscoveryData& DData2copy);
00097   void reset();
00098 
00099   void setPointer(const PlugIn* pointer) { module_pointer = pointer; }
00100   const PlugIn* getPointer() { return module_pointer; }
00101   
00102   void setLayer(int layer_id) { layer_id = module_layer_id; }
00103   int getLayer() { return module_layer_id; }
00104 
00105   void setId(int id) { module_id = id; }
00106   int getId() { return module_id; }
00107   
00108   void setTclName(const char* tcl_name) { module_tcl_name.clear(); module_tcl_name = tcl_name; }
00109   const char* getTclName() { return module_tcl_name.c_str(); }
00110   
00111   void setMiracleTag(const char* miracle_tag) { module_miracle_tag.clear(); module_miracle_tag = miracle_tag;} 
00112   const char* getMiracleTag() { return module_miracle_tag.c_str(); }
00113  
00114   void setValid() { is_valid = true;}
00115   void setNotValid() {is_valid = false;}
00116 
00117 private:
00118  
00119   const PlugIn* module_pointer;
00120   int module_layer_id;
00121   int module_id;
00122   string module_tcl_name;
00123   string module_miracle_tag;
00124  
00125   bool is_valid;
00126 };
00127 
00128 
00129 class DiscoveryStorage 
00130 {
00131 
00132 public:
00133 
00134   DiscoveryStorage();
00135 //   ~DiscoveryStorage();
00136 
00137   int getDataSize();
00138   void addEntry(const PlugIn* pointer, int layer_id, int id, const char* tcl_name, const char* miracle_tag);
00139   void addEntry(DiscoveryData data);
00140   void removeEntry(int id);
00141   
00142   void printData();
00143   int getSize() {return db_id.size();}
00144 
00145   DiscoveryStorage findLayer(int layer_id);
00146   DiscoveryStorage findTag(const char* tag); 
00147   DiscoveryStorage findTclName(const char* tcl_name); 
00148   DiscoveryData findPointer(const PlugIn* pointer);
00149   DBIt begin() {return db_id.begin(); }
00150   DBIt end() {return db_id.end(); }
00151 
00152 private:
00153 
00154   DBId db_id; 
00155   DBLayer2Id db_layer;
00156   DBTag2Id db_tag;
00157   DBName2Id db_name;
00158   DBPointer2Id db_pointer;
00159 
00160   void reset();
00161 };
00162 
00163 
00164 class ClMsgDiscovery : public ClMessage
00165 {
00166 
00167 public:
00168 
00169   ClMsgDiscovery();
00170   ClMessage* copy();    // copy the message
00171 
00172   DiscoveryStorage copyStorage();
00173   void addData(const PlugIn* pointer, int layer_id, int id, const char* tcl_name, const char* miracle_tag);
00174   void addSenderData(const PlugIn* pointer, int layer_id, int id, const char* tcl_name, const char* miracle_tag);
00175   void removeData(int id);  
00176   void removeSenderData();
00177   void printReplyData();
00178 
00179   int getDBSize();
00180 
00181   DiscoveryData getSenderData();
00182 
00183   DiscoveryStorage findLayer(int layer_id ); 
00184   DiscoveryStorage findTag(const char* tag); 
00185   DiscoveryStorage findTclName(const char* tcl_name); 
00186   DiscoveryData findPointer(const PlugIn* pointer);
00187 
00188         
00189 private:
00190 
00191   DiscoveryStorage reply_storage;
00192   DiscoveryData sender_data;
00193 };
00194 
00195 
00196 #endif /* CLMSG_DISCOVERY_H */
00197 
00198 

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2