42 maxChunksize = lmaxChunksize;
43 if (maxChunksize == 0)
44 throw MCS_ERROR(MSG_SIZE_CHUNK, maxChunksize);
47 case MCS_SERIAL_UNKNOWN:
48 case MCS_SERIAL_FILENAME:
49 case MCS_SERIAL_BUFFER:
52 throw MCS_ERROR(MSG_INVALID_SWITCH, type);
60 init(MCS_SERIAL_UNKNOWN, lmaxChunksize);
65 bool freeAfterUse,
unsigned int lmaxChunksize)
67 init(MCS_SERIAL_BUFFER, lmaxChunksize);
69 this->from = (
char*) from;
70 this->freeAfterUse = freeAfterUse;
76 init(MCS_SERIAL_FILENAME, lmaxChunksize);
77 this->filename = filename;
84 init(type, lmaxChunksize);
94 unsigned int& chunksize,
bool firstTime)
96 throw MCS_ERROR(MSG_METHOD_MUST_BE_OVERLOADED,
"Serializable::nextChunk_unknown");
99 char* mcs::Serializable::serialize_unknown()
104 bool mcs::Serializable::serialize_buffer(
char*& from,
unsigned int& size)
111 string mcs::Serializable::serialize_filename()
118 void mcs::Serializable::serialize()
125 case MCS_SERIAL_UNKNOWN:
126 userdata = serialize_unknown();
127 buf = (
char*) malloc(maxChunksize);
129 case MCS_SERIAL_BUFFER:
130 freeAfterUse = serialize_buffer(from, lsize);
133 case MCS_SERIAL_FILENAME:
134 filename = serialize_filename();
136 throw MCS_ERROR(MSG_CANT_OPEN_FILE, filename.csz);
138 stream =
new ifstream(filename.c_str(), ios::binary);
139 buf = (
char*) malloc(maxChunksize);
145 void mcs::Serializable::serialize_end()
148 if (type != MCS_SERIAL_BUFFER) {
158 if (type == MCS_SERIAL_BUFFER)
171 unsigned int size_to_send;
177 case MCS_SERIAL_BUFFER:
178 size_to_send = lsize - (buf - from);
179 chunksize = ( size_to_send < maxChunksize ? size_to_send : maxChunksize );
183 size_to_send = lsize - (buf - from);
184 chunksize = ( size_to_send < maxChunksize ? size_to_send : maxChunksize );
187 if (size_to_send == 0) {
193 case MCS_SERIAL_FILENAME:
197 stream->read(buf, maxChunksize);
198 chunksize = stream->gcount();
202 case MCS_SERIAL_UNKNOWN:
203 chunksize = maxChunksize;
204 if (! (userdata = nextChunk_unknown(userdata, buf, chunksize, firstTime)))
216 void* mcs::Serializable::getEntireBuffer(
unsigned int& size)
222 while(( tmp = nextChunk(chunk) ))
239 unsigned int nchunk = (
unsigned int) (floor((((
float) lsize)/maxChunksize)));
Serializable(const Serializable &)
Declared to avoid using of default copy constructor.
virtual char * nextChunk_unknown(char *userdata, char *buf, unsigned int &chunksize, bool firstTime)
Custom routine to fill a buffer with a chunk.
bool File_Dir_Exist(string fn, unsigned int &size)
Check if a file or directory exists.
unsigned int size()
Return size of the buffer.
virtual ~Serializable()
Destructor.
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
bool knowSize()
Reinitialize internal data.
unsigned int size()
If knowSize() is true, return the size of the entire block of data.
void * nextChunk(unsigned int &chunksize)
Fills a buffer with next chunk to be sent.
Main include file for all MCS based applications.
void init(int type, unsigned int lmaxChunksize)
Common initialization.
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.
Namespace for MCS library.