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
00040 namespace sc {
00041
00045 class MsgStateSend: public StateOut {
00046 private:
00047
00048 MsgStateSend(const MsgStateSend&);
00049 void operator=(const MsgStateSend&);
00050 protected:
00051 Ref<MessageGrp> grp;
00052 int nbuf;
00053 int bufsize;
00054 char* buffer;
00055 char* send_buffer;
00056 int nheader;
00057 int* nbuf_buffer;
00058
00059 int put_array_void(const void*, int);
00060 public:
00061 MsgStateSend(const Ref<MessageGrp>&);
00062 virtual ~MsgStateSend();
00063
00065 virtual void flush() = 0;
00066
00069 void set_buffer_size(int);
00070
00073 int put(const ClassDesc*);
00074 int put(char r);
00075 int put(unsigned int r);
00076 int put(int r);
00077 int put(float r);
00078 int put(double r);
00079 int put(const char*,int);
00080 int put(const int*,int);
00081 int put(const unsigned int*,int);
00082 int put(const float*,int);
00083 int put(const double*,int);
00084 };
00085
00089 class MsgStateBufRecv: public StateIn {
00090 private:
00091
00092 MsgStateBufRecv(const MsgStateBufRecv&);
00093 void operator=(const MsgStateBufRecv&);
00094 protected:
00095 Ref<MessageGrp> grp;
00096 int nbuf;
00097 int ibuf;
00098 int bufsize;
00099 char* buffer;
00100 char* send_buffer;
00101 int nheader;
00102 int* nbuf_buffer;
00103
00104 int get_array_void(void*,int);
00105
00107 virtual void next_buffer() = 0;
00108 public:
00110 MsgStateBufRecv(const Ref<MessageGrp>&);
00112 MsgStateBufRecv();
00113
00114 virtual ~MsgStateBufRecv();
00115
00118 void set_buffer_size(int);
00119 };
00120
00123 class MsgStateRecv: public MsgStateBufRecv {
00124 private:
00125
00126 MsgStateRecv(const MsgStateRecv&);
00127 void operator=(const MsgStateRecv&);
00128 public:
00130 MsgStateRecv(const Ref<MessageGrp>&);
00131
00132 virtual ~MsgStateRecv();
00133
00137 int version(const ClassDesc*);
00138
00141 int get(const ClassDesc**);
00142 int get(char&r, const char *key = 0);
00143 int get(unsigned int&r, const char *key = 0);
00144 int get(int&r, const char *key = 0);
00145 int get(float&r, const char *key = 0);
00146 int get(double&r, const char *key = 0);
00147 int get(char*&);
00148 int get(unsigned int*&);
00149 int get(int*&);
00150 int get(float*&);
00151 int get(double*&);
00152 };
00153
00157 class StateSend: public MsgStateSend {
00158 private:
00159
00160 StateSend(const StateSend&);
00161 void operator=(const StateSend&);
00162 private:
00163 int type_;
00164 int target_;
00165 public:
00167 StateSend(const Ref<MessageGrp>&);
00168
00169 ~StateSend();
00171 void target(int);
00173 int get_target() const { return target_; }
00175 void type(int);
00177 int get_type() const { return type_; }
00179 void flush();
00180 };
00181
00185 class StateRecv: public MsgStateRecv {
00186 private:
00187
00188 StateRecv(const StateRecv&);
00189 void operator=(const StateRecv&);
00190 private:
00191 int source_;
00192 int type_;
00193 int last_source_;
00194 int last_type_;
00195 protected:
00196 void next_buffer();
00197 public:
00199 StateRecv(const Ref<MessageGrp>&);
00201 void source(int);
00203 void type(int);
00205 int last_source();
00207 int last_type();
00208 };
00209
00213 class BcastStateSend: public MsgStateSend {
00214 private:
00215
00216 BcastStateSend(const BcastStateSend&);
00217 void operator=(const BcastStateSend&);
00218 public:
00220 BcastStateSend(const Ref<MessageGrp>&);
00221
00222 ~BcastStateSend();
00224 void flush();
00225 };
00226
00230 class BcastStateRecv: public MsgStateRecv {
00231 private:
00232
00233 BcastStateRecv(const BcastStateRecv&);
00234 void operator=(const BcastStateRecv&);
00235 protected:
00236 int source_;
00237 void next_buffer();
00238 public:
00240 BcastStateRecv(const Ref<MessageGrp>&, int source = 0);
00242 void source(int s);
00243 };
00244
00248 class BcastState {
00249 private:
00250 BcastStateRecv *recv_;
00251 BcastStateSend *send_;
00252 public:
00254 BcastState(const Ref<MessageGrp> &, int source = 0);
00255
00256 ~BcastState();
00257
00261 void bcast(int &);
00262 void bcast(double &);
00263 void bcast(int *&, int);
00264 void bcast(double *&, int);
00265 template <class T> void bcast(Ref<T>&a)
00266 {
00267 if (recv_) {
00268 a << SavableState::restore_state(*recv_);
00269 }
00270 else if (send_) {
00271 SavableState::save_state(a.pointer(),*send_);
00272 }
00273 }
00274
00277 void flush();
00278
00281 void forget_references();
00282
00284 void set_buffer_size(int);
00285 };
00286
00290 class BcastStateInBin: public MsgStateBufRecv {
00291 private:
00292
00293 BcastStateInBin(const BcastStateRecv&);
00294 void operator=(const BcastStateRecv&);
00295 protected:
00296 int opened_;
00297 int file_position_;
00298 std::streambuf *buf_;
00299
00300 void next_buffer();
00301 int get_array_void(void*, int);
00302 public:
00304 BcastStateInBin(const Ref<KeyVal> &);
00306 BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
00307
00308 ~BcastStateInBin();
00309
00310 virtual int open(const char *name);
00311 virtual void close();
00312
00313 void seek(int loc);
00314 int seekable();
00315 int tell();
00316 int use_directory();
00317 };
00318
00319 }
00320
00321 #endif
00322
00323
00324
00325
00326