version 1.2.2.1, 2009/08/17 13:47:46
|
version 1.5.2.18, 2014/03/14 17:30:20
|
|
|
// | // |
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// |
// | // |
|
// Class CIMResponseData encapsulates the possible types of response data |
|
// representations and supplies conversion methods between these types. |
|
// PEP#348 - The CMPI infrastructure using SCMO (Single Chunk Memory Objects) |
|
// describes its usage in the server flow. |
|
// The design document can be found on the OpenPegasus website openpegasus.org |
|
// at https://collaboration.opengroup.org/pegasus/pp/documents/21210/PEP_348.pdf |
|
// |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include "CIMResponseData.h" | #include "CIMResponseData.h" |
#include "XmlWriter.h" |
#include <Pegasus/Common/Tracer.h> |
#include "XmlReader.h" |
#include <Pegasus/Common/XmlWriter.h> |
#include "Tracer.h" |
#include <Pegasus/Common/SCMOXmlWriter.h> |
|
#include <Pegasus/Common/XmlReader.h> |
|
#include <Pegasus/Common/CIMInternalXmlEncoder.h> |
|
#include <Pegasus/Common/SCMOInternalXmlEncoder.h> |
|
|
| |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
//----------------------------------------------------------------------------- |
// Defines debug code in CIMResponseData. This under this |
// |
// special compile flag so that it can be compiled independent of |
// CIMInstanceNamesResponseData |
// PEGASUS_DEBUG flags. |
// |
#define CIMRESPONSEDATA_DEBUG |
//----------------------------------------------------------------------------- |
|
|
#define LOCAL_MIN(a, b) ((a < b) ? a : b) |
|
// C++ objects interface handling |
|
|
|
// KS_TODO Remove this completely when finished testing. |
|
bool CIMResponseData::sizeValid() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(valid()); |
|
#ifdef CIMRESPONSEDATA_DEBUG |
|
if (_size > 1000000) |
|
{ |
|
cout << "CIMResponseData::TEST_SIZE_VALID _size too big " |
|
<< _size << endl; |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL4, |
|
"CIMResponseData::TEST_SIZE_VALID _size too big %u",_size )); |
|
return false; |
|
} |
|
#endif |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL4, |
|
"CIMResponseData Size _size=%u", _size)); |
|
return true; |
|
} |
|
|
|
/* |
|
Append an InstanceElement to the Buffer. This function accounts |
|
for the existence of a propertyList. |
|
*/ |
|
void CIMResponseData::_appendInstanceElement( |
|
Buffer& out, |
|
SCMOInstance _scmoInstance) |
|
{ |
|
if(_propertyList.isNull()) |
|
{ |
|
Array<Uint32> emptyNodes; |
|
SCMOXmlWriter::appendInstanceElement( |
|
out, |
|
_scmoInstance, |
|
false, |
|
emptyNodes); |
|
} |
|
else |
|
{ |
|
Array<propertyFilterNodesArray_t> propFilterNodesArrays; |
|
// This searches for an already created array of nodes, |
|
//if not found, creates it inside propFilterNodesArrays |
|
const Array<Uint32> & nodes= |
|
SCMOXmlWriter::getFilteredNodesArray( |
|
propFilterNodesArrays, |
|
_scmoInstance, |
|
_propertyList); |
|
SCMOXmlWriter::appendInstanceElement( |
|
out, |
|
_scmoInstance, |
|
true, |
|
nodes); |
|
} |
|
} |
| |
//------------------------------------------------------------------------------ |
// Instance Names handling |
// Takes a binary stream of object paths from a CIMBuffer and stores it in the |
Array<CIMObjectPath>& CIMResponseData::getInstanceNames() |
// responsedata. |
|
// @param hasLen Indicates if the binary object path stream is prepended with an |
|
// Uint32 value indicating the number of paths in the stream. |
|
//------------------------------------------------------------------------------ |
|
bool CIMInstanceNamesResponseData::setBinaryCimInstanceNames( |
|
CIMBuffer& in, bool hasLen) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
TEST_SIZE_VALID; |
"CIMInstanceNamesResponseData::setBinaryCimInstanceNames"); |
PEGASUS_DEBUG_ASSERT( |
|
(_dataType==RESP_INSTNAMES || _dataType==RESP_OBJECTPATHS)); |
|
_resolveToCIM(); |
|
PEGASUS_DEBUG_ASSERT(_encoding==RESP_ENC_CIM || _encoding == 0); |
|
return _instanceNames; |
|
} |
|
|
|
// Get a single instance as a CIM instance. |
|
// This converts all of the objects in the response data to |
|
// CIM form as part of the conversion. |
|
// If there are no instances in the object, returns CIMInstance(), |
|
// an empty instance. |
|
CIMInstance& CIMResponseData::getInstance() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(_dataType == RESP_INSTANCE); |
|
_resolveToCIM(); |
|
if (0 == _instances.size()) |
|
{ |
|
_instances.append(CIMInstance()); |
|
} |
|
return _instances[0]; |
|
} |
|
|
|
// Instances handling |
|
Array<CIMInstance>& CIMResponseData::getInstances() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(_dataType == RESP_INSTANCES); |
|
_resolveToCIM(); |
|
return _instances; |
|
} |
|
|
|
// Instances handling specifically for the client where the call may |
|
// get either instances or objects and must convert them to instances |
|
// NOTE: This is a temporary solution to satisfy the BinaryCodec passing |
|
// of data to the client where the data could be either instances or |
|
// objects. The correct solution is to convert back when the provider, etc. |
|
// returns the data to the server. We must convert to that solution but |
|
// this keeps it working for the moment. |
|
Array<CIMInstance>& CIMResponseData::getInstancesFromInstancesOrObjects() |
|
{ |
|
if (_dataType == RESP_INSTANCES) |
|
{ |
|
_resolveToCIM(); |
|
return _instances; |
|
} |
|
else if (_dataType == RESP_OBJECTS) |
|
{ |
|
_resolveToCIM(); |
|
for (Uint32 i = 0 ; i < _objects.size() ; i++) |
|
{ |
|
_instances.append((CIMInstance)_objects[i]); |
|
} |
|
return _instances; |
|
|
|
} |
|
PEGASUS_ASSERT(false); |
|
} |
| |
if (hasLen) |
// Objects handling |
|
Array<CIMObject>& CIMResponseData::getObjects() |
{ | { |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMResponseData::getObjects"); |
|
PEGASUS_DEBUG_ASSERT(_dataType == RESP_OBJECTS); |
|
_resolveToCIM(); |
|
PEG_METHOD_EXIT(); |
|
return _objects; |
|
} |
|
|
|
// SCMO representation, single instance stored as one element array |
|
// object paths are represented as SCMOInstance |
|
// Resolve all of the information in the CIMResponseData container to |
|
// SCMO and return all scmoInstances. |
|
// Note that since the SCMO representation, |
|
// a is single instance stored as one element array and object paths are |
|
// represented as SCMOInstance this returns array of SCMOInstance. |
|
Array<SCMOInstance>& CIMResponseData::getSCMO() |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMResponseData::getSCMO"); |
|
// This function resolves to instances and so cannot handle responses to |
|
// the associators,etc.requests that return classes (input object path with |
|
// no keys). That issue is resolved however, since CIMResponseData uses the |
|
// _isClassOperation variable (set by the request) to determine whether |
|
// the responses are classpaths or instancepaths and the default is |
|
// false(instancePaths) so that this should always produce instance paths. |
|
|
|
_resolveToSCMO(); |
|
PEG_METHOD_EXIT(); |
|
return _scmoInstances; |
|
} |
|
|
|
// set an array of SCMOInstances into the response data object |
|
void CIMResponseData::setSCMO(const Array<SCMOInstance>& x) |
|
{ |
|
|
|
PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMResponseData::setSCMO"); |
|
//// AutoMutex autoMut(testLock); |
|
TEST_SIZE_VALID; |
|
_scmoInstances=x; |
|
_encoding |= RESP_ENC_SCMO; |
|
_size += x.size(); |
|
PEG_METHOD_EXIT(); |
|
} |
|
|
|
// Binary data is just a data stream |
|
Array<Uint8>& CIMResponseData::getBinary() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(_encoding == RESP_ENC_BINARY || _encoding == 0); |
|
return _binaryData; |
|
} |
|
|
|
bool CIMResponseData::setBinary(CIMBuffer& in) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMResponseData::setBinary"); |
|
//// AutoMutex autoMut(testLock); |
|
|
|
// Append all serial data from the CIMBuffer to the local data store. |
|
// Returns error if input not a serialized Uint8A |
if (!in.getUint8A(_binaryData)) | if (!in.getUint8A(_binaryData)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to get binary object path data!"); |
"Failed to get binary input data!"); |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return false; | return false; |
} | } |
|
_encoding |= RESP_ENC_BINARY; |
|
PEG_METHOD_EXIT(); |
|
return true; |
} | } |
else |
|
|
bool CIMResponseData::setRemainingBinaryData(CIMBuffer& in) |
{ | { |
size_t remainingDataLength = in.capacity() - in.size(); |
//// AutoMutex autoMut(testLock); |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMResponseData::setRemainingBinaryData"); |
} |
|
| |
_resolveCallback = _resolveBinaryInstanceNames; |
// Append any data that has not been deserialized already from |
_encoding = RESP_ENC_BINARY; |
// the CIMBuffer. |
|
size_t remainingDataLength = in.remainingDataLength(); |
|
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
| |
|
_encoding |= RESP_ENC_BINARY; |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; | return true; |
}; |
} |
| |
bool CIMInstanceNamesResponseData::setXmlCimInstanceNames(CIMBuffer& in) |
bool CIMResponseData::setXml(CIMBuffer& in) |
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMResponseData::setXml"); |
"CIMInstanceNamesResponseData::setXmlCimInstanceNames"); |
|
| |
|
switch (_dataType) |
|
{ |
|
case RESP_INSTANCE: |
|
{ |
|
Array<Sint8> inst; |
|
Array<Sint8> ref; |
|
CIMNamespaceName ns; |
|
String host; |
|
if (!in.getSint8A(inst)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML instance data!"); |
|
return false; |
|
} |
|
_instanceData.insert(0,inst); |
|
if (!in.getSint8A(ref)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML instance data (reference)!"); |
|
return false; |
|
} |
|
_referencesData.insert(0,ref); |
|
if (!in.getString(host)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML instance data (host)!"); |
|
return false; |
|
} |
|
_hostsData.insert(0,host); |
|
if (!in.getNamespaceName(ns)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML instance data (namespace)!"); |
|
return false; |
|
} |
|
_nameSpacesData.insert(0,ns); |
|
_size++; |
|
break; |
|
} |
|
case RESP_INSTANCES: |
|
{ |
Uint32 count; | Uint32 count; |
|
|
if (!in.getUint32(count)) | if (!in.getUint32(count)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to get XML objectpath data (number of paths)!"); |
"Failed to get XML instance data (number of instance)!"); |
PEG_METHOD_EXIT(); |
|
return false; | return false; |
} | } |
|
|
for (Uint32 i = 0; i < count; i++) | for (Uint32 i = 0; i < count; i++) |
{ | { |
|
Array<Sint8> inst; |
Array<Sint8> ref; | Array<Sint8> ref; |
CIMNamespaceName ns; | CIMNamespaceName ns; |
String host; | String host; |
|
if (!in.getSint8A(inst)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML instance data (instances)!"); |
|
return false; |
|
} |
if (!in.getSint8A(ref)) | if (!in.getSint8A(ref)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to get XML objectpath data (references)!"); |
"Failed to get XML instance data (references)!"); |
PEG_METHOD_EXIT(); |
|
return false; | return false; |
} | } |
|
|
if (!in.getString(host)) | if (!in.getString(host)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to get XML instance data (host)!"); | "Failed to get XML instance data (host)!"); |
PEG_METHOD_EXIT(); |
|
return false; | return false; |
} | } |
|
|
if (!in.getNamespaceName(ns)) | if (!in.getNamespaceName(ns)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to get XML instance data (namespace)!"); | "Failed to get XML instance data (namespace)!"); |
PEG_METHOD_EXIT(); |
|
return false; | return false; |
} | } |
|
_instanceData.append(inst); |
_referencesData.append(ref); | _referencesData.append(ref); |
_hostsData.append(host); | _hostsData.append(host); |
_nameSpacesData.append(ns); | _nameSpacesData.append(ns); |
} | } |
|
_size += count; |
_resolveCallback = _resolveXMLInstanceNames; |
break; |
_encoding = RESP_ENC_XML; |
} |
|
case RESP_OBJECTS: |
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
// Encodes the array of CIMObjectPath representation contained in the current |
|
// CIMResponseData object in binary response message format. |
|
// This code corresponds to method _resolveBinaryInstanceNames, which is used |
|
// revert a binary objectpath array representation back into an array of |
|
// CIMInstance |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceNamesResponseData::encodeBinaryResponse(CIMBuffer& out) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
Uint32 count; |
"CIMInstanceNamesResponseData::encodeBinaryResponse"); |
if (!in.getUint32(count)) |
|
|
if (_resolveCallback && (_encoding == RESP_ENC_BINARY)) |
|
{ | { |
const Array<Uint8>& data = _binaryData; |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
out.putBytes(data.getData(), data.size()); |
"Failed to get XML object data (number of objects)!"); |
|
return false; |
} | } |
else |
for (Uint32 i = 0; i < count; i++) |
{ | { |
_resolve(); |
Array<Sint8> obj; |
out.putObjectPathA(_instanceNames, false); |
Array<Sint8> ref; |
} |
CIMNamespaceName ns; |
PEG_METHOD_EXIT(); |
String host; |
|
if (!in.getSint8A(obj)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML object data (object)!"); |
|
return false; |
} | } |
|
if (!in.getSint8A(ref)) |
//------------------------------------------------------------------------------ |
|
// Encodes the array of CIMObjectPath representation contained in the current |
|
// CIMResponseData object in xml response message format. |
|
// This code corresponds to method _resolveXmlInstanceNames, which is used |
|
// revert a CIM-XML objectpath array representation back into an array of |
|
// CIMObjectPath. |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceNamesResponseData::encodeXmlResponse(Buffer& out) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"CIMInstanceNamesResponseData::encodeXmlResponse"); |
"Failed to get XML object data (reference)!"); |
|
return false; |
if (_resolveCallback && (_encoding == RESP_ENC_XML)) |
} |
|
if (!in.getString(host)) |
{ | { |
const Array<ArraySint8>& a = _referencesData; |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML object data (host)!"); |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
return false; |
|
} |
|
if (!in.getNamespaceName(ns)) |
{ | { |
out.append((char*)a[i].getData(), a[i].size() - 1); |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML object data (namespace)!"); |
|
return false; |
|
} |
|
_instanceData.append(obj); |
|
_referencesData.append(ref); |
|
_hostsData.append(host); |
|
_nameSpacesData.append(ns); |
} | } |
|
_size += count; |
|
break; |
} | } |
else |
// internal xml encoding of instance names and object paths not |
|
// done today |
|
case RESP_INSTNAMES: |
|
case RESP_OBJECTPATHS: |
|
default: |
{ | { |
_resolve(); |
PEGASUS_ASSERT(false); |
for (Uint32 i = 0, n = _instanceNames.size(); i < n; i++) |
} |
XmlWriter::appendInstanceNameElement(out,_instanceNames[i]); |
|
} | } |
|
_encoding |= RESP_ENC_XML; |
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
|
return true; |
} | } |
| |
//------------------------------------------------------------------------------ |
// Move the number of objects defined by the input parameter from |
// Instantiates an array of ObjectPath from a binary representation created by |
// one CIMResponse Object to another CIMResponse Object. |
// the CIMBinMessageSerializer. |
// Returns the new size of the CIMResponseData object. |
// Returns true on success. |
// NOTE: This is not protected by a mutex so the user must be certain |
//------------------------------------------------------------------------------ |
// that the from object is not used during the move. |
Boolean CIMInstanceNamesResponseData::_resolveBinaryInstanceNames( |
Uint32 CIMResponseData::moveObjects(CIMResponseData & from, Uint32 count) |
CIMInstanceNamesResponseData* data, |
|
Array<CIMObjectPath>& cops) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMResponseData::moveObjects"); |
"CIMInstanceNamesResponseData::_resolveBinaryInstanceNames"); |
|
| |
cops.clear(); |
//// AutoMutex autoMut(testLock); |
| |
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
PEG_TRACE((TRC_XML, Tracer::LEVEL3, |
|
"CIMResponseData::move(%u)", count)); |
| |
while (in.more()) |
PEGASUS_DEBUG_ASSERT(valid()); // KS_TEMP |
|
PEGASUS_DEBUG_ASSERT(_size == 0); // Validate size == 0 or fix below |
|
PEGASUS_DEBUG_ASSERT(_dataType == from._dataType); |
|
|
|
Uint32 rtnSize = 0; |
|
Uint32 toMove = count; |
|
|
|
if (RESP_ENC_XML == (from._encoding & RESP_ENC_XML)) |
{ | { |
if (!in.getObjectPathA(cops)) |
switch (_dataType) |
{ | { |
in.release(); |
case RESP_OBJECTPATHS: |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
case RESP_INSTNAMES: |
"Failed to resolve binary objectpath!"); |
break; |
PEG_METHOD_EXIT(); |
case RESP_INSTANCE: |
return false; |
{ |
|
if (from._instanceData.size() > 0) |
|
{ |
|
// temp test to assure all sizes are the same. |
|
PEGASUS_DEBUG_ASSERT(from._hostsData.size() == |
|
from._instanceData.size()); |
|
PEGASUS_DEBUG_ASSERT(from._referencesData.size() == |
|
from._instanceData.size()); |
|
PEGASUS_DEBUG_ASSERT(from._nameSpacesData.size() == |
|
from._instanceData.size()); |
|
_instanceData.append(from._instanceData.getData(),1); |
|
from._instanceData.remove(0, 1); |
|
_referencesData.append( |
|
from._referencesData.getData(),1); |
|
from._referencesData.remove(0, 1); |
|
if (_hostsData.size()) |
|
{ |
|
_hostsData.append(from._hostsData.getData(),1); |
|
from._hostsData.remove(0, 1); |
} | } |
|
if (_nameSpacesData.size()) |
|
{ |
|
_nameSpacesData.append( |
|
from._nameSpacesData.getData(),1); |
|
from._nameSpacesData.remove(0, 1); |
} | } |
|
rtnSize += 1; |
in.release(); |
toMove--; |
PEG_METHOD_EXIT(); |
_encoding |= RESP_ENC_XML; |
return true; |
|
} | } |
|
} |
|
break; |
| |
|
// KS-TODO The above could probably be folded into the following. |
|
// Need something like an assert if there is ever more than |
|
// one instance in _instanceData for type RESP_INSTANCE |
|
case RESP_INSTANCES: |
|
case RESP_OBJECTS: |
|
{ |
|
Uint32 moveCount = LOCAL_MIN(toMove, |
|
from._instanceData.size()); |
| |
|
PEGASUS_DEBUG_ASSERT(from._referencesData.size() == |
|
from._instanceData.size()); |
|
_instanceData.append(from._instanceData.getData(), |
|
moveCount); |
|
from._instanceData.remove(0, moveCount); |
|
_referencesData.append(from._referencesData.getData(), |
|
moveCount); |
|
from._referencesData.remove(0, moveCount); |
|
_hostsData.append(from._hostsData.getData(), |
|
moveCount); |
|
from._hostsData.remove(0, moveCount); |
|
_nameSpacesData.append(from._nameSpacesData.getData(), |
|
moveCount); |
|
from._nameSpacesData.remove(0, moveCount); |
|
rtnSize += moveCount; |
|
toMove -= moveCount; |
|
_encoding |= RESP_ENC_XML; |
|
} |
|
break; |
|
} |
|
} |
|
if (RESP_ENC_BINARY == (from._encoding & RESP_ENC_BINARY)) |
|
{ |
|
// Cannot resolve this one without actually processing |
|
// the data since it is a stream. Concluded that we do not |
|
// want to do that since cost higher than gain. Therefore we do |
|
// not allow this option. Should only mean that provider agent |
|
// cannot generate binary for pull operations. |
|
rtnSize += 0; |
|
PEGASUS_ASSERT(false); |
|
} |
| |
//------------------------------------------------------------------------------ |
if (RESP_ENC_SCMO == (from._encoding & RESP_ENC_SCMO)) |
// Instantiates an array of CIMObjectPath from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceNamesResponseData::_resolveXMLInstanceNames( |
|
CIMInstanceNamesResponseData* data, |
|
Array<CIMObjectPath>& cops) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
Uint32 moveCount = LOCAL_MIN(toMove, from._scmoInstances.size()); |
"CIMInstanceNamesResponseData::_resolveXMLInstanceNames"); |
|
| |
cops.clear(); |
_scmoInstances.append(from._scmoInstances.getData(), moveCount); |
|
from._scmoInstances.remove(0, moveCount); |
|
rtnSize += moveCount; |
|
toMove -= moveCount; |
|
_encoding |= RESP_ENC_SCMO; |
|
} |
| |
for (Uint32 i = 0; i < data->_referencesData.size(); i++) |
if (RESP_ENC_CIM == (from._encoding & RESP_ENC_CIM)) |
{ | { |
CIMObjectPath cop; |
switch (_dataType) |
|
|
// Deserialize path: |
|
{ | { |
XmlParser parser((char*)data->_referencesData[i].getData()); |
case RESP_OBJECTPATHS: |
|
case RESP_INSTNAMES: |
|
{ |
|
Uint32 moveCount = LOCAL_MIN(toMove, |
|
from._instanceNames.size()); |
| |
if (XmlReader::getInstanceNameElement(parser, cop)) |
_instanceNames.append( |
|
from._instanceNames.getData(), moveCount); |
|
from._instanceNames.remove(0, moveCount); |
|
rtnSize += moveCount; |
|
toMove -= moveCount; |
|
_encoding |= RESP_ENC_CIM; |
|
} |
|
break; |
|
case RESP_INSTANCE: |
|
case RESP_INSTANCES: |
{ | { |
if (!data->_nameSpacesData[i].isNull()) |
|
cop.setNameSpace(data->_nameSpacesData[i]); |
|
| |
if (data->_hostsData[i].size()) |
Uint32 moveCount = LOCAL_MIN(toMove, |
cop.setHost(data->_hostsData[i]); |
from._instances.size()); |
|
|
|
_instances.append(from._instances.getData(), moveCount); |
|
from._instances.remove(0, moveCount); |
|
rtnSize += moveCount; |
|
toMove -= moveCount; |
|
_encoding |= RESP_ENC_CIM; |
|
} |
|
break; |
|
case RESP_OBJECTS: |
|
{ |
|
Uint32 moveCount = LOCAL_MIN(toMove, |
|
from._objects.size()); |
|
_objects.append(from._objects.getData(), moveCount); |
|
from._objects.remove(0, moveCount); |
|
rtnSize += moveCount; |
|
toMove -= moveCount; |
|
_encoding |= RESP_ENC_CIM; |
|
} |
|
break; |
} | } |
} | } |
|
PEGASUS_ASSERT(rtnSize == (count - toMove)); |
|
|
|
_size += rtnSize; |
|
|
|
// insure that _size never goes negative. This is probably a |
|
// diagnostics KS_TODO remove before release |
|
if (from._size >= rtnSize) |
|
{ |
| |
cops.append(cop); |
from._size -= rtnSize; |
|
} |
|
else |
|
{ |
|
from._size = 0; |
|
//// KS_TODO Diagnostic since this should never occur |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL1, |
|
"Size in from set to zero from= %u rtnSize= %u", |
|
from._size, rtnSize)); |
} | } |
| |
|
//// KS_TODO diagnostic that we should be able to remove |
|
if (rtnSize != _size) |
|
{ |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL1, |
|
"Size calc error _size %u rtnSWize = %u", _size, rtnSize)); |
|
} |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
return rtnSize; |
} | } |
| |
//------------------------------------------------------------------------------ |
Boolean CIMResponseData::hasBinaryData() const |
// Instantiates an array of CIMObjectPath from an array of SCMOInstances |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceNamesResponseData::_resolveSCMOInstanceNames( |
|
CIMInstanceNamesResponseData* data, |
|
Array<CIMObjectPath>& cops) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
return (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)); |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames"); |
} |
|
// Sets the _size variable based on the internal size counts. |
cops.clear(); |
void CIMResponseData::setSize() |
|
{ |
//--rk-->TBD: Do the actual coding here |
PEGASUS_DEBUG_ASSERT(valid()); //KS_TEMP KS_TODO |
| |
fprintf(stderr,"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
Uint32 rtnSize = 0; |
"Poorly implemented!!!\n"); |
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
try |
|
{ | { |
for (Uint32 x=0; x < data->_scmoInstanceNames.size(); x++) |
switch (_dataType) |
{ | { |
/*SCMODump dmp; |
case RESP_OBJECTPATHS: |
dmp.dumpSCMOInstanceKeyBindings(data->_scmoInstanceNames[x]);*/ |
case RESP_INSTNAMES: |
CIMObjectPath cop; |
break; |
data->_scmoInstanceNames[x].getCIMObjectPath(cop); |
case RESP_INSTANCE: |
cops.append(cop); |
rtnSize +=1; |
|
break; |
|
case RESP_INSTANCES: |
|
case RESP_OBJECTS: |
|
rtnSize += _instanceData.size(); |
|
break; |
} | } |
} | } |
catch (CIMException& ex) |
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
{ | { |
fprintf(stderr, |
// KS_PULL_TODO |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
// Cannot resolve this one without actually processing |
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
// the data since it is a stream. |
|
rtnSize += 0; |
} | } |
catch (Exception& ex) |
|
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
{ | { |
fprintf(stderr, |
rtnSize += _scmoInstances.size(); |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
|
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
|
} | } |
catch (exception& ex) |
|
|
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
{ | { |
fprintf(stderr, |
switch (_dataType) |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
|
"exception:\n%s\n",(const char*)ex.what()); |
|
} |
|
catch (...) |
|
{ | { |
fprintf(stderr, |
case RESP_OBJECTPATHS: |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
case RESP_INSTNAMES: |
"Exception: UNKNOWN\n"); |
rtnSize += _instanceNames.size(); |
|
break; |
|
case RESP_INSTANCE: |
|
case RESP_INSTANCES: |
|
rtnSize += _instances.size(); |
|
break; |
|
case RESP_OBJECTS: |
|
rtnSize += _objects.size(); |
|
break; |
} | } |
data->_resolveCallback = 0; |
} |
|
_size = rtnSize; |
PEG_METHOD_EXIT(); |
|
return true; |
|
} | } |
| |
|
// Return the number of CIM objects in the CIM Response data object |
//----------------------------------------------------------------------------- |
|
// | // |
// CIMInstanceResponseData |
#define TEMPLOG PEG_TRACE((TRC_XML, Tracer::LEVEL4, \ |
// |
"rtnSize %u size %u line %u", rtnSize, _size, __LINE__)) |
//----------------------------------------------------------------------------- |
//#define TEMPLOG cout << "rtnSize " << rtnSize << " _size " << _size |
|
//<< " line " << __LINE__ << endl |
//------------------------------------------------------------------------------ |
|
// Takes a binary stream representing an instances from a CIMBuffer and stores |
Uint32 CIMResponseData::size() |
// it in the responsedata. |
{ |
// @param hasLen Indicates if the binary instance stream is prepended with an |
AutoMutex autoMut(testLock); |
// Uint32 value indicating the number of instances in the stream. |
PEG_METHOD_ENTER(TRC_XML,"CIMResponseData::size()"); |
//------------------------------------------------------------------------------ |
TEST_SIZE_VALID; |
bool CIMInstanceResponseData::setBinaryCimInstance(CIMBuffer& in, bool hasLen) |
// If debug mode, add up all the individual size components to |
|
// determine overall size of this object. Then compare this with |
|
// the _size variable. this is a good check on the completeness of the |
|
// size computations. We should be able to remove this at some point |
|
// but there are many sources of size info and we need to be sure we |
|
// have covered them all. |
|
#ifdef PEGASUS_DEBUG |
|
PEGASUS_DEBUG_ASSERT(valid()); //KS_TEMP KS_TODO |
|
|
|
Uint32 rtnSize = 0; |
|
TEMPLOG; |
|
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
|
{ |
|
TEMPLOG; |
|
switch (_dataType) |
|
{ |
|
case RESP_OBJECTPATHS: |
|
case RESP_INSTNAMES: |
|
break; |
|
case RESP_INSTANCE: |
|
rtnSize +=1; |
|
break; |
|
case RESP_INSTANCES: |
|
case RESP_OBJECTS: |
|
rtnSize += _instanceData.size(); |
|
break; |
|
} |
|
TEST_SIZE_VALID; |
|
TEMPLOG; |
|
} |
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
|
{ |
|
TEMPLOG; |
|
// KS_PULL_TODO |
|
// Cannot resolve this one without actually processing |
|
// the data since it is a stream. |
|
rtnSize += 0; |
|
// KS_TODO flag on this one |
|
//// PEGASUS_ASSERT(false); |
|
TEMPLOG; |
|
} |
|
|
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
|
{ |
|
TEST_SIZE_VALID; |
|
TEMPLOG; |
|
rtnSize += _scmoInstances.size(); |
|
TEMPLOG; |
|
} |
|
|
|
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
{ |
|
TEST_SIZE_VALID; |
|
TEMPLOG; |
|
switch (_dataType) |
|
{ |
|
case RESP_OBJECTPATHS: |
|
case RESP_INSTNAMES: |
|
rtnSize += _instanceNames.size(); |
|
break; |
|
case RESP_INSTANCE: |
|
case RESP_INSTANCES: |
|
rtnSize += _instances.size(); |
|
break; |
|
case RESP_OBJECTS: |
|
rtnSize += _objects.size(); |
|
break; |
|
} |
|
TEST_SIZE_VALID; |
|
TEMPLOG; |
|
} |
|
// Test of actual count against _size variable. KS_TODO diagnostic |
|
if (rtnSize != _size) |
|
{ |
|
TEMPLOG; |
|
TEST_SIZE_VALID; |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL1, |
|
"CIMResponseData::size ERROR. debug size mismatch." |
|
"Computed = %u. variable = %u",rtnSize, _size )); |
|
// KS_TEMP |
|
cout << "Size err Computed(rtnsize)=" << rtnSize << " _size=" << _size |
|
<< " diff=" << (rtnSize - _size) << endl; |
|
TEMPLOG; |
|
} |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL1, "ReturnSize=%u", _size )); |
|
#endif |
|
PEG_METHOD_EXIT(); |
|
return _size; |
|
} |
|
|
|
// function used by OperationAggregator to aggregate response data in a |
|
// single ResponseData object. Adds all data in the from ResponseData object |
|
// input variable to the target ResponseData object |
|
// target array |
|
void CIMResponseData::appendResponseData(const CIMResponseData & x) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, |
|
"CIMResponseData::appendResponseData"); |
|
//// AutoMutex autoMut(testLock); |
|
// Confirm that the CIMResponseData type matches the type |
|
// of the data being appended |
|
|
|
PEGASUS_DEBUG_ASSERT(valid()); // KS_TEMP |
|
PEGASUS_DEBUG_ASSERT(_dataType == x._dataType); |
|
_encoding |= x._encoding; |
|
|
|
// add all binary data |
|
_binaryData.appendArray(x._binaryData); |
|
// KS_TBD TODO PULL Add the counter incrementer for binary |
|
|
|
// add all the C++ stuff |
|
_instanceNames.appendArray(x._instanceNames); |
|
_size += x._instanceNames.size(); |
|
_instances.appendArray(x._instances); |
|
_size += x._instances.size(); |
|
_objects.appendArray(x._objects); |
|
_size += x._objects.size(); |
|
|
|
// add the SCMO instances |
|
_scmoInstances.appendArray(x._scmoInstances); |
|
_size += x._scmoInstances.size(); |
|
|
|
// add Xml encodings |
|
// KS_TODO these are temporary. delete before release |
|
PEGASUS_ASSERT(x._referencesData.size() == x._instanceData.size()); |
|
PEGASUS_ASSERT(x._instanceData.size() == x._hostsData.size()); |
|
PEGASUS_ASSERT(x._instanceData.size() == x._nameSpacesData.size()); |
|
|
|
_referencesData.appendArray(x._referencesData); |
|
_instanceData.appendArray(x._instanceData); |
|
_hostsData.appendArray(x._hostsData); |
|
_nameSpacesData.appendArray(x._nameSpacesData); |
|
_size += x._instanceData.size(); |
|
|
|
// transfer property list |
|
_propertyList = x._propertyList; |
|
|
|
PEG_METHOD_EXIT(); |
|
} |
|
|
|
// Encoding responses into output format |
|
void CIMResponseData::encodeBinaryResponse(CIMBuffer& out) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, |
|
"CIMResponseData::encodeBinaryResponse"); |
|
|
|
TEST_SIZE_VALID; |
|
|
|
// Need to do a complete job here by transferring all contained data |
|
// into binary format and handing it out in the CIMBuffer |
|
// KS_TODO |
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEGASUS_ASSERT(false); // KS_TEMP |
"CIMInstanceResponseData::setBinaryCimInstance"); |
|
|
// Binary does NOT need a marker as it consists of C++ and SCMO |
|
const Array<Uint8>& data = _binaryData; |
|
out.putBytes(data.getData(), data.size()); |
|
} |
| |
if (hasLen) |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
{ | { |
if (!in.getUint8A(_binaryData)) |
out.putTypeMarker(BIN_TYPE_MARKER_CPPD); |
|
switch (_dataType) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
case RESP_INSTNAMES: |
"Failed to get binary instance data!"); |
{ |
PEG_METHOD_EXIT(); |
out.putObjectPathA(_instanceNames); |
return false; |
break; |
} | } |
|
case RESP_INSTANCE: |
|
{ |
|
if (0 == _instances.size()) |
|
{ |
|
_instances.append(CIMInstance()); |
} | } |
else |
out.putInstance(_instances[0], true, true); |
|
break; |
|
} |
|
case RESP_INSTANCES: |
{ | { |
size_t remainingDataLength = in.capacity() - in.size(); |
out.putInstanceA(_instances); |
|
break; |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
|
} | } |
|
case RESP_OBJECTS: |
_resolveCallback = _resolveBinaryInstance; |
|
_binaryEncoding = true; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
|
|
|
bool CIMInstanceResponseData::setXmlCimInstance(CIMBuffer& in) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
out.putObjectA(_objects); |
"CIMInstanceResponseData::setXmlCimInstance"); |
break; |
|
} |
if (!in.getSint8A(_instanceData)) |
case RESP_OBJECTPATHS: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
out.putObjectPathA(_instanceNames); |
"Failed to get XML instance data!"); |
break; |
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
default: |
if (!in.getSint8A(_referenceData)) |
|
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
PEGASUS_DEBUG_ASSERT(false); |
"Failed to get XML instance data (reference)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
} |
if (!in.getString(_hostData)) |
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
out.putTypeMarker(BIN_TYPE_MARKER_SCMO); |
"Failed to get XML instance data (host)!"); |
out.putSCMOInstanceA(_scmoInstances); |
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
if (!in.getNamespaceName(_nameSpaceData)) |
|
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
// This actually should not happen following general code logic |
"Failed to get XML instance data (namespace)!"); |
PEGASUS_DEBUG_ASSERT(false); |
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
| |
_resolveCallback = _resolveXMLInstance; |
|
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
} |
}; |
|
| |
//------------------------------------------------------------------------------ |
void CIMResponseData::completeNamespace(const SCMOInstance * x) |
// Encodes the CIMInstance representation contained in the current |
|
// CIMResponseData object in binary response message format. |
|
// This code corresponds to method _resolveBinaryInstance, which is used |
|
// revert a binary instance representation back into a CIMInstance |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceResponseData::encodeBinaryResponse(CIMBuffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
const char * ns; |
"CIMInstanceResponseData::encodeBinaryResponse"); |
Uint32 len; |
|
ns = x->getNameSpace_l(len); |
if (_resolveCallback && _binaryEncoding) |
// Both internal XML as well as binary always contain a namespace |
|
// don't have to do anything for those two encodings |
|
if ((RESP_ENC_BINARY == (_encoding&RESP_ENC_BINARY)) && (len != 0)) |
{ | { |
const Array<Uint8>& data = _binaryData; |
_defaultNamespace = CIMNamespaceName(ns); |
out.putBytes(data.getData(), data.size()); |
|
} | } |
else |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
{ |
|
CIMNamespaceName nsName(ns); |
|
switch (_dataType) |
{ | { |
out.putInstance(_cimInstance, false, false); |
case RESP_INSTANCE: |
|
{ |
|
if (_instances.size() > 0) |
|
{ |
|
const CIMInstance& inst = _instances[0]; |
|
CIMObjectPath& p = |
|
const_cast<CIMObjectPath&>(inst.getPath()); |
|
if (p.getNameSpace().isNull()) |
|
{ |
|
p.setNameSpace(nsName); |
} | } |
PEG_METHOD_EXIT(); |
|
} | } |
|
break; |
//------------------------------------------------------------------------------ |
} |
// Encodes the CIMInstanc representation contained in the current |
case RESP_INSTANCES: |
// CIMResponseData object in xml response message format. |
|
// This code corresponds to method _resolveXmlInstance, which is used |
|
// revert a CIM-XML instance representation back into a CIMInstance. |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceResponseData::encodeXmlResponse(Buffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
for (Uint32 j = 0, n = _instances.size(); j < n; j++) |
"CIMInstanceResponseData::encodeXmlResponse"); |
{ |
|
const CIMInstance& inst = _instances[j]; |
if (_resolveCallback && !_binaryEncoding) |
CIMObjectPath& p = |
|
const_cast<CIMObjectPath&>(inst.getPath()); |
|
if (p.getNameSpace().isNull()) |
{ | { |
out.append( (char*)_instanceData.getData(),_instanceData.size()-1); |
p.setNameSpace(nsName); |
} | } |
else |
} |
|
break; |
|
} |
|
case RESP_OBJECTS: |
{ | { |
XmlWriter::appendInstanceElement(out, _cimInstance); |
for (Uint32 j = 0, n = _objects.size(); j < n; j++) |
|
{ |
|
const CIMObject& object = _objects[j]; |
|
CIMObjectPath& p = |
|
const_cast<CIMObjectPath&>(object.getPath()); |
|
if (p.getNameSpace().isNull()) |
|
{ |
|
p.setNameSpace(nsName); |
|
} |
|
} |
|
break; |
|
} |
|
case RESP_INSTNAMES: |
|
case RESP_OBJECTPATHS: |
|
{ |
|
for (Uint32 j = 0, n = _instanceNames.size(); j < n; j++) |
|
{ |
|
CIMObjectPath& p = _instanceNames[j]; |
|
if (p.getNameSpace().isNull()) |
|
{ |
|
p.setNameSpace(nsName); |
|
} |
|
} |
|
break; |
|
} |
|
default: |
|
{ |
|
PEGASUS_DEBUG_ASSERT(false); |
|
} |
|
} |
|
} |
|
|
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
|
{ |
|
for (Uint32 j = 0, n = _scmoInstances.size(); j < n; j++) |
|
{ |
|
SCMOInstance & scmoInst=_scmoInstances[j]; |
|
if (0 == scmoInst.getNameSpace()) |
|
{ |
|
scmoInst.setNameSpace_l(ns,len); |
|
} |
|
} |
} | } |
PEG_METHOD_EXIT(); |
|
} | } |
| |
//------------------------------------------------------------------------------ |
void CIMResponseData::completeHostNameAndNamespace( |
// Instantiates a CIMInstance from a binary representation created by |
const String & hn, |
// the CIMBinMessageSerializer. |
const CIMNamespaceName & ns, |
// Returns true on success. |
Boolean isPullOperation) |
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceResponseData::_resolveBinaryInstance( |
|
CIMInstanceResponseData* data, |
|
CIMInstance& instance) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstanceResponseData::_resolveBinaryInstance"); |
"CIMResponseData::completeHostNameAndNamespace"); |
| |
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
PEGASUS_DEBUG_ASSERT(valid()); // KS_TEMP |
| |
if (!in.getInstance(instance)) |
Uint32 count = 0; //// KS_TODO this counter is just diagnostic |
|
|
|
PEG_TRACE(( TRC_DISPATCHER, Tracer::LEVEL4, // KS_TODO TEMP |
|
"completeHostNameAndNamespace Setting hostName, etc " |
|
"host %s ns %s set for dataType=%u encoding=%u isPull=%s", |
|
(const char *)hn.getCString(), |
|
(const char *)ns.getString().getCString(), |
|
_dataType, _encoding, boolToString(isPullOperation) )); |
|
|
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
{ | { |
instance = CIMInstance(); |
// On binary need to remember hostname and namespace in case someone |
in.release(); |
// builds C++ default objects or Xml types later i.e. |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
// -> usage: See resolveBinary() |
"Failed to resolve binary instance!"); |
_defaultNamespace=ns; |
PEG_METHOD_EXIT(); |
_defaultHostname=hn; |
return false; |
count++; |
|
} |
|
// InternalXml does not support objectPath calls |
|
if ((RESP_ENC_XML == (_encoding & RESP_ENC_XML)) && |
|
(RESP_OBJECTS == _dataType)) |
|
{ |
|
for (Uint32 j = 0, n = _referencesData.size(); j < n; j++) |
|
{ |
|
if (0 == _hostsData[j].size()) |
|
{ |
|
_hostsData[j]=hn; |
|
count++; |
|
} |
|
if (_nameSpacesData[j].isNull()) |
|
{ |
|
_nameSpacesData[j]=ns; |
|
} |
|
} |
|
} |
|
// Need to set for Pull Enumeration operations |
|
if ((RESP_ENC_XML == (_encoding & RESP_ENC_XML)) && |
|
((RESP_INSTANCES == _dataType) || isPullOperation)) |
|
{ |
|
for (Uint32 j = 0, n = _referencesData.size(); j < n; j++) |
|
{ |
|
if (0 == _hostsData[j].size()) |
|
{ |
|
count++; |
|
_hostsData[j]=hn; |
|
} |
|
if (_nameSpacesData[j].isNull()) |
|
{ |
|
_nameSpacesData[j]=ns; |
} | } |
| |
in.release(); |
// KS_TODO Remove Diagnostic |
PEG_METHOD_EXIT(); |
PEG_TRACE(( TRC_DISPATCHER, Tracer::LEVEL4, |
return true; |
"completeHostNameAndNamespace Setting hostName, etc " |
|
"host %s ns %s set to _hostData %s _namespaceData %s", |
|
(const char *)hn.getCString(), |
|
(const char *)ns.getString().getCString(), |
|
(const char *)_hostsData[j].getCString(), |
|
(const char *)_nameSpacesData[j].getString().getCString() )); |
|
} |
} | } |
| |
//------------------------------------------------------------------------------ |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
// Instantiates a CIMInstance from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceResponseData::_resolveXMLInstance( |
|
CIMInstanceResponseData* data, |
|
CIMInstance& cimInstance) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
switch (_dataType) |
"CIMInstanceResponseData::_resolveXMLInstance"); |
|
|
|
// Deserialize instance: |
|
{ | { |
XmlParser parser((char*)data->_instanceData.getData()); |
// Instances added to account for namedInstance in Pull operations. |
|
case RESP_INSTANCES: |
| |
if (!XmlReader::getInstanceElement(parser, cimInstance)) |
for (Uint32 j = 0, n = _instances.size(); j < n; j++) |
{ | { |
cimInstance = CIMInstance(); |
const CIMInstance& instance = _instances[j]; |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
CIMObjectPath& p = |
"Failed to resolve XML instance, parser error!"); |
const_cast<CIMObjectPath&>(instance.getPath()); |
PEG_METHOD_EXIT(); |
if (p.getHost().size()==0) |
return false; |
{ |
|
count++; |
|
p.setHost(hn); |
} | } |
|
if (p.getNameSpace().isNull()) |
|
{ |
|
p.setNameSpace(ns); |
} | } |
|
} |
// Deserialize path: |
case RESP_OBJECTS: |
{ | { |
XmlParser parser((char*)data->_referenceData.getData()); |
for (Uint32 j = 0, n = _objects.size(); j < n; j++) |
CIMObjectPath cimObjectPath; |
|
|
|
if (XmlReader::getValueReferenceElement(parser, cimObjectPath)) |
|
{ | { |
if (data->_hostData.size()) |
const CIMObject& object = _objects[j]; |
cimObjectPath.setHost(data->_hostData); |
CIMObjectPath& p = |
|
const_cast<CIMObjectPath&>(object.getPath()); |
if (!data->_nameSpaceData.isNull()) |
if (p.getHost().size()==0) |
cimObjectPath.setNameSpace(data->_nameSpaceData); |
{ |
|
count++; |
cimInstance.setPath(cimObjectPath); |
p.setHost(hn); |
|
} |
|
if (p.getNameSpace().isNull()) |
|
{ |
|
p.setNameSpace(ns); |
|
} |
|
} |
|
break; |
|
} |
|
// INSTNAMES added to account for instance paths in pull name |
|
// operations |
|
case RESP_INSTNAMES: |
|
case RESP_OBJECTPATHS: |
|
{ |
|
for (Uint32 j = 0, n = _instanceNames.size(); j < n; j++) |
|
{ |
|
CIMObjectPath& p = _instanceNames[j]; |
|
if (p.getHost().size() == 0) |
|
{ |
|
count++; |
|
p.setHost(hn); |
|
} |
|
if (p.getNameSpace().isNull()) |
|
{ |
|
p.setNameSpace(ns); |
} | } |
} | } |
|
break; |
|
} |
|
default: |
|
{ |
|
PEGASUS_DEBUG_ASSERT(false); |
|
} |
|
} |
|
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
|
{ |
|
CString hnCString=hn.getCString(); |
|
const char* hnChars = hnCString; |
|
Uint32 hnLen = strlen(hnChars); |
|
CString nsCString=ns.getString().getCString(); |
|
const char* nsChars=nsCString; |
|
Uint32 nsLen = strlen(nsChars); |
|
switch (_dataType) |
|
{ |
|
// KS_PULL add Instances and InstNames to cover pull operations |
|
// KS_PULL - Confirm that this OK. |
|
case RESP_INSTNAMES: |
|
case RESP_INSTANCES: |
|
case RESP_OBJECTS: |
|
case RESP_OBJECTPATHS: |
|
{ |
|
for (Uint32 j = 0, n = _scmoInstances.size(); j < n; j++) |
|
{ |
|
count++; |
|
SCMOInstance & scmoInst=_scmoInstances[j]; |
|
scmoInst.completeHostNameAndNamespace( |
|
hnChars, |
|
hnLen, |
|
nsChars, |
|
nsLen); |
|
} |
|
break; |
|
} |
|
default: |
|
{ |
|
PEGASUS_DEBUG_ASSERT(false); |
|
} |
|
} |
|
} |
|
PEG_TRACE(( TRC_DISPATCHER, Tracer::LEVEL4, // KS_TODO TEMP |
|
"completeHostNameAndNamespace Set hostName, etc count %u " |
|
"host %s ns %s set for dataType=%u encoding=%u isPull=%s", |
|
count, |
|
(const char *)hn.getCString(), |
|
(const char *)ns.getString().getCString(), |
|
_dataType, _encoding, boolToString(isPullOperation) )); |
|
|
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
|
} | } |
| |
|
// NOTE: The reason for the isPullResponse variable is that there are |
|
// some variations in ouput to Xml depending on whether the responses |
|
// are one of the pull responses or not |
|
void CIMResponseData::encodeXmlResponse(Buffer& out, |
|
Boolean isPullResponse, |
|
Boolean encodeInstanceOnly) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, |
|
"CIMResponseData::encodeXmlResponse"); |
| |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL3, |
|
"CIMResponseData::encodeXmlResponse(encoding=%X,dataType=%X, pull= %s)", |
|
_encoding, |
|
_dataType, |
|
(isPullResponse? "true" : "false"))); |
| |
//----------------------------------------------------------------------------- |
// already existing Internal XML does not need to be encoded further |
// |
// binary input is not actually impossible here, but we have an established |
// CIMInstancesResponseData |
// fallback |
// |
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
//----------------------------------------------------------------------------- |
{ |
|
_resolveBinaryToSCMO(); |
|
} |
|
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
|
{ |
|
switch (_dataType) |
|
{ |
|
case RESP_INSTANCE: |
|
{ |
|
const Array<ArraySint8>& a = _instanceData; |
|
out.append((char*)a[0].getData(), a[0].size() - 1); |
|
break; |
|
} |
|
case RESP_INSTANCES: |
|
{ |
|
const Array<ArraySint8>& a = _instanceData; |
|
const Array<ArraySint8>& b = _referencesData; |
| |
//------------------------------------------------------------------------------ |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
// Takes a binary stream of instances from a CIMBuffer and stores it in the |
|
// responsedata. |
|
// @param hasLen Indicates if the binary instance stream is prepended with an |
|
// Uint32 value indicating the number of instances in the stream. |
|
//------------------------------------------------------------------------------ |
|
bool CIMInstancesResponseData::setBinaryCimInstances(CIMBuffer& in, bool hasLen) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
if (isPullResponse) |
"CIMInstancesResponseData::setBinaryCimInstances"); |
{ |
|
// KS_TODO these are temporary. delete before release |
|
PEGASUS_ASSERT(a.size() == b.size()); |
|
PEGASUS_ASSERT(a.size() == _hostsData.size()); |
|
PEGASUS_ASSERT(a.size() == _nameSpacesData.size()); |
|
|
|
out << STRLIT("<VALUE.INSTANCEWITHPATH>\n"); |
|
out << STRLIT("<INSTANCEPATH>\n"); |
|
XmlWriter::appendNameSpacePathElement(out, |
|
_hostsData[i], |
|
_nameSpacesData[i]); |
|
out.append((char*)b[i].getData(), b[i].size() - 1); |
|
out << STRLIT("</INSTANCEPATH>\n"); |
|
out.append((char *)a[i].getData(), a[i].size() - 1); |
|
out << STRLIT("</VALUE.INSTANCEWITHPATH>\n"); |
|
} |
|
else |
|
{ |
|
out << STRLIT("<VALUE.NAMEDINSTANCE>\n"); |
|
out.append((char*)b[i].getData(), b[i].size() - 1); |
|
out.append((char *)a[i].getData(), a[i].size() - 1); |
|
out << STRLIT("</VALUE.NAMEDINSTANCE>\n"); |
|
} |
|
} |
|
break; |
|
} |
|
case RESP_OBJECTS: |
|
{ |
|
const Array<ArraySint8>& a = _instanceData; |
|
const Array<ArraySint8>& b = _referencesData; |
| |
if (hasLen) |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
{ | { |
if (!in.getUint8A(_binaryData)) |
out << STRLIT("<VALUE.OBJECTWITHPATH>\n"); |
|
out << STRLIT("<INSTANCEPATH>\n"); |
|
XmlWriter::appendNameSpacePathElement( |
|
out, |
|
_hostsData[i], |
|
_nameSpacesData[i]); |
|
// Leave out the surrounding tags "<VALUE.REFERENCE>\n" |
|
// and "</VALUE.REFERENCE>\n" which are 18 and 19 characters |
|
// long |
|
out.append( |
|
((char*)b[i].getData())+18, |
|
b[i].size() - 1 - 18 -19); |
|
out << STRLIT("</INSTANCEPATH>\n"); |
|
// append instance body |
|
out.append((char*)a[i].getData(), a[i].size() - 1); |
|
out << STRLIT("</VALUE.OBJECTWITHPATH>\n"); |
|
} |
|
break; |
|
} |
|
// internal xml encoding of instance names and object paths not |
|
// done today |
|
case RESP_INSTNAMES: |
|
case RESP_OBJECTPATHS: |
|
default: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
PEGASUS_ASSERT(false); |
"Failed to get binary instance data!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
} | } |
|
} |
|
|
|
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
{ |
|
switch (_dataType) |
|
{ |
|
case RESP_INSTNAMES: |
|
{ |
|
for (Uint32 i = 0, n = _instanceNames.size(); i < n; i++) |
|
{ |
|
// Element type is different for Pull responses |
|
if (isPullResponse) |
|
{ |
|
XmlWriter::appendInstancePathElement(out, |
|
_instanceNames[i]); |
|
} |
else | else |
{ | { |
size_t remainingDataLength = in.capacity() - in.size(); |
XmlWriter::appendInstanceNameElement(out, |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
_instanceNames[i]); |
|
} |
|
} |
|
break; |
|
} |
|
case RESP_INSTANCE: |
|
{ |
|
if (_instances.size() > 0) |
|
{ |
|
XmlWriter::appendInstanceElement( |
|
out, |
|
_instances[0], |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_propertyList); |
|
} |
|
break; |
|
} |
|
case RESP_INSTANCES: |
|
{ |
|
for (Uint32 i = 0, n = _instances.size(); i < n; i++) |
|
{ |
|
cout << "CIMReponseData IncludeQualifiers " |
|
<< boolToString(_includeQualifiers) << endl; |
|
if (isPullResponse) |
|
{ |
|
if (encodeInstanceOnly) |
|
{ |
|
XmlWriter::appendInstanceElement( |
|
out, |
|
_instances[i], |
|
_includeQualifiers, |
|
// KS_TODO should not have to block this here |
|
_includeClassOrigin, |
|
_propertyList); |
|
} |
|
else |
|
{ |
|
XmlWriter::appendValueInstanceWithPathElement( |
|
out, |
|
_instances[i], |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_propertyList); |
|
} |
|
} |
|
else |
|
{ |
|
XmlWriter::appendValueNamedInstanceElement( |
|
out, |
|
_instances[i], |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_propertyList); |
|
} |
|
} |
|
break; |
|
} |
|
case RESP_OBJECTS: |
|
{ |
|
for (Uint32 i = 0; i < _objects.size(); i++) |
|
{ |
|
// If pull, map to instances |
|
if (isPullResponse) |
|
{ |
|
CIMInstance x = (CIMInstance)_objects[i]; |
|
XmlWriter::appendValueInstanceWithPathElement( |
|
out, x, |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_propertyList); |
|
} |
|
else |
|
{ |
|
XmlWriter::appendValueObjectWithPathElement( |
|
out, |
|
_objects[i], |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_isClassOperation, |
|
_propertyList); |
} | } |
|
} |
|
break; |
|
} |
|
case RESP_OBJECTPATHS: |
|
{ |
|
for (Uint32 i = 0, n = _instanceNames.size(); i < n; i++) |
|
{ |
|
// ObjectPaths come from providers for pull operations |
|
// but are encoded as instancePathElements |
|
if (isPullResponse) |
| |
_resolveCallback = _resolveBinaryInstances; |
{ |
_encoding = RESP_ENC_BINARY; |
XmlWriter::appendInstancePathElement(out, |
|
_instanceNames[i]); |
|
} |
|
else |
|
{ |
|
out << "<OBJECTPATH>\n"; |
|
XmlWriter::appendValueReferenceElement( |
|
out, |
|
_instanceNames[i], |
|
_isClassOperation, |
|
false); |
|
out << "</OBJECTPATH>\n"; |
|
} |
|
} |
|
break; |
|
} |
|
default: |
|
{ |
|
PEGASUS_ASSERT(false); |
|
} |
|
} |
|
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
|
{ |
|
switch (_dataType) |
|
{ |
|
case RESP_INSTNAMES: |
|
{ |
|
for (Uint32 i = 0, n = _scmoInstances.size();i < n; i++) |
|
{ |
|
if (isPullResponse) |
|
{ |
|
SCMOXmlWriter::appendInstancePathElement( |
|
out, |
|
_scmoInstances[i]); |
|
} |
|
else |
|
{ |
|
SCMOXmlWriter::appendInstanceNameElement( |
|
out, |
|
_scmoInstances[i]); |
|
} |
|
} |
|
break; |
|
} |
|
case RESP_INSTANCE: |
|
{ |
|
if (_scmoInstances.size() > 0) |
|
{ |
|
_appendInstanceElement(out, _scmoInstances[0]); |
|
} |
|
break; |
|
} |
|
case RESP_INSTANCES: |
|
{ |
|
if (isPullResponse) |
|
{ |
|
// pull and encodeInstanceOnly (i.e. response to |
|
// OpenQueryInstances and pullInstances |
|
if (encodeInstanceOnly) |
|
{ |
|
for (Uint32 i = 0, n = _scmoInstances.size();i < n; i++) |
|
{ |
|
_appendInstanceElement(out, _scmoInstances[i]); |
|
} |
|
} |
|
else |
|
{ |
|
SCMOXmlWriter::appendValueSCMOInstanceWithPathElements( |
|
out, _scmoInstances, _propertyList); |
|
} |
|
} |
|
else |
|
{ |
|
SCMOXmlWriter::appendValueSCMOInstanceElements( |
|
out, _scmoInstances, _propertyList); |
|
} |
|
break; |
|
} |
|
case RESP_OBJECTS: |
|
{ |
|
if (isPullResponse) |
|
{ |
|
SCMOXmlWriter::appendValueSCMOInstanceWithPathElements( |
|
out,_scmoInstances, _propertyList); |
|
} |
|
else |
|
{ |
|
// KS_TODO why is this one named element rather than |
|
// elements |
|
SCMOXmlWriter::appendValueObjectWithPathElement( |
|
out, _scmoInstances, _propertyList); |
|
} |
|
break; |
|
} |
|
case RESP_OBJECTPATHS: |
|
{ |
|
for (Uint32 i = 0, n = _scmoInstances.size(); i < n; i++) |
|
{ |
|
if (isPullResponse) |
|
{ |
|
SCMOXmlWriter::appendInstancePathElement(out, |
|
_scmoInstances[i]); |
|
} |
|
else |
|
{ |
|
out << "<OBJECTPATH>\n"; |
|
SCMOXmlWriter::appendValueReferenceElement( |
|
out, _scmoInstances[i], |
|
false); |
|
out << "</OBJECTPATH>\n"; |
|
} |
|
} |
|
break; |
|
} |
|
default: |
|
{ |
|
PEGASUS_ASSERT(false); |
|
} |
|
} |
|
} |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
} |
}; |
|
| |
bool CIMInstancesResponseData::setXmlCimInstances(CIMBuffer& in) |
// contrary to encodeXmlResponse this function encodes the Xml in a format |
|
// not usable by clients |
|
void CIMResponseData::encodeInternalXmlResponse(CIMBuffer& out) |
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstancesResponseData::setXmlCimInstances"); |
"CIMResponseData::encodeInternalXmlResponse"); |
| |
Uint32 count; |
PEG_TRACE((TRC_XML, Tracer::LEVEL3, |
|
"CIMResponseData::encodeInternalXmlResponse(encoding=%X,content=%X)", |
|
_encoding, |
|
_dataType)); |
|
// For mixed (CIM+SCMO) responses, we need to tell the receiver the |
|
// total number of instances. The totalSize variable is used to keep track |
|
// of this. |
|
Uint32 totalSize = 0; |
| |
if (!in.getUint32(count)) |
// already existing Internal XML does not need to be encoded further |
|
// binary input is not actually impossible here, but we have an established |
|
// fallback |
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
_resolveBinaryToSCMO(); |
"Failed to get XML instance data (number of instance)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
if ((0 == _encoding) || |
for (Uint32 i = 0; i < count; i++) |
(RESP_ENC_CIM == (_encoding & RESP_ENC_CIM))) |
{ | { |
Array<Sint8> inst; |
switch (_dataType) |
Array<Sint8> ref; |
|
CIMNamespaceName ns; |
|
String host; |
|
|
|
if (!in.getSint8A(inst)) |
|
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
case RESP_INSTANCE: |
"Failed to get XML instance data (instances)!"); |
{ |
PEG_METHOD_EXIT(); |
if (0 == _instances.size()) |
return false; |
{ |
|
_instances.append(CIMInstance()); |
|
CIMInternalXmlEncoder::_putXMLInstance( |
|
out, |
|
_instances[0]); |
|
break; |
} | } |
|
CIMInternalXmlEncoder::_putXMLInstance( |
if (!in.getSint8A(ref)) |
out, |
|
_instances[0], |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_propertyList); |
|
break; |
|
} |
|
case RESP_INSTANCES: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
Uint32 n = _instances.size(); |
"Failed to get XML instance data (references)!"); |
totalSize = n + _scmoInstances.size(); |
PEG_METHOD_EXIT(); |
out.putUint32(totalSize); |
return false; |
for (Uint32 i = 0; i < n; i++) |
|
{ |
|
CIMInternalXmlEncoder::_putXMLNamedInstance( |
|
out, |
|
_instances[i], |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_propertyList); |
} | } |
|
break; |
if (!in.getString(host)) |
} |
|
case RESP_OBJECTS: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
Uint32 n = _objects.size(); |
"Failed to get XML instance data (host)!"); |
totalSize = n + _scmoInstances.size(); |
PEG_METHOD_EXIT(); |
out.putUint32(totalSize); |
return false; |
for (Uint32 i = 0; i < n; i++) |
|
{ |
|
CIMInternalXmlEncoder::_putXMLObject( |
|
out, |
|
_objects[i], |
|
_includeQualifiers, |
|
_includeClassOrigin, |
|
_propertyList); |
} | } |
|
break; |
if (!in.getNamespaceName(ns)) |
} |
|
// internal xml encoding of instance names and object paths not |
|
// done today |
|
case RESP_INSTNAMES: |
|
case RESP_OBJECTPATHS: |
|
default: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
PEGASUS_DEBUG_ASSERT(false); |
"Failed to get XML instance data (namespace)!"); |
} |
PEG_METHOD_EXIT(); |
} |
return false; |
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
|
{ |
|
switch (_dataType) |
|
{ |
|
case RESP_INSTANCE: |
|
{ |
|
if (0 == _scmoInstances.size()) |
|
{ |
|
_scmoInstances.append(SCMOInstance()); |
|
} |
|
SCMOInternalXmlEncoder::_putXMLInstance( |
|
out, |
|
_scmoInstances[0], |
|
_propertyList); |
|
break; |
|
} |
|
case RESP_INSTANCES: |
|
{ |
|
Uint32 n = _scmoInstances.size(); |
|
// Only put the size when not already done above |
|
if (0==totalSize) |
|
{ |
|
out.putUint32(n); |
|
} |
|
SCMOInternalXmlEncoder::_putXMLNamedInstance( |
|
out, |
|
_scmoInstances, |
|
_propertyList); |
|
break; |
|
} |
|
case RESP_OBJECTS: |
|
{ |
|
Uint32 n = _scmoInstances.size(); |
|
// Only put the size when not already done above |
|
if (0==totalSize) |
|
{ |
|
out.putUint32(n); |
|
} |
|
SCMOInternalXmlEncoder::_putXMLObject( |
|
out, |
|
_scmoInstances, |
|
_propertyList); |
|
break; |
|
} |
|
// internal xml encoding of instance names and object paths not |
|
// done today |
|
case RESP_INSTNAMES: |
|
case RESP_OBJECTPATHS: |
|
default: |
|
{ |
|
PEGASUS_DEBUG_ASSERT(false); |
|
} |
} | } |
|
|
_instancesData.append(inst); |
|
_referencesData.append(ref); |
|
_hostsData.append(host); |
|
_nameSpacesData.append(ns); |
|
} | } |
|
|
_resolveCallback = _resolveXMLInstances; |
|
_encoding = RESP_ENC_XML; |
|
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
} |
}; |
|
| |
|
void CIMResponseData::_resolveToCIM() |
|
{ |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL3, |
|
"CIMResponseData::_resolveToCIM(encoding=%X,content=%X)", |
|
_encoding, |
|
_dataType)); |
| |
|
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
|
{ |
|
_resolveXmlToCIM(); |
|
} |
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
|
{ |
|
_resolveBinaryToSCMO(); |
|
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
|
{ |
|
_resolveSCMOToCIM(); |
|
} |
| |
|
PEGASUS_DEBUG_ASSERT(_encoding == RESP_ENC_CIM || _encoding == 0); |
|
} |
| |
//------------------------------------------------------------------------------ |
// Resolve any binary data to SCMO. This externalfunction added because we |
// Encodes the array of CIMInstance representation contained in the current |
// cannot do a move on Binary data so convert it a to movable format |
// CIMResponseData object in binary response message format. |
void CIMResponseData::resolveBinaryToSCMO() |
// This code corresponds to method _resolveBinaryInstances, which is used |
|
// revert a binary instance array representation back into an array of |
|
// CIMInstance |
|
//------------------------------------------------------------------------------ |
|
void CIMInstancesResponseData::encodeBinaryResponse(CIMBuffer& out) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstancesResponseData::encodeBinaryResponse"); |
"CIMResponseData::resolveBinaryToSCMO"); |
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
|
{ |
|
_resolveBinaryToSCMO(); |
|
} |
|
PEG_METHOD_EXIT(); |
|
} |
| |
if (_resolveCallback && (_encoding == RESP_ENC_BINARY)) |
void CIMResponseData::_resolveToSCMO() |
{ | { |
const Array<Uint8>& data = _binaryData; |
PEG_TRACE((TRC_XML, Tracer::LEVEL3, |
out.putBytes(data.getData(), data.size()); |
"CIMResponseData::_resolveToSCMO(encoding=%X,content=%X)", |
|
_encoding, |
|
_dataType)); |
|
|
|
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
|
{ |
|
_resolveXmlToSCMO(); |
} | } |
else |
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
{ | { |
_resolve(); |
_resolveBinaryToSCMO(); |
out.putInstanceA(_namedInstances, false); |
|
} | } |
PEG_METHOD_EXIT(); |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
{ |
|
_resolveCIMToSCMO(); |
|
} |
|
PEGASUS_DEBUG_ASSERT(_encoding == RESP_ENC_SCMO || _encoding == 0); |
} | } |
| |
//------------------------------------------------------------------------------ |
// helper functions to transform different formats into one-another |
// Encodes the array of CIMInstance representation contained in the current |
// functions work on the internal data and calling of them should be |
// CIMResponseData object in xml response message format. |
// avoided whenever possible |
// This code corresponds to method _resolveXmlInstances, which is used |
void CIMResponseData::_resolveBinaryToSCMO() |
// revert a CIM-XML object array representation back into an array of |
|
// CIMInstance. |
|
//------------------------------------------------------------------------------ |
|
void CIMInstancesResponseData::encodeXmlResponse(Buffer& out) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstancesResponseData::encodeXmlResponse"); |
"CIMResponseData::_resolveBinaryToSCMO"); |
|
|
|
CIMBuffer in((char*)_binaryData.getData(), _binaryData.size()); |
| |
if (_resolveCallback && (_encoding == RESP_ENC_XML)) |
while (in.more()) |
{ | { |
const Array<ArraySint8>& a = _instancesData; |
Uint32 binaryTypeMarker=0; |
const Array<ArraySint8>& b = _referencesData; |
if(!in.getTypeMarker(binaryTypeMarker)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get type marker for binary objects!"); |
|
PEG_METHOD_EXIT(); |
|
in.release(); |
|
return; |
|
} |
| |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
if (BIN_TYPE_MARKER_SCMO==binaryTypeMarker) |
{ | { |
out << STRLIT("<VALUE.NAMEDINSTANCE>\n"); |
if (!in.getSCMOInstanceA(_scmoInstances)) |
out.append((char*)b[i].getData(), b[i].size() - 1); |
{ |
out.append((char*)a[i].getData(), a[i].size() - 1); |
_encoding &=(~RESP_ENC_BINARY); |
out << STRLIT("</VALUE.NAMEDINSTANCE>\n"); |
in.release(); |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve binary SCMOInstances!"); |
|
PEG_METHOD_EXIT(); |
|
return; |
} | } |
|
|
|
_encoding |= RESP_ENC_SCMO; |
} | } |
else | else |
{ | { |
_resolve(); |
switch (_dataType) |
for (Uint32 i = 0, n = _namedInstances.size(); i < n; i++) |
{ |
XmlWriter::appendValueNamedInstanceElement( |
case RESP_INSTNAMES: |
out, _namedInstances[i]); |
case RESP_OBJECTPATHS: |
|
{ |
|
if (!in.getObjectPathA(_instanceNames)) |
|
{ |
|
_encoding &=(~RESP_ENC_BINARY); |
|
in.release(); |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve binary CIMObjectPaths!"); |
|
PEG_METHOD_EXIT(); |
|
return; |
} | } |
|
break; |
|
} |
|
case RESP_INSTANCE: |
|
{ |
|
CIMInstance instance; |
|
if (!in.getInstance(instance)) |
|
{ |
|
_encoding &=(~RESP_ENC_BINARY); |
|
_encoding |= RESP_ENC_CIM; |
|
_instances.append(instance); |
|
in.release(); |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve binary instance!"); |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
|
return; |
} | } |
| |
//------------------------------------------------------------------------------ |
_instances.append(instance); |
// Instantiates an array of CIMInstances from a binary representation created by |
break; |
// the CIMBinMessageSerializer. |
} |
// Returns true on success. |
case RESP_INSTANCES: |
//------------------------------------------------------------------------------ |
|
Boolean CIMInstancesResponseData::_resolveBinaryInstances( |
|
CIMInstancesResponseData* data, |
|
Array<CIMInstance>& instances) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
if (!in.getInstanceA(_instances)) |
"CIMInstancesResponseData::_resolveBinaryInstances"); |
{ |
|
_encoding &=(~RESP_ENC_BINARY); |
instances.clear(); |
in.release(); |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
"Failed to resolve binary CIMInstances!"); |
|
PEG_METHOD_EXIT(); |
while (in.more()) |
return; |
|
} |
|
break; |
|
} |
|
case RESP_OBJECTS: |
{ | { |
if (!in.getInstanceA(instances)) |
if (!in.getObjectA(_objects)) |
{ | { |
in.release(); | in.release(); |
|
_encoding &=(~RESP_ENC_BINARY); |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to remove binary instance!"); |
"Failed to resolve binary CIMObjects!"); |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return false; |
return; |
} | } |
|
break; |
|
} |
|
default: |
|
{ |
|
PEGASUS_DEBUG_ASSERT(false); |
|
} |
|
} // switch |
|
_encoding |= RESP_ENC_CIM; |
|
} // else SCMO |
|
} |
|
_encoding &=(~RESP_ENC_BINARY); |
|
// fix up the hostname and namespace for objects if defaults |
|
// were set |
|
if (_defaultHostname.size() > 0 && !_defaultNamespace.isNull()) |
|
{ |
|
completeHostNameAndNamespace(_defaultHostname, _defaultNamespace); |
} | } |
|
|
in.release(); | in.release(); |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
|
} | } |
| |
| |
|
void CIMResponseData::_deserializeObject(Uint32 idx,CIMObject& cimObject) |
//------------------------------------------------------------------------------ |
|
// Instantiates an array of CIMInstances from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstancesResponseData::_resolveXMLInstances( |
|
CIMInstancesResponseData* data, |
|
Array<CIMInstance>& instances) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
|
"CIMInstancesResponseData::_resolveXMLInstances"); |
|
|
|
instances.clear(); |
|
| |
for (Uint32 i = 0; i < data->_instancesData.size(); i++) |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
|
"CIMResponseData::_deserializeObject"); |
|
// Only start the parser when instance data is present. |
|
if (0 != _instanceData[idx].size()) |
{ | { |
CIMInstance cimInstance; | CIMInstance cimInstance; |
|
CIMClass cimClass; |
| |
// Deserialize instance: |
XmlParser parser((char*)_instanceData[idx].getData()); |
{ |
|
XmlParser parser((char*)data->_instancesData[i].getData()); |
|
| |
if (!XmlReader::getInstanceElement(parser, cimInstance)) |
if (XmlReader::getInstanceElement(parser, cimInstance)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
cimObject = CIMObject(cimInstance); |
"Failed to resolve XML instance. Creating empty instance!"); |
return; |
cimInstance = CIMInstance(); |
|
} |
|
} | } |
| |
// Deserialize path: |
if (XmlReader::getClassElement(parser, cimClass)) |
{ |
|
XmlParser parser((char*)data->_referencesData[i].getData()); |
|
CIMObjectPath cimObjectPath; |
|
|
|
if (XmlReader::getInstanceNameElement(parser, cimObjectPath)) |
|
{ | { |
if (!data->_nameSpacesData[i].isNull()) |
cimObject = CIMObject(cimClass); |
cimObjectPath.setNameSpace(data->_nameSpacesData[i]); |
return; |
|
|
if (data->_hostsData[i].size()) |
|
cimObjectPath.setHost(data->_hostsData[i]); |
|
|
|
cimInstance.setPath(cimObjectPath); |
|
} |
|
} | } |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
instances.append(cimInstance); |
"Failed to resolve XML object data, parser error!"); |
} | } |
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
|
} | } |
| |
//------------------------------------------------------------------------------ |
void CIMResponseData::_deserializeInstance(Uint32 idx,CIMInstance& cimInstance) |
// Instantiates an array of CIMInstances from an array of SCMOInstances |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstancesResponseData::_resolveSCMOInstances( |
|
CIMInstancesResponseData* data, |
|
Array<CIMInstance>& instances) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstancesResponseData::_resolveSCMOInstances"); |
"CIMResponseData::_deserializeInstance"); |
|
// Only start the parser when instance data is present. |
instances.clear(); |
if (0 != _instanceData[idx].size()) |
|
|
//--rk-->TBD: Do the actual coding here |
|
|
|
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
|
"Poorly implemented!!!\n"); |
|
try |
|
{ | { |
for (Uint32 x=0; x < data->_scmoInstances.size(); x++) |
XmlParser parser((char*)_instanceData[idx].getData()); |
|
if (XmlReader::getInstanceElement(parser, cimInstance)) |
{ | { |
/*SCMODump dmp; |
return; |
dmp.dumpSCMOInstanceKeyBindings(data->_scmoInstances[x]); |
|
dmp.dumpInstanceProperties(data->_scmoInstances[x]);*/ |
|
CIMInstance newInstance; |
|
data->_scmoInstances[x].getCIMInstance(newInstance); |
|
instances.append(newInstance); |
|
} | } |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve XML instance, parser error!"); |
} | } |
catch (CIMException& ex) |
// reset instance when parsing may not be successfull or |
{ |
// no instance is present. |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
cimInstance = CIMInstance(); |
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
|
|
PEG_METHOD_EXIT(); |
} | } |
catch (Exception& ex) |
|
|
Boolean CIMResponseData::_deserializeReference( |
|
Uint32 idx, |
|
CIMObjectPath& cimObjectPath) |
{ | { |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
// Only start the parser when reference data is present. |
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
if (0 != _referencesData[idx].size()) |
} |
|
catch (exception& ex) |
|
{ | { |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
XmlParser parser((char*)_referencesData[idx].getData()); |
"exception:\n%s\n",(const char*)ex.what()); |
if (XmlReader::getValueReferenceElement(parser, cimObjectPath)) |
|
{ |
|
if (_hostsData[idx].size()) |
|
{ |
|
cimObjectPath.setHost(_hostsData[idx]); |
} | } |
catch (...) |
if (!_nameSpacesData[idx].isNull()) |
{ | { |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
cimObjectPath.setNameSpace(_nameSpacesData[idx]); |
"Exception: UNKNOWN\n"); |
|
} | } |
data->_resolveCallback = 0; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; | return true; |
} | } |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve XML reference, parser error!"); |
| |
|
} |
|
return false; |
|
} |
| |
//----------------------------------------------------------------------------- |
Boolean CIMResponseData::_deserializeInstanceName( |
// |
Uint32 idx, |
// CIMObjectsResponseData |
CIMObjectPath& cimObjectPath) |
// |
|
//----------------------------------------------------------------------------- |
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
// Takes a binary stream of objects from a CIMBuffer and stores |
|
// it in the responsedata. |
|
// @param hasLen Indicates if the binary object stream is prepended with an |
|
// Uint32 value indicating the number of objects in the stream. |
|
//------------------------------------------------------------------------------ |
|
bool CIMObjectsResponseData::setBinaryCimObjects(CIMBuffer& in, bool hasLen) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
// Only start the parser when instance name data is present. |
"CIMObjectsResponseData::setBinaryCimObjects"); |
if (0 != _referencesData[idx].size()) |
|
|
if (hasLen) |
|
{ | { |
if (!in.getUint8A(_binaryData)) |
XmlParser parser((char*)_referencesData[idx].getData()); |
|
if (XmlReader::getInstanceNameElement(parser, cimObjectPath)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
if (_hostsData[idx].size()) |
"Failed to get binary object data!"); |
{ |
PEG_METHOD_EXIT(); |
cimObjectPath.setHost(_hostsData[idx]); |
return false; |
|
} |
|
} | } |
else |
if (!_nameSpacesData[idx].isNull()) |
{ | { |
size_t remainingDataLength = in.capacity() - in.size(); |
cimObjectPath.setNameSpace(_nameSpacesData[idx]); |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
|
} | } |
|
|
_resolveCallback = _resolveBinaryObjects; |
|
_binaryEncoding = true; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; | return true; |
}; |
} |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve XML instance name, parser error!"); |
|
|
|
} |
|
return false; |
|
} |
| |
bool CIMObjectsResponseData::setXmlCimObjects(CIMBuffer& in) |
void CIMResponseData::_resolveXmlToCIM() |
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMObjectsResponseData::setXmlCimObjects"); |
"CIMResponseData::_resolveXmlToCIM"); |
|
|
Uint32 count; |
|
| |
if (!in.getUint32(count)) |
switch (_dataType) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
// Xml encoding for instance names and object paths not used |
"Failed to get XML object data (number of objects)!"); |
case RESP_OBJECTPATHS: |
PEG_METHOD_EXIT(); |
case RESP_INSTNAMES: |
return false; |
{ |
|
break; |
} | } |
|
case RESP_INSTANCE: |
for (Uint32 i = 0; i < count; i++) |
|
{ | { |
Array<Sint8> obj; |
CIMInstance cimInstance; |
Array<Sint8> ref; |
CIMObjectPath cimObjectPath; |
CIMNamespaceName ns; |
|
String host; |
|
| |
if (!in.getSint8A(obj)) |
_deserializeInstance(0,cimInstance); |
|
if (_deserializeReference(0,cimObjectPath)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
cimInstance.setPath(cimObjectPath); |
"Failed to get XML object data (object)!"); |
// A single CIMInstance has to have an objectpath. |
PEG_METHOD_EXIT(); |
// So only add it when an objectpath exists. |
return false; |
_instances.append(cimInstance); |
|
} |
|
break; |
} | } |
|
case RESP_INSTANCES: |
|
{ |
|
for (Uint32 i = 0; i < _instanceData.size(); i++) |
|
{ |
|
CIMInstance cimInstance; |
|
CIMObjectPath cimObjectPath; |
| |
if (!in.getSint8A(ref)) |
_deserializeInstance(i,cimInstance); |
|
if (_deserializeInstanceName(i,cimObjectPath)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
cimInstance.setPath(cimObjectPath); |
"Failed to get XML object data (reference)!"); |
} |
PEG_METHOD_EXIT(); |
// enumarate instances can be without name |
return false; |
_instances.append(cimInstance); |
|
} |
|
break; |
} | } |
|
case RESP_OBJECTS: |
|
{ |
|
for (Uint32 i=0, n=_instanceData.size(); i<n; i++) |
|
{ |
|
CIMObject cimObject; |
|
CIMObjectPath cimObjectPath; |
| |
if (!in.getString(host)) |
_deserializeObject(i,cimObject); |
|
if (_deserializeReference(i,cimObjectPath)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
cimObject.setPath(cimObjectPath); |
"Failed to get XML object data (host)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
_objects.append(cimObject); |
if (!in.getNamespaceName(ns)) |
} |
|
break; |
|
} |
|
default: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
PEGASUS_ASSERT(false); |
"Failed to get XML object data (namespace)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
|
_cimObjectsData.append(obj); |
|
_referencesData.append(ref); |
|
_hostsData.append(host); |
|
_nameSpacesData.append(ns); |
|
} | } |
|
// Xml was resolved, release Xml content now |
_resolveCallback = _resolveXMLObjects; |
_referencesData.clear(); |
_binaryEncoding = false; |
_hostsData.clear(); |
|
_nameSpacesData.clear(); |
|
_instanceData.clear(); |
|
// remove Xml Encoding flag |
|
_encoding &=(~RESP_ENC_XML); |
|
// add CIM Encoding flag |
|
_encoding |=RESP_ENC_CIM; |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
|
} | } |
| |
//------------------------------------------------------------------------------ |
void CIMResponseData::_resolveXmlToSCMO() |
// Encodes the array of CIMObject representation contained in the current |
|
// CIMResponseData object in binary response message format. |
|
// This code corresponds to method _resolveBinaryObjects, which is used |
|
// revert a binary object array representation back into an array of |
|
// CIMObject. |
|
//------------------------------------------------------------------------------ |
|
void CIMObjectsResponseData::encodeBinaryResponse(CIMBuffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMObjectsResponseData::encodeBinaryResponse"); |
"CIMResponseData::_resolveXmlToSCMO"); |
|
// Not optimal, can probably be improved |
|
// but on the other hand, since using the binary format this case should |
|
// actually not ever happen. |
|
_resolveXmlToCIM(); |
|
_resolveCIMToSCMO(); |
| |
if (_resolveCallback && _binaryEncoding) |
|
{ |
|
const Array<Uint8>& data = _binaryData; |
|
out.putBytes(data.getData(), data.size()); |
|
} |
|
else |
|
{ |
|
out.putObjectA(_cimObjects); |
|
} |
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
| |
//------------------------------------------------------------------------------ |
void CIMResponseData::_resolveSCMOToCIM() |
// Encodes the array of CIMObject representation contained in the current |
|
// CIMResponseData object in xml response message format. |
|
// This code corresponds to method _resolveXmlObjects, which is used |
|
// revert a CIM-XML object array representation back into an array of |
|
// CIMObject. |
|
//------------------------------------------------------------------------------ |
|
void CIMObjectsResponseData::encodeXmlResponse(Buffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMObjectsResponseData::encodeXmlResponse"); |
"CIMResponseData::_resolveSCMOToCIM"); |
|
switch(_dataType) |
if (_resolveCallback && !_binaryEncoding) |
|
{ | { |
const Array<ArraySint8>& a = _cimObjectsData; |
case RESP_INSTNAMES: |
const Array<ArraySint8>& b = _referencesData; |
case RESP_OBJECTPATHS: |
|
|
for (Uint32 i = 0, n = a.size(); i < n; i++) |
|
{ | { |
out << STRLIT("<VALUE.OBJECTWITHPATH>\n"); |
for (Uint32 x=0, n=_scmoInstances.size(); x < n; x++) |
out.append((char*)b[i].getData(), b[i].size() - 1); |
{ |
out.append((char*)a[i].getData(), a[i].size() - 1); |
CIMObjectPath newObjectPath; |
out << STRLIT("</VALUE.OBJECTWITHPATH>\n"); |
_scmoInstances[x].getCIMObjectPath(newObjectPath); |
|
_instanceNames.append(newObjectPath); |
} | } |
|
break; |
} | } |
else |
case RESP_INSTANCE: |
{ | { |
for (Uint32 i = 0; i < _cimObjects.size(); i++) |
if (_scmoInstances.size() > 0) |
{ | { |
XmlWriter::appendValueObjectWithPathElement(out, _cimObjects[i]); |
CIMInstance newInstance; |
|
_scmoInstances[0].getCIMInstance(newInstance); |
|
_instances.append(newInstance); |
} | } |
|
break; |
} | } |
PEG_METHOD_EXIT(); |
case RESP_INSTANCES: |
|
{ |
|
for (Uint32 x=0, n=_scmoInstances.size(); x < n; x++) |
|
{ |
|
CIMInstance newInstance; |
|
_scmoInstances[x].getCIMInstance(newInstance); |
|
_instances.append(newInstance); |
} | } |
|
break; |
//------------------------------------------------------------------------------ |
} |
// Instantiates an array of CIMObjects from a binary representation created by |
case RESP_OBJECTS: |
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMObjectsResponseData::_resolveBinaryObjects( |
|
CIMObjectsResponseData* data, |
|
Array<CIMObject>& cimObjects) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
for (Uint32 x=0, n=_scmoInstances.size(); x < n; x++) |
"CIMObjectsResponseData::_resolveBinaryObjects"); |
|
|
|
cimObjects.clear(); |
|
|
|
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
|
|
|
while (in.more()) |
|
{ | { |
if (!in.getObjectA(cimObjects)) |
CIMInstance newInstance; |
|
_scmoInstances[x].getCIMInstance(newInstance); |
|
_objects.append(CIMObject(newInstance)); |
|
} |
|
break; |
|
} |
|
default: |
{ | { |
in.release(); |
PEGASUS_DEBUG_ASSERT(false); |
|
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve binary data!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
} | } |
|
_scmoInstances.clear(); |
|
// remove CIM Encoding flag |
|
_encoding &=(~RESP_ENC_SCMO); |
|
// add SCMO Encoding flag |
|
_encoding |=RESP_ENC_CIM; |
| |
in.release(); |
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
|
} | } |
| |
//------------------------------------------------------------------------------ |
void CIMResponseData::_resolveCIMToSCMO() |
// Instantiates an array of CIMObjects from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMObjectsResponseData::_resolveXMLObjects( |
|
CIMObjectsResponseData* data, |
|
Array<CIMObject>& cimObjects) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMObjectsResponseData::_resolveXMLObjects"); |
"CIMResponseData::_resolveCIMToSCMO"); |
|
CString nsCString=_defaultNamespace.getString().getCString(); |
cimObjects.clear(); |
const char* _defNamespace = nsCString; |
|
Uint32 _defNamespaceLen; |
for (Uint32 i=0, n=data->_cimObjectsData.size(); i<n; i++) |
if (_defaultNamespace.isNull()) |
{ | { |
CIMObject cimObject; |
_defNamespaceLen=0; |
|
} |
// Deserialize Objects: |
else |
{ | { |
XmlParser parser((char*)data->_cimObjectsData[i].getData()); |
_defNamespaceLen=strlen(_defNamespace); |
|
} |
CIMInstance cimInstance; |
switch (_dataType) |
CIMClass cimClass; |
|
|
|
if (XmlReader::getInstanceElement(parser, cimInstance)) |
|
{ | { |
cimObject = CIMObject(cimInstance); |
case RESP_INSTNAMES: |
|
{ |
|
for (Uint32 i=0,n=_instanceNames.size();i<n;i++) |
|
{ |
|
SCMOInstance addme( |
|
_instanceNames[i], |
|
_defNamespace, |
|
_defNamespaceLen); |
|
_scmoInstances.append(addme); |
|
} |
|
_instanceNames.clear(); |
|
break; |
} | } |
else if (XmlReader::getClassElement(parser, cimClass)) |
case RESP_INSTANCE: |
{ | { |
cimObject = CIMObject(cimClass); |
if (_instances.size() > 0) |
|
{ |
|
SCMOInstance addme( |
|
_instances[0], |
|
_defNamespace, |
|
_defNamespaceLen); |
|
_scmoInstances.clear(); |
|
_scmoInstances.append(addme); |
|
_instances.clear(); |
} | } |
else |
break; |
|
} |
|
case RESP_INSTANCES: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
for (Uint32 i=0,n=_instances.size();i<n;i++) |
"Failed to get XML object data!"); |
{ |
|
SCMOInstance addme( |
|
_instances[i], |
|
_defNamespace, |
|
_defNamespaceLen); |
|
_scmoInstances.append(addme); |
} | } |
|
_instances.clear(); |
|
break; |
} | } |
|
case RESP_OBJECTS: |
// Deserialize paths: |
|
{ | { |
XmlParser parser((char*)data->_referencesData[i].getData()); |
for (Uint32 i=0,n=_objects.size();i<n;i++) |
CIMObjectPath cimObjectPath; |
{ |
|
SCMOInstance addme( |
if (XmlReader::getValueReferenceElement(parser, cimObjectPath)) |
_objects[i], |
|
_defNamespace, |
|
_defNamespaceLen); |
|
_scmoInstances.append(addme); |
|
} |
|
_objects.clear(); |
|
break; |
|
} |
|
case RESP_OBJECTPATHS: |
|
{ |
|
for (Uint32 i=0,n=_instanceNames.size();i<n;i++) |
|
{ |
|
SCMOInstance addme( |
|
_instanceNames[i], |
|
_defNamespace, |
|
_defNamespaceLen); |
|
if (_isClassOperation) |
{ | { |
if (!data->_nameSpacesData[i].isNull()) |
addme.setIsClassOnly(true); |
cimObjectPath.setNameSpace(data->_nameSpacesData[i]); |
} |
|
_scmoInstances.append(addme); |
|
} |
|
_instanceNames.clear(); |
|
break; |
|
} |
|
default: |
|
{ |
|
PEGASUS_DEBUG_ASSERT(false); |
|
} |
|
} |
| |
if (data->_hostsData[i].size()) |
// remove CIM Encoding flag |
cimObjectPath.setHost(data->_hostsData[i]); |
_encoding &=(~RESP_ENC_CIM); |
|
// add SCMO Encoding flag |
|
_encoding |=RESP_ENC_SCMO; |
| |
cimObject.setPath(cimObjectPath); |
PEG_METHOD_EXIT(); |
} | } |
|
|
|
/** |
|
* Validate the magic object for this CIMResponseData. This |
|
* compiles only in debug mode and can be use to validate the |
|
* CIMResponseData object |
|
* |
|
* @return Boolean True if valid object. |
|
*/ |
|
Boolean CIMResponseData::valid() const |
|
{ |
|
return _magic; |
} | } |
| |
cimObjects.append(cimObject); |
void CIMResponseData::setRequestProperties( |
|
const Boolean includeQualifiers, |
|
const Boolean includeClassOrigin, |
|
const CIMPropertyList& propertyList) |
|
{ |
|
_includeQualifiers = includeQualifiers; |
|
_includeClassOrigin = includeClassOrigin; |
|
_propertyList = propertyList; |
} | } |
| |
PEG_METHOD_EXIT(); |
void CIMResponseData::setIsClassOperation(Boolean b) |
return true; |
{ |
|
_isClassOperation = b; |
} | } |
| |
|
//// KS_TODO Remove. Diagnostic Display |
|
void CIMResponseData::traceResponseData() |
|
{ |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL3, |
|
"CIMResponseData::traceResponseData(encoding=%X,dataType=%X " |
|
" size=%u C++instNamecount=%u c++Instances=%u c++Objects=%u " |
|
"scomInstances=%u XMLInstData=%u binaryData=%u " |
|
"xmlref=%u xmlinst=%u, xmlhost=%u xmlns=%u", |
|
_encoding,_dataType, _size, |
|
_instanceNames.size(),_instances.size(), _objects.size(), |
|
_scmoInstances.size(),_instanceData.size(),_binaryData.size(), |
|
_referencesData.size(), _instanceData.size(), _hostsData.size(), |
|
_nameSpacesData.size() )); |
|
} |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |