00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _util_group_mstate_h
00033 #define _util_group_mstate_h
00034
00035 #include <util/state/state.h>
00036 #include <util/state/statein.h>
00037 #include <util/state/stateout.h>
00038 #include <util/group/message.h>
00039
00043 class MsgStateSend: public StateOut {
00044 private:
00045
00046 MsgStateSend(const MsgStateSend&);
00047 void operator=(const MsgStateSend&);
00048 protected:
00049 Ref<MessageGrp> grp;
00050 int nbuf;
00051 int bufsize;
00052 char* buffer;
00053 char* send_buffer;
00054 int nheader;
00055 int* nbuf_buffer;
00056
00057 int put_array_void(const void*, int);
00058 public:
00059 MsgStateSend(const Ref<MessageGrp>&);
00060 virtual ~MsgStateSend();
00061
00063 virtual void flush() = 0;
00064
00067 void set_buffer_size(int);
00068
00071 int put(const ClassDesc*);
00072 int put(char r);
00073 int put(unsigned int r);
00074 int put(int r);
00075 int put(float r);
00076 int put(double r);
00077 int put(const char*,int);
00078 int put(const int*,int);
00079 int put(const unsigned int*,int);
00080 int put(const float*,int);
00081 int put(const double*,int);
00082 };
00083
00087 class MsgStateBufRecv: public StateIn {
00088 private:
00089
00090 MsgStateBufRecv(const MsgStateBufRecv&);
00091 void operator=(const MsgStateBufRecv&);
00092 protected:
00093 Ref<MessageGrp> grp;
00094 int nbuf;
00095 int ibuf;
00096 int bufsize;
00097 char* buffer;
00098 char* send_buffer;
00099 int nheader;
00100 int* nbuf_buffer;
00101
00102 int get_array_void(void*,int);
00103
00105 virtual void next_buffer() = 0;
00106 public:
00108 MsgStateBufRecv(const Ref<MessageGrp>&);
00110 MsgStateBufRecv();
00111
00112 virtual ~MsgStateBufRecv();
00113
00116 void set_buffer_size(int);
00117 };
00118
00121 class MsgStateRecv: public MsgStateBufRecv {
00122 private:
00123
00124 MsgStateRecv(const MsgStateRecv&);
00125 void operator=(const MsgStateRecv&);
00126 public:
00128 MsgStateRecv(const Ref<MessageGrp>&);
00129
00130 virtual ~MsgStateRecv();
00131
00135 int version(const ClassDesc*);
00136
00139 int get(const ClassDesc**);
00140 int get(char&r, const char *key = 0);
00141 int get(unsigned int&r, const char *key = 0);
00142 int get(int&r, const char *key = 0);
00143 int get(float&r, const char *key = 0);
00144 int get(double&r, const char *key = 0);
00145 int get(char*&);
00146 int get(unsigned int*&);
00147 int get(int*&);
00148 int get(float*&);
00149 int get(double*&);
00150 };
00151
00155 class StateSend: public MsgStateSend {
00156 private:
00157
00158 StateSend(const StateSend&);
00159 void operator=(const StateSend&);
00160 private:
00161 int target_;
00162 public:
00164 StateSend(const Ref<MessageGrp>&);
00165
00166 ~StateSend();
00168 void target(int);
00170 void flush();
00171 };
00172
00176 class StateRecv: public MsgStateRecv {
00177 private:
00178
00179 StateRecv(const StateRecv&);
00180 void operator=(const StateRecv&);
00181 private:
00182 int source_;
00183 protected:
00184 void next_buffer();
00185 public:
00187 StateRecv(const Ref<MessageGrp>&);
00189 void source(int);
00190 };
00191
00195 class BcastStateSend: public MsgStateSend {
00196 private:
00197
00198 BcastStateSend(const BcastStateSend&);
00199 void operator=(const BcastStateSend&);
00200 public:
00202 BcastStateSend(const Ref<MessageGrp>&);
00203
00204 ~BcastStateSend();
00206 void flush();
00207 };
00208
00212 class BcastStateRecv: public MsgStateRecv {
00213 private:
00214
00215 BcastStateRecv(const BcastStateRecv&);
00216 void operator=(const BcastStateRecv&);
00217 protected:
00218 int source_;
00219 void next_buffer();
00220 public:
00222 BcastStateRecv(const Ref<MessageGrp>&, int source = 0);
00224 void source(int s);
00225 };
00226
00230 class BcastState {
00231 private:
00232 BcastStateRecv *recv_;
00233 BcastStateSend *send_;
00234 public:
00236 BcastState(const Ref<MessageGrp> &, int source = 0);
00237
00238 ~BcastState();
00239
00243 void bcast(int &);
00244 void bcast(double &);
00245 void bcast(int *&, int);
00246 void bcast(double *&, int);
00247 template <class T> void bcast(Ref<T>&a)
00248 {
00249 if (recv_) {
00250 a << SavableState::restore_state(*recv_);
00251 }
00252 else if (send_) {
00253 SavableState::save_state(a.pointer(),*send_);
00254 }
00255 }
00256
00259 void flush();
00260
00263 void forget_references();
00264
00266 void set_buffer_size(int);
00267 };
00268
00272 class BcastStateInBin: public MsgStateBufRecv {
00273 private:
00274
00275 BcastStateInBin(const BcastStateRecv&);
00276 void operator=(const BcastStateRecv&);
00277 protected:
00278 int opened_;
00279 int file_position_;
00280 std::streambuf *buf_;
00281
00282 void next_buffer();
00283 int get_array_void(void*, int);
00284 public:
00286 BcastStateInBin(const Ref<KeyVal> &);
00288 BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
00289
00290 ~BcastStateInBin();
00291
00292 virtual int open(const char *name);
00293 virtual void close();
00294
00295 void seek(int loc);
00296 int seekable();
00297 int tell();
00298 int use_directory();
00299 };
00300
00301 #endif
00302
00303
00304
00305
00306