version 1.3.4.2, 2012/02/15 17:47:07
|
version 1.10, 2014/11/13 01:47:06
|
|
|
// | // |
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// |
// | // |
|
// This code implements part of PEP#348 - The CMPI infrastructure using SCMO |
|
// (Single Chunk Memory Objects). |
|
// The design document can be found on the OpenPegasus website openpegasus.org |
|
// at https://collaboration.opengroup.org/pegasus/pp/documents/21210/PEP_348.pdf |
|
// |
|
// This file defines the SCMOInstance interfaces. The implementation of |
|
// these methods is in SCMO.cpp |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#ifndef _SCMOINSTANCE_H_ | #ifndef _SCMOINSTANCE_H_ |
|
|
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
PEGASUS_USING_STD; |
|
|
#define PEGASUS_SCMB_INSTANCE_MAGIC 0xD00D1234 | #define PEGASUS_SCMB_INSTANCE_MAGIC 0xD00D1234 |
| |
class PEGASUS_COMMON_LINKAGE SCMOInstance | class PEGASUS_COMMON_LINKAGE SCMOInstance |
|
|
* instance. The TOINSTANCE flavor is ignored. | * instance. The TOINSTANCE flavor is ignored. |
* @param includeClassOrigin A Boolean indicating whether ClassOrigin | * @param includeClassOrigin A Boolean indicating whether ClassOrigin |
* attributes are to be added to the instance. | * attributes are to be added to the instance. |
* @param propertyList Is an NULL terminated array of char* to property |
|
* names defining the properties that are included in the created instance. |
|
* If the propertyList is NULL, all properties are included to the instance. |
|
* If the propertyList is empty, no properties are added. |
|
* | * |
* Note that this function does NOT generate an error if a property name | * Note that this function does NOT generate an error if a property name |
* is supplied that is NOT in the class; | * is supplied that is NOT in the class; |
|
|
SCMOInstance( | SCMOInstance( |
SCMOClass& baseClass, | SCMOClass& baseClass, |
Boolean includeQualifiers, | Boolean includeQualifiers, |
Boolean includeClassOrigin, |
Boolean includeClassOrigin); |
const char** propertyList); |
|
| |
/** | /** |
* Builds a SCMOInstance from the given SCMOClass and copies all | * Builds a SCMOInstance from the given SCMOClass and copies all |
|
|
Boolean& isArray, | Boolean& isArray, |
Uint32& size ) const; | Uint32& size ) const; |
| |
void getSCMBValuePropertyAt( |
// KS_FUTURE removed this as not used. Compiles without it |
Uint32 pos, |
//// void getSCMBValuePropertyAt( |
SCMBValue** value, |
//// Uint32 pos, |
const char ** valueBase, |
//// SCMBValue** value, |
SCMBClassProperty ** propDef, |
//// const char ** valueBase, |
const char ** classBase) const; |
//// SCMBClassProperty ** propDef, |
|
//// const char ** classBase) const; |
| |
/** | /** |
* Gets the type and value of the named property. | * Gets the type and value of the named property. |
|
|
| |
/** | /** |
* Set/replace a property in the instance. | * Set/replace a property in the instance. |
* If the class origin is specified, it is honored at identifying |
* If the class origin is specified, it is honored when the |
* the property within the instance. |
* property is identified within the instance. |
|
* |
* Note: Only properties which are already part of the instance/class can | * Note: Only properties which are already part of the instance/class can |
* be set/replaced. |
* be set/replaced except in for special case where the flag |
|
* lags.noClassForInstance is set when the instance is created. |
|
* If the class is not found in the repository, the instance is |
|
* are marked as noClassForInstance and properties are set in |
|
* the UserDefined properties area. |
* @param name The name of the property to be set. | * @param name The name of the property to be set. |
* @param type The CIMType of the property |
* @param theType The CIMType of the property |
* @param value A pointer to the value to be set at the named property. | * @param value A pointer to the value to be set at the named property. |
* The value has to be in a SCMBUnion. |
* The value must be in a SCMBUnion. |
* The value is copied into the instance | * The value is copied into the instance |
* If the value == NULL, a null value is assumed. | * If the value == NULL, a null value is assumed. |
* If the value is an array, the value array has to be | * If the value is an array, the value array has to be |
|
|
* If the value is type of CIMTYPE_STRING, | * If the value is type of CIMTYPE_STRING, |
* the string is referenced by the structure | * the string is referenced by the structure |
* SCMBUnion.extString: | * SCMBUnion.extString: |
* pchar contains the absolut pointer to the string |
* pchar contains the absolute pointer to |
* length contains the size of the string |
* the string length contains the size of |
|
* the string |
* without trailing '\0'. | * without trailing '\0'. |
* @param isArray Indicate that the value is an array. Default false. | * @param isArray Indicate that the value is an array. Default false. |
* @param size Returns the size of the array. If not an array this | * @param size Returns the size of the array. If not an array this |
* this parameter is ignorer. Default 0. |
* this parameter is ignored. Default 0. |
* @param origin The class originality of the property. | * @param origin The class originality of the property. |
* If NULL, then it is ignorred. Default NULL. |
* If NULL, then it is ignored. Default NULL. |
* @return SCMO_OK | * @return SCMO_OK |
* SCMO_NOT_SAME_ORIGIN : The property name was found, but | * SCMO_NOT_SAME_ORIGIN : The property name was found, but |
* the origin was not the same. | * the origin was not the same. |
|
|
*/ | */ |
SCMO_RC setPropertyWithOrigin( | SCMO_RC setPropertyWithOrigin( |
const char* name, | const char* name, |
CIMType type, |
CIMType theType, |
const SCMBUnion* value, | const SCMBUnion* value, |
Boolean isArray=false, | Boolean isArray=false, |
Uint32 size = 0, | Uint32 size = 0, |
|
|
*/ | */ |
SCMO_RC getPropertyNodeIndex(const char* name, Uint32& pos) const; | SCMO_RC getPropertyNodeIndex(const char* name, Uint32& pos) const; |
| |
|
// KS_FUTURE confirm that the following is used in OpenPegasus |
|
// Apprently never referenced within any of OpenPegasus code |
/** | /** |
* Set/replace a property in the instance at node index. | * Set/replace a property in the instance at node index. |
* @param index The node index. | * @param index The node index. |
|
|
/** | /** |
* Determines if the SCMOInstance does not contain any property information. | * Determines if the SCMOInstance does not contain any property information. |
* Maybe only the class name and/or name space are available. | * Maybe only the class name and/or name space are available. |
* @return True if the SCMOInstacne is empty, false otherwise. |
* @return True if the SCMOInstance is empty, false otherwise. |
*/ | */ |
Boolean isEmpty( ) const {return (inst.hdr->theClass.ptr->isEmpty()); }; |
Boolean isEmpty( ) const; |
| |
/** | /** |
* Determines whether the instance is used as a class container. | * Determines whether the instance is used as a class container. |
|
|
void setHostName(const char* hostName); | void setHostName(const char* hostName); |
| |
/** | /** |
* Sets the provided host name unchecked at the instance. |
|
* @param hostName The host name as UTF8. |
|
* @param len The strlen of the host name. |
|
*/ |
|
void setHostName_l(const char* hostName, Uint32 len); |
|
|
|
/** |
|
* Get the host name of the instance. The caller has to make a copy ! | * Get the host name of the instance. The caller has to make a copy ! |
* @return The host name as UTF8. | * @return The host name as UTF8. |
*/ | */ |
|
|
const char* getNameSpace_l(Uint32 & length) const; | const char* getNameSpace_l(Uint32 & length) const; |
| |
/** | /** |
|
* If hostname or namespace of the SCMOInstance are NULL or empty string, |
|
* replace them with the given input. |
|
* @param hn The host name to apply to the SCMOInstance. |
|
* @param hnLen The length of the hostname in byte without closing zero. |
|
* @param ns The namespace name to apply to the SCMOInstance. |
|
* @param nsLen The length of the hostname in byte without closing zero. |
|
*/ |
|
void completeHostNameAndNamespace( |
|
const char* hn, |
|
Uint32 hnLen, |
|
const char* ns, |
|
Uint32 nsLen); |
|
|
|
/** |
* Is the name space or class name of the instance the origianl values | * Is the name space or class name of the instance the origianl values |
* set by the used SCMOClass. | * set by the used SCMOClass. |
* The class name and/or name space may differ with the associated class. | * The class name and/or name space may differ with the associated class. |
|
|
return inst.hdr->flags.isCompromised; | return inst.hdr->flags.isCompromised; |
}; | }; |
| |
|
/** |
|
returns true if there is no class defined for this instance. |
|
The flag is set when the SCMO instance is created and the |
|
repository returns no class. |
|
*/ |
|
Boolean noClassForInstance() const |
|
{ |
|
return inst.hdr->flags.noClassForInstance; |
|
}; |
| |
/** | /** |
* Mark the instance as a non validated instance. | * Mark the instance as a non validated instance. |
|
|
}; | }; |
| |
/** | /** |
|
Sets the flag indicating that there is no class for this |
|
instance. This property is used for Instances that are |
|
created where there is no class in the repository. |
|
*/ |
|
void markNoClassForInstance(Boolean x) |
|
{ |
|
inst.hdr->flags.noClassForInstance = x; |
|
}; |
|
|
|
/** |
* To indicate the export processing ( eg. XMLWriter ) | * To indicate the export processing ( eg. XMLWriter ) |
* to include qualifiers for this instance. | * to include qualifiers for this instance. |
*/ | */ |
|
|
{ | { |
if (inst.hdr->refCount.decAndTestIfZero()) | if (inst.hdr->refCount.decAndTestIfZero()) |
{ | { |
// All external references has to be destroyed. |
// All external references have to be destroyed. |
_destroyExternalReferences(); | _destroyExternalReferences(); |
// The class has also be dereferenced. | // The class has also be dereferenced. |
delete inst.hdr->theClass.ptr; | delete inst.hdr->theClass.ptr; |
|
|
_clone(); | _clone(); |
if (oldRef->refCount.decAndTestIfZero()) | if (oldRef->refCount.decAndTestIfZero()) |
{ | { |
// All external references has to be destroyed. |
// All external references have to be destroyed. |
_destroyExternalReferencesInternal(oldMgmt); | _destroyExternalReferencesInternal(oldMgmt); |
// The class has also be dereferenced. | // The class has also be dereferenced. |
delete oldRef->theClass.ptr; | delete oldRef->theClass.ptr; |
|
|
| |
void _setCIMInstance(const CIMInstance& cimInstance); | void _setCIMInstance(const CIMInstance& cimInstance); |
| |
|
// Internal but used by friend class SCMOXmlWriter.cpp |
|
// This function accounts for user-defined and class-defined properties |
void _getPropertyAt( | void _getPropertyAt( |
Uint32 pos, | Uint32 pos, |
SCMBValue** value, | SCMBValue** value, |
|
|
char* elementBase); | char* elementBase); |
/** | /** |
* Set a SCMO user defined key binding using the class CIM type tolerating | * Set a SCMO user defined key binding using the class CIM type tolerating |
* CIM key binding types converted to CIM types by fuction |
* CIM key binding types converted to CIM types by function |
* _CIMTypeFromKeyBindingType(). | * _CIMTypeFromKeyBindingType(). |
* | * |
* @parm classType The type of the key binding in the class definition | * @parm classType The type of the key binding in the class definition |
|
|
SCMBKeyBindingValue& scmoKBV | SCMBKeyBindingValue& scmoKBV |
); | ); |
| |
|
// Functions to support the use of user defined properties |
|
/* |
|
Get the node for a user defined property. |
|
@return node of the property and SCMO_OK or an error |
|
SCMO_NOT_FOUND indicating that the property cannot be |
|
found as a user-defined property. |
|
*/ |
|
SCMO_RC _getUserPropertyNodeIndex(Uint32& node, const char* name) const; |
|
|
|
/* |
|
get the Instance SCMBUserPropertyElement for the defined node index. |
|
*/ |
|
SCMBUserPropertyElement* |
|
_getUserDefinedPropertyElementAt(Uint32 index) const; |
|
|
|
void _setPropertyInUserDefinedElement( |
|
SCMBUserPropertyElement* ptrNewElement, |
|
CIMType theType, |
|
const SCMBUnion* pinVal, |
|
Boolean isArray, |
|
Uint32 size); |
|
/** |
|
Creates a new user-defined property element, chains it to |
|
the existing user-defined property chain, and populate it |
|
with name, type, isArray. isSet = false. |
|
@return pointer to new SCMBUserPropertyElement |
|
*/ |
|
SCMBUserPropertyElement* _createNewUserDefinedProperty( |
|
const char * name, |
|
Uint32 nameLen, |
|
CIMType theType); |
|
|
|
/* |
|
Returns true if the Property is in the set of |
|
properties defined in an including class |
|
*/ |
|
Boolean _isClassDefinedProperty(Uint32 node) const; |
|
|
|
SCMBValue& _getSCMBValueForNode(Uint32 node) const; |
| |
|
/* Definition of inst. Pointer to: |
|
SCMBInstance_Manin |
|
SCMBMgmt_Header |
|
or generic base pointer. |
|
*/ |
union{ | union{ |
// To access the instance main structure | // To access the instance main structure |
SCMBInstance_Main *hdr; | SCMBInstance_Main *hdr; |
|
|
friend class SCMOStreamer; | friend class SCMOStreamer; |
}; | }; |
| |
|
|
|
inline SCMBValue& SCMOInstance::_getSCMBValueForNode(Uint32 node) const |
|
{ |
|
if (_isClassDefinedProperty(node)) |
|
{ |
|
SCMBValue *theInstPropNodeArray = |
|
(SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]); |
|
|
|
return theInstPropNodeArray[node]; |
|
} |
|
|
|
SCMBUserPropertyElement* pElement = |
|
_getUserDefinedPropertyElementAt(node); |
|
|
|
return pElement->value; |
|
} |
|
|
|
|
|
// KS_TODO clarify this test since our rule is more explicit |
|
// We cannot have both user-defined and class-defined properties so this |
|
// could be a more concrete tests. |
|
inline Boolean SCMOInstance::_isClassDefinedProperty(Uint32 node) const |
|
{ |
|
return (node < inst.hdr->numberProperties); |
|
} |
|
|
|
// This internal function used by SCMOXmlWriter.cpp |
|
// It is inline because it is called only once in the CIMServer. |
inline void SCMOInstance::_getPropertyAt( | inline void SCMOInstance::_getPropertyAt( |
Uint32 pos, | Uint32 pos, |
SCMBValue** value, | SCMBValue** value, |
const char ** valueBase, | const char ** valueBase, |
SCMBClassProperty ** propDef) const |
SCMBClassProperty ** propertyDef) const |
|
{ |
|
if (_isClassDefinedProperty(pos)) |
{ | { |
SCMBValue* theInstPropNodeArray = | SCMBValue* theInstPropNodeArray = |
(SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]); | (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]); |
| |
// create a pointer to property node array of the class. | // create a pointer to property node array of the class. |
Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->propertySet.nodeArray.start; |
Uint64 idx = |
|
inst.hdr->theClass.ptr->cls.hdr->propertySet.nodeArray.start; |
SCMBClassPropertyNode* theClassPropNodeArray = | SCMBClassPropertyNode* theClassPropNodeArray = |
(SCMBClassPropertyNode*)&(inst.hdr->theClass.ptr->cls.base)[idx]; | (SCMBClassPropertyNode*)&(inst.hdr->theClass.ptr->cls.base)[idx]; |
| |
// return the absolute pointer to the property definition | // return the absolute pointer to the property definition |
*propDef= &(theClassPropNodeArray[pos].theProperty); |
*propertyDef = &(theClassPropNodeArray[pos].theProperty); |
| |
// need check if property set or not, if not set use the default value | // need check if property set or not, if not set use the default value |
if (theInstPropNodeArray[pos].flags.isSet) | if (theInstPropNodeArray[pos].flags.isSet) |
|
|
*valueBase = inst.hdr->theClass.ptr->cls.base; | *valueBase = inst.hdr->theClass.ptr->cls.base; |
} | } |
} | } |
|
else // User-defined property |
inline void SCMOInstance::getSCMBValuePropertyAt( |
|
Uint32 pos, |
|
SCMBValue** value, |
|
const char ** valueBase, |
|
SCMBClassProperty ** propDef, |
|
const char ** propDefBase) const |
|
{ | { |
_getPropertyAt(pos,value,valueBase,propDef); |
// KS_TODO mostly same code as _getPropertyAtNodeIndex |
|
SCMBUserPropertyElement* pElement = |
|
_getUserDefinedPropertyElementAt(pos); |
| |
*propDefBase = inst.hdr->theClass.ptr->cls.base; |
PEGASUS_ASSERT(pElement != 0); |
|
|
|
*value = &(pElement->value); |
|
// KS_TODO do we have to deal with isSet == false here. Probably |
|
// no but confirm with Assert. |
|
*valueBase = inst.base; |
|
} |
|
} |
|
|
|
inline Uint32 SCMOInstance::getPropertyCount() const |
|
{ |
|
return(inst.hdr->numberProperties + inst.hdr->numberUserProperties); |
} | } |
| |
|
// KS_FUTURE Remove this completely from code since apparently not used. |
|
////// Apparently never used. |
|
////inline void SCMOInstance::getSCMBValuePropertyAt( |
|
//// Uint32 pos, |
|
//// SCMBValue** value, |
|
//// const char ** valueBase, |
|
//// SCMBClassProperty ** propDef, |
|
//// const char ** propDefBase) const |
|
////{ |
|
//// _getPropertyAt(pos,value,valueBase,propDef); |
|
//// |
|
//// *propDefBase = inst.hdr->theClass.ptr->cls.base; |
|
////} |
|
|
inline SCMO_RC SCMOInstance::getKeyBindingAtUnresolved( | inline SCMO_RC SCMOInstance::getKeyBindingAtUnresolved( |
Uint32 node, | Uint32 node, |
const char** pname, | const char** pname, |
|
|
return rc; | return rc; |
} | } |
| |
|
inline Boolean SCMOInstance::isEmpty( ) const |
|
{ |
|
if (noClassForInstance()) |
|
{ |
|
// KS_TODO need another test for empty. Number properties |
|
// != 0 might work but that would disallow an empty embedded |
|
// instance. |
|
return false; |
|
} |
|
else |
|
{ |
|
return (inst.hdr->theClass.ptr->isEmpty()); |
|
} |
|
} |
|
|
| |
| |
#define PEGASUS_ARRAY_T SCMOInstance | #define PEGASUS_ARRAY_T SCMOInstance |