00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef BLACKBOARD_H
00021 #define BLACKBOARD_H
00022
00023 #ifdef _MSC_VER
00024 #pragma warning(disable : 4786)
00025 #endif
00026
00027 #include <omnetpp.h>
00028 #include <vector>
00029 #include <string>
00030 #include "ModuleAccess.h"
00031
00032 class ImNotifiable;
00033 class BBItem;
00034
00035
00082 class Blackboard : public cSimpleModule
00083 {
00084 protected:
00085 bool coreDebug;
00086
00087 class Subscriber
00088 {
00089 public:
00090 ImNotifiable *client;
00091 int scopeModuleId;
00092 public:
00093 Subscriber(ImNotifiable *c=0, int b=-1) :
00094 client(c), scopeModuleId(b) {};
00095 };
00096
00097
00098 typedef std::vector<Subscriber> SubscriberVector;
00099 typedef std::vector<SubscriberVector> ClientVector;
00100
00101 typedef std::vector<const char* > CategoryDescriptions;
00102
00103 typedef std::vector<int> ParentVector;
00104
00105 typedef ClientVector::iterator ClientVectorIter;
00106 typedef CategoryDescriptions::iterator DescriptionsIter;
00107 typedef ParentVector::iterator ParentVectorIter;
00108
00109 ClientVector clientVector;
00110 CategoryDescriptions categoryDescriptions;
00111 ParentVector parentVector;
00112
00113 int nextCategory;
00114
00115 friend std::ostream& operator<<(std::ostream&, const SubscriberVector&);
00116
00117 protected:
00121 const char* categoryName(int category);
00126 int findAndCreateDescription(bool *isNewEntry, const BBItem *category);
00127
00133 void fillParentVector(const BBItem *category, int cat);
00134
00135 public:
00136 Module_Class_Members(Blackboard, cSimpleModule, 0);
00137 virtual ~Blackboard();
00138
00142 virtual void initialize();
00143
00147 virtual void handleMessage(cMessage *msg);
00148
00160 int subscribe(ImNotifiable *client, const BBItem *category, int scopeModuleId=-1);
00172 int subscribe(ImNotifiable *client, int category, int scopeModuleId=-1);
00176 void unsubscribe(ImNotifiable *client, int category);
00178
00203 void publishBBItem(int category, const BBItem* details, int scopeModuleId);
00204
00209 int getCategory(const BBItem* details);
00211 };
00212
00224 class ImNotifiable
00225 {
00226 public:
00255 virtual void receiveBBItem(int category, const BBItem *details, int scopeModuleId) = 0;
00256
00258 virtual ~ImNotifiable() { }
00259 };
00260
00266 class BlackboardAccess : public ModuleAccess<Blackboard>
00267 {
00268 public:
00269 BlackboardAccess() : ModuleAccess<Blackboard>("blackboard") {}
00270 };
00271
00298 class BBItem : public cPolymorphic
00299 {
00300 public:
00301 virtual BBItem *parentObject() const {
00302 return new BBItem();
00303 }
00304 };
00305
00314 #define BBITEM_METAINFO(BASECLASS) \
00315 public: \
00316 virtual BBItem* parentObject() const { \
00317 return new BASECLASS(); }
00318
00319 #endif
00320