00001
00007
00008
00009
00010
00011
00012
00013 #include "charm++.h"
00014 #include "main.h"
00015 #include "UniqueSet.h"
00016 #include "UniqueSetIter.h"
00017 #include "ProcessorPrivate.h"
00018 #include "BroadcastMgr.decl.h"
00019
00020 #ifndef _BCASTMGR_H
00021 #define _BCASTMGR_H
00022
00023 #define BCASTMSGSIZE (9*sizeof(double))
00024
00025 class BroadcastMsg : public CMessage_BroadcastMsg {
00026 friend class BroadcastMgr;
00027 public:
00028 ~BroadcastMsg() { }
00029 BroadcastMsg() { }
00030
00031 private:
00032
00033 char msg[BCASTMSGSIZE];
00034 int size;
00035 int id;
00036 int tag;
00037 int node;
00038 };
00039
00040 class BroadcastClient;
00041
00042 class BroadcastClientElem {
00043 public:
00044 BroadcastClientElem() {}
00045 BroadcastClientElem(BroadcastClient * c) : broadcastClient(c) {}
00046 ~BroadcastClientElem() {}
00047
00048 BroadcastClient *broadcastClient;
00049
00050 size_t hash() const { return (size_t)broadcastClient; }
00051 int operator==(const BroadcastClientElem &b) const {
00052 return broadcastClient == b.broadcastClient;
00053 }
00054 };
00055
00056 class TaggedMsg {
00057 public:
00058 TaggedMsg() {}
00059 TaggedMsg(int t) : tag(t) {}
00060 TaggedMsg(int t, int s, int c, void *m)
00061 : tag(t), counter(c), msgSize(s) { memcpy((void*)msg,m,s); }
00062 ~TaggedMsg() {}
00063
00064 int tag;
00065 int counter;
00066 int msgSize;
00067 char msg[BCASTMSGSIZE];
00068
00069 int hash() const { return tag; }
00070 int operator==(const TaggedMsg &tm) const { return(tag == tm.tag); }
00071 };
00072
00073 class BOID {
00074 public:
00075 BOID() {}
00076 BOID(int id) { this->id = id; }
00077 ~BOID() {}
00078
00079 int hash() const { return id; }
00080 int operator==(const BOID &b) const { return id == b.id; }
00081 int id;
00082
00083 UniqueSet<BroadcastClientElem> *broadcastSet;
00084 UniqueSet<TaggedMsg> *taggedMsg;
00085 };
00086
00087 class BroadcastMgr : public BOCclass
00088 {
00089 public:
00090 BroadcastMgr() {
00091 CpvAccess(BroadcastMgr_instance) = this;
00092 }
00093 ~BroadcastMgr(void);
00094
00095
00096 inline static BroadcastMgr *Object() {
00097 return CpvAccess(BroadcastMgr_instance);
00098 }
00099
00100 int getbuf(BroadcastClient &b, int tag, void* msg);
00101 void send(BroadcastClient &b, int tag, void *buf, size_t);
00102 void subscribe(BroadcastClient &bc);
00103 void unsubscribe(BroadcastClient &bc);
00104 void recvBroadcast(BroadcastMsg *msg);
00105
00106 private:
00107 UniqueSet<BOID> boid;
00108 };
00109
00110 #endif
00111