version 1.1.2.3, 2009/11/17 11:14:53
|
version 1.1.2.5, 2009/12/03 15:53:27
|
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
| |
#define PEGASUS_ARRAY_T SCMOResultionTable |
#define PEGASUS_ARRAY_T SCMOResolutionTable |
# include <Pegasus/Common/ArrayImpl.h> | # include <Pegasus/Common/ArrayImpl.h> |
#undef PEGASUS_ARRAY_T | #undef PEGASUS_ARRAY_T |
| |
|
|
{ | { |
}; | }; |
| |
|
// Writes a single SCMOClass to the given CIMBuffer |
|
void SCMOStreamer::serializeClass(CIMBuffer& out, const SCMOClass& scmoClass) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER,"SCMOStreamer::serializeClass"); |
|
|
|
Array<SCMBClass_Main*> classTable; |
|
classTable.append(scmoClass.cls.hdr); |
|
|
|
_putClasses(out, classTable); |
|
|
|
PEG_METHOD_EXIT(); |
|
}; |
|
|
|
// Reads a single SCMOClass from the given CIMBuffer |
|
bool SCMOStreamer::deserializeClass(CIMBuffer& in, SCMOClass& scmoClass) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER,"SCMOStreamer::deserializeClass"); |
|
|
|
Array<SCMBClass_Main*> classTable; |
|
if(!_getClasses(in, classTable)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get Class!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} |
|
|
|
if (classTable.size() > 0) |
|
{ |
|
scmoClass = SCMOClass(classTable[0]); |
|
} |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
| |
// Writes the list of SCMOInstances stored in this instance of SCMOStreamer | // Writes the list of SCMOInstances stored in this instance of SCMOStreamer |
// to the output buffer, including their referenced Classes and Instances | // to the output buffer, including their referenced Classes and Instances |
|
|
_appendToResolverTables(inst); | _appendToResolverTables(inst); |
} | } |
| |
_putClasses(); |
_putClasses(_buf,_classTable); |
| |
_putInstances(); | _putInstances(); |
| |
|
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER,"SCMOStreamer::serialize"); | PEG_METHOD_ENTER(TRC_DISPATCHER,"SCMOStreamer::serialize"); |
| |
if(!_getClasses()) |
if(!_getClasses(_buf,_classTable)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to get Classes!"); | "Failed to get Classes!"); |
|
|
const SCMOInstance& inst, | const SCMOInstance& inst, |
Uint32 idx) | Uint32 idx) |
{ | { |
SCMOResultionTable tableEntry; |
SCMOResolutionTable tableEntry; |
| |
tableEntry.scmbptr = (void*)&inst; | tableEntry.scmbptr = (void*)&inst; |
tableEntry.index = idx; | tableEntry.index = idx; |
|
|
| |
| |
// Now build a new entry for the class resolution table | // Now build a new entry for the class resolution table |
SCMOResultionTable tableEntry; |
SCMOResolutionTable tableEntry; |
| |
tableEntry.scmbptr = (void*)inst.inst.hdr; | tableEntry.scmbptr = (void*)inst.inst.hdr; |
tableEntry.index = clsIdx; | tableEntry.index = clsIdx; |
|
|
Uint32 SCMOStreamer::_appendToClassTable(const SCMOInstance& inst) | Uint32 SCMOStreamer::_appendToClassTable(const SCMOInstance& inst) |
{ | { |
Uint32 clsTableSize = _classTable.size(); | Uint32 clsTableSize = _classTable.size(); |
const SCMBClass_Main* clsPtr = inst.inst.hdr->theClass->cls.hdr; |
SCMBClass_Main* clsPtr = inst.inst.hdr->theClass->cls.hdr; |
| |
const SCMBClass_Main* const* clsArray = _classTable.getData(); | const SCMBClass_Main* const* clsArray = _classTable.getData(); |
| |
|
|
| |
| |
// Adds the list of SCMOClasses from the ClassTable to the output buffer | // Adds the list of SCMOClasses from the ClassTable to the output buffer |
void SCMOStreamer::_putClasses() |
void SCMOStreamer::_putClasses( |
|
CIMBuffer& out, |
|
Array<SCMBClass_Main*>& classTable) |
{ | { |
Uint32 numClasses = _classTable.size(); |
Uint32 numClasses = classTable.size(); |
const SCMBClass_Main* const* clsArray = _classTable.getData(); |
const SCMBClass_Main* const* clsArray = classTable.getData(); |
| |
// Number of classes | // Number of classes |
_buf.putUint32(numClasses); |
out.putUint32(numClasses); |
| |
// SCMOClasses, one by one | // SCMOClasses, one by one |
for (Uint32 x=0; x < numClasses; x++) | for (Uint32 x=0; x < numClasses; x++) |
|
|
// Calculate the in-use size of the SCMOClass data | // Calculate the in-use size of the SCMOClass data |
Uint64 size = | Uint64 size = |
clsArray[x]->header.totalSize - clsArray[x]->header.freeBytes; | clsArray[x]->header.totalSize - clsArray[x]->header.freeBytes; |
_buf.putUint64(size); |
out.putUint64(size); |
| |
// Write class data | // Write class data |
_buf.putBytes(clsArray[x],size); |
out.putBytes(clsArray[x],size); |
} | } |
| |
} | } |
| |
// Reads a list of SCMOClasses from the input buffer | // Reads a list of SCMOClasses from the input buffer |
bool SCMOStreamer::_getClasses() |
bool SCMOStreamer::_getClasses( |
|
CIMBuffer& in, |
|
Array<SCMBClass_Main*>& classTable) |
{ | { |
// Number of classes | // Number of classes |
Uint32 numClasses; | Uint32 numClasses; |
if(! _buf.getUint32(numClasses) ) |
if(! in.getUint32(numClasses) ) |
{ | { |
return false; | return false; |
} | } |
|
|
for (Uint32 x=0; x < numClasses; x++) | for (Uint32 x=0; x < numClasses; x++) |
{ | { |
Uint64 size; | Uint64 size; |
if (!_buf.getUint64(size)) |
if (!in.getUint64(size)) |
{ | { |
return false; | return false; |
} | } |
|
|
throw PEGASUS_STD(bad_alloc)(); | throw PEGASUS_STD(bad_alloc)(); |
} | } |
| |
if (!_buf.getBytes(scmbClassPtr,size)) |
if (!in.getBytes(scmbClassPtr,size)) |
{ | { |
return false; | return false; |
} | } |
|
|
scmbClassPtr->header.freeBytes = 0; | scmbClassPtr->header.freeBytes = 0; |
scmbClassPtr->refCount.set(0); | scmbClassPtr->refCount.set(0); |
| |
_classTable.append(scmbClassPtr); |
classTable.append(scmbClassPtr); |
} | } |
| |
return true; | return true; |
|
|
void SCMOStreamer::_putInstances() | void SCMOStreamer::_putInstances() |
{ | { |
Uint32 numInst = _clsResolverTable.size(); | Uint32 numInst = _clsResolverTable.size(); |
const SCMOResultionTable* instArray = _clsResolverTable.getData(); |
const SCMOResolutionTable* instArray = _clsResolverTable.getData(); |
| |
// Number of instances | // Number of instances |
_buf.putUint32(numInst); | _buf.putUint32(numInst); |
| |
// Instance to class resolution table | // Instance to class resolution table |
_buf.putBytes(instArray, numInst*sizeof(SCMOResultionTable)); |
_buf.putBytes(instArray, numInst*sizeof(SCMOResolutionTable)); |
| |
| |
Uint32 numExtRefs = _instResolverTable.size(); | Uint32 numExtRefs = _instResolverTable.size(); |
const SCMOResultionTable* extRefArray = _instResolverTable.getData(); |
const SCMOResolutionTable* extRefArray = _instResolverTable.getData(); |
| |
// Number of references | // Number of references |
_buf.putUint32(numExtRefs); | _buf.putUint32(numExtRefs); |
| |
// Instance references resolution table | // Instance references resolution table |
_buf.putBytes(extRefArray, numExtRefs*sizeof(SCMOResultionTable)); |
_buf.putBytes(extRefArray, numExtRefs*sizeof(SCMOResolutionTable)); |
| |
| |
// SCMOInstances, one by one | // SCMOInstances, one by one |
|
|
} | } |
| |
// Instance to class resolution table | // Instance to class resolution table |
SCMOResultionTable *instArray = new SCMOResultionTable[numInst]; |
SCMOResolutionTable *instArray = new SCMOResolutionTable[numInst]; |
if(!_buf.getBytes(instArray, numInst*sizeof(SCMOResultionTable))) |
if(!_buf.getBytes(instArray, numInst*sizeof(SCMOResolutionTable))) |
{ | { |
return false; | return false; |
} | } |
|
|
} | } |
| |
// Instance references resolution table | // Instance references resolution table |
SCMOResultionTable *extRefArray = new SCMOResultionTable[numExtRefs]; |
SCMOResolutionTable *extRefArray = new SCMOResolutionTable[numExtRefs]; |
Uint32 extRefIndex=0; | Uint32 extRefIndex=0; |
if (numExtRefs > 0) | if (numExtRefs > 0) |
{ | { |
if(!_buf.getBytes(extRefArray, numExtRefs*sizeof(SCMOResultionTable))) |
if(!_buf.getBytes(extRefArray, numExtRefs*sizeof(SCMOResolutionTable))) |
{ | { |
return false; | return false; |
} | } |