mstate.h
//
// mstate.h
//
// Copyright (C) 1996 Limit Point Systems, Inc.
//
// Author: Curtis Janssen <cljanss@limitpt.com>
// Maintainer: LPS
//
// This file is part of the SC Toolkit.
//
// The SC Toolkit is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// The SC Toolkit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// The U.S. Government is granted a limited license as per AL 91-7.
//
#ifdef __GNUC__
#pragma interface
#endif
#ifndef _util_group_mstate_h
#define _util_group_mstate_h
#include <util/state/state.h>
#include <util/state/statein.h>
#include <util/state/stateout.h>
#include <util/group/message.h>
namespace sc {
class MsgStateSend: public StateOut {
private:
// do not allow copy constructor or assignment
MsgStateSend(const MsgStateSend&);
void operator=(const MsgStateSend&);
protected:
Ref<MessageGrp> grp;
int nbuf; // the number of bytes used in the buffer
int bufsize; // the allocated size of the data buffer
char* buffer; // the data buffer
char* send_buffer; // the buffer used to send data (includes nbuf)
int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
int put_array_void(const void*, int);
public:
MsgStateSend(const Ref<MessageGrp>&);
virtual ~MsgStateSend();
virtual void flush() = 0;
void set_buffer_size(int);
int put(const ClassDesc*);
int put(char r);
int put(unsigned int r);
int put(int r);
int put(float r);
int put(double r);
int put(const char*,int);
int put(const int*,int);
int put(const unsigned int*,int);
int put(const float*,int);
int put(const double*,int);
};
class MsgStateBufRecv: public StateIn {
private:
// do not allow copy constructor or assignment
MsgStateBufRecv(const MsgStateBufRecv&);
void operator=(const MsgStateBufRecv&);
protected:
Ref<MessageGrp> grp;
int nbuf; // the number of bytes used in the buffer
int ibuf; // the current pointer withing the buffer
int bufsize; // the allocated size of the buffer
char* buffer; // the data buffer
char* send_buffer; // the buffer used to send data (includes nbuf)
int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
int get_array_void(void*,int);
virtual void next_buffer() = 0;
public:
MsgStateBufRecv(const Ref<MessageGrp>&);
MsgStateBufRecv();
virtual ~MsgStateBufRecv();
void set_buffer_size(int);
};
class MsgStateRecv: public MsgStateBufRecv {
private:
// do not allow copy constructor or assignment
MsgStateRecv(const MsgStateRecv&);
void operator=(const MsgStateRecv&);
public:
MsgStateRecv(const Ref<MessageGrp>&);
virtual ~MsgStateRecv();
int version(const ClassDesc*);
int get(const ClassDesc**);
int get(char&r, const char *key = 0);
int get(unsigned int&r, const char *key = 0);
int get(int&r, const char *key = 0);
int get(float&r, const char *key = 0);
int get(double&r, const char *key = 0);
int get(char*&);
int get(unsigned int*&);
int get(int*&);
int get(float*&);
int get(double*&);
};
class StateSend: public MsgStateSend {
private:
// do not allow copy constructor or assignment
StateSend(const StateSend&);
void operator=(const StateSend&);
private:
int target_;
public:
StateSend(const Ref<MessageGrp>&);
~StateSend();
void target(int);
void flush();
};
class StateRecv: public MsgStateRecv {
private:
// do not allow copy constructor or assignment
StateRecv(const StateRecv&);
void operator=(const StateRecv&);
private:
int source_;
protected:
void next_buffer();
public:
StateRecv(const Ref<MessageGrp>&);
void source(int);
};
class BcastStateSend: public MsgStateSend {
private:
// do not allow copy constructor or assignment
BcastStateSend(const BcastStateSend&);
void operator=(const BcastStateSend&);
public:
BcastStateSend(const Ref<MessageGrp>&);
~BcastStateSend();
void flush();
};
class BcastStateRecv: public MsgStateRecv {
private:
// do not allow copy constructor or assignment
BcastStateRecv(const BcastStateRecv&);
void operator=(const BcastStateRecv&);
protected:
int source_;
void next_buffer();
public:
BcastStateRecv(const Ref<MessageGrp>&, int source = 0);
void source(int s);
};
class BcastState {
private:
BcastStateRecv *recv_;
BcastStateSend *send_;
public:
BcastState(const Ref<MessageGrp> &, int source = 0);
~BcastState();
void bcast(int &);
void bcast(double &);
void bcast(int *&, int);
void bcast(double *&, int);
template <class T> void bcast(Ref<T>&a)
{
if (recv_) {
a << SavableState::restore_state(*recv_);
}
else if (send_) {
SavableState::save_state(a.pointer(),*send_);
}
}
void flush();
void forget_references();
void set_buffer_size(int);
};
class BcastStateInBin: public MsgStateBufRecv {
private:
// do not allow copy constructor or assignment
BcastStateInBin(const BcastStateRecv&);
void operator=(const BcastStateRecv&);
protected:
int opened_;
int file_position_;
std::streambuf *buf_;
void next_buffer();
int get_array_void(void*, int);
public:
BcastStateInBin(const Ref<KeyVal> &);
BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
~BcastStateInBin();
virtual int open(const char *name);
virtual void close();
void seek(int loc);
int seekable();
int tell();
int use_directory();
};
}
#endif
// Local Variables:
// mode: c++
// c-file-style: "CLJ"
// End: