Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages

Blackboard.h

00001 // -*- mode:c++ -*-
00002 // Copyright (C) 2005 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 

Generated on Fri Jan 12 08:29:32 2007 for Mobility Framework by  doxygen 1.4.4