00001
00002 #ifndef BLACK_BOARD_H
00003 #define BLACK_BOARD_H
00004
00005 #ifdef _MSC_VER
00006 #pragma warning(disable : 4786)
00007 #endif
00008
00009 #include <omnetpp.h>
00010 #include <vector>
00011 #include <string>
00012 #include "ImNotifiable.h"
00060 class Blackboard : public cSimpleModule
00061 {
00062 protected:
00063
00065 class Subscriber {
00066 public:
00068 ImNotifiable *client;
00070 int scopeModuleId;
00071 public:
00073 Subscriber(ImNotifiable *c=0, int b=-1) :
00074 client(c), scopeModuleId(b) {};
00075 };
00076
00079 typedef std::vector<Subscriber> SubscriberVector;
00080 typedef std::vector<SubscriberVector> ClientVector;
00081
00082 typedef std::vector<const char* > CategoryDescriptions;
00083
00084 typedef std::vector<int> ParentVector;
00085
00086 typedef ClientVector::iterator ClientVectorIter;
00087 typedef CategoryDescriptions::iterator DescriptionsIter;
00088 typedef ParentVector::iterator ParentVectorIter;
00091 ClientVector clientVector;
00092 CategoryDescriptions categoryDescriptions;
00093 ParentVector parentVector;
00094
00095 int nextCategory;
00096
00097 friend std::ostream& operator<<(std::ostream&, const SubscriberVector&);
00098
00099 bool coreDebug;
00100
00101 protected:
00102
00106 const char* categoryName(int category);
00111 int findAndCreateDescription(bool *isNewEntry, const BBItem *category);
00112
00118 void fillParentVector(const BBItem *category, int cat);
00119
00120 public:
00122 void handleMessage(cMessage *msg);
00123
00125 virtual void initialize(int);
00126
00127 Blackboard():
00128 nextCategory(0)
00129 {}
00130
00131 virtual ~Blackboard();
00132
00133
00145 int subscribe(ImNotifiable *client, const BBItem *category, int scopeModuleId=-1);
00157 int subscribe(ImNotifiable *client, int category, int scopeModuleId=-1);
00161 void unsubscribe(ImNotifiable *client, int category);
00163
00188 void publishBBItem(int category, const BBItem* details, int scopeModuleId);
00189
00194 int getCategory(const BBItem* details);
00196
00198 virtual int numInitStages() const {
00199 return 2;
00200 }
00201 };
00202
00203 #endif
00204