mstate.h

00001 //
00002 // mstate.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
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     // do not allow copy constructor or assignment
00048     MsgStateSend(const MsgStateSend&);
00049     void operator=(const MsgStateSend&);
00050   protected:
00051     Ref<MessageGrp> grp;
00052     int nbuf; // the number of bytes used in the buffer
00053     int bufsize; // the allocated size of the data buffer
00054     char* buffer; // the data buffer
00055     char* send_buffer; // the buffer used to send data (includes nbuf)
00056     int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
00057     int* nbuf_buffer; // the pointer to the nbuf stored in the 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     // do not allow copy constructor or assignment
00092     MsgStateBufRecv(const MsgStateBufRecv&);
00093     void operator=(const MsgStateBufRecv&);
00094   protected:
00095     Ref<MessageGrp> grp;
00096     int nbuf; // the number of bytes used in the buffer
00097     int ibuf; // the current pointer withing the buffer
00098     int bufsize; // the allocated size of the buffer
00099     char* buffer; // the data buffer
00100     char* send_buffer; // the buffer used to send data (includes nbuf)
00101     int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
00102     int* nbuf_buffer; // the pointer to the nbuf stored in the 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     // do not allow copy constructor or assignment
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     // do not allow copy constructor or assignment
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     // do not allow copy constructor or assignment
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     // do not allow copy constructor or assignment
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     // do not allow copy constructor or assignment
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     // do not allow copy constructor or assignment
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 // Local Variables:
00324 // mode: c++
00325 // c-file-style: "CLJ"
00326 // End:

Generated at Wed Sep 5 14:02:30 2007 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.5.2.
These pages are hosted on SourceForge.net