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(unsigned long r);
00078 int put(long r);
00079 int put(float r);
00080 int put(double r);
00081 int put(const char*,int);
00082 int put(const int*,int);
00083 int put(const unsigned int*,int);
00084 int put(const long*,int);
00085 int put(const unsigned long*,int);
00086 int put(const float*,int);
00087 int put(const double*,int);
00088 };
00089
00093 class MsgStateBufRecv: public StateIn {
00094 private:
00095
00096 MsgStateBufRecv(const MsgStateBufRecv&);
00097 void operator=(const MsgStateBufRecv&);
00098 protected:
00099 Ref<MessageGrp> grp;
00100 int nbuf;
00101 int ibuf;
00102 int bufsize;
00103 char* buffer;
00104 char* send_buffer;
00105 int nheader;
00106 int* nbuf_buffer;
00107
00108 int get_array_void(void*,int);
00109
00111 virtual void next_buffer() = 0;
00112 public:
00114 MsgStateBufRecv(const Ref<MessageGrp>&);
00116 MsgStateBufRecv();
00117
00118 virtual ~MsgStateBufRecv();
00119
00122 void set_buffer_size(int);
00123 };
00124
00127 class MsgStateRecv: public MsgStateBufRecv {
00128 private:
00129
00130 MsgStateRecv(const MsgStateRecv&);
00131 void operator=(const MsgStateRecv&);
00132 public:
00134 MsgStateRecv(const Ref<MessageGrp>&);
00135
00136 virtual ~MsgStateRecv();
00137
00141 int version(const ClassDesc*);
00142
00145 int get(const ClassDesc**);
00146 int get(char&r, const char *key = 0);
00147 int get(unsigned int&r, const char *key = 0);
00148 int get(int&r, const char *key = 0);
00149 int get(unsigned long&r, const char *key = 0);
00150 int get(long&r, const char *key = 0);
00151 int get(float&r, const char *key = 0);
00152 int get(double&r, const char *key = 0);
00153 int get(char*&);
00154 int get(unsigned int*&);
00155 int get(int*&);
00156 int get(unsigned long*&);
00157 int get(long*&);
00158 int get(float*&);
00159 int get(double*&);
00160 };
00161
00165 class StateSend: public MsgStateSend {
00166 private:
00167
00168 StateSend(const StateSend&);
00169 void operator=(const StateSend&);
00170 private:
00171 int type_;
00172 int target_;
00173 public:
00175 StateSend(const Ref<MessageGrp>&);
00176
00177 ~StateSend();
00179 void target(int);
00181 int get_target() const { return target_; }
00183 void type(int);
00185 int get_type() const { return type_; }
00187 void flush();
00188 };
00189
00193 class StateRecv: public MsgStateRecv {
00194 private:
00195
00196 StateRecv(const StateRecv&);
00197 void operator=(const StateRecv&);
00198 private:
00199 int source_;
00200 int type_;
00201 int last_source_;
00202 int last_type_;
00203 protected:
00204 void next_buffer();
00205 public:
00207 StateRecv(const Ref<MessageGrp>&);
00209 void source(int);
00211 void type(int);
00213 int last_source();
00215 int last_type();
00216 };
00217
00221 class BcastStateSend: public MsgStateSend {
00222 private:
00223
00224 BcastStateSend(const BcastStateSend&);
00225 void operator=(const BcastStateSend&);
00226 public:
00228 BcastStateSend(const Ref<MessageGrp>&);
00229
00230 ~BcastStateSend();
00232 void flush();
00233 };
00234
00238 class BcastStateRecv: public MsgStateRecv {
00239 private:
00240
00241 BcastStateRecv(const BcastStateRecv&);
00242 void operator=(const BcastStateRecv&);
00243 protected:
00244 int source_;
00245 void next_buffer();
00246 public:
00248 BcastStateRecv(const Ref<MessageGrp>&, int source = 0);
00250 void source(int s);
00251 };
00252
00256 class BcastState {
00257 private:
00258 BcastStateRecv *recv_;
00259 BcastStateSend *send_;
00260 public:
00262 BcastState(const Ref<MessageGrp> &, int source = 0);
00263
00264 ~BcastState();
00265
00271 void bcast(int &);
00272 void bcast(double &);
00273 void bcast(int *&, int);
00274 void bcast(double *&, int);
00275 template <class T> void bcast(Ref<T>&a)
00276 {
00277 if (recv_) {
00278 a << SavableState::restore_state(*recv_);
00279 }
00280 else if (send_) {
00281 SavableState::save_state(a.pointer(),*send_);
00282 }
00283 }
00285
00288 void flush();
00289
00292 void forget_references();
00293
00295 void set_buffer_size(int);
00296 };
00297
00301 class BcastStateInBin: public MsgStateBufRecv {
00302 private:
00303
00304 BcastStateInBin(const BcastStateRecv&);
00305 void operator=(const BcastStateRecv&);
00306 protected:
00307 int opened_;
00308 int file_position_;
00309 std::streambuf *buf_;
00310
00311 void next_buffer();
00312 int get_array_void(void*, int);
00313 public:
00315 BcastStateInBin(const Ref<KeyVal> &);
00317 BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
00318
00319 ~BcastStateInBin();
00320
00321 virtual int open(const char *name);
00322 virtual void close();
00323
00324 void seek(int loc);
00325 int seekable();
00326 int tell();
00327 int use_directory();
00328 };
00329
00330 }
00331
00332 #endif
00333
00334
00335
00336
00337