NAMD
BroadcastObject.h
Go to the documentation of this file.
1 
7 /*
8  Coordinates broadcast of a data type from a Controller/Seq
9  to all other Controller/Sequencer type objects (they must
10  run in a thread!)
11 */
12 
13 #ifndef _BCASTOBJ_H
14 #define _BCASTOBJ_H
15 
16 #include "BroadcastMgr.h"
17 #include "BroadcastClient.h"
18 #include "LdbCoordinator.h"
19 #include "common.h"
20 
21 template <class T> class SimpleBroadcastObject : public BroadcastClient {
22 
23  public:
24 
25  const LDObjHandle *ldObjPtr;
26 
27  SimpleBroadcastObject(int id, const LDObjHandle *h = 0) : BroadcastClient(id), ldObjPtr(h) {
28  if ( sizeof(T) > BCASTMSGSIZE ) {
29  NAMD_bug("SimpleBroadcastObject instantiated on class larger than BCASTMSGSIZE");
30  }
31  }
33 
34  T get(int tag) {
35  T tmp;
37  while ( BroadcastMgr::Object()->getbuf(*this, tag, (void*)(&tmp)) < 0 ) {
38  suspendFor(tag);
39  }
41  return tmp;
42  }
43 
44  void publish(int tag,const T &t ) {
45  BroadcastMgr::Object()->send(*this, tag, (void*)(&t), sizeof(T));
46  }
47 
48 };
49 
50 #endif
void startWork(const LDObjHandle &handle)
SimpleBroadcastObject(int id, const LDObjHandle *h=0)
void pauseWork(const LDObjHandle &handle)
const LDObjHandle * ldObjPtr
void send(BroadcastClient &b, int tag, void *buf, size_t)
Definition: BroadcastMgr.C:49
void NAMD_bug(const char *err_msg)
Definition: common.C:129
static LdbCoordinator * Object()
void publish(int tag, const T &t)
void suspendFor(int tag)
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:96
#define BCASTMSGSIZE
Definition: BroadcastMgr.h:23