(file) Return to SCMO.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/SCMO.cpp between version 1.2.2.38 and 1.26

version 1.2.2.38, 2009/10/13 09:36:35 version 1.26, 2014/09/30 11:04:31
Line 27 
Line 27 
 // //
 ////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
 // //
   // 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
   //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/SCMO.h> #include <Pegasus/Common/SCMO.h>
Line 42 
Line 47 
 #include <Pegasus/Common/CIMNameCast.h> #include <Pegasus/Common/CIMNameCast.h>
 #include <Pegasus/Common/CommonUTF.h> #include <Pegasus/Common/CommonUTF.h>
 #include <Pegasus/Common/StrLit.h> #include <Pegasus/Common/StrLit.h>
   #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/XmlWriter.h> #include <Pegasus/Common/XmlWriter.h>
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
 #include <Pegasus/Common/StringConversion.h> #include <Pegasus/Common/StringConversion.h>
 #include <Pegasus/Common/ArrayIterator.h> #include <Pegasus/Common/ArrayIterator.h>
 #include <Pegasus/Common/PegasusAssert.h> #include <Pegasus/Common/PegasusAssert.h>
   #include <Pegasus/Common/CIMValueRep.h>
   
   # if defined PEGASUS_OS_ZOS
 #include <strings.h> #include <strings.h>
   # else
   #  include <string.h>
   # endif
  
 #ifdef PEGASUS_OS_ZOS #ifdef PEGASUS_OS_ZOS
   #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>   #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>
Line 76 
Line 88 
  */  */
 #define NULLSTR(x) ((x) == 0 ? "" : (x)) #define NULLSTR(x) ((x) == 0 ? "" : (x))
  
 #define NEWCIMSTR(ptr,base) \  
       ((ptr).length == 0 ?  \  
       (String()) :           \  
       (String(&(base)[(ptr).start],((ptr).length)-1)))  
   
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 #define PEGASUS_ARRAY_T SCMOInstance #define PEGASUS_ARRAY_T SCMOInstance
 # include "ArrayImpl.h" # include "ArrayImpl.h"
 #undef PEGASUS_ARRAY_T #undef PEGASUS_ARRAY_T
  
   // KS_FUTURE bug 9930 this is not really complete list of all qualifiers with
   // latest  CIM_Schemas. At least struct and reference should be in this list.
 const StrLit SCMOClass::_qualifierNameStrLit[72] = const StrLit SCMOClass::_qualifierNameStrLit[72] =
 { {
     STRLIT(""),     STRLIT(""),
Line 167 
Line 175 
 #define _NUM_QUALIFIER_NAMES \ #define _NUM_QUALIFIER_NAMES \
            (sizeof(_qualifierNameStrLit)/sizeof(_qualifierNameStrLit[0]))            (sizeof(_qualifierNameStrLit)/sizeof(_qualifierNameStrLit[0]))
  
   
 /***************************************************************************** /*****************************************************************************
  * Internal inline functions.   * The static declaration of the common SCMO memory functions.
  *****************************************************************************/  *****************************************************************************/
  
 inline SCMOClass* _getSCMOClass(  static Uint64 _getFreeSpace(
     const CIMObjectPath& theCIMObj,      SCMBDataPtr& ptr,
     const char* altNS,      Uint32 size,
     Uint64 altNSlength)      SCMBMgmt_Header** pmem);
 {  
     SCMOClass* theClass=0;  
  
     if (theCIMObj.getClassName().isNull())  static void _setString(
     {      const String& theString,
         return 0;      SCMBDataPtr& ptr,
     }      SCMBMgmt_Header** pmem);
  
     if (theCIMObj.getNameSpace().isNull())  static void _setBinary(
     {      const void* theBuffer,
         // the name space of the object path is empty,      Uint32 bufferSize,
         // use alternative name space.      SCMBDataPtr& ptr,
         CString clsName = theCIMObj.getClassName().getString().getCString();      SCMBMgmt_Header** pmem);
  
         SCMOClassCache* theCache = SCMOClassCache::getInstance();  
         theClass = theCache->getSCMOClass(  
             altNS,  
             altNSlength,  
             (const char*)clsName,  
             strlen(clsName));  
  
   
   /*****************************************************************************
    * Internal inline functions.
    *****************************************************************************/
   
   inline String _newCimString(const SCMBDataPtr & ptr, const char * base)
   {
       if (ptr.size > 0)
       {
           return String(&(base[ptr.start]),ptr.size-1);
     }     }
     else     else
     {     {
         CString nameSpace = theCIMObj.getNameSpace().getString().getCString();          return String();
         CString clsName = theCIMObj.getClassName().getString().getCString();  
   
         SCMOClassCache* theCache = SCMOClassCache::getInstance();  
         theClass = theCache->getSCMOClass(  
             (const char*)nameSpace,  
             strlen(nameSpace),  
             (const char*)clsName,  
             strlen(clsName));  
     }     }
   
     return theClass;  
 } }
  
 inline void _deleteArrayExtReference( inline void _deleteArrayExtReference(
Line 220 
Line 221 
     SCMBUnion* ptr;     SCMBUnion* ptr;
     // if the array was already set,     // if the array was already set,
     // the previous references has to be deleted     // the previous references has to be deleted
     if(theArray.length != 0)      if(theArray.size != 0)
     {     {
         Uint32 oldArraySize=(theArray.length/sizeof(SCMBUnion));          Uint32 oldArraySize=(theArray.size/sizeof(SCMBUnion));
  
         ptr = (SCMBUnion*)&(((char*)*pmem)[theArray.start]);         ptr = (SCMBUnion*)&(((char*)*pmem)[theArray.start]);
         for (Uint32 i = 0 ; i < oldArraySize ; i++)         for (Uint32 i = 0 ; i < oldArraySize ; i++)
         {         {
             delete ptr[i].extRefPtr;             delete ptr[i].extRefPtr;
               ptr[i].extRefPtr = 0;
         }         }
     }     }
 } }
  
 inline void _copyArrayExtReference(  static void _deleteExternalReferenceInternal(
     SCMBDataPtr& theArray,      SCMBMgmt_Header* memHdr, SCMOInstance *extRefPtr)
     SCMBMgmt_Header** pmem )  
 { {
     SCMBUnion* ptr;      Uint32 nuExtRef = memHdr->numberExtRef;
     // if the array was already set,      char * base = ((char*)memHdr);
     // the previous references has to be deleted      Uint64* array =
     if(theArray.length != 0)          (Uint64*)&(base[memHdr->extRefIndexArray.start]);
     {      Uint32 extRefIndex = PEG_NOT_FOUND;
         Uint32 oldArraySize=(theArray.length/sizeof(SCMBUnion));  
  
         ptr = (SCMBUnion*)&(((char*)*pmem)[theArray.start]);      for (Uint32 i = 0; i < nuExtRef; i++)
         for (Uint32 i = 0 ; i < oldArraySize ; i++)  
         {         {
             if (ptr[i].extRefPtr != 0)           if (((SCMBUnion*)(&(base[array[i]])))->extRefPtr == extRefPtr)
             {             {
                 ptr[i].extRefPtr = new SCMOInstance(*ptr[i].extRefPtr);               extRefIndex = i;
                break;
             }             }
         }         }
       PEGASUS_ASSERT (extRefIndex != PEG_NOT_FOUND);
   
      // Shrink extRefIndexArray
   
       for (Uint32 i = extRefIndex + 1; i < nuExtRef; i++)
       {
           array[i-1] = array[i];
     }     }
   
       array[nuExtRef-1] = 0;
       memHdr->numberExtRef--;
   
       delete extRefPtr;
 } }
  
 /***************************************************************************** /*****************************************************************************
Line 259 
Line 271 
  *****************************************************************************/  *****************************************************************************/
 SCMOClass::SCMOClass() SCMOClass::SCMOClass()
 { {
     cls.mem = 0;      _initSCMOClass();
 }  
   
 void SCMOClass::_destroyExternalReferences()  
 {  
     // TODO: Has to be optimized not to loop through all props.  
     // Address the property array  
     SCMBClassPropertyNode* nodeArray =  
         (SCMBClassPropertyNode*)  
             &(cls.base[cls.hdr->propertySet.nodeArray.start]);  
   
     SCMBValue* theValue;  
   
     for (Uint32 i = 0; i < cls.hdr->propertySet.number; i++)  
     {  
         theValue = &(nodeArray[i].theProperty.defaultValue);  
  
         // if not an NULL value !      _setBinary("",1,cls.hdr->className,&cls.mem );
         if(!theValue->flags.isNull)      _setBinary("",1,cls.hdr->nameSpace,&cls.mem );
         {      cls.hdr->flags.isEmpty=true;
             if (theValue->valueType == CIMTYPE_REFERENCE ||  
                 theValue->valueType == CIMTYPE_OBJECT ||  
                 theValue->valueType == CIMTYPE_INSTANCE )  
             {  
                 if (theValue->flags.isArray)  
                 {  
                     _deleteArrayExtReference(  
                         theValue->value.arrayValue,  
                         &cls.mem);  
                 }  
                 else  
                 {  
                     delete theValue->value.extRefPtr;  
                 }  // end is Array  
             } // end is ext. reference.  
         }// end is not null  
     }// loop throug all properties  
 } }
  
 inline void SCMOClass::_initSCMOClass() inline void SCMOClass::_initSCMOClass()
Line 323 
Line 303 
     cls.hdr->header.startOfFreeSpace=sizeof(SCMBClass_Main);     cls.hdr->header.startOfFreeSpace=sizeof(SCMBClass_Main);
  
     cls.hdr->refCount=1;     cls.hdr->refCount=1;
   
 } }
  
 SCMOClass::SCMOClass(const char* className, const char* nameSpaceName ) SCMOClass::SCMOClass(const char* className, const char* nameSpaceName )
 { {
       Uint32 clsNameLen = strlen(className);
       Uint32 nsNameLen = strlen(nameSpaceName);
   
     if (0 == className)     if (0 == className)
     {     {
         String message("SCMOClass: Class name not set (null pointer)!");         String message("SCMOClass: Class name not set (null pointer)!");
Line 342 
Line 324 
  
     _initSCMOClass();     _initSCMOClass();
  
     _setBinary(className,      _setBinary(className,clsNameLen+1,cls.hdr->className,&cls.mem );
                strlen(className)+1,  
                cls.hdr->className,  
                &cls.mem );  
  
     _setBinary(nameSpaceName,      _setBinary(nameSpaceName,nsNameLen+1,cls.hdr->nameSpace,&cls.mem );
                strlen(nameSpaceName)+1,  
                cls.hdr->nameSpace,      cls.hdr->flags.isEmpty=true;
                &cls.mem );  
  
 } }
  
Line 358 
Line 336 
     const CIMClass& theCIMClass,     const CIMClass& theCIMClass,
     const char* nameSpaceName)     const char* nameSpaceName)
 { {
   
     _initSCMOClass();     _initSCMOClass();
  
     try     try
Line 371 
Line 348 
     {     {
         // there is no Super ClassName         // there is no Super ClassName
         cls.hdr->superClassName.start=0;         cls.hdr->superClassName.start=0;
         cls.hdr->superClassName.length=0;          cls.hdr->superClassName.size=0;
     }     }
  
     CIMObjectPath theObjectPath=theCIMClass.getPath();     CIMObjectPath theObjectPath=theCIMClass.getPath();
Line 404 
Line 381 
  
 } }
  
   void SCMOClass::_destroyExternalReferences()
   {
       _destroyExternalReferencesInternal(cls.mem);
   }
   
   const char* SCMOClass::getSuperClassName() const
   {
       return _getCharString(cls.hdr->superClassName,cls.base);
   }
   
   const char* SCMOClass::getSuperClassName_l(Uint32 & length) const
   {
       length = cls.hdr->superClassName.size;
       if (0 == length)
       {
           return 0;
       }
       else
       {
           length--;
       }
       return _getCharString(cls.hdr->superClassName,cls.base);
   }
   
 void  SCMOClass::getCIMClass(CIMClass& cimClass) const void  SCMOClass::getCIMClass(CIMClass& cimClass) const
 { {
     CIMClass newCimClass(     CIMClass newCimClass(
         CIMNameCast(NEWCIMSTR(cls.hdr->className,cls.base)),          CIMNameCast(_newCimString(cls.hdr->className,cls.base)),
         CIMNameCast(NEWCIMSTR(cls.hdr->superClassName,cls.base)));          CIMNameCast(_newCimString(cls.hdr->superClassName,cls.base)));
  
     // set the name space     // set the name space
     newCimClass._rep->_reference._rep->_nameSpace=     newCimClass._rep->_reference._rep->_nameSpace=
         CIMNamespaceNameCast(NEWCIMSTR(cls.hdr->nameSpace,cls.base));          CIMNamespaceNameCast(_newCimString(cls.hdr->nameSpace,cls.base));
  
     // Add class qualifier if exist     // Add class qualifier if exist
     if (0 != cls.hdr->numberOfQualifiers)     if (0 != cls.hdr->numberOfQualifiers)
Line 468 
Line 469 
     if (0 != clsProp.theProperty.originClassName.start)     if (0 != clsProp.theProperty.originClassName.start)
     {     {
         retCimProperty = CIMProperty(         retCimProperty = CIMProperty(
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.name,cls.base)),              CIMNameCast(_newCimString(clsProp.theProperty.name,cls.base)),
             theCimValue,             theCimValue,
             theCimValue.getArraySize(),             theCimValue.getArraySize(),
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.refClassName,cls.base)),              CIMNameCast(
             CIMNameCast(NEWCIMSTR(                  _newCimString(clsProp.theProperty.refClassName,cls.base)),
                 clsProp.theProperty.originClassName,cls.base)),              CIMNameCast(
                   _newCimString(clsProp.theProperty.originClassName,cls.base)),
             clsProp.theProperty.flags.propagated);             clsProp.theProperty.flags.propagated);
     }     }
     else     else
     {     {
          retCimProperty = CIMProperty(          retCimProperty = CIMProperty(
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.name,cls.base)),              CIMNameCast(_newCimString(clsProp.theProperty.name,cls.base)),
             theCimValue,             theCimValue,
             theCimValue.getArraySize(),             theCimValue.getArraySize(),
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.refClassName,cls.base)),              CIMNameCast(
                   _newCimString(clsProp.theProperty.refClassName,cls.base)),
             CIMName(),             CIMName(),
             clsProp.theProperty.flags.propagated);             clsProp.theProperty.flags.propagated);
     }     }
Line 511 
Line 514 
     CIMQualifier& theCimQualifier,     CIMQualifier& theCimQualifier,
     const SCMBQualifier& scmbQualifier,     const SCMBQualifier& scmbQualifier,
     const char* base)     const char* base)
   
 { {
   
     CIMName theCimQualiName;     CIMName theCimQualiName;
     CIMValue theCimValue;     CIMValue theCimValue;
  
Line 524 
Line 525 
  
     if (scmbQualifier.name == QUALNAME_USERDEFINED)     if (scmbQualifier.name == QUALNAME_USERDEFINED)
     {     {
         theCimQualiName = NEWCIMSTR(scmbQualifier.userDefName,base);          theCimQualiName = _newCimString(scmbQualifier.userDefName,base);
     }     }
     else     else
     {     {
Line 547 
Line 548 
  
     keyNames.clear();     keyNames.clear();
  
     for (Uint32 i = 0, k = cls.hdr->propertySet.number; i < k; i++)      for (Uint32 i = 0, k = cls.hdr->keyBindingSet.number; i < k; i++)
     {     {
         // Append the key property name.         // Append the key property name.
         // The length has to be reduces by 1 not to copy the trailing '\0'          keyNames.append(_newCimString(nodeArray[i].name,cls.base));
         keyNames.append(  
             String((const char*)_getCharString(nodeArray[i].name,cls.base),  
                    nodeArray[i].name.length-1));  
   
     }     }
 } }
  
Line 569 
Line 566 
  
 SCMO_RC SCMOClass::_getKeyBindingNodeIndex(Uint32& node, const char* name) const SCMO_RC SCMOClass::_getKeyBindingNodeIndex(Uint32& node, const char* name) const
 { {
   
     Uint32 tag,len,hashIdx;     Uint32 tag,len,hashIdx;
  
     len = strlen(name);     len = strlen(name);
     tag = _generateStringTag((const char*)name, len);     tag = _generateStringTag((const char*)name, len);
     // get the node index of the hash table     // get the node index of the hash table
     hashIdx =     hashIdx =
         cls.hdr->keyBindingSet.hashTable[tag%PEGASUS_KEYBINDIG_SCMB_HASHSIZE];        cls.hdr->keyBindingSet.hashTable[tag&(PEGASUS_KEYBINDIG_SCMB_HASHSIZE-1)];
     // there is no entry in the hash table on this hash table index.     // there is no entry in the hash table on this hash table index.
     if (hashIdx == 0)     if (hashIdx == 0)
     {     {
Line 584 
Line 580 
         return SCMO_NOT_FOUND;         return SCMO_NOT_FOUND;
     }     }
  
     // get the propterty node array      // get the Key Binding node array
     SCMBKeyBindingNode* nodeArray =     SCMBKeyBindingNode* nodeArray =
         (SCMBKeyBindingNode*)         (SCMBKeyBindingNode*)
             &(cls.base[cls.hdr->keyBindingSet.nodeArray.start]);             &(cls.base[cls.hdr->keyBindingSet.nodeArray.start]);
Line 599 
Line 595 
         if (nodeArray[node].nameHashTag == tag)         if (nodeArray[node].nameHashTag == tag)
         {         {
             // Now it is worth to compare the two names             // Now it is worth to compare the two names
             if (_equalUTF8Strings(              if (_equalNoCaseUTF8Strings(nodeArray[node].name,cls.base,name,len))
                 nodeArray[node].name,cls.base,name,len))  
             {             {
                 // we found the property !                 // we found the property !
                 return SCMO_OK;                 return SCMO_OK;
Line 622 
Line 617 
     return SCMO_NOT_FOUND;     return SCMO_NOT_FOUND;
  
 } }
   /*
 SCMO_RC SCMOClass::_getProperyNodeIndex(Uint32& node, const char* name) const      Gets the property Node for class-defined properties. Returns the
       node and SCMO_OK or the error SCMO_NOT_FOUND
       This function does NOT handle user-defined properties.
   */
   SCMO_RC SCMOClass::_getPropertyNodeIndex(Uint32& node, const char* name) const
 { {
   
     Uint32 tag,len,hashIdx;     Uint32 tag,len,hashIdx;
  
     len = strlen(name);     len = strlen(name);
     tag = _generateStringTag((const char*)name, len);     tag = _generateStringTag((const char*)name, len);
     // get the node index of the hash table     // get the node index of the hash table
     hashIdx =     hashIdx =
         cls.hdr->propertySet.hashTable[tag%PEGASUS_PROPERTY_SCMB_HASHSIZE];        cls.hdr->propertySet.hashTable[tag&(PEGASUS_PROPERTY_SCMB_HASHSIZE -1)];
     // there is no entry in the hash table on this hash table index.     // there is no entry in the hash table on this hash table index.
     if (hashIdx == 0)     if (hashIdx == 0)
     {     {
Line 640 
Line 638 
         return SCMO_NOT_FOUND;         return SCMO_NOT_FOUND;
     }     }
  
     // get the propterty node array      // get the property node array
     SCMBClassPropertyNode* nodeArray =     SCMBClassPropertyNode* nodeArray =
         (SCMBClassPropertyNode*)         (SCMBClassPropertyNode*)
             &(cls.base[cls.hdr->propertySet.nodeArray.start]);             &(cls.base[cls.hdr->propertySet.nodeArray.start]);
Line 655 
Line 653 
         if (nodeArray[node].theProperty.nameHashTag == tag)         if (nodeArray[node].theProperty.nameHashTag == tag)
         {         {
             // Now it is worth to compare the two names             // Now it is worth to compare the two names
             if (_equalUTF8Strings(              if (_equalNoCaseUTF8Strings(
                 nodeArray[node].theProperty.name,cls.base,name,len))                 nodeArray[node].theProperty.name,cls.base,name,len))
             {             {
                 // we found the property !                 // we found the property !
Line 675 
Line 673 
     } while ( true );     } while ( true );
  
     // this should never be reached     // this should never be reached
     return SCMO_NOT_FOUND;      PEGASUS_UNREACHABLE(return SCMO_NOT_FOUND;)
   
 } }
  
 void SCMOClass::_setClassProperties(PropertySet& theCIMProperties) void SCMOClass::_setClassProperties(PropertySet& theCIMProperties)
Line 686 
Line 683 
     Uint32 noKeys = 0;     Uint32 noKeys = 0;
     Boolean isKey = false;     Boolean isKey = false;
  
     Uint32 keyIndex[noProps];      Array<Uint32> keyIndex(noProps);
  
     cls.hdr->propertySet.number=noProps;     cls.hdr->propertySet.number=noProps;
  
Line 694 
Line 691 
     startKeyIndexList = _getFreeSpace(     startKeyIndexList = _getFreeSpace(
         cls.hdr->keyIndexList,         cls.hdr->keyIndexList,
         noProps*sizeof(Uint32),         noProps*sizeof(Uint32),
         &cls.mem,          &cls.mem);
         true);  
  
     if(noProps != 0)     if(noProps != 0)
     {     {
Line 703 
Line 699 
         // Each property needs a bit in the mask.         // Each property needs a bit in the mask.
         // The number of Uint64 in the key mask is :         // The number of Uint64 in the key mask is :
         // Decrease the number of properties by 1 since         // Decrease the number of properties by 1 since
         // the array is starting at 0!          // the array starts at 0!
         // Divided with the number of bits in a Uint64.          // Divide by the number of bits in a Uint64.
         // e.g. number of Properties = 68         // e.g. number of Properties = 68
         // (68 - 1) / 64 = 1 --> The mask consists of two Uint64 values.         // (68 - 1) / 64 = 1 --> The mask consists of two Uint64 values.
         _getFreeSpace(cls.hdr->keyPropertyMask,         _getFreeSpace(cls.hdr->keyPropertyMask,
               sizeof(Uint64)*(((noProps-1)/64)+1),               sizeof(Uint64)*(((noProps-1)/64)+1),
               &cls.mem,true);                &cls.mem);
  
         // allocate property array and save the start index of the array.         // allocate property array and save the start index of the array.
         start = _getFreeSpace(cls.hdr->propertySet.nodeArray,         start = _getFreeSpace(cls.hdr->propertySet.nodeArray,
                       sizeof(SCMBClassPropertyNode)*noProps,                       sizeof(SCMBClassPropertyNode)*noProps,
                       &cls.mem,true);                        &cls.mem);
  
         // clear the hash table         // clear the hash table
         memset(cls.hdr->propertySet.hashTable,         memset(cls.hdr->propertySet.hashTable,
Line 724 
Line 720 
  
         for (Uint32 i = 0; i < noProps; i++)         for (Uint32 i = 0; i < noProps; i++)
         {         {
   
             _setProperty(start,&isKey ,theCIMProperties[i]);             _setProperty(start,&isKey ,theCIMProperties[i]);
             if(isKey)             if(isKey)
             {             {
Line 757 
Line 752 
             // fill the key index list             // fill the key index list
             memcpy(             memcpy(
                 &(cls.base[startKeyIndexList]),                 &(cls.base[startKeyIndexList]),
                 keyIndex,                  keyIndex.getData(),
                 noKeys*sizeof(Uint32));                 noKeys*sizeof(Uint32));
  
             for (Uint32 i = 0 ; i < noKeys; i++)             for (Uint32 i = 0 ; i < noKeys; i++)
Line 774 
Line 769 
         else         else
         {         {
             cls.hdr->keyBindingSet.nodeArray.start=0;             cls.hdr->keyBindingSet.nodeArray.start=0;
             cls.hdr->keyBindingSet.nodeArray.length=0;              cls.hdr->keyBindingSet.nodeArray.size=0;
         }         }
     }     }
     else     else
     {     {
         cls.hdr->propertySet.nodeArray.start=0;         cls.hdr->propertySet.nodeArray.start=0;
         cls.hdr->propertySet.nodeArray.length=0;          cls.hdr->propertySet.nodeArray.size=0;
         cls.hdr->keyPropertyMask.start=0;         cls.hdr->keyPropertyMask.start=0;
         cls.hdr->keyPropertyMask.length=0;          cls.hdr->keyPropertyMask.size=0;
         cls.hdr->keyBindingSet.nodeArray.start=0;         cls.hdr->keyBindingSet.nodeArray.start=0;
         cls.hdr->keyBindingSet.nodeArray.length=0;          cls.hdr->keyBindingSet.nodeArray.size=0;
     }     }
 } }
  
Line 800 
Line 795 
  
     Uint32 *hashTable = cls.hdr->keyBindingSet.hashTable;     Uint32 *hashTable = cls.hdr->keyBindingSet.hashTable;
  
     if ( newIndex >= cls.hdr->keyBindingSet.number)  
     {  
         throw IndexOutOfBoundsException();  
     }  
   
     // calculate the new hash index of the new property.     // calculate the new hash index of the new property.
     Uint32 hash = newKeyNode->nameHashTag % PEGASUS_KEYBINDIG_SCMB_HASHSIZE;      Uint32 hash = newKeyNode->nameHashTag &
           (PEGASUS_KEYBINDIG_SCMB_HASHSIZE - 1);
  
     // 0 is an invalid index in the hash table     // 0 is an invalid index in the hash table
     if (hashTable[hash] == 0)     if (hashTable[hash] == 0)
Line 845 
Line 836 
  
 void SCMOClass::_insertPropertyIntoOrderedSet(Uint64 start, Uint32 newIndex) void SCMOClass::_insertPropertyIntoOrderedSet(Uint64 start, Uint32 newIndex)
 { {
   
   
     SCMBClassPropertyNode* newPropNode =     SCMBClassPropertyNode* newPropNode =
         (SCMBClassPropertyNode*)&(cls.base[start]);         (SCMBClassPropertyNode*)&(cls.base[start]);
  
Line 856 
Line 845 
  
     Uint32 *hashTable = cls.hdr->propertySet.hashTable;     Uint32 *hashTable = cls.hdr->propertySet.hashTable;
  
     if ( newIndex >= cls.hdr->propertySet.number)  
     {  
         throw IndexOutOfBoundsException();  
     }  
   
     // calcuate the new hash index of the new property.     // calcuate the new hash index of the new property.
     Uint32 hash = newPropNode->theProperty.nameHashTag %      Uint32 hash = newPropNode->theProperty.nameHashTag &
         PEGASUS_PROPERTY_SCMB_HASHSIZE;          (PEGASUS_PROPERTY_SCMB_HASHSIZE -1);
  
     // 0 is an invalid index in the hash table     // 0 is an invalid index in the hash table
     if (hashTable[hash] == 0)     if (hashTable[hash] == 0)
Line 906 
Line 890 
     const CIMProperty& theCIMProperty)     const CIMProperty& theCIMProperty)
 { {
     CIMPropertyRep* propRep = theCIMProperty._rep;     CIMPropertyRep* propRep = theCIMProperty._rep;
     Uint64 valueStart;  
  
     // First do all _setString(). Can cause reallocation.     // First do all _setString(). Can cause reallocation.
     _setString(propRep->_name.getString(),     _setString(propRep->_name.getString(),
Line 936 
Line 919 
  
     // Create a filter to set the bit.     // Create a filter to set the bit.
     // Modulo division with 64. Shift left a bit by the remainder.     // Modulo division with 64. Shift left a bit by the remainder.
     Uint64 filter = ( (Uint64)1 << (i%64));      Uint64 filter = ( (Uint64)1 << (i & 63));
  
     // Calculate the real pointer to the Uint64 array     // Calculate the real pointer to the Uint64 array
     keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);     keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);
Line 956 
Line 939 
  
     // Create a filter to check if the bit is set:     // Create a filter to check if the bit is set:
     // Modulo division with 64. Shift left a bit by the remainder.     // Modulo division with 64. Shift left a bit by the remainder.
     Uint64 filter = ( (Uint64)1 << (i%64));      Uint64 filter = ( (Uint64)1 << (i & 63));
  
     // Calculate the real pointer to the Uint64 array     // Calculate the real pointer to the Uint64 array
     keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);     keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);
Line 971 
Line 954 
     Boolean* isKey,     Boolean* isKey,
     const CIMProperty& theCIMProperty)     const CIMProperty& theCIMProperty)
 { {
   
    *isKey = false;    *isKey = false;
  
     CIMPropertyRep* propRep = theCIMProperty._rep;     CIMPropertyRep* propRep = theCIMProperty._rep;
Line 1055 
Line 1037 
     else     else
     {     {
         scmoPropNode->theProperty.qualifierArray.start=0;         scmoPropNode->theProperty.qualifierArray.start=0;
         scmoPropNode->theProperty.qualifierArray.length=0;          scmoPropNode->theProperty.qualifierArray.size=0;
     }     }
  
     return isKey;     return isKey;
Line 1086 
Line 1068 
     else     else
     {     {
         cls.hdr->qualifierArray.start=0;         cls.hdr->qualifierArray.start=0;
         cls.hdr->qualifierArray.length=0;          cls.hdr->qualifierArray.size=0;
     }     }
 } }
  
Line 1150 
Line 1132 
             // Is set to the number of array members by the function.             // Is set to the number of array members by the function.
             scmoValue->valueArraySize,             scmoValue->valueArraySize,
             cls.hdr->nameSpace.start,             cls.hdr->nameSpace.start,
             cls.hdr->nameSpace.length,              cls.hdr->nameSpace.size,
             rep->u);             rep->u);
     }     }
     else     else
Line 1160 
Line 1142 
             &cls.mem,             &cls.mem,
             rep->type,             rep->type,
             cls.hdr->nameSpace.start,             cls.hdr->nameSpace.start,
             cls.hdr->nameSpace.length,              cls.hdr->nameSpace.size,
             rep->u);             rep->u);
     }     }
 } }
Line 1202 
Line 1184 
        (SCMBClassPropertyNode*)        (SCMBClassPropertyNode*)
            &(cls.base[cls.hdr->propertySet.nodeArray.start]);            &(cls.base[cls.hdr->propertySet.nodeArray.start]);
  
    return(_equalUTF8Strings(     return(_equalNoCaseUTF8Strings(
        nodeArray[node].theProperty.originClassName,        nodeArray[node].theProperty.originClassName,
        cls.base,        cls.base,
        origin,        origin,
Line 1226 
Line 1208 
  
     if(nodeArray[node].theProperty.defaultValue.valueType != type)     if(nodeArray[node].theProperty.defaultValue.valueType != type)
     {     {
         // Accept an property of type instance also          // Accept a property of type instance also
         // for an CIMTYPE_OBJECT property.         // for an CIMTYPE_OBJECT property.
         if (!(type == CIMTYPE_INSTANCE &&         if (!(type == CIMTYPE_INSTANCE &&
               nodeArray[node].theProperty.defaultValue.valueType               nodeArray[node].theProperty.defaultValue.valueType
Line 1267 
Line 1249 
     inst.base = 0;     inst.base = 0;
 } }
  
 SCMOInstance::SCMOInstance(SCMOClass baseClass)  SCMOInstance::SCMOInstance(SCMOClass& baseClass)
 { {
     _initSCMOInstance(new SCMOClass(baseClass));     _initSCMOInstance(new SCMOClass(baseClass));
 } }
  
 SCMOInstance::SCMOInstance( SCMOInstance::SCMOInstance(
     SCMOClass baseClass,      SCMOClass& baseClass,
     Boolean includeQualifiers,     Boolean includeQualifiers,
     Boolean includeClassOrigin,      Boolean includeClassOrigin)
     const char** propertyList)  
 { {
   
     _initSCMOInstance(new SCMOClass(baseClass));     _initSCMOInstance(new SCMOClass(baseClass));
  
     inst.hdr->flags.includeQualifiers=includeQualifiers;     inst.hdr->flags.includeQualifiers=includeQualifiers;
     inst.hdr->flags.includeClassOrigin=includeClassOrigin;     inst.hdr->flags.includeClassOrigin=includeClassOrigin;
   
     setPropertyFilter(propertyList);  
   
 } }
  
 SCMOInstance::SCMOInstance(SCMOClass baseClass, const CIMObjectPath& cimObj)  SCMOInstance::SCMOInstance(SCMOClass& baseClass, const CIMObjectPath& cimObj)
 { {
     _initSCMOInstance(new SCMOClass(baseClass));     _initSCMOInstance(new SCMOClass(baseClass));
  
     _setCIMObjectPath(cimObj);     _setCIMObjectPath(cimObj);
 } }
  
 SCMOInstance::SCMOInstance(SCMOClass baseClass, const CIMInstance& cimInstance)  SCMOInstance::SCMOInstance(SCMOClass& baseClass, const CIMInstance& cimInstance)
 { {
   
     _initSCMOInstance(new SCMOClass(baseClass));     _initSCMOInstance(new SCMOClass(baseClass));
  
     _setCIMInstance(cimInstance);     _setCIMInstance(cimInstance);
   
 } }
  
   SCMOInstance::SCMOInstance(CIMClass& theCIMClass, const char* altNameSpace)
 void SCMOInstance::_copyExternalReferences()  
 { {
     // TODO: Has to be optimized not to loop through all props.      _initSCMOInstance(new SCMOClass(theCIMClass,altNameSpace));
     // create a pointer to keybinding node array of the class.  }
     Uint64 idx = inst.hdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;  
     SCMBKeyBindingNode* theClassKeyBindNodeArray =  
         (SCMBKeyBindingNode*)&((inst.hdr->theClass->cls.base)[idx]);  
  
     // create a pointer to instanc key binding array.  /*
     SCMBKeyBindingValue* theInstanceKeyBindingNodeArray =      Construct a new SCMOInstance from a CIMInstance. This constructor
         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);      gets the SCMOClass from the cache
   */
   SCMOInstance::SCMOInstance(
       const CIMInstance& cimInstance,
       const char* altNameSpace,
       Uint32 altNSLen)
   {
       SCMOClass theSCMOClass = _getSCMOClass(
           cimInstance._rep->_reference,
           altNameSpace,
           altNSLen);
  
     for (Uint32 i = 0; i < inst.hdr->numberKeyBindings; i++)      _initSCMOInstance( new SCMOClass(theSCMOClass));
     {  
         if (theInstanceKeyBindingNodeArray[i].isSet)  
         {  
             // only references can be a key binding.  
             if (theClassKeyBindNodeArray[i].type == CIMTYPE_REFERENCE)  
             {  
                 // Use the copy constructro to ref. count the reference.  
                 // These objects are handeld by the SCMOInstance it sef.  
                 // No one can modify these instances.  
                 theInstanceKeyBindingNodeArray[i].data.extRefPtr =  
                     new SCMOInstance(  
                         *theInstanceKeyBindingNodeArray[i].data.extRefPtr);  
             }  
         }  
     }// for all key bindings defined in the class  
  
     // Are there user defined key bindings ?      // If class empty, the name info not set into the instance
     if (0 != inst.hdr->numberUserKeyBindindigs)      if(theSCMOClass.isEmpty())
     {     {
         SCMBUserKeyBindingElement* theUserDefKBElement =          // flag the instance as compromized
             (SCMBUserKeyBindingElement*)          inst.hdr->flags.isCompromised=true;
                  &(inst.base[inst.hdr->userKeyBindingElement.start]);          inst.hdr->flags.noClassForInstance=true;
  
         for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindindigs; i++)          // Copy class name of the class from the
         {          // CIMInstance
             if (theUserDefKBElement->value.isSet)  
             {  
                 // only references can be a key binding.  
                 if (theUserDefKBElement->type == CIMTYPE_REFERENCE)  
                 {  
                     // Use the copy constructro to ref. count the reference.  
                     // These objects are handeld by the SCMOInstance it sef.  
                     // No one can modify these instances.  
                     theUserDefKBElement->value.data.extRefPtr =  
                         new SCMOInstance(  
                             *theUserDefKBElement->value.data.extRefPtr);  
                 }  
             }  
  
             theUserDefKBElement =          _setString(cimInstance.getClassName().getString(),
                 (SCMBUserKeyBindingElement*)              inst.hdr->instClassName,
                      &(inst.base[theUserDefKBElement->nextElement.start]);              &inst.mem);
         } // for all user def. key bindings.  
           _setBinary(altNameSpace, altNSLen,
                      inst.hdr->instNameSpace, &inst.mem);
     }     }
  
     SCMBValue* theInstPropArray =      _setCIMInstance(cimInstance);
         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);  
  
     for (Uint32 i = 0; i < inst.hdr->numberProperties; i++)  }
     {  
         // was the property set by the provider ?  SCMOInstance::SCMOInstance(
         if(theInstPropArray[i].flags.isSet)      const CIMObject& cimObject,
         {      const char* altNameSpace,
             // is the property type reference,instance or object?      Uint32 altNSLen)
             if (theInstPropArray[i].valueType == CIMTYPE_REFERENCE ||  
                 theInstPropArray[i].valueType == CIMTYPE_OBJECT ||  
                 theInstPropArray[i].valueType == CIMTYPE_INSTANCE )  
             {             {
                 if (theInstPropArray[i].flags.isArray)      if (cimObject.isClass())
                 {                 {
                     _copyArrayExtReference(          CIMClass cimClass(cimObject);
                         theInstPropArray[i].value.arrayValue,  
                         &inst.mem);          _initSCMOInstance(new SCMOClass(cimClass,altNameSpace));
   
           inst.hdr->flags.isClassOnly=true;
                 }                 }
                 else                 else
                 {                 {
                     theInstPropArray[i].value.extRefPtr =          CIMInstance cimInstance(cimObject);
                         new SCMOInstance(*theInstPropArray[i].value.extRefPtr);  
                 } // end is arry  
             } // end is reference  
         }// end is set  
     } // for all properties.  
 }  
  
 void SCMOInstance::_destroyExternalReferences()          SCMOClass theSCMOClass = _getSCMOClass(
 {              cimInstance._rep->_reference,
     // TODO: Has to be optimized not to loop through all props.              altNameSpace,
     // create a pointer to keybinding node array of the class.              altNSLen);
     Uint64 idx = inst.hdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;  
     SCMBKeyBindingNode* theClassKeyBindNodeArray =  
         (SCMBKeyBindingNode*)&((inst.hdr->theClass->cls.base)[idx]);  
  
     // create a pointer to instanc key binding array.          _initSCMOInstance( new SCMOClass(theSCMOClass));
     SCMBKeyBindingValue* theInstanceKeyBindingNodeArray =  
         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);  
  
     for (Uint32 i = 0; i < inst.hdr->numberKeyBindings; i++)          if(theSCMOClass.isEmpty())
     {  
         if (theInstanceKeyBindingNodeArray[i].isSet)  
         {  
             // only references can be a key binding  
             if (theClassKeyBindNodeArray[i].type == CIMTYPE_REFERENCE)  
             {             {
                delete theInstanceKeyBindingNodeArray[i].data.extRefPtr;              // flag the instance as compromized
             }              inst.hdr->flags.isCompromised=true;
               inst.hdr->flags.noClassForInstance=true;
         }         }
     }// for all key bindings  
   
     // Are there user defined key bindings ?  
     if (0 != inst.hdr->numberUserKeyBindindigs)  
     {  
         SCMBUserKeyBindingElement* theUserDefKBElement =  
             (SCMBUserKeyBindingElement*)  
                  &(inst.base[inst.hdr->userKeyBindingElement.start]);  
  
         for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindindigs; i++)          _setCIMInstance(cimInstance);
         {  
             if (theUserDefKBElement->value.isSet)  
             {  
                 // only references can be a key binding.  
                 if (theUserDefKBElement->type == CIMTYPE_REFERENCE)  
                 {  
                     delete theUserDefKBElement->value.data.extRefPtr;  
                 }                 }
             }             }
  
             theUserDefKBElement =  SCMOInstance::SCMOInstance(
                 (SCMBUserKeyBindingElement*)      const CIMObjectPath& cimObj,
                      &(inst.base[theUserDefKBElement->nextElement.start]);      const char* altNameSpace,
         } // for all user def. key bindings.      Uint32 altNSLen)
     }  {
       SCMOClass theSCMOClass = _getSCMOClass(
           cimObj,
           altNameSpace,
           altNSLen);
  
     SCMBValue* theInstPropArray =      _initSCMOInstance( new SCMOClass(theSCMOClass));
         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);  
  
     for (Uint32 i = 0; i < inst.hdr->numberProperties; i++)      if(theSCMOClass.isEmpty())
     {  
         // was the property set by the provider ?  
         if(theInstPropArray[i].flags.isSet)  
         {  
             // is the property type reference,instance or object?  
             if (theInstPropArray[i].valueType == CIMTYPE_REFERENCE ||  
                 theInstPropArray[i].valueType == CIMTYPE_OBJECT ||  
                 theInstPropArray[i].valueType == CIMTYPE_INSTANCE )  
             {  
                 if (theInstPropArray[i].flags.isArray)  
                 {                 {
                     _deleteArrayExtReference(          // flag the instance as compromized
                         theInstPropArray[i].value.arrayValue,          inst.hdr->flags.isCompromised=true;
                         &inst.mem);          // KS_TODO should we set the noClassForInstance
           // and set the path for this one??
   
           inst.hdr->flags.noClassForInstance=true;
                 }                 }
                 else  
                 {       _setCIMObjectPath(cimObj);
                     delete theInstPropArray[i].value.extRefPtr;  
                 } // end is arry  
             } // end is reference  
         }// end is set  
     } // for all properties.  
 } }
  
 SCMO_RC SCMOInstance::getCIMInstance(CIMInstance& cimInstance) const  void SCMOInstance::_destroyExternalReferences()
 { {
       _destroyExternalReferencesInternal(inst.mem);
   }
  
     SCMO_RC rc = SCMO_OK;  SCMOClass SCMOInstance::_getSCMOClass(
     Uint32 noProps;      const CIMObjectPath& theCIMObj,
       const char* altNS,
       Uint32 altNSlength)
   {
       SCMOClass theClass;
   
       if (theCIMObj.getClassName().isNull())
       {
           return SCMOClass();
       }
   
       if (theCIMObj.getNameSpace().isNull())
       {
           // the name space of the object path is empty,
           // use alternative name space.
           CString clsName = theCIMObj.getClassName().getString().getCString();
   
           SCMOClassCache* theCache = SCMOClassCache::getInstance();
           theClass = theCache->getSCMOClass(
               altNS,
               altNSlength,
               (const char*)clsName,
               strlen(clsName));
       }
       else
       {
           CString nameSpace = theCIMObj.getNameSpace().getString().getCString();
           CString clsName = theCIMObj.getClassName().getString().getCString();
   
           SCMOClassCache* theCache = SCMOClassCache::getInstance();
           theClass = theCache->getSCMOClass(
               (const char*)nameSpace,
               strlen(nameSpace),
               (const char*)clsName,
               strlen(clsName));
       }
   
       return theClass;
   }
   
   #define PEGASUS_SIZE_REFERENCE_INDEX_ARRAY 8
   
   void SCMOInstance::_setExtRefIndex(SCMBUnion* pInst, SCMBMgmt_Header** pmem)
   {
       Uint64 refPtr =(((char *)pInst) - (char *)(*pmem));
       SCMBMgmt_Header* memHdr = (*pmem);
       // Save the number of external references in the array
       Uint32 noExtRef = memHdr->numberExtRef;
   
       // Allocate the external reference array
       // if it is full or empty ( 0 == 0 ).
       if (noExtRef == memHdr->sizeExtRefIndexArray)
       {
           Uint64 oldArrayStart = memHdr->extRefIndexArray.start;
           Uint32 newSize =
               memHdr->sizeExtRefIndexArray + PEGASUS_SIZE_REFERENCE_INDEX_ARRAY;
   
           // Allocate the external reference index array
           _getFreeSpace(
                 memHdr->extRefIndexArray,
                 sizeof(Uint64)*newSize,
                 pmem);
   
           // reset the pointer. It could be changed due to reallocation !
           memHdr = (*pmem);
   
           // Assign new size.
           memHdr->sizeExtRefIndexArray=newSize;
   
           // Get absolute pointer to old index array.
           Uint64* oldArray = (Uint64*)&(((char*)(*pmem))[oldArrayStart]);
           // Get absolute pointer to new index array
           Uint64* newArray =
               (Uint64*)&(((char*)(*pmem))[memHdr->extRefIndexArray.start]);
   
           // Copy all elements of the old array to the new.
           // If noExtRef = 0, no elements are copied.
           for (Uint32 i = 0 ; i < noExtRef ; i++)
           {
               newArray[i] = oldArray[i];
           }
       }
   
       // Get absolute pointer to the array
       Uint64* array =
           (Uint64*)&(((char*)(*pmem))[memHdr->extRefIndexArray.start]);
       // look in the table if the index is already in the array
       for (Uint32 i = 0 ; i < noExtRef ; i++)
       {
           // is the index already part of the array
           if (array[i] == refPtr)
           {
               // leave.
               return;
           }
       }
       // It is not part of the array -> set the new index.
       array[noExtRef] = refPtr;
       // increment the nuber of external references of this instance.
       memHdr->numberExtRef++;
   
   }
   
   SCMOInstance* SCMOInstance::getExtRef(Uint32 idx) const
   {
       Uint64* array =
           (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
       SCMBUnion* pUnion;
       pUnion = (SCMBUnion*)(&(inst.base[array[idx]]));
       return pUnion->extRefPtr;
   }
   
   void SCMOInstance::putExtRef(Uint32 idx,SCMOInstance* ptr)
   {
       Uint64* array =
           (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
       SCMBUnion* pUnion;
       pUnion = (SCMBUnion*)(&(inst.base[array[idx]]));
       pUnion->extRefPtr = ptr;
   }
   
   void SCMOInstance::_copyExternalReferences()
   {
       Uint32 number = inst.mem->numberExtRef;
   
       if (0 != number)
       {
           SCMBUnion* pUnion;
           Uint64* array =
               (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
           for (Uint32 i = 0; i < number; i++)
           {
               pUnion = (SCMBUnion*)(&(inst.base[array[i]]));
               if (0 != pUnion)
               {
                   pUnion->extRefPtr = new SCMOInstance(*(pUnion->extRefPtr));
               }
           }
   
       }
   
   }
   
   void SCMOInstance::_destroyExternalKeyBindings()
   {
       // Create a pointer to keybinding node array of the class.
       Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.nodeArray.start;
       SCMBKeyBindingNode* theClassKeyBindNodeArray =
           (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
   
       // create a pointer to instance key binding array.
       SCMBKeyBindingValue* theInstanceKeyBindingNodeArray =
           (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
   
       for (Uint32 i = 0; i < inst.hdr->numberKeyBindings; i++)
       {
           if (theInstanceKeyBindingNodeArray[i].isSet)
           {
               // only references can be a key binding
               if (theClassKeyBindNodeArray[i].type == CIMTYPE_REFERENCE)
               {
                  _deleteExternalReferenceInternal(
                      inst.mem,
                      theInstanceKeyBindingNodeArray[i].data.extRefPtr);
               }
           }
       }// for all key bindings
   
       // Are there user defined key bindings ?
       if (0 != inst.hdr->numberUserKeyBindings)
       {
           SCMBUserKeyBindingElement* theUserDefKBElement =
               (SCMBUserKeyBindingElement*)
                    &(inst.base[inst.hdr->userKeyBindingElement.start]);
   
           for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
           {
               if (theUserDefKBElement->value.isSet)
               {
                   // only references can be a key binding.
                   if (theUserDefKBElement->type == CIMTYPE_REFERENCE)
                   {
                      _deleteExternalReferenceInternal(
                          inst.mem,
                          theUserDefKBElement->value.data.extRefPtr);
                   }
               }
   
               theUserDefKBElement =
                   (SCMBUserKeyBindingElement*)
                        &(inst.base[theUserDefKBElement->nextElement.start]);
           } // for all user def. key bindings.
       }
   }
   
   SCMO_RC SCMOInstance::getCIMInstance(CIMInstance& cimInstance) const
   {
       SCMO_RC rc = SCMO_OK;
     CIMObjectPath objPath;     CIMObjectPath objPath;
  
     // For better usability define pointers to SCMO Class data structures.     // For better usability define pointers to SCMO Class data structures.
     SCMBClass_Main* clshdr = inst.hdr->theClass->cls.hdr;      SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
     char* clsbase = inst.hdr->theClass->cls.base;      char* clsbase = inst.hdr->theClass.ptr->cls.base;
  
     getCIMObjectPath(objPath);     getCIMObjectPath(objPath);
  
Line 1504 
Line 1617 
         }         }
     }     }
  
     if (inst.hdr->flags.isFiltered)      // User-defined properties and exportSetOnly
     {      // are mutually exclusive. Do not appear in same instance.
         // Get absolut pointer to property filter index map of the instance      // KS_TODO insure that this is true or change to export all.
         Uint32* propertyFilterIndexMap =      // This flag is only set by _setCIMInstance
             (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);  
   
         for(Uint32 i = 0, k = inst.hdr->filterProperties; i<k; i++)  
         {  
             // Get absolut pointer to property filter index map  
             // of the instance get the real node index of the property.  
             CIMProperty theProperty=_getCIMPropertyAtNodeIndex(  
                 propertyFilterIndexMap[i]);  
   
             newInstance._rep->_properties.append(theProperty);  
         }  
  
     }      if (inst.hdr->flags.exportSetOnly)
     else  
     {     {
         for(Uint32 i = 0, k = inst.hdr->numberProperties; i<k; i++)         for(Uint32 i = 0, k = inst.hdr->numberProperties; i<k; i++)
         {         {
Line 1537 
Line 1638 
                 newInstance._rep->_properties.append(theProperty);                 newInstance._rep->_properties.append(theProperty);
             }             }
         }         }
       }
       else
       {
           // export all properties
           Uint32 propertyCount = getPropertyCount();
           if (!noClassForInstance())
           {
               for(Uint32 i = 0, k = propertyCount; i<k; i++)
               {
                   // Set all properties in the CIMInstance gegarding they
                   // are part of the SCMOInstance or the SCMOClass.
                   CIMProperty theProperty = _getCIMPropertyAtNodeIndex(i);
   
                   newInstance._rep->_properties.append(theProperty);
               }
           }
           else
           {
               // Create cim property for all properties in SCMO Instance.
               // Work end to beginning only because User-defined properties
               // are inserted in reverse order and that upsets instance
               // identical testing
               if (propertyCount != 0)
               {
                   Uint32 i = propertyCount - 1;
                   do
                   {
                       // Set all properties in the CIMInstance whether they
                       // are part of the SCMOInstance or the SCMOClass.
                       CIMProperty theProperty = _getCIMPropertyAtNodeIndex(i);
  
                       newInstance._rep->_properties.append(theProperty);
                   }
                   while (i-- != 0);
               }
           }
     }     }
  
     cimInstance = newInstance;     cimInstance = newInstance;
Line 1547 
Line 1683 
  
 void SCMOInstance::getCIMObjectPath(CIMObjectPath& cimObj) const void SCMOInstance::getCIMObjectPath(CIMObjectPath& cimObj) const
 { {
       Array<CIMKeyBinding> keys;
     CIMObjectPath newObjectPath;  
  
     // For better usability define pointers to SCMO Class data structures.     // For better usability define pointers to SCMO Class data structures.
     SCMBClass_Main* clshdr = inst.hdr->theClass->cls.hdr;      SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
     char* clsbase = inst.hdr->theClass->cls.base;      char* clsbase = inst.hdr->theClass.ptr->cls.base;
  
     // Address the class keybinding information     // Address the class keybinding information
     SCMBKeyBindingNode* scmoClassArray =     SCMBKeyBindingNode* scmoClassArray =
Line 1578 
Line 1713 
                 0,                 0,
                 scmoInstArray[i].data,                 scmoInstArray[i].data,
                 inst.base);                 inst.base);
             newObjectPath._rep->_keyBindings.append(              keys.append(
                 CIMKeyBinding(                 CIMKeyBinding(
                     CIMNameCast(NEWCIMSTR(scmoClassArray[i].name,clsbase)),                      CIMNameCast(_newCimString(scmoClassArray[i].name,clsbase)),
                     theKeyBindingValue                     theKeyBindingValue
                     ));                     ));
         }         }
     }     }
  
     // Are there user defined key bindings ?     // Are there user defined key bindings ?
     if (0 != inst.hdr->numberUserKeyBindindigs)      if (0 != inst.hdr->numberUserKeyBindings)
     {     {
         SCMBUserKeyBindingElement* theUserDefKBElement =         SCMBUserKeyBindingElement* theUserDefKBElement =
             (SCMBUserKeyBindingElement*)             (SCMBUserKeyBindingElement*)
                  &(inst.base[inst.hdr->userKeyBindingElement.start]);                  &(inst.base[inst.hdr->userKeyBindingElement.start]);
  
         for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindindigs; i++)          for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
         {         {
             if (theUserDefKBElement->value.isSet)             if (theUserDefKBElement->value.isSet)
             {             {
Line 1606 
Line 1741 
                     theUserDefKBElement->value.data,                     theUserDefKBElement->value.data,
                     inst.base);                     inst.base);
  
                 newObjectPath._rep->_keyBindings.append(                  keys.append(
                     CIMKeyBinding(                     CIMKeyBinding(
                         CIMNameCast(                         CIMNameCast(
                             NEWCIMSTR(theUserDefKBElement->name,inst.base)),                              _newCimString(theUserDefKBElement->name,inst.base)),
                     theKeyBindingValue));                     theKeyBindingValue));
             }             }
             theUserDefKBElement =             theUserDefKBElement =
Line 1618 
Line 1753 
         } // for all user def. key bindings.         } // for all user def. key bindings.
     }     }
  
     newObjectPath._rep->_host = NEWCIMSTR(inst.hdr->hostName,inst.base);      String host = _newCimString(inst.hdr->hostName,inst.base);
   
     // Use name space and class name of the instance     // Use name space and class name of the instance
     newObjectPath._rep->_nameSpace =      CIMNamespaceName nameSpace =
         CIMNamespaceNameCast(NEWCIMSTR(inst.hdr->instNameSpace,inst.base));          CIMNamespaceNameCast(_newCimString(inst.hdr->instNameSpace,inst.base));
     newObjectPath._rep->_className=  
         CIMNameCast(NEWCIMSTR(inst.hdr->instClassName,inst.base));      CIMName className =
           CIMNameCast(_newCimString(inst.hdr->instClassName,inst.base));
  
     cimObj = newObjectPath;      cimObj.set(host,nameSpace,className,keys);
 } }
  
 CIMProperty SCMOInstance::_getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const CIMProperty SCMOInstance::_getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const
 { {
     CIMValue theValue;  
     CIMProperty retProperty;     CIMProperty retProperty;
  
     // For better usability define pointers to SCMO Class data structures.     // For better usability define pointers to SCMO Class data structures.
     SCMBClass_Main* clshdr = inst.hdr->theClass->cls.hdr;      SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
     char* clsbase = inst.hdr->theClass->cls.base;      char* clsbase = inst.hdr->theClass.ptr->cls.base;
  
       if (_isClassDefinedProperty(nodeIdx))
       {
           // For better usability define pointers to SCMO Class data structures.
  
     SCMBClassPropertyNode& clsProp =     SCMBClassPropertyNode& clsProp =
         ((SCMBClassPropertyNode*)         ((SCMBClassPropertyNode*)
Line 1645 
Line 1784 
     SCMBValue& instValue =     SCMBValue& instValue =
         ((SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]))[nodeIdx];         ((SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]))[nodeIdx];
  
     _getCIMValueFromSCMBValue(theValue,instValue,inst.base);          // if set, get value. Else get value from class
           CIMValue theCIMValue;
           if (instValue.flags.isSet)
           {
               _getCIMValueFromSCMBValue(theCIMValue,instValue,inst.base);
           }
           else
           {
               _getCIMValueFromSCMBValue(
                   theCIMValue,
                   clsProp.theProperty.defaultValue,
                   clsbase);
           }
  
           // Redo this into single call KS_TODO
  
     if (inst.hdr->flags.includeClassOrigin)     if (inst.hdr->flags.includeClassOrigin)
     {     {
         retProperty = CIMProperty(         retProperty = CIMProperty(
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.name,clsbase)),                  CIMNameCast(_newCimString(clsProp.theProperty.name,clsbase)),
             theValue,                  theCIMValue,
             theValue.getArraySize(),                  theCIMValue.getArraySize(),
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.refClassName,clsbase)),                  CIMNameCast(
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.originClassName,clsbase)),                      _newCimString(clsProp.theProperty.refClassName,clsbase)),
                   CIMNameCast(
                       _newCimString(clsProp.theProperty.originClassName,clsbase)),
             clsProp.theProperty.flags.propagated);             clsProp.theProperty.flags.propagated);
     }     }
     else     else
     {     {
          retProperty = CIMProperty(          retProperty = CIMProperty(
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.name,clsbase)),                  CIMNameCast(_newCimString(clsProp.theProperty.name,clsbase)),
             theValue,                  theCIMValue,
             theValue.getArraySize(),                  theCIMValue.getArraySize(),
             CIMNameCast(NEWCIMSTR(clsProp.theProperty.refClassName,clsbase)),                  CIMNameCast(
                       _newCimString(clsProp.theProperty.refClassName,clsbase)),
             CIMName(),             CIMName(),
             clsProp.theProperty.flags.propagated);             clsProp.theProperty.flags.propagated);
     }     }
Line 1688 
Line 1843 
             retProperty._rep->_qualifiers.addUnchecked(theCimQualifier);             retProperty._rep->_qualifiers.addUnchecked(theCimQualifier);
         }         }
     }     }
       }
       else   // User-defined property
       {
           SCMBUserPropertyElement* pElement =
               _getUserDefinedPropertyElementAt(nodeIdx);
   
           SCMBValue& instValue = pElement->value;
   
           CIMValue theCimValue;
           if (instValue.flags.isSet)
           {
               // There is No default so
               _getCIMValueFromSCMBValue(theCimValue,instValue,inst.base);
           }
           else
           {
               // There is no default. isSet MUST be set
               PEGASUS_ASSERT(false);
           }
  
           retProperty = CIMProperty(
              CIMNameCast(_newCimString(pElement->name, inst.base)),
              theCimValue,
              theCimValue.getArraySize(),
              CIMName(),          // referenceClassName
              CIMName(),          // ClassOrigin
              false);             // isPropagated == false
       }
     return retProperty;     return retProperty;
 } }
  
Line 1905 
Line 2087 
                 Array<Char16> x;                 Array<Char16> x;
                 for (Uint32 i = 0, k = arraySize; i < k ; i++)                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
                 {                 {
                     x.append(pscmbArrayUn[i].simple.val.c16);                      x.append(Char16(pscmbArrayUn[i].simple.val.c16));
                 }                 }
                 cimV.set(x);                 cimV.set(x);
             }             }
             else             else
             {             {
                 cimV.set(scmbUn.simple.val.c16);                  cimV.set(Char16(scmbUn.simple.val.c16));
             }             }
             break;             break;
         }         }
Line 1943 
Line 2125 
  
                 for (Uint32 i = 0, k = arraySize; i < k ; i++)                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
                 {                 {
                     x.append(NEWCIMSTR(pscmbArrayUn[i].stringValue,base));                      x.append(_newCimString(pscmbArrayUn[i].stringValue,base));
                 }                 }
                 cimV.set(x);                 cimV.set(x);
             }             }
             else             else
             {             {
                 cimV.set(NEWCIMSTR(scmbUn.stringValue,base));                  cimV.set(_newCimString(scmbUn.stringValue,base));
             }             }
             break;             break;
         }         }
Line 2013 
Line 2195 
         }         }
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
         {         {
             CIMInstance theInstance;              CIMInstance cimInstance;
             CIMClass theClass;              CIMClass cimClass;
  
             if(isArray)             if(isArray)
             {             {
Line 2028 
Line 2210 
                                inst.hdr->flags.isClassOnly)                                inst.hdr->flags.isClassOnly)
                         {                         {
                             pscmbArrayUn[i].extRefPtr->                             pscmbArrayUn[i].extRefPtr->
                                 inst.hdr->theClass->getCIMClass(theClass);                                  inst.hdr->theClass.ptr->getCIMClass(cimClass);
                             x.append(CIMObject(theClass));                              x.append(CIMObject(cimClass));
                         }                         }
                         else                         else
                         {                         {
                             pscmbArrayUn[i].extRefPtr->                             pscmbArrayUn[i].extRefPtr->
                                 getCIMInstance(theInstance);                                  getCIMInstance(cimInstance);
                             x.append(CIMObject(theInstance));                              x.append(CIMObject(cimInstance));
                         }                         }
                     }                     }
                     else                     else
Line 2055 
Line 2237 
                     if(scmbUn.extRefPtr->inst.hdr->flags.isClassOnly)                     if(scmbUn.extRefPtr->inst.hdr->flags.isClassOnly)
                     {                     {
                         scmbUn.extRefPtr->                         scmbUn.extRefPtr->
                             inst.hdr->theClass->getCIMClass(theClass);                              inst.hdr->theClass.ptr->getCIMClass(cimClass);
                         cimV.set(CIMObject(theClass));                          cimV.set(CIMObject(cimClass));
                     }                     }
                     else                     else
                     {                     {
                         scmbUn.extRefPtr->getCIMInstance(theInstance);                          scmbUn.extRefPtr->getCIMInstance(cimInstance);
                         cimV.set(CIMObject(theInstance));                          cimV.set(CIMObject(cimInstance));
                     }                     }
                 }                 }
                 else                 else
Line 2112 
Line 2294 
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
Line 2136 
Line 2318 
  
 void SCMOInstance::_setCIMObjectPath(const CIMObjectPath& cimObj) void SCMOInstance::_setCIMObjectPath(const CIMObjectPath& cimObj)
 { {
     CIMObjectPathRep* objRep = cimObj._rep;      CString className = cimObj.getClassName().getString().getCString();
     SCMO_RC rc;  
   
     CString className = objRep->_className.getString().getCString();  
  
     // Is the instance from the same class ?     // Is the instance from the same class ?
     if (!(_equalNoCaseUTF8Strings(     if (!(_equalNoCaseUTF8Strings(
Line 2149 
Line 2328 
              strlen(className))))              strlen(className))))
     {     {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS,         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS,
            objRep->_className.getString());             cimObj.getClassName().getString());
     }     }
  
     //set host name     //set host name
     _setString(objRep->_host,inst.hdr->hostName,&inst.mem );      _setString(cimObj.getHost(),inst.hdr->hostName,&inst.mem );
  
     for (Uint32 i = 0, k = objRep->_keyBindings.size(); i < k; i++)      const Array<CIMKeyBinding> & keys=cimObj.getKeyBindings();
       for (Uint32 i = 0, k = keys.size(); i < k; i++)
     {     {
         String key = objRep->_keyBindings[i].getValue();          String key = keys[i].getValue();
         rc = _setKeyBindingFromString(          _setKeyBindingFromString(
             (const char*)              (const char*) keys[i].getName().getString().getCString(),
                 objRep->_keyBindings[i].getName().getString().getCString(),  
             _CIMTypeFromKeyBindingType(             _CIMTypeFromKeyBindingType(
                 (const char*)key.getCString(),                 (const char*)key.getCString(),
                 objRep->_keyBindings[i].getType()),                  keys[i].getType()),
             key);             key);
   
         if (rc != SCMO_OK)  
         {  
                String message("Can not set CIMObjectPath key binding:'");  
                message.append(  
                    objRep->_keyBindings[i].getName().getString());  
                message.append("'");  
                throw CIMException(CIM_ERR_FAILED, message);  
         }  
     }     }
   
 } }
   /*
       This function handles both class and user-defined properties
       because _getSCMBValueForNode handles both
   */
 void SCMOInstance::_setCIMValueAtNodeIndex( void SCMOInstance::_setCIMValueAtNodeIndex(
     Uint32 node,     Uint32 node,
     CIMValueRep* valRep,     CIMValueRep* valRep,
     CIMType realType)     CIMType realType)
 { {
     SCMBValue* theInstPropNodeArray =      SCMBValue& theInstProp = _getSCMBValueForNode(node);
         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);  
   
   
     SCMBValue& theInstProp = theInstPropNodeArray[node];  
  
     theInstProp.valueType=realType;     theInstProp.valueType=realType;
     theInstProp.flags.isNull=valRep->isNull;     theInstProp.flags.isNull=valRep->isNull;
Line 2210 
Line 2379 
             // Is set to the number of array members by the function.             // Is set to the number of array members by the function.
             theInstProp.valueArraySize,             theInstProp.valueArraySize,
             inst.hdr->instNameSpace.start,             inst.hdr->instNameSpace.start,
             inst.hdr->instNameSpace.length,              inst.hdr->instNameSpace.size,
             valRep->u);             valRep->u);
     }     }
     else     else
Line 2220 
Line 2389 
             &inst.mem,             &inst.mem,
             realType,             realType,
             inst.hdr->instNameSpace.start,             inst.hdr->instNameSpace.start,
             inst.hdr->instNameSpace.length,              inst.hdr->instNameSpace.size,
             valRep->u);             valRep->u);
     }     }
 } }
Line 2233 
Line 2402 
  
 void SCMOInstance::setHostName(const char* hostName) void SCMOInstance::setHostName(const char* hostName)
 { {
     Uint32 len;      Uint32 len = 0;
   
       _copyOnWrite();
  
     if (hostName!=0)     if (hostName!=0)
     {     {
  
         len = strlen((const char*)hostName);         len = strlen((const char*)hostName);
         if(len != 0)      }
         {  
   
             // copy including trailing '\0'             // copy including trailing '\0'
             _setBinary(hostName,len+1,inst.hdr->hostName,&inst.mem);             _setBinary(hostName,len+1,inst.hdr->hostName,&inst.mem);
             return;  
         }  
   
     }  
     inst.hdr->hostName.start=0;  
     inst.hdr->hostName.length=0;  
 } }
  
 const char* SCMOInstance::getHostName() const const char* SCMOInstance::getHostName() const
Line 2257 
Line 2420 
     return _getCharString(inst.hdr->hostName,inst.base);     return _getCharString(inst.hdr->hostName,inst.base);
 } }
  
 const char* SCMOInstance::getHostName_l(Uint64& length) const  const char* SCMOInstance::getHostName_l(Uint32& length) const
   {
       length = inst.hdr->hostName.size;
       if (0 == length)
       {
           return 0;
       }
       else
 { {
     length = inst.hdr->hostName.length;          length--;
       }
     return _getCharString(inst.hdr->hostName,inst.base);     return _getCharString(inst.hdr->hostName,inst.base);
 } }
  
 void SCMOInstance::setClassName(const char* className) void SCMOInstance::setClassName(const char* className)
 { {
     Uint32 len;      Uint32 len=0;
   
       _copyOnWrite();
  
       // flag the instance as compromized
       inst.hdr->flags.isCompromised=true;
     if (className!=0)     if (className!=0)
     {     {
   
         len = strlen((const char*)className);         len = strlen((const char*)className);
         if(len != 0)      }
         {  
   
             // copy including trailing '\0'             // copy including trailing '\0'
       // _setBinary also sets the name to 0 if either className==0 or len+1==1
             _setBinary(className,len+1,inst.hdr->instClassName,&inst.mem);             _setBinary(className,len+1,inst.hdr->instClassName,&inst.mem);
             return;  
         }  
   
     }     }
  
     inst.hdr->instClassName.start=0;  void SCMOInstance::setClassName_l(const char* className, Uint32 len)
     inst.hdr->instClassName.length=0;  {
       _copyOnWrite();
  
     // flag the instance as compromized      // flag the instance as compromised
     inst.hdr->flags.isCompromised=true;     inst.hdr->flags.isCompromised=true;
       // copy including trailing '\0'
       // _setBinary also sets the name to 0 if either className==0 or len+1==1
       _setBinary(className,len+1,inst.hdr->instClassName,&inst.mem);
 } }
  
 const char* SCMOInstance::getClassName() const const char* SCMOInstance::getClassName() const
Line 2294 
Line 2467 
     return _getCharString(inst.hdr->instClassName,inst.base);     return _getCharString(inst.hdr->instClassName,inst.base);
 } }
  
 const char* SCMOInstance::getClassName_l(Uint64 & length) const  const char* SCMOInstance::getClassName_l(Uint32 & length) const
   {
       length = inst.hdr->instClassName.size;
       if (0 == length)
       {
           return 0;
       }
       else
 { {
     length = inst.hdr->instClassName.length;          length--;
       }
     return _getCharString(inst.hdr->instClassName,inst.base);     return _getCharString(inst.hdr->instClassName,inst.base);
 } }
  
 void SCMOInstance::setNameSpace(const char* nameSpace) void SCMOInstance::setNameSpace(const char* nameSpace)
 { {
     Uint32 len;      Uint32 len = 0;
   
       _copyOnWrite();
   
       // flag the instance as compromized
       inst.hdr->flags.isCompromised=true;
  
     if (nameSpace!=0)     if (nameSpace!=0)
     {     {
  
         len = strlen((const char*)nameSpace);         len = strlen((const char*)nameSpace);
         if(len != 0)      }
         {  
   
             // copy including trailing '\0'             // copy including trailing '\0'
             _setBinary(nameSpace,len+1,inst.hdr->instNameSpace,&inst.mem);             _setBinary(nameSpace,len+1,inst.hdr->instNameSpace,&inst.mem);
             return;  
         }         }
  
   void SCMOInstance::setNameSpace_l(const char* nameSpace, Uint32 len)
   {
       // Copy on Write is only necessary if a realloc() becomes necessary
       if (inst.mem->freeBytes < ((len+8) & ~7))
       {
           _copyOnWrite();
     }     }
   
     inst.hdr->instNameSpace.start=0;  
     inst.hdr->instNameSpace.length=0;  
   
     // flag the instance as compromized     // flag the instance as compromized
     inst.hdr->flags.isCompromised=true;     inst.hdr->flags.isCompromised=true;
       // copy including trailing '\0'
       _setBinary(nameSpace,len+1,inst.hdr->instNameSpace,&inst.mem);
 } }
  
 const char* SCMOInstance::getNameSpace() const const char* SCMOInstance::getNameSpace() const
Line 2331 
Line 2517 
     return _getCharString(inst.hdr->instNameSpace,inst.base);     return _getCharString(inst.hdr->instNameSpace,inst.base);
 } }
  
 const char* SCMOInstance::getNameSpace_l(Uint64 & length) const  const char* SCMOInstance::getNameSpace_l(Uint32 & length) const
   {
       length = inst.hdr->instNameSpace.size;
       if (0 == length)
       {
           return 0;
       }
       else
 { {
     length = inst.hdr->instNameSpace.length;          length--;
       }
     return _getCharString(inst.hdr->instNameSpace,inst.base);     return _getCharString(inst.hdr->instNameSpace,inst.base);
 } }
  
 void SCMOInstance::buildKeyBindingsFromProperties()  void SCMOInstance::completeHostNameAndNamespace(
       const char* hn,
       Uint32 hnLen,
       const char* ns,
       Uint32 nsLen)
   {
       // hostName is Null or empty String ?
       if (0 == inst.hdr->hostName.size ||
           0 == inst.base[inst.hdr->hostName.start])
 { {
           // Copy on Write is only necessary if a realloc() becomes necessary
           if (inst.mem->freeBytes < ((hnLen+8) & ~7))
           {
               _copyOnWrite();
           }
           // copy including trailing '\0'
           _setBinary(hn,hnLen+1,inst.hdr->hostName,&inst.mem);
       }
       // namespace is Null or empty String ?
       if (0 == inst.hdr->instNameSpace.size ||
           0 == inst.base[inst.hdr->instNameSpace.start])
       {
           setNameSpace_l(ns,nsLen);
       }
   }
   
  
   void SCMOInstance::buildKeyBindingsFromProperties()
   {
       Uint32 propNode;
       // The theClassKeyPropList pointer will always be valid,
       // even after a realloc() caused by copyOnWrite()
       // as this is an absolute pointer to the class which does not change
     Uint32* theClassKeyPropList =     Uint32* theClassKeyPropList =
         (Uint32*) &((inst.hdr->theClass->cls.base)          (Uint32*) &((inst.hdr->theClass.ptr->cls.base)
                           [(inst.hdr->theClass->cls.hdr->keyIndexList.start)]);                      [(inst.hdr->theClass.ptr->cls.hdr->keyIndexList.start)]);
  
     SCMBKeyBindingValue* theKeyBindValueArray;      SCMBKeyBindingValue* theKeyBindValueArray =
     SCMBValue* theInstPropNodeArray;          (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
       SCMBValue* theInstPropNodeArray=
           (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
  
     Uint32 propNode;      inst.hdr->numberKeyBindings =
           inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
  
     for (Uint32 i = 0, k = inst.hdr->numberKeyBindings; i < k; i++)     for (Uint32 i = 0, k = inst.hdr->numberKeyBindings; i < k; i++)
     {     {
         // the instance pointers has to be reinitialized each time,  
         // because in _setKeyBindingFromSCMBUnion()  
         // a reallocation can take place.  
         theKeyBindValueArray =  
            (SCMBKeyBindingValue*)&inst.base[inst.hdr->keyBindingArray.start];  
   
         theInstPropNodeArray =  
             (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];  
   
         // If the keybinding is not set.         // If the keybinding is not set.
         if (!theKeyBindValueArray[i].isSet)         if (!theKeyBindValueArray[i].isSet)
         {         {
             // get the node index for this key binding form class             // get the node index for this key binding form class
             propNode = theClassKeyPropList[i];             propNode = theClassKeyPropList[i];
  
             // if property was not set by the provider or it is null.              // if property was set by the provider and it is not null.
             if (!theInstPropNodeArray[propNode].flags.isSet ||              if ( theInstPropNodeArray[propNode].flags.isSet &&
                  theInstPropNodeArray[propNode].flags.isNull)                  !theInstPropNodeArray[propNode].flags.isNull)
             {              {
                 const char * propName =                  _copyOnWrite();
                     inst.hdr->theClass->_getPropertyNameAtNode(propNode);                  // the instance pointers have to be recalculated as copyOnWrite
                 throw NoSuchProperty(String(propName));                  // might change the absolute address of these pointers
             }                  theInstPropNodeArray =
                       (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
                   theKeyBindValueArray =
                       (SCMBKeyBindingValue*)
                           &(inst.base[inst.hdr->keyBindingArray.start]);
  
             _setKeyBindingFromSCMBUnion(             _setKeyBindingFromSCMBUnion(
                 theInstPropNodeArray[propNode].valueType,                 theInstPropNodeArray[propNode].valueType,
                 theInstPropNodeArray[propNode].value,                 theInstPropNodeArray[propNode].value,
                 inst.base,                 inst.base,
                 theKeyBindValueArray[i]);                 theKeyBindValueArray[i]);
   
                   // the instance pointers have to be reinitialized each time,
                   // because a reallocation can take place
                   // in _setKeyBindingFromSCMBUnion()
                   theKeyBindValueArray =
                       (SCMBKeyBindingValue*)
                           &(inst.base[inst.hdr->keyBindingArray.start]);
                   theInstPropNodeArray =
                       (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
   
               }
         }         }
     }     }
 } }
Line 2404 
Line 2637 
     case CIMTYPE_REAL64:     case CIMTYPE_REAL64:
     case CIMTYPE_CHAR16:     case CIMTYPE_CHAR16:
     case CIMTYPE_BOOLEAN:     case CIMTYPE_BOOLEAN:
           {
               memcpy(&keyData.data,&u,sizeof(SCMBUnion));
               keyData.data.simple.hasValue=true;
               keyData.isSet=true;
               break;
           }
     case CIMTYPE_DATETIME:     case CIMTYPE_DATETIME:
         {         {
             memcpy(&keyData.data,&u,sizeof(SCMBUnion));             memcpy(&keyData.data,&u,sizeof(SCMBUnion));
Line 2413 
Line 2652 
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
         {         {
             keyData.isSet=true;             keyData.isSet=true;
               // Check if a key binding is set within the same instance.
               // If this is the case, a reallocation can take place and the
               // uBase pointer can be invalid and cause a read in freed memory!
               if (uBase == inst.base)
               {
                   if (0 != u.stringValue.size )
                   {
                       // We are doing a in instance copy of data.
                       // We can not use the _setBinary() function because
                       // all real pointer can be in valid after
                       // the _getFreeSprace() function!
                       // We have to save all relative pointer on the stack.
                       Uint64 start;
                       SCMBDataPtr tmp;
                       tmp.size = u.stringValue.size;
                       tmp.start = u.stringValue.start;
   
                       // In this function a reallocation may take place!
                       // The keyData.data.stringValue is set
                       // before the reallocation.
                       start = _getFreeSpace(
                           keyData.data.stringValue,
                           u.stringValue.size,
                           &inst.mem);
                       // Copy the string,
                       // but using the own base pointer and the saved relative
                       // string pointer.
                       memcpy(
                           &(inst.base[start]),
                           _getCharString(tmp,inst.base),
                           tmp.size);
                   }
                   else
                   {
                      keyData.data.stringValue.size=0;
                      keyData.data.stringValue.start=0;
                   }
   
               }
               else
               {
             _setBinary(             _setBinary(
                 &uBase[u.stringValue.start],                 &uBase[u.stringValue.start],
                 u.stringValue.length,                      u.stringValue.size,
                 keyData.data.stringValue,                 keyData.data.stringValue,
                 &inst.mem);                 &inst.mem);
               }
   
             break;             break;
         }         }
     case CIMTYPE_REFERENCE:     case CIMTYPE_REFERENCE:
Line 2430 
Line 2712 
             if(u.extRefPtr)             if(u.extRefPtr)
             {             {
                 keyData.data.extRefPtr = new SCMOInstance(*u.extRefPtr);                 keyData.data.extRefPtr = new SCMOInstance(*u.extRefPtr);
                   keyData.isSet=true;
                   // This function can cause a reallocation !
                   // Pointers can be invalid after the call.
                   _setExtRefIndex(&(keyData.data),&inst.mem);
             }             }
             else             else
             {             {
                   keyData.isSet=true;
                 keyData.data.extRefPtr=0;                 keyData.data.extRefPtr=0;
             }             }
             keyData.isSet=true;  
             break;             break;
         }         }
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
Line 2447 
Line 2733 
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
Line 2458 
Line 2744 
     PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE     PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE
         - sizeof(SCMBInstance_Main)>0);         - sizeof(SCMBInstance_Main)>0);
  
   
     inst.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);     inst.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);
     if (inst.base == 0)     if (inst.base == 0)
     {     {
Line 2478 
Line 2763 
     inst.hdr->header.startOfFreeSpace=sizeof(SCMBInstance_Main);     inst.hdr->header.startOfFreeSpace=sizeof(SCMBInstance_Main);
  
     inst.hdr->refCount=1;     inst.hdr->refCount=1;
       inst.hdr->numberUserProperties = 0;
  
     //Assign the SCMBClass structure this instance based on.      if (pClass == NULL)
     inst.hdr->theClass = pClass;      {
           // Set number of properties
           inst.hdr->numberKeyBindings = 0;
           inst.hdr->numberProperties = 0;
           inst.hdr->flags.noClassForInstance = true;
       }
       else
       {
           //Assign the SCMBClass structure to this instance based on.
           inst.hdr->theClass.ptr = pClass;
  
     // Copy name space name and class name of the class     // Copy name space name and class name of the class
     _setBinary(     _setBinary(
         _getCharString(inst.hdr->theClass->cls.hdr->className,          _getCharString(inst.hdr->theClass.ptr->cls.hdr->className,
                        inst.hdr->theClass->cls.base),                         inst.hdr->theClass.ptr->cls.base),
         inst.hdr->theClass->cls.hdr->className.length,          inst.hdr->theClass.ptr->cls.hdr->className.size,
         inst.hdr->instClassName,         inst.hdr->instClassName,
         &inst.mem);         &inst.mem);
  
     _setBinary(     _setBinary(
         _getCharString(inst.hdr->theClass->cls.hdr->nameSpace,          _getCharString(inst.hdr->theClass.ptr->cls.hdr->nameSpace,
                        inst.hdr->theClass->cls.base),                         inst.hdr->theClass.ptr->cls.base),
         inst.hdr->theClass->cls.hdr->nameSpace.length,          inst.hdr->theClass.ptr->cls.hdr->nameSpace.size,
         inst.hdr->instNameSpace,         inst.hdr->instNameSpace,
         &inst.mem);         &inst.mem);
  
     // Number of key bindings     // Number of key bindings
     inst.hdr->numberKeyBindings =     inst.hdr->numberKeyBindings =
         inst.hdr->theClass->cls.hdr->keyBindingSet.number;          inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
  
     // Number of properties     // Number of properties
     inst.hdr->numberProperties =     inst.hdr->numberProperties =
         inst.hdr->theClass->cls.hdr->propertySet.number;          inst.hdr->theClass.ptr->cls.hdr->propertySet.number;
       }
  
     // Allocate the SCMOInstanceKeyBindingArray     // Allocate the SCMOInstanceKeyBindingArray
     _getFreeSpace(     _getFreeSpace(
           inst.hdr->keyBindingArray,           inst.hdr->keyBindingArray,
           sizeof(SCMBKeyBindingValue)*inst.hdr->numberKeyBindings,           sizeof(SCMBKeyBindingValue)*inst.hdr->numberKeyBindings,
           &inst.mem,            &inst.mem);
           true);  
  
     // Allocate the SCMBInstancePropertyArray     // Allocate the SCMBInstancePropertyArray
     _getFreeSpace(     _getFreeSpace(
         inst.hdr->propertyArray,         inst.hdr->propertyArray,
         sizeof(SCMBValue)*inst.hdr->numberProperties,         sizeof(SCMBValue)*inst.hdr->numberProperties,
         &inst.mem,          &inst.mem);
         true);  
   
 } }
  
   
 void SCMOInstance::_setCIMInstance(const CIMInstance& cimInstance) void SCMOInstance::_setCIMInstance(const CIMInstance& cimInstance)
 { {
     CIMPropertyRep* propRep;  
     Uint32 propNode;  
     Uint64 valueStart;  
     SCMO_RC rc;     SCMO_RC rc;
     CIMType realType;     CIMType realType;
  
Line 2535 
Line 2826 
     // The instance level qualifiers are stored on the associated SCMOClass.     // The instance level qualifiers are stored on the associated SCMOClass.
     inst.hdr->flags.includeQualifiers=(instRep->_qualifiers.getCount()>0);     inst.hdr->flags.includeQualifiers=(instRep->_qualifiers.getCount()>0);
  
       // To ensure that when converting a CIMInstance to a SCMOInstance
       // and vice versa they have the same property set.
       // If there is no class for this SCMO instance, ingore this since
       // there is no class to work from.  Have to depend on the properties
       if (!noClassForInstance())
       {
           inst.hdr->flags.exportSetOnly = true;
       }
   
     _setCIMObjectPath(instRep->_reference);     _setCIMObjectPath(instRep->_reference);
  
     // Copy all properties     // Copy all properties
     for (Uint32 i = 0, k = instRep->_properties.size(); i < k; i++)     for (Uint32 i = 0, k = instRep->_properties.size(); i < k; i++)
     {     {
         propRep = instRep->_properties[i]._rep;          CIMPropertyRep* propRep = instRep->_properties[i]._rep;
         // if not already detected that qualifiers are specified and         // if not already detected that qualifiers are specified and
         // there are qualifers at that property.         // there are qualifers at that property.
   
         if (!inst.hdr->flags.includeQualifiers &&         if (!inst.hdr->flags.includeQualifiers &&
             propRep->getQualifierCount() > 0)             propRep->getQualifierCount() > 0)
         {         {
Line 2557 
Line 2858 
         }         }
  
         // get the property node index for the property         // get the property node index for the property
         rc = inst.hdr->theClass->_getProperyNodeIndex(  
             propNode,  
             (const char*)propRep->_name.getString().getCString());  
  
         if (rc != SCMO_OK)          Uint32 propNode;
           rc = getPropertyNodeIndex(
               (const char*)propRep->_name.getString().getCString(),
               propNode);
   
           // class-defined property so map
           if (rc == SCMO_OK && !noClassForInstance())
         {         {
             throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NO_SUCH_PROPERTY,  
                propRep->_name.getString());  
         }  
         // The type stored in the class information is set on realType.         // The type stored in the class information is set on realType.
         // It must be used in further calls to guaranty consistence.         // It must be used in further calls to guaranty consistence.
         rc = inst.hdr->theClass->_isNodeSameType(              rc = inst.hdr->theClass.ptr->_isNodeSameType(
                  propNode,                  propNode,
                  propRep->_value._rep->type,                  propRep->_value._rep->type,
                  propRep->_value._rep->isArray,                  propRep->_value._rep->isArray,
                  realType);                  realType);
   
         if (rc == SCMO_OK)         if (rc == SCMO_OK)
         {         {
             _setCIMValueAtNodeIndex(propNode, propRep->_value._rep,realType);                  _setCIMValueAtNodeIndex(
                       propNode,
                       propRep->_value._rep,
                       realType);
         }         }
         else         else
         {         {
             throw PEGASUS_CIM_EXCEPTION(CIM_ERR_TYPE_MISMATCH,                  PEG_TRACE((TRC_DISCARDED_DATA,Tracer::LEVEL2,
                propRep->_name.getString());                      "CIMProperty '%s' with type '%s' "
         }                          "can not be set at SCMOInstance."
     }                          "It is has not same type '%s' as defined in "
                           "class '%s' of name space '%s'",
                        cimTypeToString(propRep->_value._rep->type),
                       (const char*)propRep->_name.getString().getCString(),
                        cimTypeToString(realType),
                       (const char*)instRep->_reference._rep->
                              _className.getString().getCString(),
                       (const char*)instRep->_reference._rep->
                              _nameSpace.getString().getCString()));
 } }
  
 SCMO_RC SCMOInstance::getProperty(          }
     const char* name,          // user-defined property and property already exists
     CIMType& type,          else if (rc == SCMO_OK && noClassForInstance())
     const SCMBUnion** pOutVal,  
     Boolean& isArray,  
     Uint32& size ) const  
 { {
               // get an existing or new user defined property
     Uint32 node;     Uint32 node;
     const char* pname;              rc = _getUserPropertyNodeIndex(node,
     SCMO_RC rc = SCMO_OK;                  (const char*)propRep->_name.getString().getCString());
   
     *pOutVal = 0;  
     isArray = false;  
     size = 0;  
  
     rc = inst.hdr->theClass->_getProperyNodeIndex(node,name);              // KS_FUTURE This would be good one to extend to handle
     if (rc != SCMO_OK)              // both user and class defined properties.
     {              _setCIMValueAtNodeIndex(
         return rc;                  propNode,
                   propRep->_value._rep,
                   propRep->_value._rep->type);
     }     }
           // User-defined property that has not yet been created.
     // is filtering on ?          else if (rc == SCMO_NOT_FOUND && noClassForInstance())
     if (inst.hdr->flags.isFiltered)  
     {     {
         // Is the property NOT in the property filter ?              _createNewUserDefinedProperty(
         if(!_isPropertyInFilter(node))                  (const char*)propRep->_name.getString().getCString(),
                   propRep->_name.getString().size(),
                   realType);
   
               // get the node  for element we just created.
   
               rc = getPropertyNodeIndex(
                   (const char*)propRep->_name.getString().getCString(),
                   propNode);
   
               _setCIMValueAtNodeIndex(
                   propNode,
                   propRep->_value._rep,
                   propRep->_value._rep->type);
           }
           else
         {         {
             // The named propery is not part of this instance  
             // due to filtering.              PEG_TRACE((TRC_DISCARDED_DATA,Tracer::LEVEL2,
             return SCMO_NOT_FOUND;                  "CIMProperty '%s' can not be set at SCMOInstance."
                       "It is not part of class '%s' of name space '%s'",
                   (const char*)propRep->_name.getString().getCString(),
                   (const char*)instRep->_reference._rep->
                          _className.getString().getCString(),
                   (const char*)instRep->_reference._rep->
                          _nameSpace.getString().getCString()));
         }         }
     }     }
   
     return  _getPropertyAtNodeIndex(node,&pname,type,pOutVal,isArray,size);  
 } }
   /*
 SCMO_RC SCMOInstance::getPropertyAt(      Gets a SCMO Property from the instance based on the property name
         Uint32 idx,      in the instance. This gets both class based properties and
         const char** pname,      user-defined properties
   */
   SCMO_RC SCMOInstance::getProperty(
       const char* name,
         CIMType& type,         CIMType& type,
         const SCMBUnion** pOutVal,         const SCMBUnion** pOutVal,
         Boolean& isArray,         Boolean& isArray,
         Uint32& size ) const         Uint32& size ) const
 { {
     *pname = 0;      Uint32 node;
       const char* pname;
       SCMO_RC rc = SCMO_OK;
   
     *pOutVal = 0;     *pOutVal = 0;
     isArray = false;     isArray = false;
     size = 0;     size = 0;
     Uint32 node;  
  
     // is filtering on ?      // Try to get node from class
     if (inst.hdr->flags.isFiltered)      // KS_TODO. This would be simpler if we used the public
     {      // getPropertyNodeIndex
         // check the number of properties part of the filter      rc = inst.hdr->theClass.ptr->_getPropertyNodeIndex(node,name);
         if (idx >= inst.hdr->filterProperties)  
         {  
             return SCMO_INDEX_OUT_OF_BOUND;  
         }  
  
         // Get absolut pointer to property filter index map of the instance  //  Error, not in class. Try to get from instance user-defined properties.
         Uint32* propertyFilterIndexMap =      if (rc != SCMO_OK)
         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);  
   
         // get the real node index of the property.  
         node = propertyFilterIndexMap[idx];  
     }  
     else  
     {     {
         // the index is used as node index.          if ((rc == SCMO_NOT_FOUND) && noClassForInstance())
         node = idx;  
         if (node >= inst.hdr->numberProperties)  
         {         {
             return SCMO_INDEX_OUT_OF_BOUND;              rc = _getUserPropertyNodeIndex(node, name);
         }         }
     }          if (rc != SCMO_OK)
   
     return  _getPropertyAtNodeIndex(node,pname,type,pOutVal,isArray,size);  
 }  
   
 SCMO_RC SCMOInstance::getPropertyAt(  
     Uint32 pos,  
     SCMBValue** value,  
     const char ** valueBase,  
     SCMBClassProperty ** propDef) const  
 {  
     Uint32 node;  
     // is filtering on ?  
     if (inst.hdr->flags.isFiltered)  
     {  
         // check the number of properties part of the filter  
         if (pos >= inst.hdr->filterProperties)  
         {         {
             return SCMO_INDEX_OUT_OF_BOUND;              return rc;
         }  
   
         // Get absolut pointer to property filter index map of the instance  
         Uint32* propertyFilterIndexMap =  
         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);  
   
         // get the real node index of the property.  
         node = propertyFilterIndexMap[pos];  
     }     }
     else  
     {  
         // the index is used as node index.  
         node = pos;  
         if (node >= inst.hdr->numberProperties)  
         {  
             return SCMO_INDEX_OUT_OF_BOUND;  
         }         }
       return  _getPropertyAtNodeIndex(node,&pname,type,pOutVal,isArray,size);
     }     }
  
     SCMBValue* theInstPropNodeArray =  /*
         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);      getPropertyAt - This function supports both class-defined and user
       defined properties. It is one of the public interfaces. Note that
     // create a pointer to property node array of the class.      there is no public way to distinguish class-defined and user-defined
     Uint64 idx = inst.hdr->theClass->cls.hdr->propertySet.nodeArray.start;      properties.
     SCMBClassPropertyNode* theClassPropNodeArray =  */
         (SCMBClassPropertyNode*)&(inst.hdr->theClass->cls.base)[idx];  
   
     // return the absolute pointer to the property definition  
     *propDef= &(theClassPropNodeArray[node].theProperty);  
  
     // need check if property set or not, if not set use the default value  SCMO_RC SCMOInstance::getPropertyAt(
     if (theInstPropNodeArray[node].flags.isSet)          Uint32 idx,
           const char** pname,
           CIMType& type,
           const SCMBUnion** pOutVal,
           Boolean& isArray,
           Uint32& size ) const
     {     {
         // return the absolute pointer to the property value in the instance      *pname = 0;
         *value = &(theInstPropNodeArray[node]);      *pOutVal = 0;
         *valueBase = inst.base;      isArray = false;
     }      size = 0;
     else  
       if (idx >= getPropertyCount())
     {     {
         // return the absolute pointer to          return SCMO_INDEX_OUT_OF_BOUND;
         *value = &(theClassPropNodeArray[node].theProperty.defaultValue);  
         *valueBase = inst.hdr->theClass->cls.base;  
     }     }
  
     return SCMO_OK;      return  _getPropertyAtNodeIndex(idx,pname,type,pOutVal,isArray,size);
 } }
  
   /*
       Gets the Node index of a property by name. This supports both
       class and user-defined properties.
       Returns the 0-origin node of the property and SCMO_OK or
       SCMO_NOT_FOUND.
       If the PropertyName argument is empty, it returns SCMO_INVALID_PARAMTER.
   */
 SCMO_RC SCMOInstance::getPropertyNodeIndex(const char* name, Uint32& node) const SCMO_RC SCMOInstance::getPropertyNodeIndex(const char* name, Uint32& node) const
 { {
     SCMO_RC rc;     SCMO_RC rc;
Line 2734 
Line 3030 
         return SCMO_INVALID_PARAMETER;         return SCMO_INVALID_PARAMETER;
     }     }
  
     rc = inst.hdr->theClass->_getProperyNodeIndex(node,name);      if (noClassForInstance())
       {
           rc = _getUserPropertyNodeIndex(node, name);
       }
       else
       {
           rc = inst.hdr->theClass.ptr->_getPropertyNodeIndex(node, name);
       }
     return rc;     return rc;
  
 } }
   /*
       set a property with name from input parameters.  This will set
       into the normal properties array if the property is in the class
       or into the user-defined array if the property is NOT in the array and
       the noClassForInstance is set.
   */
 SCMO_RC SCMOInstance::setPropertyWithOrigin( SCMO_RC SCMOInstance::setPropertyWithOrigin(
     const char* name,     const char* name,
     CIMType type,      CIMType theType,
     const SCMBUnion* pInVal,     const SCMBUnion* pInVal,
     Boolean isArray,     Boolean isArray,
     Uint32 size,     Uint32 size,
     const char* origin)     const char* origin)
 { {
       // In this function no  _copyOnWrite(), it does not change the instance.
     Uint32 node;     Uint32 node;
     SCMO_RC rc;     SCMO_RC rc;
     CIMType realType;     CIMType realType;
  
     rc = inst.hdr->theClass->_getProperyNodeIndex(node,name);      // find the property in the class.
     if (rc != SCMO_OK)      rc = inst.hdr->theClass.ptr->_getPropertyNodeIndex(node,name);
   
       // If the instance flags indicate that there was no support class for
       // this instance and noClassForInstance set, handle the property as
       // a user-defined property in the user-defined property section of the
       // instance
       if (noClassForInstance())
     {     {
         return rc;          rc = _getUserPropertyNodeIndex(node, name);
   
           SCMBUserPropertyElement* pElement;
           if (rc == SCMO_OK)
           {
               pElement = _getUserDefinedPropertyElementAt(node);
               if (pElement->value.flags.isSet
                   && (pElement->value.valueType != theType))
               {
                   return SCMO_TYPE_MISSMATCH;
               }
     }     }
  
     // Is the traget type OK ?          else if (rc == SCMO_NOT_FOUND)
     // The type stored in the class information is set on realType.          {
     // It must be used in further calls to guaranty consistence.              pElement =_createNewUserDefinedProperty(name, strlen(name),
     rc = inst.hdr->theClass->_isNodeSameType(node,type,isArray,realType);                                                theType);
     if (rc != SCMO_OK)          }
           else
     {     {
         return rc;         return rc;
     }     }
           // check class origin if set.
           if ((origin != 0) && (pElement->classOrigin.start != 0))
           {
               if (!_equalNoCaseUTF8Strings(pElement->classOrigin,
                                           inst.base,
                                           origin,
                                           strlen(origin)))
               {
                   return SCMO_NOT_SAME_ORIGIN;
               }
               else
               {
                   // Copy the origin name including the trailing '\0'
                   _setBinary(origin,strlen(name)+1,
                       pElement->classOrigin,&inst.mem);
               }
           }
           // Test for same type and array type
           SCMBValue& instVal = pElement->value;
           if (instVal.flags.isSet)
           {
               if (instVal.valueType != theType)
               {
                   // Accept a property of type instance also
                   // for an CIMTYPE_OBJECT property.
                   if (!(theType == CIMTYPE_INSTANCE &&
                         instVal.valueType == CIMTYPE_OBJECT))
                   {
                       return SCMO_WRONG_TYPE;
                   }
               }
  
     // is filtering on ?              if (instVal.flags.isArray != isArray)
     if (inst.hdr->flags.isFiltered)  
     {     {
         // Is the property NOT in the property filter ?                  return (instVal.flags.isArray?
         if(!_isPropertyInFilter(node))                          SCMO_NOT_AN_ARRAY : SCMO_IS_AN_ARRAY);
               }
           }
   
           // KS_FUTURE. This used only once so no need for separate function
           _setPropertyInUserDefinedElement(
               pElement,
               theType,
               pInVal,
               isArray,
               size);
   
           // test and set classOrigin, etc.
           return SCMO_OK;
       }
   
       //
       // This is a class-defined instance
       //
       if (rc != SCMO_OK)
         {         {
             // The named propery is not part of this instance          return rc;
             // due to filtering.  
             return SCMO_NOT_FOUND;  
         }         }
   
       // Is the target type OK ?
       // The type stored in the class information is set to real Type.
       // It must be used in further calls to guaranty consistence.
       rc = inst.hdr->theClass.ptr->_isNodeSameType(node,theType,isArray,realType);
       if (rc != SCMO_OK)
       {
           return rc;
     }     }
  
     // check class origin if set.     // check class origin if set.
     if (origin!= 0)     if (origin!= 0)
     {     {
         if(!inst.hdr->theClass->_isSamePropOrigin(node,origin))          if(!inst.hdr->theClass.ptr->_isSamePropOrigin(node,origin))
         {         {
             return SCMO_NOT_SAME_ORIGIN;             return SCMO_NOT_SAME_ORIGIN;
         }         }
     }     }
       // KS_FUTURE should this be user-defined capable so could delete
       // the user set above.
     _setPropertyAtNodeIndex(node,realType,pInVal,isArray,size);     _setPropertyAtNodeIndex(node,realType,pInVal,isArray,size);
  
     return SCMO_OK;     return SCMO_OK;
 } }
  
   // KS_TODO This method never called in OpenPegasus.
   // Is there a reason for it or should we delete it.
  SCMO_RC SCMOInstance::setPropertyWithNodeIndex(  SCMO_RC SCMOInstance::setPropertyWithNodeIndex(
      Uint32 node,      Uint32 node,
      CIMType type,      CIMType type,
Line 2801 
Line 3183 
      Boolean isArray,      Boolean isArray,
      Uint32 size)      Uint32 size)
  {  {
       // In this function no  _copyOnWrite(), it does not change the instance.
   
      SCMO_RC rc;      SCMO_RC rc;
      CIMType realType;      CIMType realType;
  
Line 2809 
Line 3193 
          return SCMO_INDEX_OUT_OF_BOUND;          return SCMO_INDEX_OUT_OF_BOUND;
      }      }
  
      // is filtering on ?  
      if (inst.hdr->flags.isFiltered)  
      {  
          // Is the property NOT in the property filter ?  
          if(!_isPropertyInFilter(node))  
          {  
              // The proptery of the is not set due to filtering.  
              return SCMO_OK;  
          }  
      }  
   
      // Is the traget type OK ?      // Is the traget type OK ?
      // The type stored in the class information is set on realType.      // The type stored in the class information is set on realType.
      // It must be used in further calls to guaranty consistence.      // It must be used in further calls to guaranty consistence.
      rc = inst.hdr->theClass->_isNodeSameType(node,type,isArray,realType);      rc = inst.hdr->theClass.ptr->_isNodeSameType(node,type,isArray,realType);
      if (rc != SCMO_OK)      if (rc != SCMO_OK)
      {      {
          return rc;          return rc;
Line 2834 
Line 3207 
      return SCMO_OK;      return SCMO_OK;
  }  }
  
   // KS_TODO this one NOT user-defined capable now
 void SCMOInstance::_setPropertyAtNodeIndex( void SCMOInstance::_setPropertyAtNodeIndex(
     Uint32 node,     Uint32 node,
     CIMType type,     CIMType type,
Line 2841 
Line 3215 
     Boolean isArray,     Boolean isArray,
     Uint32 size)     Uint32 size)
 { {
   
       _copyOnWrite();
   
     SCMBValue* theInstPropNodeArray =     SCMBValue* theInstPropNodeArray =
         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
  
Line 2859 
Line 3236 
     }     }
     else     else
     {     {
           theInstPropNodeArray[node].flags.isNull=false;
         _setSCMBUnion(         _setSCMBUnion(
             pInVal,             pInVal,
             type,             type,
Line 2867 
Line 3245 
             theInstPropNodeArray[node].value);             theInstPropNodeArray[node].value);
     }     }
 } }
   /*
       This function can cause a reallocation.
   */
 void SCMOInstance::_setSCMBUnion( void SCMOInstance::_setSCMBUnion(
     const SCMBUnion* pInVal,     const SCMBUnion* pInVal,
     CIMType type,     CIMType type,
Line 2875 
Line 3255 
     Uint32 size,     Uint32 size,
     SCMBUnion & u)     SCMBUnion & u)
 { {
   
     switch (type)     switch (type)
     {     {
     case CIMTYPE_BOOLEAN:     case CIMTYPE_BOOLEAN:
Line 2890 
Line 3269 
     case CIMTYPE_REAL32:     case CIMTYPE_REAL32:
     case CIMTYPE_REAL64:     case CIMTYPE_REAL64:
     case CIMTYPE_CHAR16:     case CIMTYPE_CHAR16:
           {
               if (isArray)
               {
                   _setBinary(pInVal,size*sizeof(SCMBUnion),
                              u.arrayValue,
                              &inst.mem );
               }
               else
               {
                   memcpy(&u,pInVal,sizeof(SCMBUnion));
                   u.simple.hasValue=true;
               }
               break;
           }
     case CIMTYPE_DATETIME:     case CIMTYPE_DATETIME:
         {         {
             if (isArray)             if (isArray)
Line 2901 
Line 3294 
             else             else
             {             {
                 memcpy(&u,pInVal,sizeof(SCMBUnion));                 memcpy(&u,pInVal,sizeof(SCMBUnion));
   
             }             }
             break;             break;
         }         }
Line 2914 
Line 3308 
                 startPtr = _getFreeSpace(                 startPtr = _getFreeSpace(
                     u.arrayValue,                     u.arrayValue,
                     size*sizeof(SCMBUnion),                     size*sizeof(SCMBUnion),
                     &inst.mem,true);                      &inst.mem);
  
                 for (Uint32 i = 0; i < size; i++)                 for (Uint32 i = 0; i < size; i++)
                 {                 {
Line 2955 
Line 3349 
                 startPtr = _getFreeSpace(                 startPtr = _getFreeSpace(
                     u.arrayValue,                     u.arrayValue,
                     size*sizeof(SCMBUnion),                     size*sizeof(SCMBUnion),
                     &inst.mem,false);                      &inst.mem);
  
                 ptr = (SCMBUnion*)&(inst.base[startPtr]);                 ptr = (SCMBUnion*)&(inst.base[startPtr]);
  
Line 2965 
Line 3359 
                     {                     {
                         ptr[i].extRefPtr=                         ptr[i].extRefPtr=
                             new SCMOInstance(*(pInVal[i].extRefPtr));                             new SCMOInstance(*(pInVal[i].extRefPtr));
   
                           // This function can cause a reallocation !
                           // Pointers can be invalid after the call.
                           _setExtRefIndex(&(ptr[i]),&inst.mem);
                     }                     }
                     else                     else
                     {                     {
Line 2983 
Line 3381 
                 if(pInVal->extRefPtr)                 if(pInVal->extRefPtr)
                 {                 {
                     u.extRefPtr = new SCMOInstance(*(pInVal->extRefPtr));                     u.extRefPtr = new SCMOInstance(*(pInVal->extRefPtr));
                       // This function can cause a reallocation !
                       // Pointers can be invalid after the call.
                       _setExtRefIndex(&u,&inst.mem);
   
                 }                 }
                 else                 else
                 {                 {
Line 2993 
Line 3395 
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
Line 3005 
Line 3407 
     CIMType type,     CIMType type,
     Uint32& n,     Uint32& n,
     Uint64 startNS,     Uint64 startNS,
     Uint64 lenNS,      Uint32 sizeNS,
     Union& u)     Union& u)
 { {
     SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);     SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);
Line 3023 
Line 3425 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Boolean> iterator(*x);             ConstArrayIterator<Boolean> iterator(*x);
  
Line 3045 
Line 3446 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Uint8> iterator(*x);             ConstArrayIterator<Uint8> iterator(*x);
  
Line 3067 
Line 3467 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Sint8> iterator(*x);             ConstArrayIterator<Sint8> iterator(*x);
  
Line 3089 
Line 3488 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Uint16> iterator(*x);             ConstArrayIterator<Uint16> iterator(*x);
  
Line 3111 
Line 3509 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Sint16> iterator(*x);             ConstArrayIterator<Sint16> iterator(*x);
  
Line 3133 
Line 3530 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Uint32> iterator(*x);             ConstArrayIterator<Uint32> iterator(*x);
  
Line 3155 
Line 3551 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Sint32> iterator(*x);             ConstArrayIterator<Sint32> iterator(*x);
  
Line 3177 
Line 3572 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Uint64> iterator(*x);             ConstArrayIterator<Uint64> iterator(*x);
  
Line 3199 
Line 3593 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Sint64> iterator(*x);             ConstArrayIterator<Sint64> iterator(*x);
  
Line 3221 
Line 3614 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Real32> iterator(*x);             ConstArrayIterator<Real32> iterator(*x);
  
Line 3243 
Line 3635 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Real64> iterator(*x);             ConstArrayIterator<Real64> iterator(*x);
  
Line 3265 
Line 3656 
             arrayStart = _getFreeSpace(             arrayStart = _getFreeSpace(
                 scmoUnion->arrayValue,                 scmoUnion->arrayValue,
                 loop*sizeof(SCMBUnion),                 loop*sizeof(SCMBUnion),
                 pmem,                  pmem);
                 true);  
  
             ConstArrayIterator<Char16> iterator(*x);             ConstArrayIterator<Char16> iterator(*x);
  
Line 3348 
Line 3738 
  
             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
  
             SCMOClass* theRefClass;  
   
             for (Uint32 i = 0; i < loop ; i++)             for (Uint32 i = 0; i < loop ; i++)
             {             {
                   ptargetUnion[i].extRefPtr =
                 theRefClass = _getSCMOClass(                      new SCMOInstance(
                     iterator[i],                     iterator[i],
                     &(((const char*)*pmem)[startNS]),                     &(((const char*)*pmem)[startNS]),
                     lenNS);                          sizeNS-1);
                   // Was the conversion successful?
                 if (theRefClass != 0)                  if (ptargetUnion[i].extRefPtr->isEmpty())
                 {                 {
                     ptargetUnion[i].extRefPtr =                      // N0, delete the SCMOInstance.
                         new SCMOInstance(*theRefClass,iterator[i]);                      delete ptargetUnion[i].extRefPtr;
                 } else  
                 {  
                     //There is no reference class for the object path  
                     ptargetUnion[i].extRefPtr = 0;                     ptargetUnion[i].extRefPtr = 0;
                 }                 }
                   else
                   {
                       _setExtRefIndex(&(ptargetUnion[i]),pmem);
                   }
             }             }
  
             break;             break;
Line 3391 
Line 3780 
  
             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
  
             SCMOClass* theRefClass;  
   
             for (Uint32 i = 0; i < loop ; i++)             for (Uint32 i = 0; i < loop ; i++)
             {             {
                 if (iterator[i].isUninitialized())                 if (iterator[i].isUninitialized())
Line 3404 
Line 3791 
                 {                 {
                     if (iterator[i].isClass())                     if (iterator[i].isClass())
                     {                     {
                         CIMClass theClass(iterator[i]);                          CIMClass cimClass(iterator[i]);
                         ptargetUnion[i].extRefPtr = new SCMOInstance(theClass);  
                           ptargetUnion[i].extRefPtr =
                               new SCMOInstance(
                                   cimClass,
                                   (&((const char*)*pmem)[startNS]));
                         // marke as class only !                         // marke as class only !
                         ptargetUnion[i].extRefPtr->                         ptargetUnion[i].extRefPtr->
                             inst.hdr->flags.isClassOnly=true;                             inst.hdr->flags.isClassOnly=true;
   
                           // This function can cause a reallocation !
                           // Pointers can be invalid after the call.
                           _setExtRefIndex(&(ptargetUnion[i]),pmem);
                     }                     }
                     else                     else
                     {                     {
                         CIMInstance theInst(iterator[i]);                         CIMInstance theInst(iterator[i]);
                         theRefClass = _getSCMOClass(  
                             theInst.getPath(),  
                             &(((const char*)*pmem)[startNS]),  
                             lenNS);  
  
                         if (theRefClass != 0)  
                         {  
                             ptargetUnion[i].extRefPtr =                             ptargetUnion[i].extRefPtr =
                                 new SCMOInstance(*theRefClass,theInst);                              new SCMOInstance(
                         } else                                  theInst,
                                   &(((const char*)*pmem)[startNS]),
                                   sizeNS-1);
                            // Was the conversion successful?
                            if (ptargetUnion[i].extRefPtr->isEmpty())
                         {                         {
                             //There is no reference class for the object path                               // N0, delete the SCMOInstance.
                                delete ptargetUnion[i].extRefPtr;
                             ptargetUnion[i].extRefPtr = 0;                             ptargetUnion[i].extRefPtr = 0;
                         }                         }
                            else
                            {
                                // This function can cause a reallocation !
                                // Pointers can be invalid after the call.
                                _setExtRefIndex(&(ptargetUnion[i]),pmem);
                            }
                     }                     }
                 }                 }
             }             }
Line 3454 
Line 3853 
  
             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
  
             SCMOClass* theRefClass;  
   
             for (Uint32 i = 0; i < loop ; i++)             for (Uint32 i = 0; i < loop ; i++)
             {             {
                 if (iterator[i].isUninitialized())                 if (iterator[i].isUninitialized())
Line 3465 
Line 3862 
                 }                 }
                 else                 else
                 {                 {
                     theRefClass = _getSCMOClass(  
                         iterator[i].getPath(),  
                         &(((const char*)*pmem)[startNS]),  
                         lenNS);  
   
   
                     if (theRefClass != 0)  
                     {  
                         ptargetUnion[i].extRefPtr =                         ptargetUnion[i].extRefPtr =
                             new SCMOInstance(*theRefClass,iterator[i]);                          new SCMOInstance(
                     } else                              iterator[i],
                               &(((const char*)*pmem)[startNS]),
                               sizeNS-1);
                       // Was the conversion successful?
                       if (ptargetUnion[i].extRefPtr->isEmpty())
                     {                     {
                         //There is no reference class for the object path                          // N0, delete the SCMOInstance.
                           delete ptargetUnion[i].extRefPtr;
                         ptargetUnion[i].extRefPtr = 0;                         ptargetUnion[i].extRefPtr = 0;
                     }                     }
                       else
                       {
                           // This function can cause a reallocation !
                           // Pointers can be invalid after the call.
                           _setExtRefIndex(&(ptargetUnion[i]),pmem);
                       }
   
                 }                 }
             }             }
  
Line 3487 
Line 3888 
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
Line 3499 
Line 3900 
     SCMBMgmt_Header** pmem,     SCMBMgmt_Header** pmem,
     CIMType type,     CIMType type,
     Uint64 startNS,     Uint64 startNS,
     Uint64 lenNS,      Uint32 sizeNS,
     Union& u)     Union& u)
 { {
     SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);     SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);
Line 3592 
Line 3993 
  
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
         {         {
             _setString(*((String*)((void*)&u)),              // KS_TODO why do this when there is a _setChar function
               // that directly uses Strings??? low priority question but
               // this would seem less efficient that _setString with the
               // strlen function in it.
               CString cstr = ((String*)((void*)&u))->getCString();
               const char *cptr = (const char*)cstr;
               _setBinary(
                   cptr,
                   strlen(cptr) + 1,
                        scmoUnion->stringValue,                        scmoUnion->stringValue,
                        pmem );                        pmem );
             break;             break;
Line 3624 
Line 4033 
             CIMObjectPath* theCIMObj =             CIMObjectPath* theCIMObj =
                 (CIMObjectPath*)((void*)&u._referenceValue);                 (CIMObjectPath*)((void*)&u._referenceValue);
  
             SCMOClass* theRefClass = _getSCMOClass(              scmoUnion->extRefPtr =
                   new SCMOInstance(
                 *theCIMObj,                 *theCIMObj,
                 &(((const char*)*pmem)[startNS]),                 &(((const char*)*pmem)[startNS]),
                 lenNS);                      sizeNS-1);
  
             if (theRefClass != 0)              // Was the conversion successful?
             {              if (scmoUnion->extRefPtr->isEmpty())
                 scmoUnion->extRefPtr =  
                     new SCMOInstance(*theRefClass,*theCIMObj);  
             } else  
             {             {
                 //There is no reference class for the object path                  // N0, delete the SCMOInstance.
                   delete scmoUnion->extRefPtr;
                 scmoUnion->extRefPtr = 0;                 scmoUnion->extRefPtr = 0;
             }             }
               else
               {
                   // This function can cause a reallocation !
                   // Pointers can be invalid after the call.
                   _setExtRefIndex(scmoUnion,pmem);
               }
   
             break;             break;
         }         }
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
Line 3655 
Line 4070 
             }             }
  
             CIMObject* theCIMObject =(CIMObject*)((void*)&u._objectValue);             CIMObject* theCIMObject =(CIMObject*)((void*)&u._objectValue);
             SCMOClass* theRefClass;  
  
             if (theCIMObject->isUninitialized())             if (theCIMObject->isUninitialized())
             {             {
Line 3666 
Line 4080 
             {             {
                 if (theCIMObject->isClass())                 if (theCIMObject->isClass())
                 {                 {
                     CIMClass theClass(*theCIMObject);                      CIMClass cimClass(*theCIMObject);
                     scmoUnion->extRefPtr = new SCMOInstance(theClass);  
                     // marke as class only !                      scmoUnion->extRefPtr =
                           new SCMOInstance(
                               cimClass,
                               (&((const char*)*pmem)[startNS]));
                       // mark as class only !
                     scmoUnion->extRefPtr->inst.hdr->flags.isClassOnly=true;                     scmoUnion->extRefPtr->inst.hdr->flags.isClassOnly=true;
   
                       // This function can cause a reallocation !
                       // Pointers can be invalid after the call.
                       _setExtRefIndex(scmoUnion,pmem);
                 }                 }
                 else                 else
                 {                 {
                     CIMInstance theInst(*theCIMObject);                      CIMInstance theCIMInst(*theCIMObject);
                     theRefClass = _getSCMOClass(  
                         theInst.getPath(),  
                         &(((const char*)*pmem)[startNS]),  
                         lenNS);  
  
                     if (theRefClass != 0)  
                     {  
                         scmoUnion->extRefPtr =                         scmoUnion->extRefPtr =
                             new SCMOInstance(*theRefClass,theInst);                          new SCMOInstance(
                     } else                              theCIMInst,
                               &(((const char*)*pmem)[startNS]),
                               sizeNS);
   
                        // Was the conversion successful?
                       if (scmoUnion->extRefPtr->isEmpty())
                     {                     {
                         //There is no reference class for the object path                           // N0, delete the SCMOInstance.
                            delete scmoUnion->extRefPtr;
                         scmoUnion->extRefPtr = 0;                         scmoUnion->extRefPtr = 0;
                     }                     }
                        else
                        {
                            // This function can cause a reallocation !
                            // Pointers can be invalid after the call.
                            _setExtRefIndex(scmoUnion,pmem);
                        }
                 }                 }
             }             }
             break;             break;
Line 3717 
Line 4144 
             }             }
             else             else
             {             {
                 SCMOClass* theRefClass = _getSCMOClass(  
                     theCIMInst->getPath(),  
                     &(((const char*)*pmem)[startNS]),  
                     lenNS);  
                 if (theRefClass != 0)  
                 {  
                     scmoUnion->extRefPtr =                     scmoUnion->extRefPtr =
                         new SCMOInstance(*theRefClass,*theCIMInst);                      new SCMOInstance(
                 } else                          *theCIMInst,
                           &(((const char*)*pmem)[startNS]),
                           sizeNS-1);
   
                    // Was the conversion successful?
                    if (scmoUnion->extRefPtr->isEmpty())
                 {                 {
                     //There is no reference class for the object path                       // N0, delete the SCMOInstance.
                        delete scmoUnion->extRefPtr;
                     scmoUnion->extRefPtr = 0;                     scmoUnion->extRefPtr = 0;
                 }                 }
                    else
                    {
                        // This function can cause a reallocation !
                        // Pointers can be invalid after the call.
                        _setExtRefIndex(scmoUnion,pmem);
                    }
             }             }
             break;             break;
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
 } }
  
   /*
       Gets the property at the defined node index. This covers both
       normal and user defined properties.
   */
 SCMO_RC SCMOInstance::_getPropertyAtNodeIndex( SCMO_RC SCMOInstance::_getPropertyAtNodeIndex(
         Uint32 node,         Uint32 node,
         const char** pname,         const char** pname,
Line 3749 
Line 4186 
         Boolean& isArray,         Boolean& isArray,
         Uint32& size ) const         Uint32& size ) const
 { {
       if (_isClassDefinedProperty(node))
       {
     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->cls.hdr->propertySet.nodeArray.start;          Uint64 idx =
               inst.hdr->theClass.ptr->cls.hdr->propertySet.nodeArray.start;
   
     SCMBClassPropertyNode* theClassPropNodeArray =     SCMBClassPropertyNode* theClassPropNodeArray =
         (SCMBClassPropertyNode*)&(inst.hdr->theClass->cls.base)[idx];              (SCMBClassPropertyNode*)&(inst.hdr->theClass.ptr->cls.base)[idx];
  
     // the property name is always from the class.     // the property name is always from the class.
     // return the absolut pointer to the property name,          // return the absolute pointer to the property name,
     // the caller has to copy the name!     // the caller has to copy the name!
     *pname=_getCharString(     *pname=_getCharString(
         theClassPropNodeArray[node].theProperty.name,         theClassPropNodeArray[node].theProperty.name,
         inst.hdr->theClass->cls.base);              inst.hdr->theClass.ptr->cls.base);
  
     // the property was set by the provider.     // the property was set by the provider.
     if (theInstPropNodeArray[node].flags.isSet)     if (theInstPropNodeArray[node].flags.isSet)
     {     {
   
         type = theInstPropNodeArray[node].valueType;         type = theInstPropNodeArray[node].valueType;
         isArray = theInstPropNodeArray[node].flags.isArray;         isArray = theInstPropNodeArray[node].flags.isArray;
         if (isArray)         if (isArray)
Line 3782 
Line 4222 
  
         // calculate the relative index for the value.         // calculate the relative index for the value.
         Uint64 start =         Uint64 start =
             (const char*)&(theInstPropNodeArray[node].value) -                  (const char*)&(theInstPropNodeArray[node].value) - inst.base;
             inst.base;  
  
         // the caller has to copy the value !         // the caller has to copy the value !
         *pvalue = _resolveSCMBUnion(type,isArray,size,start,inst.base);         *pvalue = _resolveSCMBUnion(type,isArray,size,start,inst.base);
Line 3806 
Line 4245 
         return SCMO_NULL_VALUE;         return SCMO_NULL_VALUE;
     }     }
  
     // calcutate the relativ start address of the value          // calculate the relative start address of the value in the class
     Uint64 start =     Uint64 start =
         (const char*)         (const char*)
                &(theClassPropNodeArray[node].theProperty.defaultValue.value) -                &(theClassPropNodeArray[node].theProperty.defaultValue.value) -
         (inst.hdr->theClass->cls.base);              (inst.hdr->theClass.ptr->cls.base);
  
     *pvalue = _resolveSCMBUnion(     *pvalue = _resolveSCMBUnion(
         type,         type,
         isArray,         isArray,
         size,         size,
         start,         start,
         (inst.hdr->theClass->cls.base)              (inst.hdr->theClass.ptr->cls.base));
         );      }
   
       // else treated as user-defined property
       else
       {
           SCMBUserPropertyElement* pElement =
               _getUserDefinedPropertyElementAt(node);
   
           if (pElement == 0)
           {
               return SCMO_INDEX_OUT_OF_BOUND;
           }
   
           SCMBValue& instValue = pElement->value;
   
           *pname = _getCharString(pElement->name,inst.base);
  
           if (instValue.flags.isSet)
           {
               type = instValue.valueType;
   
               isArray = instValue.flags.isArray;
               if (isArray)
               {
                   size = instValue.valueArraySize;
               }
   
               if (instValue.flags.isNull)
               {
                   return SCMO_NULL_VALUE;
               }
           }
           else
           {
               // KS_TODO sort out what we do if user-defined element not
               // initialized.
               // Should never happen
               return SCMO_NULL_VALUE;
           }
   
           // resolve start for the Union.
           // KS_TODO we should be able to combine following and
           // the same for normal properties
           Uint64 start =
                   (const char*)&(instValue.value) - inst.base;
   
           *pvalue = _resolveSCMBUnion(type,isArray,size,start,inst.base);
       }
     return SCMO_OK;     return SCMO_OK;
  
 } }
Line 3829 
Line 4314 
     if (objectPathOnly)     if (objectPathOnly)
     {     {
         // Create a new, empty SCMOInstance         // Create a new, empty SCMOInstance
         SCMOInstance newInst(*(this->inst.hdr->theClass));          SCMOInstance newInst(*(this->inst.hdr->theClass.ptr));
  
         // Copy the host name to tha new instance-          // Copy the host name to the new instance-
         _setBinary(         _setBinary(
             _resolveDataPtr(this->inst.hdr->hostName,this->inst.base),             _resolveDataPtr(this->inst.hdr->hostName,this->inst.base),
             this->inst.hdr->hostName.length,              this->inst.hdr->hostName.size,
             newInst.inst.hdr->hostName,             newInst.inst.hdr->hostName,
             &newInst.inst.mem);             &newInst.inst.mem);
  
           newInst.inst.hdr->flags.isCompromised =
               this->inst.hdr->flags.isCompromised;
   
           // If the instance contains a user set class and/or name space name
           if (this->inst.hdr->flags.isCompromised)
           {
               // Copy the class name to the new instance-
               _setBinary(
                   _resolveDataPtr(this->inst.hdr->instClassName,this->inst.base),
                   this->inst.hdr->instClassName.size,
                   newInst.inst.hdr->instClassName,
                   &newInst.inst.mem);
   
               // Copy the name space name to tha new instance-
               _setBinary(
                   _resolveDataPtr(this->inst.hdr->instNameSpace,this->inst.base),
                   this->inst.hdr->instNameSpace.size,
                   newInst.inst.hdr->instNameSpace,
                   &newInst.inst.mem);
           }
   
         // Copy the key bindings to that new instance.         // Copy the key bindings to that new instance.
         this->_copyKeyBindings(newInst);         this->_copyKeyBindings(newInst);
  
Line 3845 
Line 4351 
     }     }
  
     SCMOInstance newInst;     SCMOInstance newInst;
     newInst.inst.base = (char*)malloc(this->inst.mem->totalSize);      newInst.inst.base = inst.base;
     if (newInst.inst.base == 0 )      newInst._clone();
   
       return newInst;
   }
   
   void SCMOInstance::_clone()
   {
       char* newBase;
       newBase = (char*)malloc((size_t)inst.mem->totalSize);
       if (0 == newBase )
     {     {
         throw PEGASUS_STD(bad_alloc)();         throw PEGASUS_STD(bad_alloc)();
     }     }
  
     memcpy( newInst.inst.base,this->inst.base,this->inst.mem->totalSize);      memcpy( newBase,inst.base,(size_t)inst.mem->totalSize);
     // reset the refcounter of this new instance  
     newInst.inst.hdr->refCount = 1;      // make new new memory block to mine.
       inst.base = newBase;
       // reset the refcounter of this instance
       inst.hdr->refCount = 1;
     // keep the ref counter of the class correct !     // keep the ref counter of the class correct !
     newInst.inst.hdr->theClass = new SCMOClass(*(this->inst.hdr->theClass));      inst.hdr->theClass.ptr = new SCMOClass(*(inst.hdr->theClass.ptr));
     // keep the ref count for external references     // keep the ref count for external references
     newInst._copyExternalReferences();      _copyExternalReferences();
   
     return newInst;  
 } }
  
 void SCMOInstance::_copyKeyBindings(SCMOInstance& targetInst) const void SCMOInstance::_copyKeyBindings(SCMOInstance& targetInst) const
Line 3870 
Line 4386 
         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
  
     // Address the class keybinding information     // Address the class keybinding information
     const SCMBClass_Main* clshdr = inst.hdr->theClass->cls.hdr;      const SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
     const char * clsbase = inst.hdr->theClass->cls.base;      const char * clsbase = inst.hdr->theClass.ptr->cls.base;
     SCMBKeyBindingNode* scmoClassArray =     SCMBKeyBindingNode* scmoClassArray =
         (SCMBKeyBindingNode*)&(clsbase[clshdr->keyBindingSet.nodeArray.start]);         (SCMBKeyBindingNode*)&(clsbase[clshdr->keyBindingSet.nodeArray.start]);
  
Line 3879 
Line 4395 
  
     for (Uint32 i = 0; i < noBindings; i++)     for (Uint32 i = 0; i < noBindings; i++)
     {     {
         // hast to be set every time, because of reallocation.          // has to be set every time, because of reallocation.
         targetArray=(SCMBKeyBindingValue*)&(targetInst.inst.base)         targetArray=(SCMBKeyBindingValue*)&(targetInst.inst.base)
                              [targetInst.inst.hdr->keyBindingArray.start];                              [targetInst.inst.hdr->keyBindingArray.start];
         if(sourceArray[i].isSet)         if(sourceArray[i].isSet)
Line 3893 
Line 4409 
         }         }
     }     }
  
     // Are there user defined key bindings ?      // Are there user defined key bindings ? If so, copy them
     if (0 != inst.hdr->numberUserKeyBindindigs)      if (0 != inst.hdr->numberUserKeyBindings)
     {     {
         SCMBUserKeyBindingElement* theUserDefKBElement =         SCMBUserKeyBindingElement* theUserDefKBElement =
             (SCMBUserKeyBindingElement*)             (SCMBUserKeyBindingElement*)
                  &(inst.base[inst.hdr->userKeyBindingElement.start]);                  &(inst.base[inst.hdr->userKeyBindingElement.start]);
  
         for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindindigs; i++)          for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
         {         {
             if (theUserDefKBElement->value.isSet)             if (theUserDefKBElement->value.isSet)
             {             {
Line 3915 
Line 4431 
     }     }
 } }
  
   /*
       Set theInsertElement into new or existing user-defined key
       binding.
   */
 void SCMOInstance::_setUserDefinedKeyBinding( void SCMOInstance::_setUserDefinedKeyBinding(
         SCMBUserKeyBindingElement& theInsertElement,         SCMBUserKeyBindingElement& theInsertElement,
         char* elementBase)         char* elementBase)
 { {
   
     SCMBUserKeyBindingElement* ptrNewElement;     SCMBUserKeyBindingElement* ptrNewElement;
  
     // get an exsiting or new user defined key binding     // get an exsiting or new user defined key binding
     ptrNewElement = _getUserDefinedKeyBinding(     ptrNewElement = _getUserDefinedKeyBinding(
         _getCharString(theInsertElement.name,elementBase),         _getCharString(theInsertElement.name,elementBase),
         // lenght is without the trailing '\0'          // length is without the trailing '\0'
         theInsertElement.name.length-1,          theInsertElement.name.size-1,
         theInsertElement.type);         theInsertElement.type);
  
     // Copy the data     // Copy the data
Line 3936 
Line 4454 
                 theInsertElement.value.data,                 theInsertElement.value.data,
                 elementBase,                 elementBase,
                 ptrNewElement->value);                 ptrNewElement->value);
   
 } }
  
  
 SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBindingAt( SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBindingAt(
     Uint32 index ) const     Uint32 index ) const
 { {
   
     // Get the start element     // Get the start element
     SCMBUserKeyBindingElement *ptrNewElement =     SCMBUserKeyBindingElement *ptrNewElement =
         (SCMBUserKeyBindingElement*)         (SCMBUserKeyBindingElement*)
              &(inst.base[inst.hdr->userKeyBindingElement.start]);              &(inst.base[inst.hdr->userKeyBindingElement.start]);
  
     // calculate the index within the user defined key bindings      // Calculate the index within the user defined key bindings
   
     index = index - inst.hdr->numberKeyBindings;     index = index - inst.hdr->numberKeyBindings;
  
     // traverse trough the user defindes key binding nodes.      // traverse through the user defined key binding nodes.
     for (Uint32 i = 0; i < index; i ++)     for (Uint32 i = 0; i < index; i ++)
     {     {
         PEGASUS_ASSERT(ptrNewElement->nextElement.start != 0);         PEGASUS_ASSERT(ptrNewElement->nextElement.start != 0);
Line 3963 
Line 4480 
     return ptrNewElement;     return ptrNewElement;
 } }
  
   /*
       If the user-defined keybinding already exists, return a pointer to
       that element. Otherwise allocate a new element and return pointer
       to the new element
   */
 SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBinding( SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBinding(
     const char* name,     const char* name,
     Uint32 nameLen,     Uint32 nameLen,
Line 3979 
Line 4501 
     }     }
     else // Not found, create a new user defined key binding.     else // Not found, create a new user defined key binding.
     {     {
   
         _getFreeSpace(newElement,         _getFreeSpace(newElement,
                       sizeof(SCMBUserKeyBindingElement),                       sizeof(SCMBUserKeyBindingElement),
                       &inst.mem);                       &inst.mem);
Line 3988 
Line 4509 
             (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);             (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);
  
         // link new first user defined key binding element into chain:         // link new first user defined key binding element into chain:
         // - Assing the start point of user key binding element chain          // - Adding the start point of user key binding element chain
         //   to the next element of the new element.         //   to the next element of the new element.
         ptrNewElement->nextElement.start =         ptrNewElement->nextElement.start =
             inst.hdr->userKeyBindingElement.start;             inst.hdr->userKeyBindingElement.start;
         ptrNewElement->nextElement.length =          ptrNewElement->nextElement.size =
             inst.hdr->userKeyBindingElement.length;              inst.hdr->userKeyBindingElement.size;
         // - Assing the the new element          // - Adding the the new element
         //   to the  start point of user key binding element chain         //   to the  start point of user key binding element chain
         inst.hdr->userKeyBindingElement.start = newElement.start;         inst.hdr->userKeyBindingElement.start = newElement.start;
         inst.hdr->userKeyBindingElement.length = newElement.length;          inst.hdr->userKeyBindingElement.size = newElement.size;
         // Adjust the couter of user defined key bindings.          // Adjust the counter of user defined key bindings.
         inst.hdr->numberUserKeyBindindigs++;          inst.hdr->numberUserKeyBindings++;
   
  
         // Copy the type         // Copy the type
         ptrNewElement->type = type;         ptrNewElement->type = type;
Line 4012 
Line 4532 
         // reset the pointer. May the instance was reallocated.         // reset the pointer. May the instance was reallocated.
         ptrNewElement =         ptrNewElement =
             (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);             (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);
       }
       return ptrNewElement;
   }
   
   /*
       Create a new UserDefined Property Element, link it into the User-defined
       chain, and populate it with name, type, and isArray.  Set isSet to ftrue.
       Returns pointer to the new element
   */
   SCMBUserPropertyElement* SCMOInstance::_createNewUserDefinedProperty(
       const char * name,
       Uint32 nameLen,
       CIMType theType)
   {
       SCMBDataPtr newElement;
       _getFreeSpace(newElement,
                     sizeof(SCMBUserPropertyElement),
                     &inst.mem);
   
       SCMBUserPropertyElement* pElement =
           (SCMBUserPropertyElement*)&(inst.base[newElement.start]);
   
       // link new first user defined property element into chain:
       // - Add the start point of user property element chain
       //   to the next element of the new element.
       pElement->nextElement.start =
           inst.hdr->userPropertyElement.start;
       pElement->nextElement.size =
           inst.hdr->userPropertyElement.size;
       // Add the the new element to the  start point of user property
       // element chain
       inst.hdr->userPropertyElement.start = newElement.start;
       inst.hdr->userPropertyElement.size = newElement.size;
       // Adjust the counter of user defined key bindings.
       inst.hdr->numberUserProperties++;
  
       // Copy the type
       pElement->value.valueType = theType;
       pElement->value.flags.isSet=false;
   
       // Copy the property name including the trailing '\0'
       _setBinary(name,nameLen+1,pElement->name,&inst.mem);
   
       // reset the pointer. Maybe the instance was reallocated.
       pElement =
           (SCMBUserPropertyElement*)&(inst.base[newElement.start]);
       return pElement;
     }     }
   /*
       set either a new or existing UserDefinedProperty with the
       InsertElement provided
   */
   
   void SCMOInstance::_setPropertyInUserDefinedElement(
           SCMBUserPropertyElement* pElement,
           CIMType theType,
           const SCMBUnion* pInVal,
           Boolean isArray,
           Uint32 size)
   {
       _copyOnWrite();
  
       SCMBValue& instVal = pElement->value;
  
     return ptrNewElement;      // Set data into element
       instVal.flags.isSet=true;
       instVal.valueType=theType;
       instVal.flags.isArray= isArray;
       pElement->classOrigin.start = 0;
  
       if (isArray)
       {
           instVal.valueArraySize = size;
 } }
  
 Uint32 SCMOInstance::getPropertyCount() const      if (pInVal==0)
 { {
     if (inst.hdr->flags.isFiltered)          instVal.flags.isNull=true;
       }
       else
     {     {
         return(inst.hdr->filterProperties);          instVal.flags.isNull=false;
           _setSCMBUnion(
               pInVal,
               theType,
               isArray,
               size,
               instVal.value);
     }     }
  
     return(inst.hdr->numberProperties);  }
   
   /*
       Get the user-defined propertyElement defined by index arguement
       Returns the Element.
       KS_TODO what do we do if it runs through the end of the list.
       Right now it is an assert so somewhere a check is needed.
       Probablly the callers
   */
   SCMBUserPropertyElement* SCMOInstance::_getUserDefinedPropertyElementAt(
       Uint32 index ) const
   {
       // Get the start element
       SCMBUserPropertyElement* pElement =
           (SCMBUserPropertyElement*)
                &(inst.base[inst.hdr->userPropertyElement.start]);
   
       XCOUT << "inst.hdr->userPropertyElement.start address "
               << pElement  << " relative "
           << inst.hdr->userPropertyElement.start
           << " number of user properties " << inst.hdr->numberUserProperties
           << endl;
   
       // calculate the index within the user defined properties
       // based on numberProperties in instance. This should
       // be verified against numberUserProperties
   
       index = index - inst.hdr->numberProperties;
   
       // traverse  the user defined property nodes.
       for (Uint32 i = 0; i < index; i ++)
       {
           PEGASUS_ASSERT(pElement->nextElement.start != 0);
           pElement = (SCMBUserPropertyElement*)
                 &(inst.base[pElement->nextElement.start]);
           // KS_TODO should be able to compute this error from number
           // properties
           // return NULL if this index not found.
           if (pElement == 0)
           {
               // This error should never occur.
               PEGASUS_ASSERT(false);
               return 0;
           }
       }
       return pElement;
 } }
  
 SCMBUnion * SCMOInstance::_resolveSCMBUnion( SCMBUnion * SCMOInstance::_resolveSCMBUnion(
Line 4037 
Line 4677 
     Uint64 start,     Uint64 start,
     char* base) const     char* base) const
 { {
   
     SCMBUnion* u = (SCMBUnion*)&(base[start]);     SCMBUnion* u = (SCMBUnion*)&(base[start]);
  
       XCOUT << "_resolveSCMBUnion Enter. Union at " << u
             << " isArray " << boolToString(isArray)
             << " type " << cimTypeToString(type)
             << " start " << start
             << endl;
     SCMBUnion* av = 0;     SCMBUnion* av = 0;
  
     if (isArray)     if (isArray)
Line 4078 
Line 4722 
             {             {
                 return(u);                 return(u);
             }             }
             break;  
         }         }
  
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
Line 4100 
Line 4743 
                     ptr[i].extString.pchar =                     ptr[i].extString.pchar =
                         (char*)_getCharString(av[i].stringValue,base);                         (char*)_getCharString(av[i].stringValue,base);
                     // lenght with out the trailing /0 !                     // lenght with out the trailing /0 !
                     ptr[i].extString.length = av[i].stringValue.length-1;                      ptr[i].extString.length = av[i].stringValue.size-1;
                 }                 }
             }             }
             else             else
Line 4109 
Line 4752 
                 ptr->extString.pchar =                 ptr->extString.pchar =
                     (char*)_getCharString(u->stringValue,base);                     (char*)_getCharString(u->stringValue,base);
                 // lenght with out the trailing /0 !                 // lenght with out the trailing /0 !
                 ptr->extString.length = u->stringValue.length-1;                  ptr->extString.length = u->stringValue.size-1;
             }             }
  
              return(ptr);              return(ptr);
             break;  
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
     return 0;     return 0;
 } }
  
   void SCMOInstance::clearKeyBindings()
   {
       _copyOnWrite();
   
       // First destroy all external references in the key bindings
       _destroyExternalKeyBindings();
   
       // reset user keybindings
       inst.hdr->numberUserKeyBindings = 0;
       inst.hdr->userKeyBindingElement.start = 0;
       inst.hdr->userKeyBindingElement.size = 0;
   
       // Allocate a clean the SCMOInstanceKeyBindingArray
       _getFreeSpace(
             inst.hdr->keyBindingArray,
             sizeof(SCMBKeyBindingValue)*inst.hdr->numberKeyBindings,
             &inst.mem);
   
       // Clear the keybindings after the allocation. Setting the keybindings
       // later causes this value to be reinitialized.
       inst.hdr->numberKeyBindings = 0;
   
       markAsCompromised();
   }
   
 Uint32 SCMOInstance::getKeyBindingCount() const Uint32 SCMOInstance::getKeyBindingCount() const
 { {
     // count of class keys + user definded keys     // count of class keys + user definded keys
     return(inst.hdr->numberKeyBindings+     return(inst.hdr->numberKeyBindings+
            inst.hdr->numberUserKeyBindindigs);             inst.hdr->numberUserKeyBindings);
 } }
  
  
Line 4147 
Line 4814 
  
     // count of class keys + user definded keys     // count of class keys + user definded keys
     if (node >= (inst.hdr->numberKeyBindings+     if (node >= (inst.hdr->numberKeyBindings+
                  inst.hdr->numberUserKeyBindindigs))                   inst.hdr->numberUserKeyBindings))
     {     {
         return SCMO_INDEX_OUT_OF_BOUND;         return SCMO_INDEX_OUT_OF_BOUND;
     }     }
Line 4182 
Line 4849 
  
     *pvalue = 0;     *pvalue = 0;
  
     rc = inst.hdr->theClass->_getKeyBindingNodeIndex(node,name);      rc = inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name);
     if (rc != SCMO_OK)     if (rc != SCMO_OK)
     {     {
         // look at the user defined key bindings.         // look at the user defined key bindings.
Line 4224 
Line 4891 
             (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);             (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
  
         // create a pointer to key binding node array of the class.         // create a pointer to key binding node array of the class.
         Uint64 idx = inst.hdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;          Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
               keyBindingSet.nodeArray.start;
         SCMBKeyBindingNode* theClassKeyBindNodeArray =         SCMBKeyBindingNode* theClassKeyBindNodeArray =
             (SCMBKeyBindingNode*)&((inst.hdr->theClass->cls.base)[idx]);              (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
  
         type = theClassKeyBindNodeArray[node].type;         type = theClassKeyBindNodeArray[node].type;
  
         // First resolve pointer to the key binding name         // First resolve pointer to the key binding name
         pnameLen = theClassKeyBindNodeArray[node].name.length;          pnameLen = theClassKeyBindNodeArray[node].name.size;
         *pname = _getCharString(         *pname = _getCharString(
             theClassKeyBindNodeArray[node].name,             theClassKeyBindNodeArray[node].name,
             inst.hdr->theClass->cls.base);              inst.hdr->theClass.ptr->cls.base);
  
         // There is no value set in the instance         // There is no value set in the instance
         if (!theInstKeyBindValueArray[node].isSet)         if (!theInstKeyBindValueArray[node].isSet)
Line 4246 
Line 4914 
     }     }
     else // look at the user defined key bindings     else // look at the user defined key bindings
     {     {
   
         SCMBUserKeyBindingElement* theElem = _getUserDefinedKeyBindingAt(node);         SCMBUserKeyBindingElement* theElem = _getUserDefinedKeyBindingAt(node);
  
         type = theElem->type;         type = theElem->type;
  
         pnameLen = theElem->name.length;          pnameLen = theElem->name.size;
         *pname = _getCharString(theElem->name,inst.base);         *pname = _getCharString(theElem->name,inst.base);
  
         // There is no value set in the instance         // There is no value set in the instance
Line 4274 
Line 4941 
  
     Uint32 len = strlen(name);     Uint32 len = strlen(name);
     node = 0;     node = 0;
     SCMBUserKeyBindingElement* theUserDefKBElement;  
  
     Uint64 elementStart = inst.hdr->userKeyBindingElement.start;     Uint64 elementStart = inst.hdr->userKeyBindingElement.start;
  
Line 4283 
Line 4949 
         SCMBUserKeyBindingElement* theUserDefKBElement =         SCMBUserKeyBindingElement* theUserDefKBElement =
             (SCMBUserKeyBindingElement*)&(inst.base[elementStart]);             (SCMBUserKeyBindingElement*)&(inst.base[elementStart]);
  
         if (_equalUTF8Strings(theUserDefKBElement->name,inst.base,name,len))          if (_equalNoCaseUTF8Strings(
               theUserDefKBElement->name,inst.base,name,len))
         {         {
             // the node index of a user defined key binding has an offset             // the node index of a user defined key binding has an offset
             // by the number of key bindings defined in the class             // by the number of key bindings defined in the class
Line 4297 
Line 4964 
     return SCMO_NOT_FOUND;     return SCMO_NOT_FOUND;
  
 } }
   /*
       Get the node index for a user-defined property
       // KS_TODO confirm not duplicated elsewhere
   */
   SCMO_RC SCMOInstance::_getUserPropertyNodeIndex(
       Uint32& node,
       const char* name) const
   {
       Uint32 len = strlen(name);
       node = 0;
   
       Uint64 elementStart = inst.hdr->userPropertyElement.start;
       XCOUT << "inst.hdr->userPropertyElement.start "
               << elementStart  << endl;
   
       while (elementStart != 0)
       {
           SCMBUserPropertyElement* pElement =
               (SCMBUserPropertyElement*)&(inst.base[elementStart]);
   
           XCOUT << "SCMBUserPropertyElement get at "
               << static_cast<void*>(pElement)
               << " node " << node << endl;
   
           if (_equalNoCaseUTF8Strings(
               pElement->name,inst.base,name,len))
           {
               // the node index of a user defined key binding has an offset
               // by the number of user-defined properties defined in the class
               node = node + inst.hdr->numberKeyBindings;
               return SCMO_OK;
           }
           node++;
           elementStart = pElement->nextElement.start;
       }
       return SCMO_NOT_FOUND;
   
   }
  
 CIMType SCMOInstance::_CIMTypeFromKeyBindingType( CIMType SCMOInstance::_CIMTypeFromKeyBindingType(
     const char* key,     const char* key,
Line 4332 
Line 5037 
                         return CIMTYPE_REAL64;                         return CIMTYPE_REAL64;
                     }                     }
                 }                 }
                 break;  
             }             }
  
  
         case CIMKeyBinding::STRING:         case CIMKeyBinding::STRING:
         {         {
             return CIMTYPE_STRING;             return CIMTYPE_STRING;
             break;  
         }         }
  
         case CIMKeyBinding::BOOLEAN:         case CIMKeyBinding::BOOLEAN:
         {         {
             return CIMTYPE_BOOLEAN;             return CIMTYPE_BOOLEAN;
             break;  
         }         }
  
         case CIMKeyBinding::REFERENCE:         case CIMKeyBinding::REFERENCE:
         {         {
             return CIMTYPE_REFERENCE;             return CIMTYPE_REFERENCE;
             break;  
         }         }
  
         default:         default:
Line 4367 
Line 5068 
     )     )
 { {
     scmoKBV.isSet=false;     scmoKBV.isSet=false;
       // If it not a simple value, it will be over written.
       scmoKBV.data.simple.hasValue=false;
  
     if ( kbs.size() == 0 && type != CIMTYPE_STRING)     if ( kbs.size() == 0 && type != CIMTYPE_STRING)
     {     {
Line 4386 
Line 5089 
                 StringConversion::checkUintBounds(x, type))                 StringConversion::checkUintBounds(x, type))
             {             {
               scmoKBV.data.simple.val.u8 = Uint8(x);               scmoKBV.data.simple.val.u8 = Uint8(x);
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4397 
Line 5101 
                 StringConversion::checkUintBounds(x, type))                 StringConversion::checkUintBounds(x, type))
             {             {
               scmoKBV.data.simple.val.u16 = Uint16(x);               scmoKBV.data.simple.val.u16 = Uint16(x);
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4409 
Line 5114 
                 StringConversion::checkUintBounds(x, type))                 StringConversion::checkUintBounds(x, type))
             {             {
               scmoKBV.data.simple.val.u32 = Uint32(x);               scmoKBV.data.simple.val.u32 = Uint32(x);
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4420 
Line 5126 
             if (StringConversion::stringToUnsignedInteger(v, x))             if (StringConversion::stringToUnsignedInteger(v, x))
             {             {
               scmoKBV.data.simple.val.u64 = x;               scmoKBV.data.simple.val.u64 = x;
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4432 
Line 5139 
                 StringConversion::checkSintBounds(x, type))                 StringConversion::checkSintBounds(x, type))
             {             {
               scmoKBV.data.simple.val.s8 = Sint8(x);               scmoKBV.data.simple.val.s8 = Sint8(x);
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4444 
Line 5152 
                 StringConversion::checkSintBounds(x, type))                 StringConversion::checkSintBounds(x, type))
             {             {
               scmoKBV.data.simple.val.s16 = Sint16(x);               scmoKBV.data.simple.val.s16 = Sint16(x);
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4456 
Line 5165 
                 StringConversion::checkSintBounds(x, type))                 StringConversion::checkSintBounds(x, type))
             {             {
               scmoKBV.data.simple.val.s32 = Sint32(x);               scmoKBV.data.simple.val.s32 = Sint32(x);
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4467 
Line 5177 
             if (StringConversion::stringToSignedInteger(v, x))             if (StringConversion::stringToSignedInteger(v, x))
             {             {
               scmoKBV.data.simple.val.s64 = x;               scmoKBV.data.simple.val.s64 = x;
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4500 
Line 5211 
             if (StringConversion::stringToReal64(v, x))             if (StringConversion::stringToReal64(v, x))
             {             {
               scmoKBV.data.simple.val.r32 = Real32(x);               scmoKBV.data.simple.val.r32 = Real32(x);
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4512 
Line 5224 
             if (StringConversion::stringToReal64(v, x))             if (StringConversion::stringToReal64(v, x))
             {             {
               scmoKBV.data.simple.val.r64 = x;               scmoKBV.data.simple.val.r64 = x;
                 scmoKBV.data.simple.hasValue=true;
               scmoKBV.isSet=true;               scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4522 
Line 5235 
             if (kbs.size() == 1)             if (kbs.size() == 1)
             {             {
                 scmoKBV.data.simple.val.c16 = kbs[0];                 scmoKBV.data.simple.val.c16 = kbs[0];
                   scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;                 scmoKBV.isSet=true;
             }             }
             break;             break;
Line 4531 
Line 5245 
             if (String::equalNoCase(kbs,"TRUE"))             if (String::equalNoCase(kbs,"TRUE"))
             {             {
                 scmoKBV.data.simple.val.bin = true;                 scmoKBV.data.simple.val.bin = true;
                   scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;                 scmoKBV.isSet=true;
             }             }
             else if (String::equalNoCase(kbs,"FALSE"))             else if (String::equalNoCase(kbs,"FALSE"))
                  {                  {
                      scmoKBV.data.simple.val.bin = false;                      scmoKBV.data.simple.val.bin = false;
                        scmoKBV.data.simple.hasValue=true;
                      scmoKBV.isSet=true;                      scmoKBV.isSet=true;
                  }                  }
             break;             break;
Line 4547 
Line 5263 
             // Can cause reallocation !             // Can cause reallocation !
             _setString(kbs,scmoKBV.data.stringValue,&inst.mem);             _setString(kbs,scmoKBV.data.stringValue,&inst.mem);
             return true;             return true;
             break;  
         }         }
     case CIMTYPE_REFERENCE:     case CIMTYPE_REFERENCE:
         {         {
Line 4559 
Line 5274 
             }             }
             // TBD: Optimize parsing and SCMOInstance creation.             // TBD: Optimize parsing and SCMOInstance creation.
             CIMObjectPath theCIMObj(kbs);             CIMObjectPath theCIMObj(kbs);
             SCMOClass* theRefClass = _getSCMOClass(  
                 theCIMObj,  
                 _getCharString(inst.hdr->instNameSpace,inst.base),  
                 inst.hdr->instNameSpace.length);  
  
             if (theRefClass != 0)              scmoKBV.data.extRefPtr = new SCMOInstance(theCIMObj);
             {              scmoKBV.isSet=true;
                 scmoKBV.data.extRefPtr =  
                     new SCMOInstance(*theRefClass,theCIMObj);              // Was the conversion successful?
             } else              if (scmoKBV.data.extRefPtr->isEmpty())
             {             {
                   // N0, delete the SCMOInstance.
                   delete scmoKBV.data.extRefPtr;
                 scmoKBV.data.extRefPtr = 0;                 scmoKBV.data.extRefPtr = 0;
                   scmoKBV.isSet=false;
               }
               else
               {
                   // This function can cause a reallocation !
                   // Pointers can be invalid after the call.
                   _setExtRefIndex(&(scmoKBV.data),&inst.mem);
             }             }
             scmoKBV.isSet=true;  
             break;             break;
         }         }
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
Line 4580 
Line 5299 
         {         {
             // From PEP 194: EmbeddedObjects cannot be keys.             // From PEP 194: EmbeddedObjects cannot be keys.
             throw TypeMismatchException();             throw TypeMismatchException();
             break;  
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
Line 4597 
Line 5315 
     CIMType type,     CIMType type,
     String cimKeyBinding)     String cimKeyBinding)
 { {
     SCMO_RC rc;  
     Uint32 node;     Uint32 node;
  
     if (0 == name)     if (0 == name)
Line 4605 
Line 5322 
         return SCMO_INVALID_PARAMETER;         return SCMO_INVALID_PARAMETER;
     }     }
  
     if (SCMO_OK == inst.hdr->theClass->_getKeyBindingNodeIndex(node,name))      if (SCMO_OK == inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name))
     {     {
         // create a pointer to keybinding node array of the class.         // create a pointer to keybinding node array of the class.
         Uint64 idx = inst.hdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;          Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
               keyBindingSet.nodeArray.start;
         SCMBKeyBindingNode* theClassKeyBindNodeArray =         SCMBKeyBindingNode* theClassKeyBindNodeArray =
             (SCMBKeyBindingNode*)&((inst.hdr->theClass->cls.base)[idx]);              (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
  
         // create a pointer to instance keybinding values         // create a pointer to instance keybinding values
         SCMBKeyBindingValue* theInstKeyBindValueArray =         SCMBKeyBindingValue* theInstKeyBindValueArray =
Line 4628 
Line 5346 
         return SCMO_OK;         return SCMO_OK;
     }     }
  
     // the key binig does not belong to the associated class      // the key binding does not belong to the associated class
     // add/set it as user defined key binding.     // add/set it as user defined key binding.
     SCMBUserKeyBindingElement* ptrNewElement;     SCMBUserKeyBindingElement* ptrNewElement;
  
Line 4665 
Line 5383 
         return SCMO_INVALID_PARAMETER;         return SCMO_INVALID_PARAMETER;
     }     }
  
     rc = inst.hdr->theClass->_getKeyBindingNodeIndex(node,name);      _copyOnWrite();
   
       // If keybindings exists and cleared using the clearKeyBindings()
       // method, reset the value to the actual keybindings count exists
       // in the class.
       if (!inst.hdr->numberKeyBindings)
       {
           inst.hdr->numberKeyBindings =
               inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
       }
   
       rc = inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name);
   
     if (rc != SCMO_OK)     if (rc != SCMO_OK)
     {     {
         // the key bindig does not belong to the associated class          // the key binding does not belong to the associated class
         // add/set it as user defined key binding.         // add/set it as user defined key binding.
         SCMBUserKeyBindingElement *theNode;          SCMBUserKeyBindingElement *pElement;
  
         theNode = _getUserDefinedKeyBinding( name,strlen(name),type);          pElement = _getUserDefinedKeyBinding( name,strlen(name),type);
  
         // Is this a new node or an existing user key binding?         // Is this a new node or an existing user key binding?
         if (theNode->value.isSet && (theNode->type != type))          if (pElement->value.isSet && (pElement->type != type))
         {         {
             return SCMO_TYPE_MISSMATCH;             return SCMO_TYPE_MISSMATCH;
   
         }         }
  
         theNode->value.isSet=true;          pElement->value.isSet=true;
  
         _setSCMBUnion(         _setSCMBUnion(
             keyvalue,             keyvalue,
             type,             type,
             false, // a key binding can never be an array.             false, // a key binding can never be an array.
             0,             0,
             theNode->value.data);              pElement->value.data);
  
          return SCMO_OK;          return SCMO_OK;
     }     }
Line 4701 
Line 5430 
         CIMType type,         CIMType type,
         const SCMBUnion* keyvalue)         const SCMBUnion* keyvalue)
 { {
     SCMO_RC rc;  
   
    // create a pointer to keybinding node array of the class.  
     Uint64 idx = inst.hdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;  
     SCMBKeyBindingNode* theClassKeyBindNodeArray =  
         (SCMBKeyBindingNode*)&((inst.hdr->theClass->cls.base)[idx]);  
   
     if (0 == keyvalue)     if (0 == keyvalue)
     {     {
         return SCMO_INVALID_PARAMETER;         return SCMO_INVALID_PARAMETER;
Line 4715 
Line 5437 
  
     // count of class keys + user definded keys     // count of class keys + user definded keys
     if (node >= (inst.hdr->numberKeyBindings+     if (node >= (inst.hdr->numberKeyBindings+
                  inst.hdr->numberUserKeyBindindigs))                   inst.hdr->numberUserKeyBindings))
     {     {
         return SCMO_INDEX_OUT_OF_BOUND;         return SCMO_INDEX_OUT_OF_BOUND;
     }     }
  
     // is the node a user defined key binding ?      _copyOnWrite();
   
       // If keybindings exists and cleared using the clearKeyBindings()
       // method, reset the value to the actual keybindings count exists
       // in the class.
       if (!inst.hdr->numberKeyBindings)
       {
           inst.hdr->numberKeyBindings =
               inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
       }
   
   
      // create a pointer to keybinding node array of the class.
       Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
           keyBindingSet.nodeArray.start;
       SCMBKeyBindingNode* theClassKeyBindNodeArray =
           (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
   
       // is the node a user defined key binding ? Tests if node ge number
       // of key bindings.
     if (node >= inst.hdr->numberKeyBindings)     if (node >= inst.hdr->numberKeyBindings)
     {     {
         SCMBUserKeyBindingElement* theNode = _getUserDefinedKeyBindingAt(node);         SCMBUserKeyBindingElement* theNode = _getUserDefinedKeyBindingAt(node);
Line 4800 
Line 5541 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.u8=Uint8(keyValue->simple.val.u64);                 kbValue.data.simple.val.u8=Uint8(keyValue->simple.val.u64);
                 return SCMO_OK;  
                 break;                 break;
             }             }
         case CIMTYPE_UINT16:         case CIMTYPE_UINT16:
Line 4808 
Line 5548 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.u16=Uint16(keyValue->simple.val.u64);                 kbValue.data.simple.val.u16=Uint16(keyValue->simple.val.u64);
                 return SCMO_OK;  
                 break;                 break;
             }             }
         case CIMTYPE_UINT32:         case CIMTYPE_UINT32:
Line 4816 
Line 5555 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.u32=Uint32(keyValue->simple.val.u64);                 kbValue.data.simple.val.u32=Uint32(keyValue->simple.val.u64);
                 return SCMO_OK;  
                 break;                 break;
             }             }
         case CIMTYPE_UINT64:         case CIMTYPE_UINT64:
Line 4824 
Line 5562 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.u64=keyValue->simple.val.u64;                 kbValue.data.simple.val.u64=keyValue->simple.val.u64;
                 return SCMO_OK;  
                 break;                 break;
             }             }
         default:         default:
             {             {
                 return SCMO_TYPE_MISSMATCH;                 return SCMO_TYPE_MISSMATCH;
                 break;  
             }             }
         }         }
           return SCMO_OK;
   
     }     }
  
     if (setType == CIMTYPE_SINT64)     if (setType == CIMTYPE_SINT64)
Line 4845 
Line 5583 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.s8=Sint8(keyValue->simple.val.s64);                 kbValue.data.simple.val.s8=Sint8(keyValue->simple.val.s64);
                 return SCMO_OK;  
                 break;                 break;
             }             }
         case CIMTYPE_SINT16:         case CIMTYPE_SINT16:
Line 4853 
Line 5590 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.s16=Sint16(keyValue->simple.val.s64);                 kbValue.data.simple.val.s16=Sint16(keyValue->simple.val.s64);
                 return SCMO_OK;  
                 break;                 break;
             }             }
         case CIMTYPE_SINT32:         case CIMTYPE_SINT32:
Line 4861 
Line 5597 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.s32=Sint32(keyValue->simple.val.s64);                 kbValue.data.simple.val.s32=Sint32(keyValue->simple.val.s64);
                 return SCMO_OK;  
                 break;                 break;
             }             }
         case CIMTYPE_SINT64:         case CIMTYPE_SINT64:
Line 4869 
Line 5604 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.s64=keyValue->simple.val.s64;                 kbValue.data.simple.val.s64=keyValue->simple.val.s64;
                 return SCMO_OK;  
                 break;                 break;
             }             }
         default:         default:
             {             {
                 return SCMO_TYPE_MISSMATCH;                 return SCMO_TYPE_MISSMATCH;
                 break;  
             }             }
         }         }
           return SCMO_OK;
     }     }
  
     if (setType == CIMTYPE_REAL64)     if (setType == CIMTYPE_REAL64)
Line 4889 
Line 5623 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.r32=Real32(keyValue->simple.val.r64);                 kbValue.data.simple.val.r32=Real32(keyValue->simple.val.r64);
                 return SCMO_OK;  
                 break;                 break;
             }             }
         case CIMTYPE_REAL64:         case CIMTYPE_REAL64:
Line 4897 
Line 5630 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 kbValue.data.simple.hasValue=true;                 kbValue.data.simple.hasValue=true;
                 kbValue.data.simple.val.r64=keyValue->simple.val.r64;                 kbValue.data.simple.val.r64=keyValue->simple.val.r64;
                 return SCMO_OK;  
                 break;                 break;
             }             }
         default:         default:
             {             {
                 return SCMO_TYPE_MISSMATCH;                 return SCMO_TYPE_MISSMATCH;
                 break;  
             }             }
         }         }
           return SCMO_OK;
     }     }
     else     else
     {     {
           // If type defined in the class and the provided type does not match
           // at this point, no convertaion can be done and the provided type
           // is handlend as type missmatch.
           if (classType != setType)
           {
               return SCMO_TYPE_MISSMATCH;
           }
   
         switch (classType)         switch (classType)
         {         {
           case CIMTYPE_DATETIME:
         case CIMTYPE_BOOLEAN:         case CIMTYPE_BOOLEAN:
         case CIMTYPE_UINT64:         case CIMTYPE_UINT64:
         case CIMTYPE_SINT64:         case CIMTYPE_SINT64:
Line 4921 
Line 5662 
                 kbValue.isSet=true;                 kbValue.isSet=true;
                 _setSCMBUnion(keyValue,classType,false, 0,kbValue.data);                 _setSCMBUnion(keyValue,classType,false, 0,kbValue.data);
                 return SCMO_OK;                 return SCMO_OK;
                 break;  
             }             }
         default:         default:
             {             {
                 return SCMO_TYPE_MISSMATCH;                 return SCMO_TYPE_MISSMATCH;
                 break;              }
             }          }
         }      }
     }  
   
     return SCMO_TYPE_MISSMATCH;  
   
 }  
   
   
 void SCMOInstance::setPropertyFilter(const char **propertyList)  
 {  
     SCMO_RC rc;  
     Uint32 node,i = 0;  
   
     if (inst.hdr->propertyFilter.start == 0)  
     {  
         // Allocate the SCMBPropertyFilter  
         _getFreeSpace(  
             inst.hdr->propertyFilter,  
             sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1),  
             &inst.mem,  
             true);  
   
         // Allocate the SCMBPropertyFilterIndexMap  
         _getFreeSpace(  
             inst.hdr->propertyFilterIndexMap,  
             sizeof(Uint32)*inst.hdr->numberProperties,  
             &inst.mem,  
             true);  
     }  
     // Get absolut pointer to property filter index map of the instance  
     Uint32* propertyFilterIndexMap =  
         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);  
   
     // All properties are accepted  
     if (propertyList == 0)  
     {  
         // Clear filtering:  
         // Switch filtering off.  
         inst.hdr->flags.isFiltered = false;  
   
         // Clear filter index map  
         memset(  
             propertyFilterIndexMap,  
             0,  
             sizeof(Uint32)*inst.hdr->numberProperties);  
   
         //reset number filter properties to all  
         inst.hdr->filterProperties = inst.hdr->numberProperties;  
   
         return;  
     }  
   
     // Switch filtering on.  
     inst.hdr->flags.isFiltered = true;  
   
     // intit the filter with the key properties  
     inst.hdr->filterProperties=_initPropFilterWithKeys();  
   
     // add the properties to the filter.  
     while (propertyList[i] != 0)  
     {  
         // the hash index of the property if the property name is found  
         rc = inst.hdr->theClass->_getProperyNodeIndex(node,propertyList[i]);  
   
         // if property is already in the filter  
         // ( eg. key properties ) do not add them !  
         if (rc == SCMO_OK && !_isPropertyInFilter(node))  
         {  
             // The property name was found. Otherwise ignore this property name.  
             // insert the hash index into the filter index map  
             propertyFilterIndexMap[inst.hdr->filterProperties]=node;  
             // increase number of properties in filter.  
             inst.hdr->filterProperties++;  
             // set bit in the property filter  
             _setPropertyInPropertyFilter(node);  
         }  
         // Proceed with the next property name.  
         i++;  
     }  
   
 }  
   
   
 Uint32 SCMOInstance::_initPropFilterWithKeys()  
 {  
   
     // Get absolut pointer to the key property mask of the class.  
     Uint64 idx = inst.hdr->theClass->cls.hdr->keyPropertyMask.start;  
     Uint64* keyMask =(Uint64*)&(inst.hdr->theClass->cls.base)[idx];  
   
     // Get absolut pointer to property filter mask  
     Uint64* propertyFilterMask =  
         (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);  
   
     // copy the key mask to the property filter mask  
     memcpy(  
         propertyFilterMask,  
         keyMask,  
         sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1));  
   
     // Get absolut pointer to key index list of the class  
     idx=inst.hdr->theClass->cls.hdr->keyIndexList.start;  
     Uint32* keyIndex = (Uint32*)&(inst.hdr->theClass->cls.base)[idx];  
   
     // Get absolut pointer to property filter index map of the instance  
     Uint32* propertyFilterIndexMap =  
         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);  
   
     Uint32 noKeys = inst.hdr->theClass->cls.hdr->keyBindingSet.number;  
     memcpy(propertyFilterIndexMap,keyIndex,sizeof(Uint32)*noKeys);  
   
     // return the number of properties already in the filter index map  
     return noKeys;  
   
 }  
   
 void SCMOInstance::_clearPropertyFilter()  
 {  
     Uint64 *propertyFilter;  
   
     // Calculate the real pointer to the Uint64 array  
     propertyFilter = (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);  
   
     // the number of Uint64 in the key mask is :  
     // Decrease the number of properties by 1  
     // since the array is starting at index 0!  
     // Divide with the number of bits in a Uint64.  
     // e.g. number of Properties = 68  
     // (68 - 1) / 64 = 1 --> The mask consists of 2 Uint64  
   
     memset(propertyFilter,  
            0,  
            sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1));  
   
 }  
 void SCMOInstance::_setPropertyInPropertyFilter(Uint32 i)  
 {  
     Uint64 *propertyFilter;  
   
     // In which Uint64 of key mask is the bit for property i ?  
     // Divide with the number of bits in a Uint64.  
     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].  
     Uint32 idx = i/64 ;  
   
     // Create a filter to set the bit.  
     // Modulo division with 64. Shift left a bit by the remainder.  
     Uint64 filter = ( (Uint64)1 << (i%64));  
   
     // Calculate the real pointer to the Uint64 array  
     propertyFilter = (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);  
   
     propertyFilter[idx] = propertyFilter[idx] | filter ;  
 }  
   
 Boolean SCMOInstance::_isPropertyInFilter(Uint32 i) const  
 {  
     Uint64 *propertyFilter;  
   
     // In which Uint64 of key mask is the bit for property i ?  
     // Divide with the number of bits in a Uint64.  
     // e.g. number of Properties = 68  
     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].  
     Uint32 idx = i/64 ;  
   
     // Create a filter to check if the bit is set:  
     // Modulo division with 64. Shift left a bit by the remainder.  
     Uint64 filter = ( (Uint64)1 << (i%64));  
   
     // Calculate the real pointer to the Uint64 array  
     propertyFilter = (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);  
  
     // If the bit is set the property is NOT filtered.      return SCMO_TYPE_MISSMATCH;
     // So the result has to be negated!  
     return propertyFilter[idx] & filter ;  
  
 } }
  
   // class SCMODump only in debug builds available
   #ifdef PEGASUS_DEBUG
 /****************************************************************************** /******************************************************************************
  * SCMODump Print and Dump functions  * SCMODump Print and Dump functions
  *****************************************************************************/  *****************************************************************************/
 SCMODump::SCMODump() SCMODump::SCMODump()
 { {
     _out = stdout;      _out = stderr;
     _fileOpen = false;     _fileOpen = false;
  
 #ifdef PEGASUS_OS_ZOS #ifdef PEGASUS_OS_ZOS
Line 5178 
Line 5749 
  
 Boolean SCMODump::compareFile(String master) Boolean SCMODump::compareFile(String master)
 { {
   
     if (!_fileOpen)     if (!_fileOpen)
     {     {
         return false;         return false;
     }     }
   
     closeFile();     closeFile();
  
     return (FileSystem::compareFiles(_filename, master));      ifstream isMaster;
       ifstream isDumpFile;
   
       Open(isDumpFile, _filename);
       Open(isMaster, master);
   
       String aLine;
       String bLine;
   
       while (GetLine(isDumpFile, aLine) && GetLine(isMaster, bLine))
       {
           if (aLine != bLine)
           {
               cout << "|" << aLine << "|" << endl;
               cout << "|" << bLine << "|" << endl;
               isDumpFile.close();
               isMaster.close();
               return false;
           }
       };
       isDumpFile.close();
       isMaster.close();
       return true;
 } }
  
 void SCMODump::dumpSCMOInstance(SCMOInstance& testInst) const  void SCMODump::dumpSCMOInstance(SCMOInstance& testInst,
       Boolean inclMemHdr,
       Boolean verbose) const
 { {
     SCMBInstance_Main* insthdr = testInst.inst.hdr;     SCMBInstance_Main* insthdr = testInst.inst.hdr;
     char* instbase = testInst.inst.base;     char* instbase = testInst.inst.base;
  
     fprintf(_out,"\n\nDump of SCMOInstance\n");     fprintf(_out,"\n\nDump of SCMOInstance\n");
     // The magic number for SCMO class  
     fprintf(_out,"\nheader.magic=%08X",insthdr->header.magic);      if (inclMemHdr)
     // Total size of the instance memory block( # bytes )      {
     fprintf(_out,"\nheader.totalSize=%llu",insthdr->header.totalSize);          _dumpSCMBMgmt_Header(insthdr->header,instbase);
       }
   
     // The reference counter for this c++ class     // The reference counter for this c++ class
       // KS_FUTURE Modify the bool displays to use boolToString
     fprintf(_out,"\nrefCount=%i",insthdr->refCount.get());     fprintf(_out,"\nrefCount=%i",insthdr->refCount.get());
     fprintf(_out,"\ntheClass: %p",insthdr->theClass);      fprintf(_out,"\ntheClass: %p",insthdr->theClass.ptr);
     fprintf(_out,"\n\nThe Flags:");     fprintf(_out,"\n\nThe Flags:");
     fprintf(_out,"\n   includeQualifiers: %s",     fprintf(_out,"\n   includeQualifiers: %s",
            (insthdr->flags.includeQualifiers ? "True" : "False"));            (insthdr->flags.includeQualifiers ? "True" : "False"));
     fprintf(_out,"\n   includeClassOrigin: %s",     fprintf(_out,"\n   includeClassOrigin: %s",
            (insthdr->flags.includeClassOrigin ? "True" : "False"));            (insthdr->flags.includeClassOrigin ? "True" : "False"));
     fprintf(_out,"\n   isFiltered: %s",  
            (insthdr->flags.isFiltered ? "True" : "False"));  
     fprintf(_out,"\n   isClassOnly: %s",     fprintf(_out,"\n   isClassOnly: %s",
            (insthdr->flags.isClassOnly ? "True" : "False"));            (insthdr->flags.isClassOnly ? "True" : "False"));
     fprintf(_out,"\n   isCompromised: %s",     fprintf(_out,"\n   isCompromised: %s",
            (insthdr->flags.isCompromised ? "True" : "False"));            (insthdr->flags.isCompromised ? "True" : "False"));
       fprintf(_out,"\n   exportSetOnly: %s",
              (insthdr->flags.exportSetOnly ? "True" : "False"));
       fprintf(_out,"\n   noClassForThisInstance: %s",
              (insthdr->flags.noClassForInstance ? "True" : "False"));
     fprintf(_out,"\n\ninstNameSpace: \'%s\'",     fprintf(_out,"\n\ninstNameSpace: \'%s\'",
            NULLSTR(_getCharString(insthdr->instNameSpace,instbase)));            NULLSTR(_getCharString(insthdr->instNameSpace,instbase)));
     fprintf(_out,"\n\ninstClassName: \'%s\'",     fprintf(_out,"\n\ninstClassName: \'%s\'",
Line 5220 
Line 5818 
     fprintf(_out,"\n\nhostName: \'%s\'",     fprintf(_out,"\n\nhostName: \'%s\'",
            NULLSTR(_getCharString(insthdr->hostName,instbase)));            NULLSTR(_getCharString(insthdr->hostName,instbase)));
  
     dumpSCMOInstanceKeyBindings(testInst);      dumpSCMOInstanceKeyBindings(testInst, verbose);
  
     dumpSCMOInstancePropertyFilter(testInst);      dumpInstanceProperties(testInst, verbose);
   
     dumpInstanceProperties(testInst);  
     fprintf(_out,"\n\n");     fprintf(_out,"\n\n");
  
 } }
  
 void SCMODump::dumpSCMOInstancePropertyFilter(SCMOInstance& testInst) const  void SCMODump::dumpInstanceProperties(
 {      SCMOInstance& testInst,
     SCMBInstance_Main* insthdr = testInst.inst.hdr;      Boolean verbose) const
     char* instbase = testInst.inst.base;  
   
     if (!insthdr->flags.isFiltered)  
     {  
         fprintf(_out,"\n\nNo propterty filter!\n\n");  
         return;  
     }  
   
     fprintf(_out,"\n\nInstance Property Filter :");  
     fprintf(_out,"\n==========================");  
     fprintf(_out,"\n\nNumber of properties in the filter : %u\n"  
         ,insthdr->filterProperties);  
   
     dumpPropertyFilter(testInst);  
   
     dumpPropertyFilterIndexMap(testInst);  
   
 }  
   
 void SCMODump::dumpInstanceProperties(SCMOInstance& testInst) const  
 { {
     SCMBInstance_Main* insthdr = testInst.inst.hdr;     SCMBInstance_Main* insthdr = testInst.inst.hdr;
     char* instbase = testInst.inst.base;     char* instbase = testInst.inst.base;
Line 5267 
Line 5843 
     for (Uint32 i = 0, k = insthdr->numberProperties; i < k; i++)     for (Uint32 i = 0, k = insthdr->numberProperties; i < k; i++)
     {     {
         fprintf(_out,"\n\nInstance property (#%3u) %s\n",i,         fprintf(_out,"\n\nInstance property (#%3u) %s\n",i,
                 NULLSTR(insthdr->theClass->_getPropertyNameAtNode(i)));                  NULLSTR(insthdr->theClass.ptr->_getPropertyNameAtNode(i)));
         if(insthdr->flags.isFiltered && !testInst._isPropertyInFilter(i))  
         {  
             fprintf(_out,"\nProperty is filtered out!");  
         }  
         else  
         {  
             printSCMOValue(val[i],instbase);  
         }  
     }  
  
           printSCMOValue(val[i],instbase,verbose);
 } }
       fprintf(_out,"\n\nInstance User-DefinedProperties :");
       fprintf(_out,"\n=====================");
       fprintf(_out,"\n\nNumber of user-defined properties in instance : %u\n",
              insthdr->numberUserProperties);
  
 void SCMODump::dumpPropertyFilterIndexMap(SCMOInstance& testInst) const      SCMBUserPropertyElement* theElement;
 {  
  
     SCMBInstance_Main* insthdr = testInst.inst.hdr;      Uint64 start = insthdr->userPropertyElement.start;
     char* instbase = testInst.inst.base;  
  
     if (!insthdr->flags.isFiltered)      Uint32 count = 0;
       while (start != 0)
     {     {
         fprintf(_out,"\n\nNo propterty filter!\n\n");          theElement = (SCMBUserPropertyElement*)&(instbase[start]);
         return;  
     }  
  
     fprintf(_out,"\n\nProperty Filter Index Max:");          // KS_TODO eliminate this display. Once we are actually running
     fprintf(_out,"\n==========================\n");          // it is of little value.
           fprintf(_out, "\nUser-defined PropertyElement # %u %s", count++,
                   ((theElement->nextElement.start != 0)?
                       "" : "last"));
  
     // Get absolut pointer to key index list of the class          _dumpUserDefinedPropertyElement(
     Uint32* keyIndex =              instbase,theElement, verbose);
         (Uint32*)&(instbase)[insthdr->propertyFilterIndexMap.start];  
  
     Uint32 line,j,i,k = insthdr->filterProperties;          start = theElement->nextElement.start;
       } // for all user def. key bindings.
   }
  
     for (j = 0; j < k; j = j + line)  void SCMODump::_dumpUserDefinedPropertyElement(char* instbase,
       SCMBUserPropertyElement* theElement, Boolean verbose) const
     {     {
         if ((insthdr->filterProperties-j)/16)          if (theElement->value.flags.isSet)
         {  
             line = 16 ;  
         }  
         else  
         {         {
             line = insthdr->filterProperties%16;              fprintf(_out,"\n\nName: '%s'\nType: '%s'",
         }                  NULLSTR(_getCharString(theElement->name,instbase)),
                   cimTypeToString(theElement->value.valueType));
  
         fprintf(_out,"Index :");              printSCMOValue(
         for (i = 0; i < line; i++)                  theElement->value,
         {                  instbase,
             fprintf(_out," %3u",j+i);                  verbose);
         }         }
           else
         fprintf(_out,"\nNode  :");  
         for (i = 0; i < line; i++)  
         {         {
             fprintf(_out," %3u",keyIndex[j+i]);              fprintf(_out,"\n\n    %s : Not Set",
         }                  NULLSTR(_getCharString(theElement->name,instbase)));
   
         fprintf(_out,"\n\n");  
   
     }     }
   
 } }
  
 void SCMODump::dumpPropertyFilter(SCMOInstance& testInst) const  void SCMODump::dumpSCMOInstanceKeyBindings(
       SCMOInstance& testInst,
       Boolean verbose) const
 { {
   
     SCMBInstance_Main* insthdr = testInst.inst.hdr;     SCMBInstance_Main* insthdr = testInst.inst.hdr;
     char* instbase = testInst.inst.base;     char* instbase = testInst.inst.base;
  
     if (!insthdr->flags.isFiltered)      // create a pointer to keybinding node array of the class.
     {      Uint64 idx = insthdr->theClass.ptr->cls.hdr->keyBindingSet.nodeArray.start;
         fprintf(_out,"\n\nNo propterty filter!");      SCMBKeyBindingNode* theClassKeyBindNodeArray =
         return;          (SCMBKeyBindingNode*)&((insthdr->theClass.ptr->cls.base)[idx]);
     }  
  
     Uint64 *thePropertyFilter =      SCMBKeyBindingValue* ptr =
         (Uint64*)&(instbase[insthdr->propertyFilter.start]);          (SCMBKeyBindingValue*)
      Uint32 end, noProperties = insthdr->numberProperties;               _resolveDataPtr(insthdr->keyBindingArray,instbase);
      Uint32 noMasks = (noProperties-1)/64;  
      Uint64 printMask = 1;  
  
      for (Uint32 i = 0; i <= noMasks; i++ )      fprintf(_out,"\n\nInstance Key Bindings :");
       fprintf(_out,"\n=======================");
       fprintf(_out,"\n\nNumber of Key Bindings defined in the Class: %u",
               insthdr->numberKeyBindings);
   
       for (Uint32 i = 0, k = insthdr->numberKeyBindings; i < k; i++)
      {      {
          printMask = 1;          if (ptr[i].isSet)
          if (i < noMasks)  
          {          {
              end = 64;              fprintf(_out,"\n\nName: '%s'\nType: '%s'",
                   NULLSTR(_getCharString(
                       theClassKeyBindNodeArray[i].name,
                       insthdr->theClass.ptr->cls.base)),
                   cimTypeToString(theClassKeyBindNodeArray[i].type));
               printUnionValue(
                   theClassKeyBindNodeArray[i].type,
                   ptr[i].data,
                   instbase,
                   verbose);
          }          }
          else          else
          {          {
              end = noProperties%64;              fprintf(_out,"\n\nName: '%s': Not Set",
                   NULLSTR(_getCharString(
                       theClassKeyBindNodeArray[i].name,
                       insthdr->theClass.ptr->cls.base)));
           }
          }          }
  
          fprintf(_out,"\npropertyFilter[%02u]= ",i);      fprintf(_out,"\n\nNumber of User Defined Key Bindings: %u",
               insthdr->numberUserKeyBindings);
  
          for (Uint32 j = 0; j < end; j++)  
          {      SCMBUserKeyBindingElement* theUserDefKBElement;
              if (j > 0 && !(j%8))  
       Uint64 start = insthdr->userKeyBindingElement.start;
       while (start != 0)
              {              {
                  fprintf(_out," ");          theUserDefKBElement = (SCMBUserKeyBindingElement*)&(instbase[start]);
              }  
  
              if (thePropertyFilter[i] & printMask)          if (theUserDefKBElement->value.isSet)
              {              {
                  fprintf(_out,"1");              fprintf(_out,"\n\nName: '%s'\nType: '%s'",
                   NULLSTR(_getCharString(theUserDefKBElement->name,instbase)),
                   cimTypeToString(theUserDefKBElement->type));
               printUnionValue(
                   theUserDefKBElement->type,
                   theUserDefKBElement->value.data,
                   instbase,
                   verbose);
              }              }
              else              else
              {              {
                  fprintf(_out,"0");              fprintf(_out,"\n\n    %s : Not Set",
              }                  NULLSTR(_getCharString(theUserDefKBElement->name,instbase)));
  
              printMask = printMask << 1;  
          }  
          fprintf(_out,"\n");  
      }  
 } }
           start = theUserDefKBElement->nextElement.start;
       } // for all user def. key bindings.
  
 void SCMODump::dumpSCMOInstanceKeyBindings(SCMOInstance& testInst) const      fprintf(_out,"\n\n");
 {  
     SCMBInstance_Main* insthdr = testInst.inst.hdr;  
     char* instbase = testInst.inst.base;  
   
     // create a pointer to keybinding node array of the class.  
     Uint64 idx = insthdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;  
     SCMBKeyBindingNode* theClassKeyBindNodeArray =  
         (SCMBKeyBindingNode*)&((insthdr->theClass->cls.base)[idx]);  
  
     SCMBKeyBindingValue* ptr =  }
         (SCMBKeyBindingValue*)  
              _resolveDataPtr(insthdr->keyBindingArray,instbase);  
  
     fprintf(_out,"\n\nInstance Key Bindings :");  void SCMODump::_dumpSCMBMgmt_Header(SCMBMgmt_Header& header,char* base) const
     fprintf(_out,"\n=======================");  {
     fprintf(_out,"\n\nNumber of Key Bindings : %u",insthdr->numberKeyBindings);      fprintf(_out,"\nThe Management Header:");
       // The magic number
       fprintf(_out,"\n   magic=%08X",header.magic);
       // Total size of the memory block( # bytes )
       fprintf(_out,"\n   totalSize=%llu",header.totalSize);
       // Free bytes in the block
       fprintf(_out,"\n   freeBytes=%llu",header.freeBytes);
       // Index to the start of the free space in this SCMB memory block.
       fprintf(_out,"\n   startOfFreeSpace=%llu",header.startOfFreeSpace);
       // Number of external references in this instance.
       fprintf(_out,"\n   numberExtRef=%u",header.numberExtRef);
       // Size of external reference index array;
       fprintf(_out,"\n   sizeExtRefIndexArray=%u",header.sizeExtRefIndexArray);
   
       if (header.numberExtRef > 0)
       {
           fprintf(_out,"\n   extRefIndexArray=[");
           Uint64* extRefIndexArray =
               (Uint64*)&(base[header.extRefIndexArray.start]);
  
     for (Uint32 i = 0, k = insthdr->numberKeyBindings; i < k; i++)          for (Uint32 i = 0; i < header.numberExtRef;)
     {     {
         if (ptr[i].isSet)              fprintf(_out,"%llu",extRefIndexArray[i]);
               i++;
               if (i != header.numberExtRef)
         {         {
             fprintf(_out,"\n\nNo %u : '%s'",i,                  fprintf(_out,", ");
                 (const char*)printUnionValue(              }
                     theClassKeyBindNodeArray[i].type,          }
                     ptr[i].data,          fprintf(_out,"\n");
                     instbase).getCString());  
         }         }
         else         else
         {         {
             fprintf(_out,"\n\nNo %u : Not Set",i);             fprintf(_out,"\n   extRefIndexArray=[NO INDEX]\n");
   
         }         }
     }     }
     fprintf(_out,"\n");  
 }  
  
 void SCMODump::dumpSCMOClass(SCMOClass& testCls) const  void SCMODump::dumpSCMOClass(SCMOClass& testCls, Boolean inclMemHdr) const
 { {
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;     char* clsbase = testCls.cls.base;
  
     fprintf(_out,"\n\nDump of SCMOClass\n");     fprintf(_out,"\n\nDump of SCMOClass\n");
     // The magic number for SCMO class  
     fprintf(_out,"\nheader.magic=%08X",clshdr->header.magic);      if (inclMemHdr)
     // Total size of the instance memory block( # bytes )      {
     fprintf(_out,"\nheader.totalSize=%llu",clshdr->header.totalSize);          _dumpSCMBMgmt_Header(clshdr->header,clsbase);
       }
   
     // The reference counter for this c++ class     // The reference counter for this c++ class
     fprintf(_out,"\nrefCount=%i",clshdr->refCount.get());     fprintf(_out,"\nrefCount=%i",clshdr->refCount.get());
       fprintf(_out,"\n\nThe Flags:");
       fprintf(_out,"\n   isEmpty: %s",
              (clshdr->flags.isEmpty ? "True" : "False"));
     fprintf(_out,"\n\nsuperClassName: \'%s\'",     fprintf(_out,"\n\nsuperClassName: \'%s\'",
            NULLSTR(_getCharString(clshdr->superClassName,clsbase)));            NULLSTR(_getCharString(clshdr->superClassName,clsbase)));
     fprintf(_out,"\nnameSpace: \'%s\'",     fprintf(_out,"\nnameSpace: \'%s\'",
Line 5477 
Line 6073 
  
 void SCMODump::hexDumpSCMOClass(SCMOClass& testCls) const void SCMODump::hexDumpSCMOClass(SCMOClass& testCls) const
 { {
     char* tmp;  
   
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;     char* clsbase = testCls.cls.base;
  
Line 5508 
Line 6102 
         }         }
         else         else
         {         {
             line = clshdr->propertySet.number%16;              line = clshdr->propertySet.number & 15;
         }         }
  
  
Line 5533 
Line 6127 
 void SCMODump::dumpKeyBindingSet(SCMOClass& testCls) const void SCMODump::dumpKeyBindingSet(SCMOClass& testCls) const
 { {
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;  
  
     fprintf(_out,"\n\nKey Binding Set:");     fprintf(_out,"\n\nKey Binding Set:");
     fprintf(_out,"\n=================\n");     fprintf(_out,"\n=================\n");
Line 5576 
Line 6169 
  
         fprintf(_out,"\nHash Tag %3u Hash Index %3u",         fprintf(_out,"\nHash Tag %3u Hash Index %3u",
                nodeArray[i].nameHashTag,                nodeArray[i].nameHashTag,
                nodeArray[i].nameHashTag%PEGASUS_KEYBINDIG_SCMB_HASHSIZE);                 nodeArray[i].nameHashTag & (PEGASUS_KEYBINDIG_SCMB_HASHSIZE -1));
  
         fprintf(_out,"\nType: %s",cimTypeToString(nodeArray[i].type));         fprintf(_out,"\nType: %s",cimTypeToString(nodeArray[i].type));
  
Line 5587 
Line 6180 
 void SCMODump::dumpClassProperties(SCMOClass& testCls) const void SCMODump::dumpClassProperties(SCMOClass& testCls) const
 { {
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;  
  
     fprintf(_out,"\n\nClass Properties:");     fprintf(_out,"\n\nClass Properties:");
     fprintf(_out,"\n=================\n");     fprintf(_out,"\n=================\n");
Line 5637 
Line 6229 
  
     fprintf(_out,"\nHash Tag %3u Hash Index %3u",     fprintf(_out,"\nHash Tag %3u Hash Index %3u",
            prop.nameHashTag,            prop.nameHashTag,
            prop.nameHashTag%PEGASUS_PROPERTY_SCMB_HASHSIZE);             prop.nameHashTag & (PEGASUS_PROPERTY_SCMB_HASHSIZE -1));
     fprintf(_out,"\nPropagated: %s isKey: %s",     fprintf(_out,"\nPropagated: %s isKey: %s",
            (prop.flags.propagated?"TRUE":"FALSE"),            (prop.flags.propagated?"TRUE":"FALSE"),
            (prop.flags.isKey?"TRUE":"FALSE")            (prop.flags.isKey?"TRUE":"FALSE")
Line 5671 
Line 6263 
         }         }
         else         else
         {         {
             line = size%16;              line = size & 15;
         }         }
  
  
Line 5733 
Line 6325 
      printSCMOValue(theQualifier.value,clsbase);      printSCMOValue(theQualifier.value,clsbase);
  
 } }
   /*
       printSCMOValue is a superset of printUnionValue.  It prints type
       information, flags, and then the UnionValue for the element
       or all elements in the array
   */
 void SCMODump::printSCMOValue( void SCMODump::printSCMOValue(
     const SCMBValue& theValue,     const SCMBValue& theValue,
     char* base) const      char* base,
       Boolean verbose) const
 { {
    fprintf(_out,"\nValueType : %s",cimTypeToString(theValue.valueType));    fprintf(_out,"\nValueType : %s",cimTypeToString(theValue.valueType));
    fprintf(_out,"\nValue was set: %s",    fprintf(_out,"\nValue was set: %s",
Line 5748 
Line 6345 
    }    }
    if (theValue.flags.isArray)    if (theValue.flags.isArray)
    {    {
        fprintf(_out,         fprintf(
              _out,
                "\nThe value is an Array of size: %u",                "\nThe value is an Array of size: %u",
                theValue.valueArraySize);                theValue.valueArraySize);
        fprintf(_out,"\nThe values are: %s",         printArrayValue(
               (const char*)printArrayValue(  
                   theValue.valueType,                   theValue.valueType,
                   theValue.valueArraySize,                   theValue.valueArraySize,
                   theValue.value,                   theValue.value,
                   base).getCString());             base,
              verbose);
    }    }
    else    else
    {    {
       fprintf(_out,"\nThe Value is: '%s'",         printUnionValue(theValue.valueType,theValue.value,base,verbose);
           (const char*)  
              printUnionValue(theValue.valueType,theValue.value,base)  
              .getCString());  
    }    }
  
    return;    return;
Line 5790 
Line 6385 
          }          }
          else          else
          {          {
              end = noProperties%64;               end = noProperties & 63;
          }          }
  
          fprintf(_out,"\nkeyPropertyMask[%02u]= ",i);          fprintf(_out,"\nkeyPropertyMask[%02u]= ",i);
  
          for (Uint32 j = 0; j < end; j++)          for (Uint32 j = 0; j < end; j++)
          {          {
              if (j > 0 && !(j%8))               if (j > 0 && !(j & 7))
              {              {
                  fprintf(_out," ");                  fprintf(_out," ");
              }              }
Line 5816 
Line 6411 
          fprintf(_out,"\n");          fprintf(_out,"\n");
      }      }
 } }
   void SCMODump::_dumpEmbeddedInstance(SCMBUnion u, Boolean verbose) const
 void SCMODump::_hexDump(char* buffer,int length) const  {
       if (verbose)
       {
           fprintf(_out,"\n-----------> "
                         "Start of embedded external reference"
                         " <-----------\n");
           dumpSCMOInstance(*u.extRefPtr, true, verbose);
           fprintf(_out,"\n-----------> "
                        "End of embedded external reference"
                        " <-----------\n");
       }
       else
       {
           fprintf(_out,
               "\nPointer to external Reference : \'%p\'",
               u.extRefPtr);
       }
   }
   void SCMODump::_hexDump(char* buffer,Uint64 length) const
 { {
  
     unsigned char printLine[3][80];     unsigned char printLine[3][80];
Line 5825 
Line 6438 
     int len;     int len;
     unsigned char item;     unsigned char item;
  
     for (int i = 0; i < length;i=i+1)      for (Uint64 i = 0; i < length;i=i+1)
     {     {
         p = i%80;          p = (int)i%80;
  
         if ((p == 0 && i > 0) || i == length-1 )         if ((p == 0 && i > 0) || i == length-1 )
         {         {
Line 5868 
Line 6481 
         }         }
  
         printLine[1][p] = item/16;         printLine[1][p] = item/16;
         printLine[2][p] = item%16;          printLine[2][p] = item & 15;
  
     }     }
 } }
  
 String SCMODump::printArrayValue(  void SCMODump::printArrayValue(
     CIMType type,     CIMType type,
     Uint32 size,     Uint32 size,
     SCMBUnion u,     SCMBUnion u,
     char* base) const      char* base,
       Boolean verbose) const
 { {
     Buffer out;     Buffer out;
  
Line 5898 
Line 6512 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 5913 
Line 6528 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 5928 
Line 6544 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 5943 
Line 6560 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 5958 
Line 6576 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 5973 
Line 6592 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 5988 
Line 6608 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 6003 
Line 6624 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 6018 
Line 6640 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 6033 
Line 6656 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 6048 
Line 6672 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 6063 
Line 6688 
                           STRLIT("FALSE)"));                           STRLIT("FALSE)"));
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
         {         {
             SCMBDataPtr* p = (SCMBDataPtr*)&(base[u.arrayValue.start]);  
             for (Uint32 i = 0; i < size; i++)             for (Uint32 i = 0; i < size; i++)
             {             {
                 if ( 0 != p[i].length)                  if ( 0 != p[i].stringValue.size)
                 {                 {
                     out.append('\'');                     out.append('\'');
                     out.append((const char*)_getCharString(p[i],base),                      out.append(
                                p[i].length-1);                          (const char*)_getCharString(p[i].stringValue,base),
                           p[i].stringValue.size-1);
                     out.append('\'');                     out.append('\'');
                 }                 }
                 else                 else
Line 6084 
Line 6710 
                 }                 }
                 out.append(';');                 out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_DATETIME:     case CIMTYPE_DATETIME:
         {         {
             SCMBDateTime* p = (SCMBDateTime*)&(base[u.arrayValue.start]);  
             CIMDateTime x;             CIMDateTime x;
             for (Uint32 i = 0; i < size; i++)             for (Uint32 i = 0; i < size; i++)
             {             {
                 memcpy(x._rep,&(p[i]),sizeof(SCMBDateTime));                  memcpy(x._rep,&(p[i].dateTimeValue),sizeof(SCMBDateTime));
                 _toString(out,x);                 _toString(out,x);
                 out.append(' ');                 out.append(' ');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
Line 6104 
Line 6731 
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
     case CIMTYPE_INSTANCE:     case CIMTYPE_INSTANCE:
         {         {
             // TODO: has to dump SCMOInstance ...              if (verbose)
               {
                   for (Uint32 i = 0; i < size; i++)
                   {
                       fprintf(_out,"\n-----------> "
                                     "Start of embedded external reference [%d]"
                                     " <-----------\n\n",i);
                       dumpSCMOInstance(*(p[i].extRefPtr), false, verbose);
                       fprintf(_out,"\n-----------> "
                                     "End of embedded external reference [%d]"
                                     " <-----------\n\n",i);
                   }
   
               } else
               {
                   fprintf(_out,"\nThe values are: ");
   
                   for (Uint32 i = 0; i < size; i++)
                   {
                       fprintf(
                           _out,
                           "\nPointer to external Reference[%d] : \'%p\';",
                           i,p[i].extRefPtr);
                   }
               }
   
             break;             break;
   
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
  
     return out.getData();      return;
 } }
  
 String SCMODump::printUnionValue(  /*
       printUnionValue outputs a single Union Value.
       Note: this requires the base to output string information
   */
   
   // KS_FUTURE this display does not represent or use the hasValue flag
   void SCMODump::printUnionValue(
     CIMType type,     CIMType type,
     SCMBUnion u,     SCMBUnion u,
     char* base) const      char* base,
       Boolean verbose) const
 { {
   
     Buffer out;     Buffer out;
  
     switch (type)     switch (type)
Line 6130 
Line 6789 
     case CIMTYPE_BOOLEAN:     case CIMTYPE_BOOLEAN:
         {         {
             _toString(out,u.simple.val.bin);             _toString(out,u.simple.val.bin);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT8:     case CIMTYPE_UINT8:
         {         {
             _toString(out,u.simple.val.u8);             _toString(out,u.simple.val.u8);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT8:     case CIMTYPE_SINT8:
         {         {
             _toString(out,u.simple.val.s8);             _toString(out,u.simple.val.s8);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT16:     case CIMTYPE_UINT16:
         {         {
             _toString(out,(Uint32)u.simple.val.u16);             _toString(out,(Uint32)u.simple.val.u16);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT16:     case CIMTYPE_SINT16:
         {         {
             _toString(out,u.simple.val.s16);             _toString(out,u.simple.val.s16);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT32:     case CIMTYPE_UINT32:
         {         {
             _toString(out,u.simple.val.u32);             _toString(out,u.simple.val.u32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT32:     case CIMTYPE_SINT32:
         {         {
             _toString(out,u.simple.val.s32);             _toString(out,u.simple.val.s32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT64:     case CIMTYPE_UINT64:
         {         {
             _toString(out,u.simple.val.u64);             _toString(out,u.simple.val.u64);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT64:     case CIMTYPE_SINT64:
         {         {
             _toString(out,u.simple.val.s64);             _toString(out,u.simple.val.s64);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REAL32:     case CIMTYPE_REAL32:
         {         {
             _toString(out,u.simple.val.r32);             _toString(out,u.simple.val.r32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REAL64:     case CIMTYPE_REAL64:
         {         {
             _toString(out,u.simple.val.r32);             _toString(out,u.simple.val.r32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_CHAR16:     case CIMTYPE_CHAR16:
         {         {
             _toString(out,u.simple.val.c16);             _toString(out,u.simple.val.c16);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
         {         {
             if ( 0 != u.stringValue.length)              if ( 0 != u.stringValue.size)
             {             {
                 out.append((const char*)_getCharString(u.stringValue,base),                 out.append((const char*)_getCharString(u.stringValue,base),
                            u.stringValue.length-1);                             u.stringValue.size-1);
             }             }
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
Line 6214 
Line 6886 
             CIMDateTime x;             CIMDateTime x;
             memcpy(x._rep,&(u.dateTimeValue),sizeof(SCMBDateTime));             memcpy(x._rep,&(u.dateTimeValue),sizeof(SCMBDateTime));
             _toString(out,x);             _toString(out,x);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
Line 6221 
Line 6894 
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
     case CIMTYPE_INSTANCE:     case CIMTYPE_INSTANCE:
         {         {
             // TODO: Has to dump SCMOInstance.              _dumpEmbeddedInstance(u, verbose);
             break;             break;
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(false);              PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
             break;             break;
         }         }
     }     }
  
   return out.getData();    return;
 } }
   #endif // PEGASUS_DEBUG (class SCMODump only in debug builds available)
  
  
 /***************************************************************************** /*****************************************************************************
  * The constant functions  * The constant functions
  *****************************************************************************/  *****************************************************************************/
  
 static Boolean _equalUTF8Strings(  
     const SCMBDataPtr& ptr_a,  
     char* base,  
     const char* name,  
     Uint32 len)  
   
 {  
     // size without trailing '\0' !!  
     if (ptr_a.length-1 != len)  
     {  
         return false;  
     }  
     const char* a = (const char*)_getCharString(ptr_a,base);  
   
     // lets do a loop-unrolling optimized compare here  
     while (len >= 8)  
     {  
         if ((a[0] - name[0]) || (a[1] - name[1]) ||  
             (a[2] - name[2]) || (a[3] - name[3]) ||  
             (a[4] - name[4]) || (a[5] - name[5]) ||  
             (a[6] - name[6]) || (a[7] - name[7]))  
         {  
             return false;  
         }  
         len -= 8;  
         a += 8;  
         name += 8;  
     }  
     while (len >= 4)  
     {  
         if ((a[0] - name[0]) || (a[1] - name[1]) ||  
             (a[2] - name[2]) || (a[3] - name[3]))  
         {  
             return false;  
         }  
         len -= 4;  
         a += 4;  
         name += 4;  
     }  
     while (len--)  
     {  
         if (a[0] - name[0])  
         {  
             return false;  
         }  
         a++;  
         name++;  
     }  
     return true;  
 }  
   
   
 static Boolean _equalNoCaseUTF8Strings(  
     const SCMBDataPtr& ptr_a,  
     char* base,  
     const char* name,  
     Uint32 len)  
   
 {  
   
     //both are empty strings, so they are equal.  
     if (ptr_a.length == 0 && len == 0)  
     {  
         return true;  
     }  
   
     // size without trailing '\0' !!  
     if (ptr_a.length-1 != len)  
     {  
         return false;  
     }  
   
     const char* a = (const char*)_getCharString(ptr_a,base);  
   
 #ifdef PEGASUS_HAS_ICU  
     return ( _utf8ICUncasecmp(a,name,len)== 0);  
 #else  
     return ( strncasecmp(a,name,len )== 0 );  
 #endif  
 }  
   
 #ifdef PEGASUS_HAS_ICU #ifdef PEGASUS_HAS_ICU
 static Uint32 _utf8ICUncasecmp(  Uint32 _utf8ICUncasecmp(
     const char* a,     const char* a,
     const char* b,     const char* b,
     Uint32 len)     Uint32 len)
Line 6405 
Line 6998 
 #endif #endif
  
 /** /**
  * This function calcutates a free memory slot in the single chunk memory block.   * This function calculates a free memory slot in the single
  * Warning: In this routine a reallocation may take place.   * chunk memory block. Warning: In this routine a reallocation
    * may take place.
  * @param ptr A reference to a data SCMB data pointer. The values to the free  * @param ptr A reference to a data SCMB data pointer. The values to the free
  *            block is written into this pointer. If the provided ptr is  *            block is written into this pointer. If the provided ptr is
  *            located in the single chunk memory block, this pointer may be  *            located in the single chunk memory block, this pointer may be
Line 6415 
Line 7009 
  * @parm size The requested free memory slot.  * @parm size The requested free memory slot.
  * @parm pmem A reference to the pointer of the single chunk memory block.  * @parm pmem A reference to the pointer of the single chunk memory block.
  *            e.g. &cls.mem  *            e.g. &cls.mem
  * @return The relaive index of the free memory slot.   * @return The relative index of the free memory slot.
  */  */
   Uint64 _getFreeSpace(
 static Uint64 _getFreeSpace(  
     SCMBDataPtr& ptr,     SCMBDataPtr& ptr,
     Uint64 size,      Uint32 size,
     SCMBMgmt_Header** pmem,      SCMBMgmt_Header** pmem)
     Boolean clear)  
 { {
     Uint64 oldSize, start;     Uint64 oldSize, start;
       Uint64 alignedStart, reqAlignSize;
  
     if (size == 0)     if (size == 0)
     {     {
         ptr.start = 0;         ptr.start = 0;
         ptr.length = 0;          ptr.size = 0;
         return 0;         return 0;
     }     }
  
     // The SCMBDataPtr has to be set before any reallocation.     // The SCMBDataPtr has to be set before any reallocation.
     start = (*pmem)->startOfFreeSpace;     start = (*pmem)->startOfFreeSpace;
     ptr.start = start;  
     ptr.length = size;  
  
     while ((*pmem)->freeBytes < size)      // Need to align the start of freespace to 8 byte
       // boundaries to avoid alignment issues on some architectures
       // Round up to nearest multiple of 8
       alignedStart = (start + 7) & ~7;
       // due to the alignment, a little more room is needed in the SCMB
       reqAlignSize = (size + alignedStart - start);
   
       ptr.start = alignedStart;
       ptr.size = size;
       // add 8 bytes of size for later alignment on the next pointer
       while ((*pmem)->freeBytes < reqAlignSize)
     {     {
         // save old size of buffer         // save old size of buffer
         oldSize = (*pmem)->totalSize;         oldSize = (*pmem)->totalSize;
         // reallocate the buffer, double the space !         // reallocate the buffer, double the space !
         // This is a working approach until a better algorithm is found.         // This is a working approach until a better algorithm is found.
         (*pmem) = (SCMBMgmt_Header*)realloc((*pmem),oldSize*2);          void* newBlockPtr = realloc((*pmem),(size_t)oldSize*2);
         if ((*pmem) == 0)          if ((newBlockPtr) == 0)
         {         {
             // Not enough memory!             // Not enough memory!
             throw PEGASUS_STD(bad_alloc)();             throw PEGASUS_STD(bad_alloc)();
         }         }
           (*pmem) = (SCMBMgmt_Header*)newBlockPtr;
         // increase the total size and free space         // increase the total size and free space
         (*pmem)->freeBytes+=oldSize;         (*pmem)->freeBytes+=oldSize;
         (*pmem)->totalSize+=oldSize;         (*pmem)->totalSize+=oldSize;
     }     }
  
     (*pmem)->freeBytes -= size;      (*pmem)->freeBytes -= reqAlignSize;
     (*pmem)->startOfFreeSpace += size;      (*pmem)->startOfFreeSpace = alignedStart + size;
  
     if (clear)      // Init memory from unaligned start up to the size required with alignment
     {      // to zero.
         // If requested, set memory to 0.      memset(&((char*)(*pmem))[start],0,(size_t)reqAlignSize);
         memset(&((char*)(*pmem))[start],0,size);      PEGASUS_DEBUG_ASSERT(
     }          ((*pmem)->freeBytes+(*pmem)->startOfFreeSpace) == (*pmem)->totalSize);
     return start;  
       return alignedStart;
 } }
  
 static void _setString(  void _setString(
     const String& theString,     const String& theString,
     SCMBDataPtr& ptr,     SCMBDataPtr& ptr,
     SCMBMgmt_Header** pmem)     SCMBMgmt_Header** pmem)
Line 6477 
Line 7080 
     // Get the real size of the UTF8 sting + \0.     // Get the real size of the UTF8 sting + \0.
     // It maybe greater then the length in the String due to     // It maybe greater then the length in the String due to
     // 4 byte encoding of non ASCII chars.     // 4 byte encoding of non ASCII chars.
     Uint64 start,length = strlen((const char*)theCString)+1;      Uint64 start;
       Uint32 length = strlen((const char*)theCString)+1;
  
     // If the string is not empty.     // If the string is not empty.
     if (length != 1)     if (length != 1)
Line 6493 
Line 7097 
     else     else
     {     {
         ptr.start = 0;         ptr.start = 0;
         ptr.length = 0;          ptr.size = 0;
     }     }
 } }
  
 static void _setBinary(  void _setBinary(
     const void* theBuffer,     const void* theBuffer,
     Uint64 bufferSize,      Uint32 bufferSize,
     SCMBDataPtr& ptr,     SCMBDataPtr& ptr,
     SCMBMgmt_Header** pmem)     SCMBMgmt_Header** pmem)
 { {
  
     // If buffer is not empty.     // If buffer is not empty.
     if (bufferSize != 1 && theBuffer != 0)      if (bufferSize != 0 && theBuffer != 0)
     {     {
  
         Uint64 start;         Uint64 start;
Line 6522 
Line 7126 
     else     else
     {     {
         ptr.start = 0;         ptr.start = 0;
         ptr.length = 0;          ptr.size = 0;
       }
   }
   
   void _destroyExternalReferencesInternal(SCMBMgmt_Header* memHdr)
   {
   
       Uint32 number = memHdr->numberExtRef;
   
       if (0 != number)
       {
           char * base = ((char*)memHdr);
           Uint64* array =
               (Uint64*)&(base[memHdr->extRefIndexArray.start]);
           for (Uint32 i = 0; i < number; i++)
           {
                delete ((SCMBUnion*)(&(base[array[i]])))->extRefPtr;
           }
   
     }     }
 } }
  


Legend:
Removed from v.1.2.2.38  
changed lines
  Added in v.1.26

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2