mcs::Serializable Class Reference

#include <mcs.hh>

Inheritance diagram for mcs::Serializable:

Inheritance graph
[legend]

List of all members.


Detailed Description

Serialize memory buffers or files into chunks.

This class is used from the Socket class to split data buffers into chunks of a maximum size, so they can be sent across the network. Objects that must be sent through the network must derive this class and eventually implement its virtual methods.

Chunks are extracted from the source using the serialize_buffer() virtual method.

This class has an internal type specification which is used to determine how to retrieve data, this specification can be one of MCS_SERIAL_BUFFER (for memory buffers), MCS_SERIAL_FILENAME (for files) and MCS_SERIAL_UNKNOWN (for custom data). In this last case the user must implement the serialize_unknown() and nextChunk_unknown() virtual methods to properly read data into the internal buffer.

Definition at line 1331 of file mcs.hh.


Public Member Functions

void * getEntireBuffer (unsigned int &size)
bool knowSize ()
 Reinitialize internal data.
unsigned int maxChunkSize ()
 Return the max size allowed for a chunk.
unsigned int nChunk ()
 If knowSize() is true, return how many chunks are required to send all data.
void * nextChunk (unsigned int &chunksize)
 Fills a buffer with next chunk to be sent.
Serializableoperator= (const Serializable &)
 Declared to avoid using of default assignment operator.
 Serializable (int type, unsigned int lmaxChunksize=16384)
 Serializable (string filename, unsigned int lmaxChunksize=16384)
 Constructor, for files (type = SERIAL_FILENAME).
 Serializable (void *from, unsigned int size, bool freeAfterUse, unsigned int lmaxChunksize=16384)
 Constructor, for memory buffers (type = SERIAL_BUFFER).
 Serializable (unsigned int lmaxChunksize=16384)
 Constructor, for custom data (type = SERIAL_UNKNOWN).
 Serializable (const Serializable &)
 Declared to avoid using of default copy constructor.
unsigned int size ()
 If knowSize() is true, return the size of the entire block of data.
virtual ~Serializable ()
 Destructor.

Private Member Functions

void init (int type, unsigned int lmaxChunksize)
 Common initialization.
virtual char * nextChunk_unknown (char *userdata, char *buf, unsigned int &chunksize, bool firstTime)
 Custom routine to fill a buffer with a chunk.
void serialize ()
virtual bool serialize_buffer (char *&from, unsigned int &size)
void serialize_end ()
virtual string serialize_filename ()
virtual char * serialize_unknown ()

Private Attributes

char * buf
 Pointer to temporary buffer containing the next chunk.
string filename
 Filename of the file being sent, if type = MCS_SERIAL_FILENAME.
bool firstTime
bool freeAfterUse
 If true the external buffer will be automatically freed, used when type = MCS_SERIAL_BUFFER.
char * from
 Pointer to source buffer, if type = MCS_SERIAL_BUFFER.
unsigned int lsize
 Size of the actual chunk.
unsigned int maxChunksize
 Maximum size of the chunk.
 MCS_DEBUG_ALLOC
ifstream * stream
 Pointer to an ifstream, if type = MCS_SERIAL_FILENAME.
int type
 Type of data to be sent.
char * userdata

Constructor & Destructor Documentation

mcs::Serializable::Serializable ( const Serializable  ) 

Declared to avoid using of default copy constructor.

Warning:
This constructor is declared but not implemented. If you try to use it you will get a compilation error.

mcs::Serializable::Serializable ( unsigned int  lmaxChunksize = 16384  ) 

Constructor, for custom data (type = SERIAL_UNKNOWN).

Parameters:
lmaxChunksize Max allowed size for a chunk, default is MCS_CHUNKSIZE bytes.

Definition at line 59 of file Serializable.cc.

mcs::Serializable::Serializable ( void *  from,
unsigned int  size,
bool  freeAfterUse,
unsigned int  lmaxChunksize = 16384 
)

Constructor, for memory buffers (type = SERIAL_BUFFER).

Parameters:
buf Address of the buffer containing data to be sent.
size Size of the buffer.
lmaxChunksize Max allowed size for a chunk, default is MCS_CHUNKSIZE.

Definition at line 64 of file Serializable.cc.

mcs::Serializable::Serializable ( string  filename,
unsigned int  lmaxChunksize = 16384 
)

Constructor, for files (type = SERIAL_FILENAME).

Parameters:
filename File to be sent.
lmaxChunksize Max allowed size for a chunk, default is MCS_CHUNKSIZE.

Definition at line 74 of file Serializable.cc.

mcs::Serializable::~Serializable (  )  [virtual]

Destructor.

Definition at line 88 of file Serializable.cc.


Member Function Documentation

void mcs::Serializable::init ( int  type,
unsigned int  lmaxChunksize 
) [private]

Common initialization.

Parameters:
lmaxChunksize Max allowed size for a chunk.

Definition at line 31 of file Serializable.cc.

bool mcs::Serializable::knowSize (  ) 

Reinitialize internal data.

Reinitialize internal data, so that next call to fillBuffer() will read data from the beginning of the buffer or the file. If type = SERIAL_UNKNOWN the next call to fillBuffer will have firstTime = true.

Tells if the object is in use.

If a call to fillBuffer() has already be done, and data are not yet finished this will return true. Otherwise return false.

Tells if we already know the size of entire block of data.

If type = SERIAL_FILENAME or SERIAL_BUFFER, we already know the size of the entire block of data, and this return true. If type = SERIAL_UNKNOWN return false.

Definition at line 232 of file Serializable.cc.

unsigned int mcs::Serializable::maxChunkSize (  ) 

Return the max size allowed for a chunk.

Definition at line 251 of file Serializable.cc.

unsigned int mcs::Serializable::nChunk (  ) 

If knowSize() is true, return how many chunks are required to send all data.

Definition at line 237 of file Serializable.cc.

void * mcs::Serializable::nextChunk ( unsigned int &  chunksize  ) 

Fills a buffer with next chunk to be sent.

Parameters:
chunksize Upon exit contains the size of the chunk.
Returns:
Address of the buffer containing the chunk, or NULL if there are no more data.

Definition at line 169 of file Serializable.cc.

char * mcs::Serializable::nextChunk_unknown ( char *  userdata,
char *  buf,
unsigned int &  chunksize,
bool  firstTime 
) [private, virtual]

Custom routine to fill a buffer with a chunk.

This virtual method should be overloadd in derived class, to fill the internal buffer when type = SERIAL_UNKNOWN. This method is called automatically by fillBuffer().

Parameters:
buf Address of the buffer to fill with the chunk.
chunksize Upon exit must contain the size of the chunk.
firstTime Tell if it is the first time the method is called.

Definition at line 93 of file Serializable.cc.

Serializable& mcs::Serializable::operator= ( const Serializable  ) 

Declared to avoid using of default assignment operator.

Warning:
This operator is declared but not implemented. If you try to use it you will get a compilation error.

unsigned int mcs::Serializable::size (  ) 

If knowSize() is true, return the size of the entire block of data.

Definition at line 245 of file Serializable.cc.


Member Data Documentation

char* mcs::Serializable::buf [private]

Pointer to temporary buffer containing the next chunk.

Reimplemented in mcs::Data.

Definition at line 1337 of file mcs.hh.

string mcs::Serializable::filename [private]

Filename of the file being sent, if type = MCS_SERIAL_FILENAME.

Definition at line 1346 of file mcs.hh.

bool mcs::Serializable::freeAfterUse [private]

If true the external buffer will be automatically freed, used when type = MCS_SERIAL_BUFFER.

Definition at line 1358 of file mcs.hh.

char* mcs::Serializable::from [private]

Pointer to source buffer, if type = MCS_SERIAL_BUFFER.

Definition at line 1352 of file mcs.hh.

unsigned int mcs::Serializable::lsize [private]

Size of the actual chunk.

Definition at line 1343 of file mcs.hh.

unsigned int mcs::Serializable::maxChunksize [private]

Maximum size of the chunk.

Definition at line 1340 of file mcs.hh.

ifstream* mcs::Serializable::stream [private]

Pointer to an ifstream, if type = MCS_SERIAL_FILENAME.

Definition at line 1361 of file mcs.hh.

int mcs::Serializable::type [private]

Type of data to be sent.

Definition at line 1349 of file mcs.hh.


The documentation for this class was generated from the following files:
mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012