BroadcastObject.h

Go to the documentation of this file.
00001 
00007 /*
00008    Coordinates broadcast of a data type from a Controller/Seq
00009    to all other Controller/Sequencer type objects (they must
00010    run in a thread!)
00011 */
00012 
00013 #ifndef _BCASTOBJ_H
00014 #define _BCASTOBJ_H
00015 
00016 #include "BroadcastMgr.h"
00017 #include "BroadcastClient.h"
00018 #include "LdbCoordinator.h"
00019 #include "common.h"
00020 
00021 template <class T> class SimpleBroadcastObject : public BroadcastClient {
00022 
00023   public:
00024 
00025     const LDObjHandle *ldObjPtr;
00026 
00027     SimpleBroadcastObject(int id, const LDObjHandle *h = 0) : BroadcastClient(id), ldObjPtr(h) {
00028       if ( sizeof(T) > BCASTMSGSIZE ) {
00029         NAMD_bug("SimpleBroadcastObject instantiated on class larger than BCASTMSGSIZE");
00030       }
00031     }
00032     ~SimpleBroadcastObject() { }
00033 
00034     T get(int tag) {
00035       T tmp;
00036       if ( ldObjPtr ) LdbCoordinator::Object()->pauseWork(*ldObjPtr);
00037       while ( BroadcastMgr::Object()->getbuf(*this, tag, (void*)(&tmp)) < 0 ) {
00038         suspendFor(tag);
00039       }
00040       if ( ldObjPtr ) LdbCoordinator::Object()->startWork(*ldObjPtr);
00041       return tmp;
00042     }
00043     
00044     void publish(int tag,const T &t ) {
00045       BroadcastMgr::Object()->send(*this, tag, (void*)(&t), sizeof(T));
00046     }
00047 
00048 };
00049 
00050 #endif

Generated on Fri Sep 22 01:17:10 2017 for NAMD by  doxygen 1.4.7