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

   1 thilo.boehm 1.1 //%LICENSE////////////////////////////////////////////////////////////////
   2                 //
   3                 // Licensed to The Open Group (TOG) under one or more contributor license
   4                 // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   5                 // this work for additional information regarding copyright ownership.
   6                 // Each contributor licenses this file to you under the OpenPegasus Open
   7                 // Source License; you may not use this file except in compliance with the
   8                 // License.
   9                 //
  10                 // Permission is hereby granted, free of charge, to any person obtaining a
  11                 // copy of this software and associated documentation files (the "Software"),
  12                 // to deal in the Software without restriction, including without limitation
  13                 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14                 // and/or sell copies of the Software, and to permit persons to whom the
  15                 // Software is furnished to do so, subject to the following conditions:
  16                 //
  17                 // The above copyright notice and this permission notice shall be included
  18                 // in all copies or substantial portions of the Software.
  19                 //
  20                 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21                 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22 thilo.boehm 1.1 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23                 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24                 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25                 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26                 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27                 //
  28                 //////////////////////////////////////////////////////////////////////////
  29                 //
  30                 //%/////////////////////////////////////////////////////////////////////////////
  31                 
  32 thilo.boehm 1.3 #include <Pegasus/Common/SCMO.h>
  33                 #include <Pegasus/Common/SCMOClass.h>
  34                 #include <Pegasus/Common/SCMOInstance.h>
  35                 #include <Pegasus/Common/SCMODump.h>
  36                 #include <Pegasus/Common/SCMOClassCache.h>
  37 thilo.boehm 1.1 #include <Pegasus/Common/CharSet.h>
  38                 #include <Pegasus/Common/CIMDateTimeRep.h>
  39                 #include <Pegasus/Common/CIMPropertyRep.h>
  40 thilo.boehm 1.3 #include <Pegasus/Common/CIMInstanceRep.h>
  41                 #include <Pegasus/Common/CIMObjectPathRep.h>
  42                 #include <Pegasus/Common/CIMNameCast.h>
  43 thilo.boehm 1.1 #include <Pegasus/Common/CommonUTF.h>
  44                 #include <Pegasus/Common/StrLit.h>
  45 thilo.boehm 1.3 #include <Pegasus/Common/Tracer.h>
  46 thilo.boehm 1.2 #include <Pegasus/Common/XmlWriter.h>
  47 thilo.boehm 1.3 #include <Pegasus/Common/System.h>
  48                 #include <Pegasus/Common/FileSystem.h>
  49                 #include <Pegasus/Common/StringConversion.h>
  50                 #include <Pegasus/Common/ArrayIterator.h>
  51                 #include <Pegasus/Common/PegasusAssert.h>
  52                 #include <Pegasus/Common/CIMValueRep.h>
  53                 
  54                 # if defined PEGASUS_OS_ZOS
  55                 #  include <strings.h>
  56                 # else
  57                 #  include <string.h>
  58                 # endif
  59                 
  60                 #ifdef PEGASUS_OS_ZOS
  61                   #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>
  62                 #endif
  63                 
  64                 #ifdef PEGASUS_HAS_ICU
  65                 # include <unicode/platform.h>
  66                 # include <unicode/urename.h>
  67                 # include <unicode/ures.h>
  68 thilo.boehm 1.3 # include <unicode/ustring.h>
  69                 # include <unicode/uchar.h>
  70                 # include <unicode/ucnv.h>
  71                 #endif
  72 thilo.boehm 1.1 
  73                 PEGASUS_USING_STD;
  74                 
  75                 #define SCMB_INITIAL_MEMORY_CHUNK_SIZE 4096
  76                 
  77 thilo.boehm 1.3 /**
  78                  * This macro is used at the SCMODump class
  79                  * for generating C/C++ runtime independend output.
  80                  * For example on Linux if fprintf got a NULL pointer
  81                  * for a string format specification, the string "(null)" is
  82                  * substituted. On other platforms no string "" is substituded.
  83                  */
  84                 #define NULLSTR(x) ((x) == 0 ? "" : (x))
  85                 
  86 thilo.boehm 1.1 PEGASUS_NAMESPACE_BEGIN
  87                 
  88 thilo.boehm 1.3 #define PEGASUS_ARRAY_T SCMOInstance
  89                 # include "ArrayImpl.h"
  90                 #undef PEGASUS_ARRAY_T
  91                 
  92                 const StrLit SCMOClass::_qualifierNameStrLit[72] =
  93 thilo.boehm 1.1 {
  94 thilo.boehm 1.2     STRLIT(""),
  95                     STRLIT("ABSTRACT"),
  96                     STRLIT("AGGREGATE"),
  97                     STRLIT("AGGREGATION"),
  98                     STRLIT("ALIAS"),
  99 thilo.boehm 1.3     STRLIT("ARRAYTYPE"),
 100                     STRLIT("ASSOCIATION"),
 101 thilo.boehm 1.2     STRLIT("BITMAP"),
 102                     STRLIT("BITVALUES"),
 103                     STRLIT("CLASSCONSTRAINT"),
 104                     STRLIT("COMPOSITION"),
 105                     STRLIT("CORRELATABLE"),
 106 thilo.boehm 1.1     STRLIT("COUNTER"),
 107                     STRLIT("DELETE"),
 108 thilo.boehm 1.2     STRLIT("DEPRECATED"),
 109 thilo.boehm 1.1     STRLIT("DESCRIPTION"),
 110 thilo.boehm 1.2     STRLIT("DISPLAYDESCRIPTION"),
 111                     STRLIT("DISPLAYNAME"),
 112                     STRLIT("DN"),
 113 thilo.boehm 1.1     STRLIT("EMBEDDEDINSTANCE"),
 114 thilo.boehm 1.2     STRLIT("EMBEDDEDOBJECT"),
 115                     STRLIT("EXCEPTION"),
 116                     STRLIT("EXPENSIVE"),
 117                     STRLIT("EXPERIMENTAL"),
 118                     STRLIT("GAUGE"),
 119 thilo.boehm 1.3     STRLIT("IFDELETED"),
 120 thilo.boehm 1.2     STRLIT("IN"),
 121 thilo.boehm 1.3     STRLIT("INDICATION"),
 122 thilo.boehm 1.2     STRLIT("INVISIBLE"),
 123 thilo.boehm 1.1     STRLIT("ISPUNIT"),
 124 thilo.boehm 1.2     STRLIT("KEY"),
 125 thilo.boehm 1.1     STRLIT("LARGE"),
 126 thilo.boehm 1.2     STRLIT("MAPPINGSTRINGS"),
 127                     STRLIT("MAX"),
 128                     STRLIT("MAXLEN"),
 129                     STRLIT("MAXVALUE"),
 130 thilo.boehm 1.1     STRLIT("METHODCONSTRAINT"),
 131 thilo.boehm 1.2     STRLIT("MIN"),
 132                     STRLIT("MINLEN"),
 133                     STRLIT("MINVALUE"),
 134                     STRLIT("MODELCORRESPONDENCE"),
 135                     STRLIT("NONLOCAL"),
 136                     STRLIT("NONLOCALTYPE"),
 137                     STRLIT("NULLVALUE"),
 138                     STRLIT("OCTETSTRING"),
 139                     STRLIT("OUT"),
 140                     STRLIT("OVERRIDE"),
 141 thilo.boehm 1.1     STRLIT("PROPAGATED"),
 142 thilo.boehm 1.2     STRLIT("PROPERTYCONSTRAINT"),
 143                     STRLIT("PROPERTYUSAGE"),
 144                     STRLIT("PROVIDER"),
 145                     STRLIT("PUNIT"),
 146                     STRLIT("READ"),
 147                     STRLIT("REQUIRED"),
 148                     STRLIT("REVISION"),
 149                     STRLIT("SCHEMA"),
 150                     STRLIT("SOURCE"),
 151                     STRLIT("SOURCETYPE"),
 152                     STRLIT("STATIC"),
 153                     STRLIT("SYNTAX"),
 154                     STRLIT("SYNTAXTYPE"),
 155                     STRLIT("TERMINAL"),
 156                     STRLIT("TRIGGERTYPE"),
 157                     STRLIT("UMLPACKAGEPATH"),
 158 thilo.boehm 1.1     STRLIT("UNITS"),
 159 thilo.boehm 1.2     STRLIT("UNKNOWNVALUES"),
 160 thilo.boehm 1.1     STRLIT("UNSUPPORTEDVALUES"),
 161 thilo.boehm 1.2     STRLIT("VALUEMAP"),
 162                     STRLIT("VALUES"),
 163                     STRLIT("VERSION"),
 164 thilo.boehm 1.3     STRLIT("WEAK"),
 165 thilo.boehm 1.1     STRLIT("WRITE")
 166                 };
 167                 
 168 thilo.boehm 1.2 #define _NUM_QUALIFIER_NAMES \
 169                            (sizeof(_qualifierNameStrLit)/sizeof(_qualifierNameStrLit[0]))
 170 thilo.boehm 1.1 
 171                 /*****************************************************************************
 172 thilo.boehm 1.3  * Internal inline functions.
 173                  *****************************************************************************/
 174                 
 175 marek       1.5 inline String _newCimString(const SCMBDataPtr & ptr, const char * base)
 176                 {
 177                     if (ptr.size > 0)
 178                     {
 179                         return String(&(base[ptr.start]),ptr.size-1);
 180                     }
 181                     else
 182                     {
 183                         return String();
 184                     }
 185                 }
 186                 
 187 thilo.boehm 1.3 inline void _deleteArrayExtReference(
 188                     SCMBDataPtr& theArray,
 189                     SCMBMgmt_Header** pmem )
 190                 {
 191                     SCMBUnion* ptr;
 192                     // if the array was already set,
 193                     // the previous references has to be deleted
 194                     if(theArray.size != 0)
 195                     {
 196                         Uint32 oldArraySize=(theArray.size/sizeof(SCMBUnion));
 197                 
 198                         ptr = (SCMBUnion*)&(((char*)*pmem)[theArray.start]);
 199                         for (Uint32 i = 0 ; i < oldArraySize ; i++)
 200                         {
 201                             delete ptr[i].extRefPtr;
 202                             ptr[i].extRefPtr = 0;
 203                         }
 204                     }
 205                 }
 206                 
 207                 /*****************************************************************************
 208 thilo.boehm 1.1  * The SCMOClass methods
 209                  *****************************************************************************/
 210 thilo.boehm 1.2 SCMOClass::SCMOClass()
 211 thilo.boehm 1.1 {
 212 thilo.boehm 1.3     _initSCMOClass();
 213                 
 214                     _setBinary("",1,cls.hdr->className,&cls.mem );
 215                     _setBinary("",1,cls.hdr->nameSpace,&cls.mem );
 216                     cls.hdr->flags.isEmpty=true;
 217 thilo.boehm 1.1 }
 218                 
 219 thilo.boehm 1.3 inline void SCMOClass::_initSCMOClass()
 220 thilo.boehm 1.1 {
 221                     PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE
 222                         - sizeof(SCMBClass_Main)>0);
 223                 
 224 thilo.boehm 1.3     cls.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);
 225                     if (cls.base == 0)
 226 thilo.boehm 1.1     {
 227 thilo.boehm 1.2         // Not enough memory!
 228 thilo.boehm 1.1         throw PEGASUS_STD(bad_alloc)();
 229                     }
 230                 
 231 thilo.boehm 1.3     memset(cls.base,0,sizeof(SCMBClass_Main));
 232                 
 233 thilo.boehm 1.1     // initalize eye catcher
 234                     cls.hdr->header.magic=PEGASUS_SCMB_CLASS_MAGIC;
 235                     cls.hdr->header.totalSize=SCMB_INITIAL_MEMORY_CHUNK_SIZE;
 236 thilo.boehm 1.2     // The # of bytes free
 237 thilo.boehm 1.1     cls.hdr->header.freeBytes=
 238                         SCMB_INITIAL_MEMORY_CHUNK_SIZE-sizeof(SCMBClass_Main);
 239                 
 240                     // Index to the start of the free space in this instance
 241                     cls.hdr->header.startOfFreeSpace=sizeof(SCMBClass_Main);
 242                 
 243                     cls.hdr->refCount=1;
 244                 
 245 thilo.boehm 1.3 }
 246                 
 247                 SCMOClass::SCMOClass(const char* className, const char* nameSpaceName )
 248                 {
 249                     Uint32 clsNameLen = strlen(className);
 250                     Uint32 nsNameLen = strlen(nameSpaceName);
 251                 
 252                     if (0 == className )
 253                     {
 254                         String message("SCMOClass: Class name not set (null pointer)!");
 255                         throw CIMException(CIM_ERR_FAILED,message );
 256                     }
 257                 
 258                     if (0 == nameSpaceName)
 259                     {
 260                         String message("SCMOClass: Name Space not set (null pointer)!");
 261                         throw CIMException(CIM_ERR_FAILED,message );
 262                     }
 263                 
 264                     _initSCMOClass();
 265                 
 266 thilo.boehm 1.3     _setBinary(className,clsNameLen+1,cls.hdr->className,&cls.mem );
 267                 
 268                     _setBinary(nameSpaceName,nsNameLen+1,cls.hdr->nameSpace,&cls.mem );
 269                 
 270                     cls.hdr->flags.isEmpty=true;
 271                 
 272                 }
 273                 
 274                 SCMOClass::SCMOClass(
 275                     const CIMClass& theCIMClass,
 276                     const char* nameSpaceName)
 277                 {
 278                 
 279                     _initSCMOClass();
 280                 
 281 thilo.boehm 1.1     try
 282                     {
 283                         _setString(theCIMClass.getSuperClassName().getString(),
 284                                    cls.hdr->superClassName,
 285                                    &cls.mem );
 286                     }
 287                     catch (UninitializedObjectException&)
 288                     {
 289                         // there is no Super ClassName
 290                         cls.hdr->superClassName.start=0;
 291 thilo.boehm 1.3         cls.hdr->superClassName.size=0;
 292 thilo.boehm 1.1     }
 293                 
 294                     CIMObjectPath theObjectPath=theCIMClass.getPath();
 295                 
 296                     //set name space
 297 thilo.boehm 1.3     if (nameSpaceName)
 298                     {
 299                         _setBinary(nameSpaceName,
 300                                    strlen(nameSpaceName)+1,
 301                                    cls.hdr->nameSpace,
 302                                    &cls.mem );
 303                     }
 304                     else
 305                     {
 306                         _setString(theObjectPath.getNameSpace().getString(),
 307                                   cls.hdr->nameSpace,
 308                                   &cls.mem );
 309                     }
 310 thilo.boehm 1.1 
 311                     //set class name
 312                     _setString(theObjectPath.getClassName().getString(),
 313                                cls.hdr->className,
 314                                &cls.mem );
 315                 
 316                     //set class Qualifiers
 317 thilo.boehm 1.3     _setClassQualifers(theCIMClass._rep->_qualifiers);
 318 thilo.boehm 1.1 
 319                     //set properties
 320 thilo.boehm 1.3     _setClassProperties(theCIMClass._rep->_properties);
 321                 
 322                 }
 323                 
 324                 void SCMOClass::_destroyExternalReferences()
 325                 {
 326                     _destroyExternalReferencesInternal(cls.mem);
 327                 }
 328                 
 329                 const char* SCMOClass::getSuperClassName() const
 330                 {
 331                     return _getCharString(cls.hdr->superClassName,cls.base);
 332                 }
 333                 
 334                 const char* SCMOClass::getSuperClassName_l(Uint32 & length) const
 335                 {
 336                     length = cls.hdr->superClassName.size;
 337                     if (0 == length)
 338                     {
 339                         return 0;
 340                     }
 341 thilo.boehm 1.3     else
 342                     {
 343                         length--;
 344                     }
 345                     return _getCharString(cls.hdr->superClassName,cls.base);
 346                 }
 347 thilo.boehm 1.1 
 348 thilo.boehm 1.3 void  SCMOClass::getCIMClass(CIMClass& cimClass) const
 349                 {
 350                     CIMClass newCimClass(
 351 marek       1.5         CIMNameCast(_newCimString(cls.hdr->className,cls.base)),
 352                         CIMNameCast(_newCimString(cls.hdr->superClassName,cls.base)));
 353 thilo.boehm 1.3 
 354                     // set the name space
 355                     newCimClass._rep->_reference._rep->_nameSpace=
 356 marek       1.5         CIMNamespaceNameCast(_newCimString(cls.hdr->nameSpace,cls.base));
 357 thilo.boehm 1.3 
 358                     // Add class qualifier if exist
 359                     if (0 != cls.hdr->numberOfQualifiers)
 360                     {
 361                         SCMBQualifier* qualiArray =
 362                             (SCMBQualifier*)&(cls.base[cls.hdr->qualifierArray.start]);
 363                 
 364                         CIMQualifier theCimQualifier;
 365                 
 366                         Uint32 i, k = cls.hdr->numberOfQualifiers;
 367                         for ( i = 0 ; i < k ; i++)
 368                         {
 369                             _getCIMQualifierFromSCMBQualifier(
 370                                 theCimQualifier,
 371                                 qualiArray[i],
 372                                 cls.base);
 373                 
 374                             newCimClass._rep->_qualifiers.addUnchecked(theCimQualifier);
 375                         }
 376                     }
 377                 
 378 thilo.boehm 1.3     // If properties are in that class
 379                     if (0 != cls.hdr->propertySet.number)
 380                     {
 381                         Uint32 i, k = cls.hdr->propertySet.number;
 382                         for ( i = 0 ; i < k ; i++)
 383                         {
 384                            newCimClass._rep->_properties.append(
 385                                _getCIMPropertyAtNodeIndex(i));
 386                         }
 387                     }
 388                 
 389                     cimClass = newCimClass;
 390                 }
 391                 
 392                 CIMProperty SCMOClass::_getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const
 393                 {
 394                     CIMValue theCimValue;
 395                     CIMProperty retCimProperty;
 396                 
 397                     SCMBClassPropertyNode& clsProp =
 398                         ((SCMBClassPropertyNode*)
 399 thilo.boehm 1.3          &(cls.base[cls.hdr->propertySet.nodeArray.start]))[nodeIdx];
 400                 
 401                     // get the default value
 402                     SCMOInstance::_getCIMValueFromSCMBValue(
 403                         theCimValue,
 404                         clsProp.theProperty.defaultValue,
 405                         cls.base);
 406                 
 407                     // have to check if there is the origin class name set.
 408                     // An empty origin class name is differnt then a NULL class name
 409                     if (0 != clsProp.theProperty.originClassName.start)
 410                     {
 411                         retCimProperty = CIMProperty(
 412 marek       1.5             CIMNameCast(_newCimString(clsProp.theProperty.name,cls.base)),
 413 thilo.boehm 1.3             theCimValue,
 414                             theCimValue.getArraySize(),
 415 marek       1.5             CIMNameCast(
 416                                 _newCimString(clsProp.theProperty.refClassName,cls.base)),
 417                             CIMNameCast(
 418                                 _newCimString(clsProp.theProperty.originClassName,cls.base)),
 419 thilo.boehm 1.3             clsProp.theProperty.flags.propagated);
 420                     }
 421                     else
 422                     {
 423                          retCimProperty = CIMProperty(
 424 marek       1.5             CIMNameCast(_newCimString(clsProp.theProperty.name,cls.base)),
 425 thilo.boehm 1.3             theCimValue,
 426                             theCimValue.getArraySize(),
 427 marek       1.5             CIMNameCast(
 428                                 _newCimString(clsProp.theProperty.refClassName,cls.base)),
 429 thilo.boehm 1.3             CIMName(),
 430                             clsProp.theProperty.flags.propagated);
 431                     }
 432                 
 433                     SCMBQualifier* qualiArray =
 434                         (SCMBQualifier*)
 435                              &(cls.base[clsProp.theProperty.qualifierArray.start]);
 436                 
 437                     CIMQualifier theCimQualifier;
 438                     Uint32 i, k = clsProp.theProperty.numberOfQualifiers;
 439                     for ( i = 0 ; i < k ; i++)
 440                     {
 441                         _getCIMQualifierFromSCMBQualifier(
 442                             theCimQualifier,
 443                             qualiArray[i],
 444                             cls.base);
 445                 
 446                         retCimProperty._rep->_qualifiers.addUnchecked(theCimQualifier);
 447                     }
 448                 
 449                     return retCimProperty;
 450 thilo.boehm 1.3 
 451                 }
 452                 
 453                 void SCMOClass::_getCIMQualifierFromSCMBQualifier(
 454                     CIMQualifier& theCimQualifier,
 455                     const SCMBQualifier& scmbQualifier,
 456                     const char* base)
 457                 
 458                 {
 459                 
 460                     CIMName theCimQualiName;
 461                     CIMValue theCimValue;
 462                 
 463                     SCMOInstance::_getCIMValueFromSCMBValue(
 464                         theCimValue,
 465                         scmbQualifier.value,
 466                         base);
 467                 
 468                     if (scmbQualifier.name == QUALNAME_USERDEFINED)
 469                     {
 470 marek       1.5         theCimQualiName = _newCimString(scmbQualifier.userDefName,base);
 471 thilo.boehm 1.3     }
 472                     else
 473                     {
 474                         theCimQualiName = String(
 475                             SCMOClass::qualifierNameStrLit(scmbQualifier.name).str,
 476                             SCMOClass::qualifierNameStrLit(scmbQualifier.name).size);
 477                     }
 478                 
 479                     theCimQualifier = CIMQualifier(
 480                         theCimQualiName,
 481                         theCimValue,
 482                         scmbQualifier.flavor,
 483                         scmbQualifier.propagated);
 484 thilo.boehm 1.1 }
 485                 
 486                 void SCMOClass::getKeyNamesAsString(Array<String>& keyNames) const
 487                 {
 488                     SCMBKeyBindingNode* nodeArray =
 489                     (SCMBKeyBindingNode*)&(cls.base[cls.hdr->keyBindingSet.nodeArray.start]);
 490                 
 491                     keyNames.clear();
 492                 
 493 thilo.boehm 1.3     for (Uint32 i = 0, k = cls.hdr->keyBindingSet.number; i < k; i++)
 494 thilo.boehm 1.1     {
 495 thilo.boehm 1.2         // Append the key property name.
 496 marek       1.5         keyNames.append(_newCimString(nodeArray[i].name,cls.base));
 497 thilo.boehm 1.3     }
 498                 }
 499 thilo.boehm 1.1 
 500 thilo.boehm 1.3 const char* SCMOClass::_getPropertyNameAtNode(Uint32 propNode) const
 501                 {
 502                     SCMBClassPropertyNode* nodeArray =
 503                         (SCMBClassPropertyNode*)
 504                             &(cls.base[cls.hdr->propertySet.nodeArray.start]);
 505                 
 506                     return(_getCharString(nodeArray[propNode].theProperty.name,cls.base));
 507 thilo.boehm 1.1 }
 508                 
 509                 SCMO_RC SCMOClass::_getKeyBindingNodeIndex(Uint32& node, const char* name) const
 510                 {
 511                 
 512                     Uint32 tag,len,hashIdx;
 513                 
 514                     len = strlen(name);
 515 thilo.boehm 1.3     tag = _generateStringTag((const char*)name, len);
 516 thilo.boehm 1.1     // get the node index of the hash table
 517 thilo.boehm 1.2     hashIdx =
 518 thilo.boehm 1.1         cls.hdr->keyBindingSet.hashTable[tag%PEGASUS_KEYBINDIG_SCMB_HASHSIZE];
 519                     // there is no entry in the hash table on this hash table index.
 520                     if (hashIdx == 0)
 521                     {
 522                         // property name not found
 523                         return SCMO_NOT_FOUND;
 524                     }
 525                 
 526                     // get the propterty node array
 527 thilo.boehm 1.2     SCMBKeyBindingNode* nodeArray =
 528 thilo.boehm 1.1         (SCMBKeyBindingNode*)
 529                             &(cls.base[cls.hdr->keyBindingSet.nodeArray.start]);
 530                 
 531 thilo.boehm 1.2     // set property node array index.
 532 thilo.boehm 1.1     // The hash table index to the node arra in one larger!
 533                     node = hashIdx - 1;
 534                 
 535                     do
 536                     {
 537                         // do they have the same hash tag ?
 538                         if (nodeArray[node].nameHashTag == tag)
 539                         {
 540                             // Now it is worth to compare the two names
 541 thilo.boehm 1.3             if (_equalNoCaseUTF8Strings(nodeArray[node].name,cls.base,name,len))
 542 thilo.boehm 1.1             {
 543                                 // we found the property !
 544                                 return SCMO_OK;
 545                             }
 546                         }
 547                         // Are we at the end of the chain ?
 548                         if (!nodeArray[node].hasNext)
 549                         {
 550                             // property name not found
 551                             return SCMO_NOT_FOUND;
 552                         }
 553                 
 554                         // get next node index.
 555                         node = nodeArray[node].nextNode;
 556                 
 557                     } while ( true );
 558                 
 559                     // this should never be reached
 560                     return SCMO_NOT_FOUND;
 561                 
 562                 }
 563 thilo.boehm 1.1 
 564                 SCMO_RC SCMOClass::_getProperyNodeIndex(Uint32& node, const char* name) const
 565                 {
 566                 
 567                     Uint32 tag,len,hashIdx;
 568                 
 569                     len = strlen(name);
 570 thilo.boehm 1.3     tag = _generateStringTag((const char*)name, len);
 571 thilo.boehm 1.1     // get the node index of the hash table
 572 thilo.boehm 1.2     hashIdx =
 573 thilo.boehm 1.1         cls.hdr->propertySet.hashTable[tag%PEGASUS_PROPERTY_SCMB_HASHSIZE];
 574                     // there is no entry in the hash table on this hash table index.
 575                     if (hashIdx == 0)
 576                     {
 577                         // property name not found
 578                         return SCMO_NOT_FOUND;
 579                     }
 580                 
 581                     // get the propterty node array
 582 thilo.boehm 1.2     SCMBClassPropertyNode* nodeArray =
 583 thilo.boehm 1.1         (SCMBClassPropertyNode*)
 584                             &(cls.base[cls.hdr->propertySet.nodeArray.start]);
 585                 
 586 thilo.boehm 1.2     // set property node array index.
 587 thilo.boehm 1.1     // The hash table index to the node arra in one larger!
 588                     node = hashIdx - 1;
 589                 
 590                     do
 591                     {
 592                         // do they have the same hash tag ?
 593                         if (nodeArray[node].theProperty.nameHashTag == tag)
 594                         {
 595                             // Now it is worth to compare the two names
 596 thilo.boehm 1.3             if (_equalNoCaseUTF8Strings(
 597 thilo.boehm 1.1                 nodeArray[node].theProperty.name,cls.base,name,len))
 598                             {
 599                                 // we found the property !
 600                                 return SCMO_OK;
 601                             }
 602                         }
 603                         // Are we at the end of the chain ?
 604                         if (!nodeArray[node].hasNext)
 605                         {
 606                             // property name not found
 607                             return SCMO_NOT_FOUND;
 608                         }
 609                 
 610                         // get next node index.
 611                         node = nodeArray[node].nextNode;
 612                 
 613                     } while ( true );
 614                 
 615 thilo.boehm 1.8     // this should never be reached
 616                     PEGASUS_UNREACHABLE(return SCMO_NOT_FOUND;)
 617 thilo.boehm 1.1 }
 618                 
 619 thilo.boehm 1.3 void SCMOClass::_setClassProperties(PropertySet& theCIMProperties)
 620 thilo.boehm 1.1 {
 621 thilo.boehm 1.3     Uint32 noProps = theCIMProperties.size();
 622 thilo.boehm 1.1     Uint64 start, startKeyIndexList;
 623                     Uint32 noKeys = 0;
 624                     Boolean isKey = false;
 625                 
 626 thilo.boehm 1.3     Array<Uint32> keyIndex(noProps);
 627 thilo.boehm 1.1 
 628                     cls.hdr->propertySet.number=noProps;
 629                 
 630                     // allocate the keyIndexList
 631                     startKeyIndexList = _getFreeSpace(
 632                         cls.hdr->keyIndexList,
 633                         noProps*sizeof(Uint32),
 634 thilo.boehm 1.3         &cls.mem);
 635 thilo.boehm 1.2 
 636 thilo.boehm 1.1     if(noProps != 0)
 637                     {
 638 thilo.boehm 1.2         // Allocate key property mask.
 639                         // Each property needs a bit in the mask.
 640 thilo.boehm 1.1         // The number of Uint64 in the key mask is :
 641 thilo.boehm 1.2         // Decrease the number of properties by 1 since
 642 thilo.boehm 1.1         // the array is starting at 0!
 643                         // Divided with the number of bits in a Uint64.
 644                         // e.g. number of Properties = 68
 645 thilo.boehm 1.2         // (68 - 1) / 64 = 1 --> The mask consists of two Uint64 values.
 646 thilo.boehm 1.1         _getFreeSpace(cls.hdr->keyPropertyMask,
 647                               sizeof(Uint64)*(((noProps-1)/64)+1),
 648                               &cls.mem);
 649                 
 650                         // allocate property array and save the start index of the array.
 651                         start = _getFreeSpace(cls.hdr->propertySet.nodeArray,
 652                                       sizeof(SCMBClassPropertyNode)*noProps,
 653 thilo.boehm 1.2                       &cls.mem);
 654 thilo.boehm 1.1 
 655                         // clear the hash table
 656                         memset(cls.hdr->propertySet.hashTable,
 657                                0,
 658                                PEGASUS_PROPERTY_SCMB_HASHSIZE*sizeof(Uint32));
 659                 
 660                 
 661                         for (Uint32 i = 0; i < noProps; i++)
 662                         {
 663                 
 664 thilo.boehm 1.3             _setProperty(start,&isKey ,theCIMProperties[i]);
 665 thilo.boehm 1.1             if(isKey)
 666                             {
 667 thilo.boehm 1.2                 // if the property is a key
 668 thilo.boehm 1.1                 // save the key index
 669                                 keyIndex[noKeys]=i;
 670                                 noKeys++;
 671                                 _setPropertyAsKeyInMask(i);
 672                             }
 673                             // Adjust ordered set management structures.
 674                             _insertPropertyIntoOrderedSet(start,i);
 675                 
 676                             start = start + sizeof(SCMBClassPropertyNode);
 677                         }
 678                 
 679                         cls.hdr->keyBindingSet.number = noKeys;
 680                 
 681                         if (noKeys != 0)
 682                         {
 683                             // allocate key binding array and save the start index of the array.
 684                             start = _getFreeSpace(cls.hdr->keyBindingSet.nodeArray,
 685                                           sizeof(SCMBKeyBindingNode)*noKeys,
 686 thilo.boehm 1.2                           &cls.mem);
 687 thilo.boehm 1.1 
 688                             // clear the hash table
 689                             memset(cls.hdr->keyBindingSet.hashTable,
 690                                    0,
 691                                    PEGASUS_KEYBINDIG_SCMB_HASHSIZE*sizeof(Uint32));
 692                 
 693                             // fill the key index list
 694                             memcpy(
 695                                 &(cls.base[startKeyIndexList]),
 696 thilo.boehm 1.3                 keyIndex.getData(),
 697 thilo.boehm 1.1                 noKeys*sizeof(Uint32));
 698                 
 699                             for (Uint32 i = 0 ; i < noKeys; i++)
 700                             {
 701                 
 702 thilo.boehm 1.3                 _setClassKeyBinding(start,theCIMProperties[keyIndex[i]]);
 703 thilo.boehm 1.1                 // Adjust ordered set management structures.
 704                                 _insertKeyBindingIntoOrderedSet(start,i);
 705                 
 706                                 start = start + sizeof(SCMBKeyBindingNode);
 707                             }
 708                 
 709                         }
 710                         else
 711                         {
 712                             cls.hdr->keyBindingSet.nodeArray.start=0;
 713 thilo.boehm 1.3             cls.hdr->keyBindingSet.nodeArray.size=0;
 714 thilo.boehm 1.1         }
 715                     }
 716                     else
 717                     {
 718                         cls.hdr->propertySet.nodeArray.start=0;
 719 thilo.boehm 1.3         cls.hdr->propertySet.nodeArray.size=0;
 720 thilo.boehm 1.1         cls.hdr->keyPropertyMask.start=0;
 721 thilo.boehm 1.3         cls.hdr->keyPropertyMask.size=0;
 722 thilo.boehm 1.1         cls.hdr->keyBindingSet.nodeArray.start=0;
 723 thilo.boehm 1.3         cls.hdr->keyBindingSet.nodeArray.size=0;
 724 thilo.boehm 1.1     }
 725                 }
 726                 
 727                 void SCMOClass::_insertKeyBindingIntoOrderedSet(Uint64 start, Uint32 newIndex)
 728                 {
 729                 
 730 thilo.boehm 1.2     SCMBKeyBindingNode* newKeyNode =
 731 thilo.boehm 1.1         (SCMBKeyBindingNode*)&(cls.base[start]);
 732                 
 733                     SCMBKeyBindingNode* scmoKeyNodeArray =
 734                         (SCMBKeyBindingNode*)
 735                             &(cls.base[cls.hdr->keyBindingSet.nodeArray.start]);
 736                 
 737                     Uint32 *hashTable = cls.hdr->keyBindingSet.hashTable;
 738                 
 739                     // calculate the new hash index of the new property.
 740                     Uint32 hash = newKeyNode->nameHashTag % PEGASUS_KEYBINDIG_SCMB_HASHSIZE;
 741                 
 742                     // 0 is an invalid index in the hash table
 743                     if (hashTable[hash] == 0)
 744                     {
 745                         hashTable[hash] = newIndex + 1;
 746                         return;
 747                     }
 748                 
 749                     // get the first node of the hash chain.
 750                     Uint32 nodeIndex = hashTable[hash]-1;
 751                 
 752 thilo.boehm 1.1     do
 753                     {
 754                         // is this the same note ?
 755                         if (nodeIndex == newIndex)
 756                         {
 757                             // The node is already in the ordered set
 758                             return;
 759                         }
 760                 
 761                         // Are we at the end of the chain ?
 762                         if (!scmoKeyNodeArray[nodeIndex].hasNext)
 763                         {
 764                             // link the new element at the end of the chain
 765                             scmoKeyNodeArray[nodeIndex].nextNode = newIndex;
 766                             scmoKeyNodeArray[nodeIndex].hasNext = true;
 767                             return;
 768                         }
 769                 
 770                         nodeIndex = scmoKeyNodeArray[nodeIndex].nextNode;
 771                 
 772                     } while ( true );
 773 thilo.boehm 1.1 
 774                     // this should never be reached
 775                 }
 776                 
 777                 void SCMOClass::_insertPropertyIntoOrderedSet(Uint64 start, Uint32 newIndex)
 778                 {
 779                 
 780                 
 781 thilo.boehm 1.2     SCMBClassPropertyNode* newPropNode =
 782 thilo.boehm 1.1         (SCMBClassPropertyNode*)&(cls.base[start]);
 783                 
 784                     SCMBClassPropertyNode* scmoPropNodeArray =
 785                         (SCMBClassPropertyNode*)
 786                              &(cls.base[cls.hdr->propertySet.nodeArray.start]);
 787                 
 788                     Uint32 *hashTable = cls.hdr->propertySet.hashTable;
 789                 
 790                     // calcuate the new hash index of the new property.
 791 thilo.boehm 1.2     Uint32 hash = newPropNode->theProperty.nameHashTag %
 792 thilo.boehm 1.1         PEGASUS_PROPERTY_SCMB_HASHSIZE;
 793                 
 794                     // 0 is an invalid index in the hash table
 795                     if (hashTable[hash] == 0)
 796                     {
 797                         hashTable[hash] = newIndex + 1;
 798                         return;
 799                     }
 800                 
 801                     // get the first node of the hash chain.
 802                     Uint32 nodeIndex = hashTable[hash]-1;
 803                 
 804                     do
 805                     {
 806                         // is this the same note ?
 807                         if (nodeIndex == newIndex)
 808                         {
 809                             // The node is already in the ordered set
 810                             return;
 811                         }
 812                 
 813 thilo.boehm 1.1         // Are we at the end of the chain ?
 814                         if (!scmoPropNodeArray[nodeIndex].hasNext)
 815                         {
 816                             // link the new element at the end of the chain
 817                             scmoPropNodeArray[nodeIndex].nextNode = newIndex;
 818                             scmoPropNodeArray[nodeIndex].hasNext = true;
 819                             return;
 820                         }
 821                 
 822                         // get next node index.
 823                         nodeIndex = scmoPropNodeArray[nodeIndex].nextNode;
 824                 
 825                     } while ( true );
 826                 
 827                     // this should never be reached
 828                 }
 829                 
 830                 void SCMOClass::_setClassKeyBinding(
 831 thilo.boehm 1.2     Uint64 start,
 832 thilo.boehm 1.1     const CIMProperty& theCIMProperty)
 833                 {
 834                     CIMPropertyRep* propRep = theCIMProperty._rep;
 835                 
 836                     // First do all _setString(). Can cause reallocation.
 837                     _setString(propRep->_name.getString(),
 838                         ((SCMBKeyBindingNode*)&(cls.base[start]))->name,
 839                         &cls.mem);
 840 thilo.boehm 1.2 
 841                     SCMBKeyBindingNode* scmoKeyBindNode =
 842 thilo.boehm 1.1         (SCMBKeyBindingNode*)&(cls.base[start]);
 843                 
 844                     // calculate the new hash tag
 845 thilo.boehm 1.2     scmoKeyBindNode->nameHashTag =
 846 thilo.boehm 1.1         _generateSCMOStringTag(scmoKeyBindNode->name,cls.base);
 847 thilo.boehm 1.3     scmoKeyBindNode->type = propRep->_value.getType();
 848 thilo.boehm 1.1     scmoKeyBindNode->hasNext=false;
 849                     scmoKeyBindNode->nextNode=0;
 850                 
 851                 }
 852                 
 853                 void SCMOClass::_setPropertyAsKeyInMask(Uint32 i)
 854                 {
 855                     Uint64 *keyMask;
 856                 
 857                     // In which Uint64 of key mask is the bit for property i ?
 858                     // Divide with the number of bits in a Uint64.
 859                     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].
 860                     Uint32 idx = i/64 ;
 861                 
 862                     // Create a filter to set the bit.
 863                     // Modulo division with 64. Shift left a bit by the remainder.
 864 thilo.boehm 1.2     Uint64 filter = ( (Uint64)1 << (i%64));
 865                 
 866 thilo.boehm 1.1     // Calculate the real pointer to the Uint64 array
 867 thilo.boehm 1.3     keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);
 868 thilo.boehm 1.1 
 869                     keyMask[idx] = keyMask[idx] | filter ;
 870                 }
 871                 
 872                 Boolean SCMOClass::_isPropertyKey(Uint32 i)
 873                 {
 874                     Uint64 *keyMask;
 875                 
 876                     // In which Uint64 of key mask is the bit for property i ?
 877                     // Divide with the number of bits in a Uint64.
 878                     // e.g. number of Properties = 68
 879                     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].
 880                     Uint32 idx = i/64 ;
 881                 
 882                     // Create a filter to check if the bit is set:
 883                     // Modulo division with 64. Shift left a bit by the remainder.
 884 thilo.boehm 1.2     Uint64 filter = ( (Uint64)1 << (i%64));
 885 thilo.boehm 1.1 
 886                     // Calculate the real pointer to the Uint64 array
 887 thilo.boehm 1.3     keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);
 888 thilo.boehm 1.1 
 889                     return keyMask[idx] & filter ;
 890                 
 891                 }
 892                 
 893                 
 894                 void SCMOClass::_setProperty(
 895 thilo.boehm 1.2     Uint64 start,
 896 thilo.boehm 1.1     Boolean* isKey,
 897                     const CIMProperty& theCIMProperty)
 898                 {
 899                 
 900                    *isKey = false;
 901                 
 902                     CIMPropertyRep* propRep = theCIMProperty._rep;
 903                 
 904                     // First do all _setString(). Can cause reallocation.
 905                 
 906                     _setString(propRep->_name.getString(),
 907                         ((SCMBClassPropertyNode*)&(cls.base[start]))->theProperty.name,
 908                         &cls.mem);
 909                 
 910                     _setString(propRep->_classOrigin.getString(),
 911                         ((SCMBClassPropertyNode*)
 912                              &(cls.base[start]))->theProperty.originClassName,
 913                         &cls.mem);
 914                 
 915                     _setString(propRep->_referenceClassName.getString(),
 916                         ((SCMBClassPropertyNode*)&(cls.base[start]))->theProperty.refClassName,
 917 thilo.boehm 1.1         &cls.mem);
 918                 
 919                 
 920 thilo.boehm 1.2     SCMBClassPropertyNode* scmoPropNode =
 921 thilo.boehm 1.1         (SCMBClassPropertyNode*)&(cls.base[start]);
 922                 
 923                     // generate new hash tag
 924 thilo.boehm 1.2     scmoPropNode->theProperty.nameHashTag =
 925 thilo.boehm 1.1         _generateSCMOStringTag(scmoPropNode->theProperty.name,cls.base);
 926                 
 927                     scmoPropNode->theProperty.flags.propagated = propRep->_propagated;
 928                 
 929                     // just for complete intialization.
 930                     scmoPropNode->hasNext=false;
 931                     scmoPropNode->nextNode=0;
 932                 
 933                     // calculate the relative pointer for the default value
 934 thilo.boehm 1.2     Uint64 valueStart =
 935 thilo.boehm 1.3         (char*)&scmoPropNode->theProperty.defaultValue - cls.base;
 936 thilo.boehm 1.1 
 937                     _setValue(valueStart,propRep->_value);
 938                 
 939                     *isKey = _setPropertyQualifiers(start,propRep->_qualifiers);
 940 thilo.boehm 1.2     // reset property node pointer
 941 thilo.boehm 1.1     scmoPropNode = (SCMBClassPropertyNode*)&(cls.base[start]);
 942                     scmoPropNode->theProperty.flags.isKey=*isKey;
 943                 }
 944                 
 945                 Boolean SCMOClass::_setPropertyQualifiers(
 946 thilo.boehm 1.2     Uint64 start,
 947 thilo.boehm 1.1     const CIMQualifierList& theQualifierList)
 948                 {
 949                     Uint32 noQuali = theQualifierList.getCount();
 950                     Uint64 startArray;
 951                     QualifierNameEnum propName;
 952                     Boolean isKey = false;
 953                 
 954 thilo.boehm 1.2     SCMBClassPropertyNode* scmoPropNode =
 955 thilo.boehm 1.1         (SCMBClassPropertyNode*)&(cls.base[start]);
 956                 
 957                     scmoPropNode->theProperty.numberOfQualifiers = noQuali;
 958                 
 959                 
 960                     if (noQuali != 0)
 961                     {
 962                         // allocate qualifier array and save the start of the array.
 963                         startArray = _getFreeSpace(scmoPropNode->theProperty.qualifierArray,
 964                                          sizeof(SCMBQualifier)*noQuali,
 965 thilo.boehm 1.2                          &cls.mem);
 966 thilo.boehm 1.1         for (Uint32 i = 0; i < noQuali; i++)
 967                         {
 968                             propName = _setQualifier(
 969                                 startArray,
 970                                 theQualifierList.getQualifier(i));
 971                             // Only set once if the property is identified as key.
 972                             if(!isKey)
 973                             {
 974                                 isKey = propName==QUALNAME_KEY;
 975                             }
 976 thilo.boehm 1.2 
 977 thilo.boehm 1.1             startArray = startArray + sizeof(SCMBQualifier);
 978                         }
 979                     }
 980                     else
 981                     {
 982                         scmoPropNode->theProperty.qualifierArray.start=0;
 983 thilo.boehm 1.3         scmoPropNode->theProperty.qualifierArray.size=0;
 984 thilo.boehm 1.1     }
 985                 
 986                     return isKey;
 987                 }
 988 thilo.boehm 1.3 
 989                 void SCMOClass::_setClassQualifers(const CIMQualifierList& theQualifierList)
 990 thilo.boehm 1.1 {
 991                 
 992 thilo.boehm 1.3     Uint32 noQuali = theQualifierList.getCount();
 993 thilo.boehm 1.1     Uint64 start;
 994                 
 995                     cls.hdr->numberOfQualifiers = noQuali;
 996                 
 997                     if (noQuali != 0)
 998                     {
 999                         // allocate qualifier array and save the start of the array.
1000                         start = _getFreeSpace(cls.hdr->qualifierArray,
1001                                       sizeof(SCMBQualifier)*noQuali,
1002 thilo.boehm 1.2                       &cls.mem);
1003 thilo.boehm 1.1         for (Uint32 i = 0; i < noQuali; i++)
1004                         {
1005 thilo.boehm 1.3             _setQualifier(start,theQualifierList.getQualifier(i));
1006 thilo.boehm 1.1             start = start + sizeof(SCMBQualifier);
1007                 
1008                         }
1009                 
1010                     }
1011                     else
1012                     {
1013                         cls.hdr->qualifierArray.start=0;
1014 thilo.boehm 1.3         cls.hdr->qualifierArray.size=0;
1015 thilo.boehm 1.1     }
1016                 }
1017                 
1018                 QualifierNameEnum SCMOClass::_setQualifier(
1019 thilo.boehm 1.2     Uint64 start,
1020 thilo.boehm 1.1     const CIMQualifier& theCIMQualifier)
1021                 {
1022                     Uint64 valueStart;
1023                     QualifierNameEnum name;
1024                 
1025                     SCMBQualifier* scmoQual = (SCMBQualifier*)&(cls.base[start]);
1026                     name=_getSCMOQualifierNameEnum(theCIMQualifier.getName());
1027                 
1028                     scmoQual->propagated = theCIMQualifier.getPropagated();
1029                     scmoQual->name = name;
1030                     scmoQual->flavor = theCIMQualifier.getFlavor().cimFlavor;
1031                 
1032 thilo.boehm 1.3     valueStart = (char*)&scmoQual->value - cls.base;
1033 thilo.boehm 1.1 
1034                     _setValue(valueStart,theCIMQualifier.getValue());
1035                 
1036                     // reset the pointer, because the base pointer could be reallocated.
1037                     scmoQual = (SCMBQualifier*)&(cls.base[start]);
1038                     if (name == QUALNAME_USERDEFINED)
1039                     {
1040                         _setString(theCIMQualifier.getName().getString(),
1041                                    scmoQual->userDefName,&cls.mem);
1042                     }
1043                 
1044                     return name;
1045                 }
1046                 
1047 thilo.boehm 1.3 void SCMOClass::_setValue(
1048                     Uint64 start,
1049                     const CIMValue& theCIMValue)
1050 thilo.boehm 1.1 {
1051                     Uint64 valueStart;
1052                 
1053                     CIMValueRep* rep = *((CIMValueRep**)&theCIMValue);
1054                 
1055                     SCMBValue* scmoValue = (SCMBValue*)&(cls.base[start]);
1056                     scmoValue->valueType = rep->type;
1057                     scmoValue->valueArraySize = 0;
1058                     scmoValue->flags.isNull = rep->isNull;
1059                     scmoValue->flags.isArray = rep->isArray;
1060                     scmoValue->flags.isSet = false;
1061                 
1062                     if (rep->isNull)
1063                     {
1064                         return;
1065                     }
1066                 
1067 thilo.boehm 1.3     valueStart = (char*)&scmoValue->value - cls.base;
1068                 
1069 thilo.boehm 1.1     if (scmoValue->flags.isArray)
1070                     {
1071 thilo.boehm 1.3         SCMOInstance::_setUnionArrayValue(
1072                             valueStart,
1073                             &cls.mem,
1074                             rep->type,
1075                             // Is set to the number of array members by the function.
1076                             scmoValue->valueArraySize,
1077                             cls.hdr->nameSpace.start,
1078                             cls.hdr->nameSpace.size,
1079                             rep->u);
1080 thilo.boehm 1.1     }
1081                     else
1082 thilo.boehm 1.2     {
1083 thilo.boehm 1.3         SCMOInstance::_setUnionValue(
1084                             valueStart,
1085                             &cls.mem,
1086                             rep->type,
1087                             cls.hdr->nameSpace.start,
1088                             cls.hdr->nameSpace.size,
1089                             rep->u);
1090 thilo.boehm 1.1     }
1091                 }
1092                 
1093 thilo.boehm 1.3 QualifierNameEnum SCMOClass::_getSCMOQualifierNameEnum(
1094                     const CIMName& theCIMName)
1095 thilo.boehm 1.1 {
1096 thilo.boehm 1.3     // Get the UTF8 CString
1097                     CString theCString=theCIMName.getString().getCString();
1098                     // Get the real size of the UTF8 sting.
1099                     Uint32 length = strlen((const char*)theCString);
1100                 
1101 thilo.boehm 1.1 
1102 thilo.boehm 1.3     // The start index is 1, because the at index 0 is a place holder for
1103                     // the user defined qualifier name which is not part of the qualifier name
1104                     // list.
1105                     for (Uint32 i = 1; i < _NUM_QUALIFIER_NAMES; i++)
1106 thilo.boehm 1.1     {
1107 thilo.boehm 1.3         if (qualifierNameStrLit(i).size == length)
1108 thilo.boehm 1.1         {
1109 thilo.boehm 1.3             // TBD: Make it more efficent...
1110                             if(String::equalNoCase(
1111                                 theCIMName.getString(),
1112                                 qualifierNameStrLit(i).str))
1113                             {
1114                                 return (QualifierNameEnum)i;
1115                             }
1116 thilo.boehm 1.1         }
1117 thilo.boehm 1.3     }
1118 thilo.boehm 1.1 
1119 thilo.boehm 1.3     return QUALNAME_USERDEFINED;
1120                 }
1121 thilo.boehm 1.1 
1122 thilo.boehm 1.3 Boolean SCMOClass::_isSamePropOrigin(Uint32 node, const char* origin) const
1123                 {
1124                    Uint32 len = strlen(origin);
1125 thilo.boehm 1.1 
1126 thilo.boehm 1.3    SCMBClassPropertyNode* nodeArray =
1127                        (SCMBClassPropertyNode*)
1128                            &(cls.base[cls.hdr->propertySet.nodeArray.start]);
1129 thilo.boehm 1.1 
1130 thilo.boehm 1.3    return(_equalNoCaseUTF8Strings(
1131                        nodeArray[node].theProperty.originClassName,
1132                        cls.base,
1133                        origin,
1134                        len));
1135                 }
1136 thilo.boehm 1.1 
1137 thilo.boehm 1.3 SCMO_RC SCMOClass::_isNodeSameType(
1138                     Uint32 node,
1139                     CIMType type,
1140                     Boolean isArray,
1141                     CIMType& realType) const
1142                 {
1143 thilo.boehm 1.1 
1144 thilo.boehm 1.3     SCMBClassPropertyNode* nodeArray =
1145                         (SCMBClassPropertyNode*)
1146                             &(cls.base[cls.hdr->propertySet.nodeArray.start]);
1147 thilo.boehm 1.1 
1148 thilo.boehm 1.3     // The type stored in the class information is set on realType.
1149                     // It must be used in further calls to guaranty consistence.
1150                     realType = nodeArray[node].theProperty.defaultValue.valueType;
1151                 
1152                     if(nodeArray[node].theProperty.defaultValue.valueType != type)
1153                     {
1154                         // Accept an property of type instance also
1155                         // for an CIMTYPE_OBJECT property.
1156                         if (!(type == CIMTYPE_INSTANCE &&
1157                               nodeArray[node].theProperty.defaultValue.valueType
1158                               == CIMTYPE_OBJECT))
1159 thilo.boehm 1.1         {
1160 thilo.boehm 1.3             return SCMO_WRONG_TYPE;
1161 thilo.boehm 1.1         }
1162 thilo.boehm 1.3     }
1163 thilo.boehm 1.1 
1164 thilo.boehm 1.3     if (isArray)
1165                     {
1166                         if (nodeArray[node].theProperty.defaultValue.flags.isArray)
1167 thilo.boehm 1.1         {
1168 thilo.boehm 1.3             return SCMO_OK;
1169 thilo.boehm 1.1         }
1170 thilo.boehm 1.3         else
1171 thilo.boehm 1.1         {
1172 thilo.boehm 1.3             return SCMO_NOT_AN_ARRAY;
1173 thilo.boehm 1.1         }
1174                 
1175 thilo.boehm 1.3     }
1176 thilo.boehm 1.1 
1177 thilo.boehm 1.3     if (nodeArray[node].theProperty.defaultValue.flags.isArray)
1178                     {
1179                         return SCMO_IS_AN_ARRAY;
1180                     }
1181 thilo.boehm 1.1 
1182 thilo.boehm 1.3     return SCMO_OK;
1183                 
1184                 }
1185 thilo.boehm 1.1 
1186 thilo.boehm 1.3 /*****************************************************************************
1187                  * The SCMOInstance methods
1188                  *****************************************************************************/
1189 thilo.boehm 1.1 
1190 thilo.boehm 1.3 SCMOInstance::SCMOInstance()
1191                 {
1192                     inst.base = 0;
1193                 }
1194 thilo.boehm 1.1 
1195 thilo.boehm 1.3 SCMOInstance::SCMOInstance(SCMOClass& baseClass)
1196                 {
1197                     _initSCMOInstance(new SCMOClass(baseClass));
1198                 }
1199 thilo.boehm 1.1 
1200 thilo.boehm 1.3 SCMOInstance::SCMOInstance(
1201                     SCMOClass& baseClass,
1202                     Boolean includeQualifiers,
1203                     Boolean includeClassOrigin,
1204                     const char** propertyList)
1205                 {
1206 thilo.boehm 1.2 
1207 thilo.boehm 1.3     _initSCMOInstance(new SCMOClass(baseClass));
1208 thilo.boehm 1.1 
1209 thilo.boehm 1.3     inst.hdr->flags.includeQualifiers=includeQualifiers;
1210                     inst.hdr->flags.includeClassOrigin=includeClassOrigin;
1211 thilo.boehm 1.1 
1212 thilo.boehm 1.3     setPropertyFilter(propertyList);
1213 thilo.boehm 1.1 
1214 thilo.boehm 1.3 }
1215 thilo.boehm 1.1 
1216 thilo.boehm 1.3 SCMOInstance::SCMOInstance(SCMOClass& baseClass, const CIMObjectPath& cimObj)
1217                 {
1218                     _initSCMOInstance(new SCMOClass(baseClass));
1219 thilo.boehm 1.1 
1220 thilo.boehm 1.3     _setCIMObjectPath(cimObj);
1221                 }
1222 thilo.boehm 1.1 
1223 thilo.boehm 1.3 SCMOInstance::SCMOInstance(SCMOClass& baseClass, const CIMInstance& cimInstance)
1224                 {
1225 thilo.boehm 1.1 
1226 thilo.boehm 1.3     _initSCMOInstance(new SCMOClass(baseClass));
1227 thilo.boehm 1.1 
1228 thilo.boehm 1.3     _setCIMInstance(cimInstance);
1229 thilo.boehm 1.1 
1230                 }
1231                 
1232 thilo.boehm 1.3 SCMOInstance::SCMOInstance(CIMClass& theCIMClass, const char* altNameSpace)
1233                 {
1234                     _initSCMOInstance(new SCMOClass(theCIMClass,altNameSpace));
1235                 
1236                 }
1237 thilo.boehm 1.1 
1238 thilo.boehm 1.3 SCMOInstance::SCMOInstance(
1239                     const CIMInstance& cimInstance,
1240                     const char* altNameSpace,
1241                     Uint32 altNSLen)
1242 thilo.boehm 1.1 {
1243 thilo.boehm 1.3     SCMOClass theSCMOClass = _getSCMOClass(
1244                         cimInstance._rep->_reference,
1245                         altNameSpace,
1246                         altNSLen);
1247 thilo.boehm 1.1 
1248 thilo.boehm 1.3     _initSCMOInstance( new SCMOClass(theSCMOClass));
1249                 
1250                     if(theSCMOClass.isEmpty())
1251                     {
1252                         // flag the instance as compromized
1253                         inst.hdr->flags.isCompromised=true;
1254                     }
1255                     else
1256 thilo.boehm 1.1     {
1257 thilo.boehm 1.3         _setCIMInstance(cimInstance);
1258                     }
1259                 }
1260 thilo.boehm 1.1 
1261 thilo.boehm 1.3 SCMOInstance::SCMOInstance(
1262                     const CIMObject& cimObject,
1263                     const char* altNameSpace,
1264                     Uint32 altNSLen)
1265                 {
1266                     if (cimObject.isClass())
1267                     {
1268                         CIMClass cimClass(cimObject);
1269 thilo.boehm 1.1 
1270 thilo.boehm 1.3         _initSCMOInstance(new SCMOClass(cimClass,altNameSpace));
1271 thilo.boehm 1.1 
1272 thilo.boehm 1.3         inst.hdr->flags.isClassOnly=true;
1273                     }
1274                     else
1275                     {
1276                         CIMInstance cimInstance(cimObject);
1277 thilo.boehm 1.1 
1278 thilo.boehm 1.3         SCMOClass theSCMOClass = _getSCMOClass(
1279                             cimInstance._rep->_reference,
1280                             altNameSpace,
1281                             altNSLen);
1282 thilo.boehm 1.1 
1283 thilo.boehm 1.3         _initSCMOInstance( new SCMOClass(theSCMOClass));
1284 thilo.boehm 1.1 
1285 thilo.boehm 1.3         if(theSCMOClass.isEmpty())
1286 thilo.boehm 1.1         {
1287 thilo.boehm 1.3             // flag the instance as compromized
1288                             inst.hdr->flags.isCompromised=true;
1289 thilo.boehm 1.1         }
1290 thilo.boehm 1.3         else
1291 thilo.boehm 1.1         {
1292 thilo.boehm 1.3             _setCIMInstance(cimInstance);
1293 thilo.boehm 1.1         }
1294 thilo.boehm 1.3     }
1295                 }
1296 thilo.boehm 1.1 
1297 thilo.boehm 1.3 SCMOInstance::SCMOInstance(
1298                     const CIMObjectPath& cimObj,
1299                     const char* altNameSpace,
1300                     Uint32 altNSLen)
1301                 {
1302                     SCMOClass theSCMOClass = _getSCMOClass(
1303                         cimObj,
1304                         altNameSpace,
1305                         altNSLen);
1306 thilo.boehm 1.1 
1307 thilo.boehm 1.3     _initSCMOInstance( new SCMOClass(theSCMOClass));
1308 thilo.boehm 1.1 
1309 thilo.boehm 1.3     if(theSCMOClass.isEmpty())
1310                     {
1311                         // flag the instance as compromized
1312                         inst.hdr->flags.isCompromised=true;
1313                     }
1314                     else
1315                     {
1316                         _setCIMObjectPath(cimObj);
1317                     }
1318                 }
1319 thilo.boehm 1.1 
1320 thilo.boehm 1.3 void SCMOInstance::_destroyExternalReferences()
1321                 {
1322                     _destroyExternalReferencesInternal(inst.mem);
1323                 }
1324 thilo.boehm 1.1 
1325 thilo.boehm 1.3 SCMOClass SCMOInstance::_getSCMOClass(
1326                     const CIMObjectPath& theCIMObj,
1327                     const char* altNS,
1328                     Uint32 altNSlength)
1329                 {
1330                     SCMOClass theClass;
1331 thilo.boehm 1.1 
1332 thilo.boehm 1.3     if (theCIMObj.getClassName().isNull())
1333                     {
1334                         return SCMOClass();
1335                     }
1336 thilo.boehm 1.1 
1337 thilo.boehm 1.3     if (theCIMObj.getNameSpace().isNull())
1338                     {
1339                         // the name space of the object path is empty,
1340                         // use alternative name space.
1341                         CString clsName = theCIMObj.getClassName().getString().getCString();
1342 thilo.boehm 1.2 
1343 thilo.boehm 1.3         SCMOClassCache* theCache = SCMOClassCache::getInstance();
1344                         theClass = theCache->getSCMOClass(
1345                             altNS,
1346                             altNSlength,
1347                             (const char*)clsName,
1348                             strlen(clsName));
1349                     }
1350                     else
1351                     {
1352                         CString nameSpace = theCIMObj.getNameSpace().getString().getCString();
1353                         CString clsName = theCIMObj.getClassName().getString().getCString();
1354 thilo.boehm 1.2 
1355 thilo.boehm 1.3         SCMOClassCache* theCache = SCMOClassCache::getInstance();
1356                         theClass = theCache->getSCMOClass(
1357                             (const char*)nameSpace,
1358                             strlen(nameSpace),
1359                             (const char*)clsName,
1360                             strlen(clsName));
1361 thilo.boehm 1.1     }
1362                 
1363 thilo.boehm 1.3     return theClass;
1364 thilo.boehm 1.1 }
1365                 
1366 thilo.boehm 1.3 #define PEGASUS_SIZE_REFERENCE_INDEX_ARRAY 8
1367                 
1368                 void SCMOInstance::_setExtRefIndex(SCMBUnion* pInst, SCMBMgmt_Header** pmem)
1369 thilo.boehm 1.1 {
1370                 
1371 thilo.boehm 1.3     Uint64 refPtr =(((char *)pInst) - (char *)(*pmem));
1372                     SCMBMgmt_Header* memHdr = (*pmem);
1373                     // Save the number of external references in the array
1374                     Uint32 noExtRef = memHdr->numberExtRef;
1375 thilo.boehm 1.1 
1376 thilo.boehm 1.3     // Allocate the external reflerence array
1377                     // if it is full or empty ( 0 == 0 ).
1378                     if (noExtRef == memHdr->sizeExtRefIndexArray)
1379 thilo.boehm 1.1     {
1380 thilo.boehm 1.3         Uint64 oldArrayStart = memHdr->extRefIndexArray.start;
1381                         Uint32 newSize =
1382                             memHdr->sizeExtRefIndexArray + PEGASUS_SIZE_REFERENCE_INDEX_ARRAY;
1383                 
1384                         // Allocate the external reference index array
1385                         _getFreeSpace(
1386                               memHdr->extRefIndexArray,
1387                               sizeof(Uint64)*newSize,
1388                               pmem);
1389                 
1390                         // reset the pointer. It could be changed due to reallocation !
1391                         memHdr = (*pmem);
1392                 
1393                         // Assign new size.
1394                         memHdr->sizeExtRefIndexArray=newSize;
1395                 
1396                         // Get absolute pointer to old index array.
1397                         Uint64* oldArray = (Uint64*)&(((char*)(*pmem))[oldArrayStart]);
1398                         // Get absolute pointer to new index array
1399                         Uint64* newArray =
1400                             (Uint64*)&(((char*)(*pmem))[memHdr->extRefIndexArray.start]);
1401 thilo.boehm 1.3 
1402                         // Copy all elements of the old array to the new.
1403                         // If noExtRef = 0, no elements are copied.
1404                         for (Uint32 i = 0 ; i < noExtRef ; i++)
1405 thilo.boehm 1.1         {
1406 thilo.boehm 1.3             newArray[i] = oldArray[i];
1407 thilo.boehm 1.1         }
1408                     }
1409                 
1410 thilo.boehm 1.3     // Get absolute pointer to the array
1411                     Uint64* array =
1412                         (Uint64*)&(((char*)(*pmem))[memHdr->extRefIndexArray.start]);
1413                     // look in the table if the index is already in the array
1414                     for (Uint32 i = 0 ; i < noExtRef ; i++)
1415                     {
1416                         // is the index already part of the array
1417                         if (array[i] == refPtr)
1418                         {
1419                             // leave.
1420                             return;
1421                         }
1422                     }
1423                     // It is not part of the array -> set the new index.
1424                     array[noExtRef] = refPtr;
1425                     // increment the nuber of external references of this instance.
1426                     memHdr->numberExtRef++;
1427 thilo.boehm 1.1 
1428                 }
1429                 
1430 thilo.boehm 1.3 SCMOInstance* SCMOInstance::getExtRef(Uint32 idx) const
1431 thilo.boehm 1.2 {
1432 thilo.boehm 1.3     Uint64* array =
1433                         (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
1434                     SCMBUnion* pUnion;
1435                     pUnion = (SCMBUnion*)(&(inst.base[array[idx]]));
1436                     return pUnion->extRefPtr;
1437 thilo.boehm 1.2 }
1438                 
1439 thilo.boehm 1.3 void SCMOInstance::putExtRef(Uint32 idx,SCMOInstance* ptr)
1440 thilo.boehm 1.1 {
1441 thilo.boehm 1.3     Uint64* array =
1442                         (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
1443                     SCMBUnion* pUnion;
1444                     pUnion = (SCMBUnion*)(&(inst.base[array[idx]]));
1445                     pUnion->extRefPtr = ptr;
1446 thilo.boehm 1.1 }
1447                 
1448 thilo.boehm 1.3 void SCMOInstance::_copyExternalReferences()
1449 thilo.boehm 1.1 {
1450 thilo.boehm 1.3     Uint32 number = inst.mem->numberExtRef;
1451 thilo.boehm 1.1 
1452 thilo.boehm 1.3     if (0 != number)
1453                     {
1454                         SCMBUnion* pUnion;
1455                         Uint64* array =
1456                             (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
1457                         for (Uint32 i = 0; i < number; i++)
1458                         {
1459                             pUnion = (SCMBUnion*)(&(inst.base[array[i]]));
1460                             if (0 != pUnion)
1461                             {
1462                                 pUnion->extRefPtr = new SCMOInstance(*(pUnion->extRefPtr));
1463                             }
1464                         }
1465 thilo.boehm 1.1 
1466 thilo.boehm 1.3     }
1467 thilo.boehm 1.1 
1468 thilo.boehm 1.2 }
1469 thilo.boehm 1.1 
1470 thilo.boehm 1.3 void SCMOInstance::_destroyExternalKeyBindings()
1471 thilo.boehm 1.2 {
1472 thilo.boehm 1.3     // Create a pointer to keybinding node array of the class.
1473                     Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.nodeArray.start;
1474                     SCMBKeyBindingNode* theClassKeyBindNodeArray =
1475                         (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
1476                 
1477                     // create a pointer to instanc key binding array.
1478                     SCMBKeyBindingValue* theInstanceKeyBindingNodeArray =
1479                         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
1480 thilo.boehm 1.1 
1481 thilo.boehm 1.3     for (Uint32 i = 0; i < inst.hdr->numberKeyBindings; i++)
1482                     {
1483                         if (theInstanceKeyBindingNodeArray[i].isSet)
1484                         {
1485                             // only references can be a key binding
1486                             if (theClassKeyBindNodeArray[i].type == CIMTYPE_REFERENCE)
1487                             {
1488                                delete theInstanceKeyBindingNodeArray[i].data.extRefPtr;
1489                             }
1490                         }
1491                     }// for all key bindings
1492 thilo.boehm 1.1 
1493 thilo.boehm 1.3     // Are there user defined key bindings ?
1494                     if (0 != inst.hdr->numberUserKeyBindings)
1495 thilo.boehm 1.2     {
1496 thilo.boehm 1.3         SCMBUserKeyBindingElement* theUserDefKBElement =
1497                             (SCMBUserKeyBindingElement*)
1498                                  &(inst.base[inst.hdr->userKeyBindingElement.start]);
1499 thilo.boehm 1.1 
1500 thilo.boehm 1.3         for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
1501                         {
1502                             if (theUserDefKBElement->value.isSet)
1503                             {
1504                                 // only references can be a key binding.
1505                                 if (theUserDefKBElement->type == CIMTYPE_REFERENCE)
1506                                 {
1507                                     delete theUserDefKBElement->value.data.extRefPtr;
1508                                 }
1509                             }
1510 thilo.boehm 1.1 
1511 thilo.boehm 1.3             theUserDefKBElement =
1512                                 (SCMBUserKeyBindingElement*)
1513                                      &(inst.base[theUserDefKBElement->nextElement.start]);
1514                         } // for all user def. key bindings.
1515                     }
1516                 }
1517 thilo.boehm 1.1 
1518 thilo.boehm 1.3 SCMO_RC SCMOInstance::getCIMInstance(CIMInstance& cimInstance) const
1519                 {
1520 thilo.boehm 1.1 
1521 thilo.boehm 1.3     SCMO_RC rc = SCMO_OK;
1522                     CIMObjectPath objPath;
1523 thilo.boehm 1.1 
1524 thilo.boehm 1.3     // For better usability define pointers to SCMO Class data structures.
1525                     SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
1526                     char* clsbase = inst.hdr->theClass.ptr->cls.base;
1527 thilo.boehm 1.1 
1528 thilo.boehm 1.3     getCIMObjectPath(objPath);
1529 thilo.boehm 1.1 
1530 thilo.boehm 1.3     CIMInstance newInstance;
1531                     newInstance._rep = new CIMInstanceRep(objPath);
1532 thilo.boehm 1.1 
1533 thilo.boehm 1.3     if (inst.hdr->flags.includeQualifiers)
1534                     {
1535                         SCMBQualifier* qualiArray =
1536                             (SCMBQualifier*)&(clsbase[clshdr->qualifierArray.start]);
1537 thilo.boehm 1.1 
1538                 
1539 thilo.boehm 1.3         CIMQualifier theCimQualifier;
1540                         Uint32 i, k = clshdr->numberOfQualifiers;
1541 thilo.boehm 1.1 
1542 thilo.boehm 1.3         for ( i = 0 ; i < k ; i++)
1543                         {
1544                             SCMOClass::_getCIMQualifierFromSCMBQualifier(
1545                                 theCimQualifier,
1546                                 qualiArray[i],
1547                                 clsbase);
1548 thilo.boehm 1.1 
1549 thilo.boehm 1.3             newInstance._rep->_qualifiers.addUnchecked(theCimQualifier);
1550                         }
1551                     }
1552 thilo.boehm 1.1 
1553 thilo.boehm 1.3     if (inst.hdr->flags.isFiltered)
1554 thilo.boehm 1.2     {
1555 thilo.boehm 1.3         // Get absolut pointer to property filter index map of the instance
1556                         Uint32* propertyFilterIndexMap =
1557                             (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);
1558 thilo.boehm 1.1 
1559 thilo.boehm 1.3         for(Uint32 i = 0, k = inst.hdr->filterProperties; i<k; i++)
1560 thilo.boehm 1.1         {
1561 thilo.boehm 1.3             // Get absolut pointer to property filter index map
1562                             // of the instance get the real node index of the property.
1563                             CIMProperty theProperty=_getCIMPropertyAtNodeIndex(
1564                                 propertyFilterIndexMap[i]);
1565                 
1566                             newInstance._rep->_properties.append(theProperty);
1567 thilo.boehm 1.1         }
1568 thilo.boehm 1.3 
1569 thilo.boehm 1.1     }
1570 thilo.boehm 1.3     else
1571                     {
1572 thilo.boehm 1.1 
1573 thilo.boehm 1.3         if (inst.hdr->flags.exportSetOnly)
1574                          {
1575                              for(Uint32 i = 0, k = inst.hdr->numberProperties; i<k; i++)
1576                              {
1577                                  SCMBValue* theInstPropArray =
1578                                      (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
1579 thilo.boehm 1.1 
1580 thilo.boehm 1.3                  // was the property set by the provider ?
1581                                  if(theInstPropArray[i].flags.isSet)
1582                                  {
1583                                      // no filtering. Counter is node index
1584                                      CIMProperty theProperty=_getCIMPropertyAtNodeIndex(i);
1585 thilo.boehm 1.1 
1586 thilo.boehm 1.3                      newInstance._rep->_properties.append(theProperty);
1587                                  }
1588                              }
1589                          }
1590                          else
1591                          {
1592                              for(Uint32 i = 0, k = inst.hdr->numberProperties; i<k; i++)
1593                              {
1594                                  SCMBValue* theInstPropArray =
1595                                      (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
1596 thilo.boehm 1.1 
1597 thilo.boehm 1.3                  // Set all properties in the CIMInstance gegarding they
1598                                  // are part of the SCMOInstance or the SCMOClass.
1599                                  CIMProperty theProperty=_getCIMPropertyAtNodeIndex(i);
1600 thilo.boehm 1.1 
1601 thilo.boehm 1.3                  newInstance._rep->_properties.append(theProperty);
1602                              }
1603                          }
1604 thilo.boehm 1.2     }
1605 thilo.boehm 1.3     cimInstance = newInstance;
1606 thilo.boehm 1.1 
1607 thilo.boehm 1.3     return rc;
1608 thilo.boehm 1.2 }
1609 thilo.boehm 1.1 
1610 thilo.boehm 1.3 void SCMOInstance::getCIMObjectPath(CIMObjectPath& cimObj) const
1611 thilo.boehm 1.2 {
1612 thilo.boehm 1.3     Array<CIMKeyBinding> keys;
1613                 
1614                     // For better usability define pointers to SCMO Class data structures.
1615                     SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
1616                     char* clsbase = inst.hdr->theClass.ptr->cls.base;
1617                 
1618                     // Address the class keybinding information
1619                     SCMBKeyBindingNode* scmoClassArray =
1620                         (SCMBKeyBindingNode*)&(clsbase[clshdr->keyBindingSet.nodeArray.start]);
1621                 
1622                     // Address the instance keybinding information
1623                     SCMBKeyBindingValue* scmoInstArray =
1624                         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
1625 thilo.boehm 1.1 
1626 thilo.boehm 1.3     Uint32 numberKeyBindings = inst.hdr->numberKeyBindings;
1627 thilo.boehm 1.1 
1628 thilo.boehm 1.3     CIMValue theKeyBindingValue;
1629 thilo.boehm 1.1 
1630 thilo.boehm 1.3     for (Uint32 i = 0; i < numberKeyBindings; i ++)
1631 thilo.boehm 1.2     {
1632 thilo.boehm 1.3         if (scmoInstArray[i].isSet)
1633 thilo.boehm 1.2         {
1634 thilo.boehm 1.3             _getCIMValueFromSCMBUnion(
1635                                 theKeyBindingValue,
1636                                 scmoClassArray[i].type,
1637                                 false, // can never be a null value
1638                                 false, // can never be an array
1639                                 0,
1640                                 scmoInstArray[i].data,
1641                                 inst.base);
1642                             keys.append(
1643                                 CIMKeyBinding(
1644 marek       1.5                     CIMNameCast(_newCimString(scmoClassArray[i].name,clsbase)),
1645 thilo.boehm 1.3                     theKeyBindingValue
1646                                     ));
1647 thilo.boehm 1.2         }
1648                     }
1649 thilo.boehm 1.1 
1650 thilo.boehm 1.3     // Are there user defined key bindings ?
1651                     if (0 != inst.hdr->numberUserKeyBindings)
1652 thilo.boehm 1.1     {
1653 thilo.boehm 1.3         SCMBUserKeyBindingElement* theUserDefKBElement =
1654                             (SCMBUserKeyBindingElement*)
1655                                  &(inst.base[inst.hdr->userKeyBindingElement.start]);
1656                 
1657                         for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
1658 thilo.boehm 1.2         {
1659 thilo.boehm 1.3             if (theUserDefKBElement->value.isSet)
1660                             {
1661                                 _getCIMValueFromSCMBUnion(
1662                                     theKeyBindingValue,
1663                                     theUserDefKBElement->type,
1664                                     false, // can never be a null value
1665                                     false, // can never be an array
1666                                     0,
1667                                     theUserDefKBElement->value.data,
1668                                     inst.base);
1669                 
1670                                 keys.append(
1671                                     CIMKeyBinding(
1672                                         CIMNameCast(
1673 marek       1.5                             _newCimString(theUserDefKBElement->name,inst.base)),
1674 thilo.boehm 1.3                     theKeyBindingValue));
1675                             }
1676                             theUserDefKBElement =
1677                                 (SCMBUserKeyBindingElement*)
1678                                      &(inst.base[theUserDefKBElement->nextElement.start]);
1679                         } // for all user def. key bindings.
1680 thilo.boehm 1.1     }
1681 thilo.boehm 1.2 
1682 marek       1.5     String host = _newCimString(inst.hdr->hostName,inst.base);
1683 thilo.boehm 1.3 
1684                     // Use name space and class name of the instance
1685                     CIMNamespaceName nameSpace =
1686 marek       1.5         CIMNamespaceNameCast(_newCimString(inst.hdr->instNameSpace,inst.base));
1687 thilo.boehm 1.3 
1688                     CIMName className =
1689 marek       1.5         CIMNameCast(_newCimString(inst.hdr->instClassName,inst.base));
1690 thilo.boehm 1.2 
1691 thilo.boehm 1.3     cimObj.set(host,nameSpace,className,keys);
1692 thilo.boehm 1.1 }
1693                 
1694 thilo.boehm 1.3 CIMProperty SCMOInstance::_getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const
1695                 {
1696                     CIMValue theValue;
1697                     CIMProperty retProperty;
1698 thilo.boehm 1.2 
1699 thilo.boehm 1.3     // For better usability define pointers to SCMO Class data structures.
1700                     SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
1701                     char* clsbase = inst.hdr->theClass.ptr->cls.base;
1702 thilo.boehm 1.1 
1703 thilo.boehm 1.2 
1704 thilo.boehm 1.3     SCMBClassPropertyNode& clsProp =
1705                         ((SCMBClassPropertyNode*)
1706                          &(clsbase[clshdr->propertySet.nodeArray.start]))[nodeIdx];
1707 thilo.boehm 1.1 
1708 thilo.boehm 1.3     SCMBValue& instValue =
1709                         ((SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]))[nodeIdx];
1710 thilo.boehm 1.1 
1711 thilo.boehm 1.3     if (instValue.flags.isSet)
1712                     {
1713                         _getCIMValueFromSCMBValue(theValue,instValue,inst.base);
1714                     }
1715                     else
1716 thilo.boehm 1.2     {
1717 thilo.boehm 1.3         _getCIMValueFromSCMBValue(
1718                             theValue,
1719                             clsProp.theProperty.defaultValue,
1720                             clsbase);
1721 thilo.boehm 1.2     }
1722 thilo.boehm 1.1 
1723 thilo.boehm 1.3 
1724                 
1725                     if (inst.hdr->flags.includeClassOrigin)
1726 thilo.boehm 1.2     {
1727 thilo.boehm 1.3         retProperty = CIMProperty(
1728 marek       1.5             CIMNameCast(_newCimString(clsProp.theProperty.name,clsbase)),
1729 thilo.boehm 1.3             theValue,
1730                             theValue.getArraySize(),
1731 marek       1.5             CIMNameCast(
1732                                 _newCimString(clsProp.theProperty.refClassName,clsbase)),
1733                             CIMNameCast(
1734                                 _newCimString(clsProp.theProperty.originClassName,clsbase)),
1735 thilo.boehm 1.3             clsProp.theProperty.flags.propagated);
1736 thilo.boehm 1.2     }
1737                     else
1738                     {
1739 thilo.boehm 1.3          retProperty = CIMProperty(
1740 marek       1.5             CIMNameCast(_newCimString(clsProp.theProperty.name,clsbase)),
1741 thilo.boehm 1.3             theValue,
1742                             theValue.getArraySize(),
1743 marek       1.5             CIMNameCast(
1744                                 _newCimString(clsProp.theProperty.refClassName,clsbase)),
1745 thilo.boehm 1.3             CIMName(),
1746                             clsProp.theProperty.flags.propagated);
1747                     }
1748                 
1749                     if (inst.hdr->flags.includeQualifiers)
1750                     {
1751                         SCMBQualifier* qualiArray =
1752                             (SCMBQualifier*)
1753                                  &(clsbase[clsProp.theProperty.qualifierArray.start]);
1754                 
1755                         CIMQualifier theCimQualifier;
1756                 
1757                         Uint32 i, k = clsProp.theProperty.numberOfQualifiers;
1758                         for ( i = 0 ; i < k ; i++)
1759                         {
1760                             SCMOClass::_getCIMQualifierFromSCMBQualifier(
1761                                 theCimQualifier,
1762                                 qualiArray[i],
1763                                 clsbase);
1764 thilo.boehm 1.1 
1765 thilo.boehm 1.3             retProperty._rep->_qualifiers.addUnchecked(theCimQualifier);
1766                         }
1767 thilo.boehm 1.2     }
1768 thilo.boehm 1.3 
1769                     return retProperty;
1770 thilo.boehm 1.1 }
1771                 
1772 thilo.boehm 1.3 void SCMOInstance::_getCIMValueFromSCMBUnion(
1773                     CIMValue& cimV,
1774                     const CIMType type,
1775                     const Boolean isNull,
1776                     const Boolean isArray,
1777                     const Uint32 arraySize,
1778                     const SCMBUnion& scmbUn,
1779                     const char * base)
1780 thilo.boehm 1.1 {
1781 thilo.boehm 1.3 
1782                     const SCMBUnion* pscmbArrayUn = 0;
1783                 
1784                     if (isNull)
1785                     {
1786                         cimV.setNullValue(type,isArray,arraySize);
1787                         return;
1788                     }
1789                 
1790                     if (isArray)
1791                     {
1792                         pscmbArrayUn =(SCMBUnion*)&(base[scmbUn.arrayValue.start]);
1793                     }
1794 thilo.boehm 1.1 
1795                     switch (type)
1796                     {
1797 thilo.boehm 1.3 
1798                     case CIMTYPE_UINT8:
1799 thilo.boehm 1.1         {
1800 thilo.boehm 1.2             if (isArray)
1801                             {
1802 thilo.boehm 1.3                 Array<Uint8> x;
1803                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1804                                 {
1805                                     x.append(pscmbArrayUn[i].simple.val.u8);
1806                                 }
1807                                 cimV.set(x);
1808 thilo.boehm 1.2             }
1809                             else
1810 thilo.boehm 1.1             {
1811 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.u8);
1812 thilo.boehm 1.1             }
1813                             break;
1814                         }
1815                 
1816 thilo.boehm 1.3     case CIMTYPE_UINT16:
1817 thilo.boehm 1.2         {
1818                             if (isArray)
1819                             {
1820 thilo.boehm 1.3                 Array<Uint16> x;
1821                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1822                                 {
1823                                     x.append(pscmbArrayUn[i].simple.val.u16);
1824                                 }
1825                                 cimV.set(x);
1826 thilo.boehm 1.2             }
1827                             else
1828                             {
1829 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.u16);
1830 thilo.boehm 1.2             }
1831 thilo.boehm 1.1             break;
1832                         }
1833                 
1834 thilo.boehm 1.3     case CIMTYPE_UINT32:
1835 thilo.boehm 1.1         {
1836 thilo.boehm 1.2             if (isArray)
1837                             {
1838 thilo.boehm 1.3                 Array<Uint32> x;
1839                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1840                                 {
1841                                     x.append(pscmbArrayUn[i].simple.val.u32);
1842                                 }
1843                                 cimV.set(x);
1844 thilo.boehm 1.2             }
1845                             else
1846                             {
1847 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.u32);
1848 thilo.boehm 1.2             }
1849 thilo.boehm 1.1             break;
1850                         }
1851                 
1852 thilo.boehm 1.3     case CIMTYPE_UINT64:
1853 thilo.boehm 1.1         {
1854 thilo.boehm 1.2             if (isArray)
1855                             {
1856 thilo.boehm 1.3                 Array<Uint64> x;
1857                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1858                                 {
1859                                     x.append(pscmbArrayUn[i].simple.val.u64);
1860                                 }
1861                                 cimV.set(x);
1862 thilo.boehm 1.2             }
1863                             else
1864                             {
1865 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.u64);
1866 thilo.boehm 1.2             }
1867 thilo.boehm 1.1             break;
1868                         }
1869                 
1870 thilo.boehm 1.3     case CIMTYPE_SINT8:
1871 thilo.boehm 1.1         {
1872 thilo.boehm 1.2             if (isArray)
1873                             {
1874 thilo.boehm 1.3                 Array<Sint8> x;
1875                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1876                                 {
1877                                     x.append(pscmbArrayUn[i].simple.val.s8);
1878                                 }
1879                                 cimV.set(x);
1880 thilo.boehm 1.2             }
1881                             else
1882                             {
1883 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.s8);
1884 thilo.boehm 1.2             }
1885 thilo.boehm 1.1             break;
1886                         }
1887                 
1888 thilo.boehm 1.3     case CIMTYPE_SINT16:
1889 thilo.boehm 1.1         {
1890 thilo.boehm 1.2             if (isArray)
1891                             {
1892 thilo.boehm 1.3                 Array<Sint16> x;
1893                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1894                                 {
1895                                     x.append(pscmbArrayUn[i].simple.val.s16);
1896                                 }
1897                                 cimV.set(x);
1898 thilo.boehm 1.2             }
1899                             else
1900                             {
1901 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.s16);
1902 thilo.boehm 1.2             }
1903 thilo.boehm 1.1             break;
1904                         }
1905                 
1906                     case CIMTYPE_SINT32:
1907                         {
1908 thilo.boehm 1.2             if (isArray)
1909                             {
1910 thilo.boehm 1.3                 Array<Sint32> x;
1911                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1912                                 {
1913                                     x.append(pscmbArrayUn[i].simple.val.s32);
1914                                 }
1915                                 cimV.set(x);
1916 thilo.boehm 1.2             }
1917                             else
1918                             {
1919 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.s32);
1920 thilo.boehm 1.2             }
1921 thilo.boehm 1.1             break;
1922                         }
1923                 
1924 thilo.boehm 1.3     case CIMTYPE_SINT64:
1925 thilo.boehm 1.1         {
1926 thilo.boehm 1.2             if (isArray)
1927                             {
1928 thilo.boehm 1.3                 Array<Sint64> x;
1929                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1930                                 {
1931                                     x.append(pscmbArrayUn[i].simple.val.s64);
1932                                 }
1933                                 cimV.set(x);
1934 thilo.boehm 1.2             }
1935                             else
1936                             {
1937 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.s64);
1938 thilo.boehm 1.2             }
1939 thilo.boehm 1.1             break;
1940                         }
1941                 
1942 thilo.boehm 1.3     case CIMTYPE_REAL32:
1943 thilo.boehm 1.1         {
1944 thilo.boehm 1.2             if (isArray)
1945                             {
1946 thilo.boehm 1.3                 Array<Real32> x;
1947                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1948                                 {
1949                                     x.append(pscmbArrayUn[i].simple.val.r32);
1950                                 }
1951                                 cimV.set(x);
1952 thilo.boehm 1.2             }
1953                             else
1954                             {
1955 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.r32);
1956 thilo.boehm 1.2             }
1957 thilo.boehm 1.1             break;
1958                         }
1959                 
1960 thilo.boehm 1.3     case CIMTYPE_REAL64:
1961 thilo.boehm 1.1         {
1962 thilo.boehm 1.2             if (isArray)
1963                             {
1964 thilo.boehm 1.3                 Array<Real64> x;
1965                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1966                                 {
1967                                     x.append(pscmbArrayUn[i].simple.val.r64);
1968                                 }
1969                                 cimV.set(x);
1970 thilo.boehm 1.2             }
1971                             else
1972                             {
1973 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.r64);
1974 thilo.boehm 1.2             }
1975 thilo.boehm 1.1             break;
1976                         }
1977                 
1978 thilo.boehm 1.3     case CIMTYPE_CHAR16:
1979 thilo.boehm 1.1         {
1980 thilo.boehm 1.2             if (isArray)
1981                             {
1982 thilo.boehm 1.3                 Array<Char16> x;
1983                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
1984                                 {
1985                                     x.append(Char16(pscmbArrayUn[i].simple.val.c16));
1986                                 }
1987                                 cimV.set(x);
1988 thilo.boehm 1.2             }
1989                             else
1990                             {
1991 thilo.boehm 1.3                 cimV.set(Char16(scmbUn.simple.val.c16));
1992 thilo.boehm 1.2             }
1993 thilo.boehm 1.1             break;
1994                         }
1995                 
1996 thilo.boehm 1.3     case CIMTYPE_BOOLEAN:
1997 thilo.boehm 1.1         {
1998 thilo.boehm 1.2             if (isArray)
1999                             {
2000 thilo.boehm 1.3                 Array<Boolean> x;
2001                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
2002                                 {
2003                                     x.append(pscmbArrayUn[i].simple.val.bin);
2004                                 }
2005                                 cimV.set(x);
2006 thilo.boehm 1.2             }
2007                             else
2008                             {
2009 thilo.boehm 1.3                 cimV.set(scmbUn.simple.val.bin);
2010 thilo.boehm 1.2             }
2011 thilo.boehm 1.1             break;
2012                         }
2013                 
2014                     case CIMTYPE_STRING:
2015                         {
2016 thilo.boehm 1.2             if (isArray)
2017                             {
2018                 
2019 thilo.boehm 1.3                 Array<String> x;
2020 thilo.boehm 1.2 
2021 thilo.boehm 1.3                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
2022 thilo.boehm 1.2                 {
2023 marek       1.5                     x.append(_newCimString(pscmbArrayUn[i].stringValue,base));
2024 thilo.boehm 1.2                 }
2025 thilo.boehm 1.3                 cimV.set(x);
2026 thilo.boehm 1.2             }
2027                             else
2028 thilo.boehm 1.1             {
2029 marek       1.5                 cimV.set(_newCimString(scmbUn.stringValue,base));
2030 thilo.boehm 1.1             }
2031                             break;
2032                         }
2033                 
2034                     case CIMTYPE_DATETIME:
2035                         {
2036 thilo.boehm 1.2             if (isArray)
2037                             {
2038 thilo.boehm 1.3                 Array<CIMDateTime> x;
2039                 
2040                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
2041                                 {
2042                                     x.append(CIMDateTime(&(pscmbArrayUn[i].dateTimeValue)));
2043                                 }
2044                                 cimV.set(x);
2045 thilo.boehm 1.2             }
2046                             else
2047 thilo.boehm 1.1             {
2048 thilo.boehm 1.3                 cimV.set(CIMDateTime(&scmbUn.dateTimeValue));
2049 thilo.boehm 1.1             }
2050                             break;
2051 thilo.boehm 1.3 
2052 thilo.boehm 1.1         }
2053                 
2054 thilo.boehm 1.3     case CIMTYPE_REFERENCE:
2055                         {
2056                             CIMObjectPath theObjPath;
2057 thilo.boehm 1.2 
2058 thilo.boehm 1.3             if(isArray)
2059                             {
2060                                 Array<CIMObjectPath> x;
2061                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
2062                                 {
2063                                     if (0 != pscmbArrayUn[i].extRefPtr)
2064                                     {
2065                                         pscmbArrayUn[i].extRefPtr->getCIMObjectPath(theObjPath);
2066                                         x.append(theObjPath);
2067                                     }
2068                                     else
2069                                     {
2070                                         // set an empty object
2071                                         x.append(CIMObjectPath());
2072                                     }
2073                                 }
2074                                 cimV.set(x);
2075                             }
2076                             else
2077                             {
2078 thilo.boehm 1.2 
2079 thilo.boehm 1.3                 if (0 != scmbUn.extRefPtr)
2080                                 {
2081                                     scmbUn.extRefPtr->getCIMObjectPath(theObjPath);
2082                                     cimV.set(theObjPath);
2083                                 }
2084                                 else
2085                                 {
2086                                     cimV.set(CIMObjectPath());
2087                                 }
2088                             }
2089 thilo.boehm 1.1             break;
2090 thilo.boehm 1.3         }
2091                     case CIMTYPE_OBJECT:
2092                         {
2093                             CIMInstance cimInstance;
2094                             CIMClass cimClass;
2095 thilo.boehm 1.1 
2096 thilo.boehm 1.3             if(isArray)
2097                             {
2098                                 Array<CIMObject> x;
2099                                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
2100                                 {
2101                                     if (0 != pscmbArrayUn[i].extRefPtr)
2102                                     {
2103                                         // check if the Object is an emedded instance or class
2104                                         if(pscmbArrayUn[i].extRefPtr->
2105                                                inst.hdr->flags.isClassOnly)
2106                                         {
2107                                             pscmbArrayUn[i].extRefPtr->
2108                                                 inst.hdr->theClass.ptr->getCIMClass(cimClass);
2109                                             x.append(CIMObject(cimClass));
2110                                         }
2111                                         else
2112                                         {
2113                                             pscmbArrayUn[i].extRefPtr->
2114                                                 getCIMInstance(cimInstance);
2115                                             x.append(CIMObject(cimInstance));
2116                                         }
2117 thilo.boehm 1.3                     }
2118                                     else
2119                                     {
2120                                         // set an empty object
2121                                         x.append(CIMObject());
2122                                     }
2123                                 }
2124                                 cimV.set(x);
2125                             }
2126                             else
2127                             {
2128                 
2129                                 if (0 != scmbUn.extRefPtr)
2130                                 {
2131                                     // check if the Object is an emedded instance or class
2132                                     if(scmbUn.extRefPtr->inst.hdr->flags.isClassOnly)
2133                                     {
2134                                         scmbUn.extRefPtr->
2135                                             inst.hdr->theClass.ptr->getCIMClass(cimClass);
2136                                         cimV.set(CIMObject(cimClass));
2137                                     }
2138 thilo.boehm 1.3                     else
2139                                     {
2140                                         scmbUn.extRefPtr->getCIMInstance(cimInstance);
2141                                         cimV.set(CIMObject(cimInstance));
2142                                     }
2143                                 }
2144                                 else
2145                                 {
2146                                     cimV.set(CIMObject());
2147                                 }
2148                             }
2149                             break;
2150                         }
2151                 
2152                     case CIMTYPE_INSTANCE:
2153                         {
2154                             CIMInstance theInstance;
2155                 
2156                             if(isArray)
2157                             {
2158                                 Array<CIMInstance> x;
2159 thilo.boehm 1.3                 for (Uint32 i = 0, k = arraySize; i < k ; i++)
2160                                 {
2161                                     if (0 != pscmbArrayUn[i].extRefPtr)
2162                                     {
2163                                         pscmbArrayUn[i].extRefPtr->
2164                                             getCIMInstance(theInstance);
2165                                         x.append(theInstance);
2166                                     }
2167                                     else
2168                                     {
2169                                         // set an empty object
2170                                         x.append(CIMInstance());
2171                                     }
2172                                 }
2173                                 cimV.set(x);
2174                             }
2175                             else
2176                             {
2177                 
2178                                 if (0 != scmbUn.extRefPtr)
2179                                 {
2180 thilo.boehm 1.3                     scmbUn.extRefPtr->getCIMInstance(theInstance);
2181                                     cimV.set(theInstance);
2182                                 }
2183                                 else
2184                                 {
2185                                     cimV.set(CIMInstance());
2186                                 }
2187                             }
2188                             break;
2189                         }
2190                     default:
2191                         {
2192                             PEGASUS_ASSERT(false);
2193 thilo.boehm 1.1             break;
2194 thilo.boehm 1.3         }
2195 thilo.boehm 1.2     }
2196                 }
2197                 
2198 thilo.boehm 1.3 void SCMOInstance::_getCIMValueFromSCMBValue(
2199                     CIMValue& cimV,
2200                     const SCMBValue& scmbV,
2201                     const char * base)
2202                 {
2203                     SCMOInstance::_getCIMValueFromSCMBUnion(
2204                         cimV,
2205                         scmbV.valueType,
2206                         scmbV.flags.isNull,
2207                         scmbV.flags.isArray,
2208                         scmbV.valueArraySize,
2209                         scmbV.value,
2210                         base);
2211                 }
2212                 
2213                 
2214                 void SCMOInstance::_setCIMObjectPath(const CIMObjectPath& cimObj)
2215                 {
2216                     CIMObjectPathRep* objRep = cimObj._rep;
2217                 
2218                     CString className = objRep->_className.getString().getCString();
2219 thilo.boehm 1.3 
2220                     // Is the instance from the same class ?
2221                     if (!(_equalNoCaseUTF8Strings(
2222                              inst.hdr->instClassName,
2223                              inst.base,
2224                              (const char*)className,
2225                              strlen(className))))
2226                     {
2227                         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS,
2228                            objRep->_className.getString());
2229                     }
2230                 
2231                     //set host name
2232                     _setString(objRep->_host,inst.hdr->hostName,&inst.mem );
2233                 
2234                     for (Uint32 i = 0, k = objRep->_keyBindings.size(); i < k; i++)
2235                     {
2236                         String key = objRep->_keyBindings[i].getValue();
2237                         _setKeyBindingFromString(
2238                             (const char*)
2239                                 objRep->_keyBindings[i].getName().getString().getCString(),
2240 thilo.boehm 1.3             _CIMTypeFromKeyBindingType(
2241                                 (const char*)key.getCString(),
2242                                 objRep->_keyBindings[i].getType()),
2243                             key);
2244                     }
2245                 
2246                 }
2247                 void SCMOInstance::_setCIMValueAtNodeIndex(
2248                     Uint32 node,
2249                     CIMValueRep* valRep,
2250                     CIMType realType)
2251 thilo.boehm 1.2 {
2252                     SCMBValue* theInstPropNodeArray =
2253 thilo.boehm 1.3         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
2254                 
2255                 
2256                     SCMBValue& theInstProp = theInstPropNodeArray[node];
2257                 
2258                     theInstProp.valueType=realType;
2259                     theInstProp.flags.isNull=valRep->isNull;
2260                     theInstProp.flags.isArray=valRep->isArray;
2261                     theInstProp.flags.isSet=true;
2262                     theInstProp.valueArraySize=0;
2263 thilo.boehm 1.2 
2264 thilo.boehm 1.3     if (valRep->isNull)
2265                     {
2266                         return;
2267                     }
2268 thilo.boehm 1.2 
2269 thilo.boehm 1.3     Uint64 start = ((const char*)&(theInstProp.value))-inst.base;
2270 thilo.boehm 1.2 
2271 thilo.boehm 1.3     if (valRep->isArray)
2272                     {
2273                         _setUnionArrayValue(
2274                             start,
2275                             &inst.mem,
2276                             realType,
2277                             // Is set to the number of array members by the function.
2278                             theInstProp.valueArraySize,
2279                             inst.hdr->instNameSpace.start,
2280                             inst.hdr->instNameSpace.size,
2281                             valRep->u);
2282                     }
2283                     else
2284 thilo.boehm 1.2     {
2285 thilo.boehm 1.3         _setUnionValue(
2286                             start,
2287                             &inst.mem,
2288                             realType,
2289                             inst.hdr->instNameSpace.start,
2290                             inst.hdr->instNameSpace.size,
2291                             valRep->u);
2292                     }
2293                 }
2294                 
2295                 
2296                 Boolean SCMOInstance::isSame(SCMOInstance& theInstance) const
2297                 {
2298                     return inst.base == theInstance.inst.base;
2299                 }
2300 thilo.boehm 1.1 
2301 thilo.boehm 1.3 void SCMOInstance::setHostName(const char* hostName)
2302                 {
2303                     Uint32 len = 0;
2304 thilo.boehm 1.2 
2305 thilo.boehm 1.3     _copyOnWrite();
2306 thilo.boehm 1.2 
2307 thilo.boehm 1.3     if (hostName!=0)
2308                     {
2309 thilo.boehm 1.2 
2310 thilo.boehm 1.3         len = strlen((const char*)hostName);
2311                     }
2312                     // copy including trailing '\0'
2313                     _setBinary(hostName,len+1,inst.hdr->hostName,&inst.mem);
2314                 }
2315 thilo.boehm 1.2 
2316 thilo.boehm 1.3 void SCMOInstance::setHostName_l(const char* hostName, Uint32 len)
2317                 {
2318                     // Copy on Write is only necessary if a realloc() becomes necessary
2319                     if (inst.mem->freeBytes < len)
2320                     {
2321                         _copyOnWrite();
2322 thilo.boehm 1.2     }
2323 thilo.boehm 1.3     // copy including trailing '\0'
2324                     _setBinary(hostName,len+1,inst.hdr->hostName,&inst.mem);
2325                 }
2326                 
2327                 const char* SCMOInstance::getHostName() const
2328                 {
2329                     return _getCharString(inst.hdr->hostName,inst.base);
2330                 }
2331 thilo.boehm 1.2 
2332 thilo.boehm 1.3 const char* SCMOInstance::getHostName_l(Uint32& length) const
2333                 {
2334                     length = inst.hdr->hostName.size;
2335                     if (0 == length)
2336                     {
2337                         return 0;
2338                     }
2339                     else
2340 thilo.boehm 1.2     {
2341 thilo.boehm 1.3         length--;
2342 thilo.boehm 1.2     }
2343 thilo.boehm 1.3     return _getCharString(inst.hdr->hostName,inst.base);
2344                 }
2345                 
2346                 void SCMOInstance::setClassName(const char* className)
2347                 {
2348                     Uint32 len=0;
2349                 
2350                     _copyOnWrite();
2351 thilo.boehm 1.2 
2352 thilo.boehm 1.3     // flag the instance as compromized
2353                     inst.hdr->flags.isCompromised=true;
2354                     if (className!=0)
2355 thilo.boehm 1.2     {
2356 thilo.boehm 1.3         len = strlen((const char*)className);
2357 thilo.boehm 1.2     }
2358 thilo.boehm 1.3     // copy including trailing '\0'
2359                     // _setBinary also sets the name to 0 if either className==0 or len+1==1
2360                     _setBinary(className,len+1,inst.hdr->instClassName,&inst.mem);
2361                 }
2362 thilo.boehm 1.2 
2363 thilo.boehm 1.3 void SCMOInstance::setClassName_l(const char* className, Uint32 len)
2364                 {
2365                     _copyOnWrite();
2366 thilo.boehm 1.2 
2367 thilo.boehm 1.3     // flag the instance as compromised
2368                     inst.hdr->flags.isCompromised=true;
2369                     // copy including trailing '\0'
2370                     // _setBinary also sets the name to 0 if either className==0 or len+1==1
2371                     _setBinary(className,len+1,inst.hdr->instClassName,&inst.mem);
2372                 }
2373 thilo.boehm 1.2 
2374 thilo.boehm 1.3 const char* SCMOInstance::getClassName() const
2375                 {
2376                     return _getCharString(inst.hdr->instClassName,inst.base);
2377                 }
2378 thilo.boehm 1.2 
2379 thilo.boehm 1.3 const char* SCMOInstance::getClassName_l(Uint32 & length) const
2380                 {
2381                     length = inst.hdr->instClassName.size;
2382                     if (0 == length)
2383                     {
2384                         return 0;
2385                     }
2386                     else
2387                     {
2388                         length--;
2389                     }
2390                     return _getCharString(inst.hdr->instClassName,inst.base);
2391 thilo.boehm 1.2 }
2392                 
2393 thilo.boehm 1.3 void SCMOInstance::setNameSpace(const char* nameSpace)
2394 thilo.boehm 1.2 {
2395 thilo.boehm 1.3     Uint32 len = 0;
2396                 
2397                     _copyOnWrite();
2398                 
2399                     // flag the instance as compromized
2400                     inst.hdr->flags.isCompromised=true;
2401                 
2402                     if (nameSpace!=0)
2403 thilo.boehm 1.2     {
2404 thilo.boehm 1.3 
2405                         len = strlen((const char*)nameSpace);
2406 thilo.boehm 1.1     }
2407 thilo.boehm 1.3     // copy including trailing '\0'
2408                     _setBinary(nameSpace,len+1,inst.hdr->instNameSpace,&inst.mem);
2409                 }
2410 thilo.boehm 1.1 
2411 thilo.boehm 1.3 void SCMOInstance::setNameSpace_l(const char* nameSpace, Uint32 len)
2412                 {
2413                     // Copy on Write is only necessary if a realloc() becomes necessary
2414                     if (inst.mem->freeBytes < len)
2415                     {
2416                         _copyOnWrite();
2417                     }
2418                     // flag the instance as compromized
2419                     inst.hdr->flags.isCompromised=true;
2420                     // copy including trailing '\0'
2421                     _setBinary(nameSpace,len+1,inst.hdr->instNameSpace,&inst.mem);
2422                 }
2423 thilo.boehm 1.2 
2424 thilo.boehm 1.3 const char* SCMOInstance::getNameSpace() const
2425                 {
2426                     return _getCharString(inst.hdr->instNameSpace,inst.base);
2427 thilo.boehm 1.2 }
2428                 
2429 thilo.boehm 1.3 const char* SCMOInstance::getNameSpace_l(Uint32 & length) const
2430 thilo.boehm 1.2 {
2431 thilo.boehm 1.3     length = inst.hdr->instNameSpace.size;
2432                     if (0 == length)
2433                     {
2434                         return 0;
2435                     }
2436                     else
2437                     {
2438                         length--;
2439                     }
2440                     return _getCharString(inst.hdr->instNameSpace,inst.base);
2441 thilo.boehm 1.1 }
2442                 
2443 thilo.boehm 1.3 void SCMOInstance::buildKeyBindingsFromProperties()
2444 thilo.boehm 1.1 {
2445 thilo.boehm 1.3     Uint32* theClassKeyPropList =
2446                         (Uint32*) &((inst.hdr->theClass.ptr->cls.base)
2447                                     [(inst.hdr->theClass.ptr->cls.hdr->keyIndexList.start)]);
2448 thilo.boehm 1.2 
2449 thilo.boehm 1.3     SCMBKeyBindingValue* theKeyBindValueArray;
2450                     SCMBValue* theInstPropNodeArray;
2451                 
2452                     Uint32 propNode;
2453 thilo.boehm 1.2 
2454 thilo.boehm 1.3     for (Uint32 i = 0, k = inst.hdr->numberKeyBindings; i < k; i++)
2455 thilo.boehm 1.2     {
2456 thilo.boehm 1.3         // the instance pointers has to be reinitialized each time,
2457                         // because in _setKeyBindingFromSCMBUnion()
2458                         // a reallocation can take place.
2459                         theKeyBindValueArray =
2460                            (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
2461                 
2462                         theInstPropNodeArray =
2463                             (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
2464                 
2465                         // If the keybinding is not set.
2466                         if (!theKeyBindValueArray[i].isSet)
2467                         {
2468                             // get the node index for this key binding form class
2469                             propNode = theClassKeyPropList[i];
2470                 
2471                             // if property was set by the provider and it is not null.
2472                             if ( theInstPropNodeArray[propNode].flags.isSet &&
2473                                 !theInstPropNodeArray[propNode].flags.isNull)
2474                             {
2475                                 _copyOnWrite();
2476                 
2477 thilo.boehm 1.3                 _setKeyBindingFromSCMBUnion(
2478                                     theInstPropNodeArray[propNode].valueType,
2479                                     theInstPropNodeArray[propNode].value,
2480                                     inst.base,
2481                                     theKeyBindValueArray[i]);
2482                             }
2483                         }
2484 thilo.boehm 1.2     }
2485 thilo.boehm 1.3 }
2486 thilo.boehm 1.2 
2487 thilo.boehm 1.3 void SCMOInstance::_setKeyBindingFromSCMBUnion(
2488                     CIMType type,
2489                     const SCMBUnion& u,
2490                     const char * uBase,
2491                     SCMBKeyBindingValue& keyData)
2492                 {
2493 thilo.boehm 1.1     switch (type)
2494                     {
2495                     case CIMTYPE_UINT8:
2496 thilo.boehm 1.3     case CIMTYPE_UINT16:
2497                     case CIMTYPE_UINT32:
2498                     case CIMTYPE_UINT64:
2499 thilo.boehm 1.1     case CIMTYPE_SINT8:
2500                     case CIMTYPE_SINT16:
2501                     case CIMTYPE_SINT32:
2502                     case CIMTYPE_SINT64:
2503                     case CIMTYPE_REAL32:
2504                     case CIMTYPE_REAL64:
2505                     case CIMTYPE_CHAR16:
2506 thilo.boehm 1.3     case CIMTYPE_BOOLEAN:
2507                         {
2508                             memcpy(&keyData.data,&u,sizeof(SCMBUnion));
2509                             keyData.data.simple.hasValue=true;
2510                             keyData.isSet=true;
2511                             break;
2512                         }
2513 thilo.boehm 1.2     case CIMTYPE_DATETIME:
2514 thilo.boehm 1.1         {
2515 thilo.boehm 1.3             memcpy(&keyData.data,&u,sizeof(SCMBUnion));
2516                             keyData.isSet=true;
2517 thilo.boehm 1.1             break;
2518                         }
2519                     case CIMTYPE_STRING:
2520                         {
2521 thilo.boehm 1.3             keyData.isSet=true;
2522                             // Check if a key binding is set with in the same instance.
2523                             // If this is the case, a reallocation can take place and the
2524                             // uBase pointer can be invalid and cause a read in freed memory!
2525                             if (uBase == inst.base)
2526 thilo.boehm 1.2             {
2527 thilo.boehm 1.3                 if (0 != u.stringValue.size )
2528 thilo.boehm 1.2                 {
2529 thilo.boehm 1.3                     // We are doing a in instance copy of data.
2530                                     // We can not use the _setBinary() function because
2531                                     // all real pointer can be in valid after
2532                                     // the _getFreeSprace() function!
2533                                     // We have to save all relative pointer on the stack.
2534                                     Uint64 start;
2535                                     SCMBDataPtr tmp;
2536                                     tmp.size = u.stringValue.size;
2537                                     tmp.start = u.stringValue.start;
2538                 
2539                                     // In this function a reallocation may take place!
2540                                     // The keyData.data.stringValue is set
2541                                     // before the rallocation.
2542                                     start = _getFreeSpace(
2543                                         keyData.data.stringValue,
2544                                         u.stringValue.size,
2545                                         &inst.mem);
2546                                     // Copy the string,
2547                                     // but using the own base pointer and the saved relative
2548                                     // string pointer.
2549                                     memcpy(
2550 thilo.boehm 1.3                         &(inst.base[start]),
2551                                         _getCharString(tmp,inst.base),
2552                                         tmp.size);
2553 thilo.boehm 1.2                 }
2554 thilo.boehm 1.3                 else
2555 thilo.boehm 1.2                 {
2556 thilo.boehm 1.3                    keyData.data.stringValue.size=0;
2557                                    keyData.data.stringValue.start=0;
2558 thilo.boehm 1.2                 }
2559 thilo.boehm 1.1 
2560 thilo.boehm 1.2             }
2561                             else
2562                             {
2563 thilo.boehm 1.3                 _setBinary(
2564                                     &uBase[u.stringValue.start],
2565                                     u.stringValue.size,
2566                                     keyData.data.stringValue,
2567                                     &inst.mem);
2568 thilo.boehm 1.2             }
2569 thilo.boehm 1.1 
2570                             break;
2571                         }
2572 thilo.boehm 1.2     case CIMTYPE_REFERENCE:
2573 thilo.boehm 1.3         {
2574                             if(0 != keyData.data.extRefPtr)
2575                             {
2576                                 delete keyData.data.extRefPtr;
2577                             }
2578 thilo.boehm 1.1 
2579 thilo.boehm 1.3             if(u.extRefPtr)
2580                             {
2581                                 keyData.data.extRefPtr = new SCMOInstance(*u.extRefPtr);
2582                                 keyData.isSet=true;
2583                                 // This function can cause a reallocation !
2584                                 // Pointers can be invalid after the call.
2585                                 _setExtRefIndex(&(keyData.data),&inst.mem);
2586                             }
2587                             else
2588                             {
2589                                 keyData.isSet=true;
2590                                 keyData.data.extRefPtr=0;
2591                             }
2592                             break;
2593                         }
2594 thilo.boehm 1.2     case CIMTYPE_OBJECT:
2595                     case CIMTYPE_INSTANCE:
2596 thilo.boehm 1.3         {
2597                             // From PEP 194: EmbeddedObjects cannot be keys.
2598                             throw TypeMismatchException();
2599                             break;
2600                         }
2601 thilo.boehm 1.2     default:
2602 thilo.boehm 1.3         {
2603                             PEGASUS_ASSERT(false);
2604                             break;
2605                         }
2606 thilo.boehm 1.2     }
2607 thilo.boehm 1.1 }
2608                 
2609 thilo.boehm 1.3 void SCMOInstance::_initSCMOInstance(SCMOClass* pClass)
2610 thilo.boehm 1.1 {
2611 thilo.boehm 1.3     PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE
2612                         - sizeof(SCMBInstance_Main)>0);
2613 thilo.boehm 1.1 
2614                 
2615 thilo.boehm 1.3     inst.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);
2616                     if (inst.base == 0)
2617                     {
2618                         // Not enough memory!
2619                         throw PEGASUS_STD(bad_alloc)();
2620                     }
2621                 
2622                     memset(inst.base,0,sizeof(SCMBInstance_Main));
2623                 
2624                     // initalize eye catcher
2625                     inst.hdr->header.magic=PEGASUS_SCMB_INSTANCE_MAGIC;
2626                     inst.hdr->header.totalSize=SCMB_INITIAL_MEMORY_CHUNK_SIZE;
2627                     // The # of bytes free
2628                     inst.hdr->header.freeBytes=
2629                         SCMB_INITIAL_MEMORY_CHUNK_SIZE-sizeof(SCMBInstance_Main);
2630                     // Index to the start of the free space in this instance
2631                     inst.hdr->header.startOfFreeSpace=sizeof(SCMBInstance_Main);
2632                 
2633                     inst.hdr->refCount=1;
2634                 
2635                     //Assign the SCMBClass structure this instance based on.
2636 thilo.boehm 1.3     inst.hdr->theClass.ptr = pClass;
2637                 
2638                     // Copy name space name and class name of the class
2639                     _setBinary(
2640                         _getCharString(inst.hdr->theClass.ptr->cls.hdr->className,
2641                                        inst.hdr->theClass.ptr->cls.base),
2642                         inst.hdr->theClass.ptr->cls.hdr->className.size,
2643                         inst.hdr->instClassName,
2644                         &inst.mem);
2645                 
2646                     _setBinary(
2647                         _getCharString(inst.hdr->theClass.ptr->cls.hdr->nameSpace,
2648                                        inst.hdr->theClass.ptr->cls.base),
2649                         inst.hdr->theClass.ptr->cls.hdr->nameSpace.size,
2650                         inst.hdr->instNameSpace,
2651                         &inst.mem);
2652                 
2653                     // Number of key bindings
2654                     inst.hdr->numberKeyBindings =
2655                         inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
2656                 
2657 thilo.boehm 1.3     // Number of properties
2658                     inst.hdr->numberProperties =
2659                         inst.hdr->theClass.ptr->cls.hdr->propertySet.number;
2660                 
2661                     // Allocate the SCMOInstanceKeyBindingArray
2662                     _getFreeSpace(
2663                           inst.hdr->keyBindingArray,
2664                           sizeof(SCMBKeyBindingValue)*inst.hdr->numberKeyBindings,
2665                           &inst.mem);
2666                 
2667                     // Allocate the SCMBInstancePropertyArray
2668                     _getFreeSpace(
2669                         inst.hdr->propertyArray,
2670                         sizeof(SCMBValue)*inst.hdr->numberProperties,
2671                         &inst.mem);
2672                 
2673                 }
2674                 
2675                 void SCMOInstance::_setCIMInstance(const CIMInstance& cimInstance)
2676 thilo.boehm 1.1 {
2677 thilo.boehm 1.3     CIMPropertyRep* propRep;
2678                     Uint32 propNode;
2679                     SCMO_RC rc;
2680                     CIMType realType;
2681                 
2682                     CIMInstanceRep* instRep = cimInstance._rep;
2683                 
2684                     // Test if the instance has qualifiers.
2685                     // The instance level qualifiers are stored on the associated SCMOClass.
2686                     inst.hdr->flags.includeQualifiers=(instRep->_qualifiers.getCount()>0);
2687                 
2688                     // To ensure that at converting a CIMInstance to a SCMOInstance
2689                     // and vice versa do have the same property set.
2690                     inst.hdr->flags.exportSetOnly=true;
2691 thilo.boehm 1.1 
2692 thilo.boehm 1.3     _setCIMObjectPath(instRep->_reference);
2693                 
2694                     // Copy all properties
2695                     for (Uint32 i = 0, k = instRep->_properties.size(); i < k; i++)
2696 thilo.boehm 1.2     {
2697 thilo.boehm 1.3         propRep = instRep->_properties[i]._rep;
2698                         // if not already detected that qualifiers are specified and
2699                         // there are qualifers at that property.
2700                         if (!inst.hdr->flags.includeQualifiers &&
2701                             propRep->getQualifierCount() > 0)
2702                         {
2703                             includeQualifiers();
2704                         }
2705                         // if not already detected that class origins are specified and
2706                         // there is a class origin specified at that property.
2707                         if (!inst.hdr->flags.includeClassOrigin &&
2708                             !propRep->_classOrigin.isNull())
2709                         {
2710                             includeClassOrigins();
2711                         }
2712                 
2713                         // get the property node index for the property
2714                         rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(
2715                             propNode,
2716                             (const char*)propRep->_name.getString().getCString());
2717                 
2718 thilo.boehm 1.3         if (rc == SCMO_OK)
2719                         {
2720                             // The type stored in the class information is set on realType.
2721                             // It must be used in further calls to guaranty consistence.
2722                             rc = inst.hdr->theClass.ptr->_isNodeSameType(
2723                                      propNode,
2724                                      propRep->_value._rep->type,
2725                                      propRep->_value._rep->isArray,
2726                                      realType);
2727                             if (rc == SCMO_OK)
2728                             {
2729                                 _setCIMValueAtNodeIndex(
2730                                     propNode,
2731                                     propRep->_value._rep,
2732                                     realType);
2733                             }
2734                             else
2735                             {
2736                                 PEG_TRACE((TRC_DISCARDED_DATA,Tracer::LEVEL2,
2737                                     "CIMProperty '%s' with type '%s' "
2738                                         "can not be set at SCMOInstance."
2739 thilo.boehm 1.3                         "It is has not same type '%s' as defined in "
2740                                         "class '%s' of name space '%s'",
2741                                      cimTypeToString(propRep->_value._rep->type),
2742                                     (const char*)propRep->_name.getString().getCString(),
2743                                      cimTypeToString(realType),
2744                                     (const char*)instRep->_reference._rep->
2745                                            _className.getString().getCString(),
2746                                     (const char*)instRep->_reference._rep->
2747                                            _nameSpace.getString().getCString()));
2748                             }
2749                 
2750                         }
2751                         else
2752                         {
2753                 
2754                             PEG_TRACE((TRC_DISCARDED_DATA,Tracer::LEVEL2,
2755                                 "CIMProperty '%s' can not be set at SCMOInstance."
2756                                     "It is not part of class '%s' of name space '%s'",
2757                                 (const char*)propRep->_name.getString().getCString(),
2758                                 (const char*)instRep->_reference._rep->
2759                                        _className.getString().getCString(),
2760 thilo.boehm 1.3                 (const char*)instRep->_reference._rep->
2761                                        _nameSpace.getString().getCString()));
2762                         }
2763 thilo.boehm 1.2     }
2764 thilo.boehm 1.1 }
2765                 
2766 thilo.boehm 1.3 SCMO_RC SCMOInstance::getProperty(
2767 thilo.boehm 1.2     const char* name,
2768 thilo.boehm 1.3     CIMType& type,
2769                     const SCMBUnion** pOutVal,
2770                     Boolean& isArray,
2771                     Uint32& size ) const
2772 thilo.boehm 1.1 {
2773 thilo.boehm 1.2     Uint32 node;
2774 thilo.boehm 1.3     const char* pname;
2775                     SCMO_RC rc = SCMO_OK;
2776                 
2777                     *pOutVal = 0;
2778                     isArray = false;
2779                     size = 0;
2780 thilo.boehm 1.1 
2781 thilo.boehm 1.3     rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(node,name);
2782 thilo.boehm 1.2     if (rc != SCMO_OK)
2783 thilo.boehm 1.1     {
2784 thilo.boehm 1.2         return rc;
2785 thilo.boehm 1.1     }
2786                 
2787 thilo.boehm 1.3     // is filtering on ?
2788                     if (inst.hdr->flags.isFiltered)
2789                     {
2790                         // Is the property NOT in the property filter ?
2791                         if(!_isPropertyInFilter(node))
2792                         {
2793                             // The named propery is not part of this instance
2794                             // due to filtering.
2795                             return SCMO_NOT_FOUND;
2796                         }
2797                     }
2798 thilo.boehm 1.1 
2799 thilo.boehm 1.3     return  _getPropertyAtNodeIndex(node,&pname,type,pOutVal,isArray,size);
2800 thilo.boehm 1.2 }
2801 thilo.boehm 1.1 
2802 thilo.boehm 1.3 SCMO_RC SCMOInstance::getPropertyAt(
2803                         Uint32 idx,
2804                         const char** pname,
2805                         CIMType& type,
2806                         const SCMBUnion** pOutVal,
2807                         Boolean& isArray,
2808                         Uint32& size ) const
2809 thilo.boehm 1.2 {
2810 thilo.boehm 1.3     *pname = 0;
2811                     *pOutVal = 0;
2812                     isArray = false;
2813                     size = 0;
2814                     Uint32 node;
2815                 
2816                     // is filtering on ?
2817                     if (inst.hdr->flags.isFiltered)
2818                     {
2819                         // check the number of properties part of the filter
2820                         if (idx >= inst.hdr->filterProperties)
2821                         {
2822                             return SCMO_INDEX_OUT_OF_BOUND;
2823                         }
2824 thilo.boehm 1.1 
2825 thilo.boehm 1.3         // Get absolut pointer to property filter index map of the instance
2826                         Uint32* propertyFilterIndexMap =
2827                         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);
2828 thilo.boehm 1.1 
2829 thilo.boehm 1.3         // get the real node index of the property.
2830                         node = propertyFilterIndexMap[idx];
2831                     }
2832                     else
2833                     {
2834                         // the index is used as node index.
2835                         node = idx;
2836                         if (node >= inst.hdr->numberProperties)
2837                         {
2838                             return SCMO_INDEX_OUT_OF_BOUND;
2839                         }
2840                     }
2841 thilo.boehm 1.1 
2842 thilo.boehm 1.3     return  _getPropertyAtNodeIndex(node,pname,type,pOutVal,isArray,size);
2843                 }
2844 thilo.boehm 1.1 
2845 thilo.boehm 1.3 SCMO_RC SCMOInstance::getPropertyNodeIndex(const char* name, Uint32& node) const
2846                 {
2847                     SCMO_RC rc;
2848                     if(name==0)
2849 thilo.boehm 1.2     {
2850 thilo.boehm 1.3         return SCMO_INVALID_PARAMETER;
2851 thilo.boehm 1.2     }
2852 thilo.boehm 1.1 
2853 thilo.boehm 1.3     rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(node,name);
2854 thilo.boehm 1.1 
2855 thilo.boehm 1.3     return rc;
2856 thilo.boehm 1.1 
2857                 }
2858                 
2859 thilo.boehm 1.3 SCMO_RC SCMOInstance::setPropertyWithOrigin(
2860 thilo.boehm 1.2     const char* name,
2861 thilo.boehm 1.3     CIMType type,
2862                     const SCMBUnion* pInVal,
2863                     Boolean isArray,
2864                     Uint32 size,
2865                     const char* origin)
2866 thilo.boehm 1.1 {
2867 thilo.boehm 1.3     // In this function no  _copyOnWrite(), it does not change the instance.
2868                 
2869                     Uint32 node;
2870 thilo.boehm 1.2     SCMO_RC rc;
2871 thilo.boehm 1.3     CIMType realType;
2872                 
2873                     rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(node,name);
2874                     if (rc != SCMO_OK)
2875                     {
2876                         return rc;
2877                     }
2878 thilo.boehm 1.1 
2879 thilo.boehm 1.3     // Is the traget type OK ?
2880                     // The type stored in the class information is set on realType.
2881                     // It must be used in further calls to guaranty consistence.
2882                     rc = inst.hdr->theClass.ptr->_isNodeSameType(node,type,isArray,realType);
2883 thilo.boehm 1.1     if (rc != SCMO_OK)
2884                     {
2885                         return rc;
2886                     }
2887                 
2888 thilo.boehm 1.3     // is filtering on ?
2889                     if (inst.hdr->flags.isFiltered)
2890                     {
2891                         // Is the property NOT in the property filter ?
2892                         if(!_isPropertyInFilter(node))
2893                         {
2894                             // The named propery is not part of this instance
2895                             // due to filtering.
2896                             return SCMO_NOT_FOUND;
2897                         }
2898                     }
2899 thilo.boehm 1.2 
2900 thilo.boehm 1.3     // check class origin if set.
2901                     if (origin!= 0)
2902 thilo.boehm 1.1     {
2903 thilo.boehm 1.3         if(!inst.hdr->theClass.ptr->_isSamePropOrigin(node,origin))
2904                         {
2905                             return SCMO_NOT_SAME_ORIGIN;
2906                         }
2907 thilo.boehm 1.1     }
2908                 
2909 thilo.boehm 1.2 
2910 thilo.boehm 1.3     _setPropertyAtNodeIndex(node,realType,pInVal,isArray,size);
2911 thilo.boehm 1.2 
2912                     return SCMO_OK;
2913 thilo.boehm 1.3 }
2914                 
2915                 SCMO_RC SCMOInstance::setPropertyWithNodeIndex(
2916                     Uint32 node,
2917                     CIMType type,
2918                     const SCMBUnion* pInVal,
2919                     Boolean isArray,
2920                     Uint32 size)
2921                 {
2922                     // In this function no  _copyOnWrite(), it does not change the instance.
2923                 
2924                     SCMO_RC rc;
2925                     CIMType realType;
2926                 
2927                     if (node >= inst.hdr->numberProperties)
2928                     {
2929                         return SCMO_INDEX_OUT_OF_BOUND;
2930                     }
2931                 
2932                     // is filtering on ?
2933                     if (inst.hdr->flags.isFiltered)
2934 thilo.boehm 1.3     {
2935                         // Is the property NOT in the property filter ?
2936                         if(!_isPropertyInFilter(node))
2937                         {
2938                             // The proptery of the is not set due to filtering.
2939                             return SCMO_OK;
2940                         }
2941                     }
2942                 
2943                     // Is the traget type OK ?
2944                     // The type stored in the class information is set on realType.
2945                     // It must be used in further calls to guaranty consistence.
2946                     rc = inst.hdr->theClass.ptr->_isNodeSameType(node,type,isArray,realType);
2947                     if (rc != SCMO_OK)
2948                     {
2949                         return rc;
2950                     }
2951                 
2952                     _setPropertyAtNodeIndex(node,realType,pInVal,isArray,size);
2953 thilo.boehm 1.2 
2954 thilo.boehm 1.3     return SCMO_OK;
2955 thilo.boehm 1.1 }
2956                 
2957 thilo.boehm 1.3 void SCMOInstance::_setPropertyAtNodeIndex(
2958                     Uint32 node,
2959                     CIMType type,
2960                     const SCMBUnion* pInVal,
2961                     Boolean isArray,
2962                     Uint32 size)
2963 thilo.boehm 1.1 {
2964 thilo.boehm 1.2 
2965 thilo.boehm 1.3     _copyOnWrite();
2966                 
2967                     SCMBValue* theInstPropNodeArray =
2968                         (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
2969                 
2970                 
2971                     theInstPropNodeArray[node].flags.isSet=true;
2972                     theInstPropNodeArray[node].valueType=type;
2973                     theInstPropNodeArray[node].flags.isArray=isArray;
2974                     if (isArray)
2975                     {
2976                         theInstPropNodeArray[node].valueArraySize=size;
2977                     }
2978 thilo.boehm 1.1 
2979 thilo.boehm 1.3     if (pInVal==0)
2980                     {
2981                         theInstPropNodeArray[node].flags.isNull=true;
2982                     }
2983                     else
2984 thilo.boehm 1.1     {
2985 thilo.boehm 1.3         theInstPropNodeArray[node].flags.isNull=false;
2986                         _setSCMBUnion(
2987                             pInVal,
2988                             type,
2989                             isArray,
2990                             size,
2991                             theInstPropNodeArray[node].value);
2992                     }
2993                 }
2994 thilo.boehm 1.2 
2995 thilo.boehm 1.3 void SCMOInstance::_setSCMBUnion(
2996                     const SCMBUnion* pInVal,
2997                     CIMType type,
2998                     Boolean isArray,
2999                     Uint32 size,
3000                     SCMBUnion & u)
3001                 {
3002                 
3003                     switch (type)
3004                     {
3005                     case CIMTYPE_BOOLEAN:
3006                     case CIMTYPE_UINT8:
3007                     case CIMTYPE_SINT8:
3008                     case CIMTYPE_UINT16:
3009                     case CIMTYPE_SINT16:
3010                     case CIMTYPE_UINT32:
3011                     case CIMTYPE_SINT32:
3012                     case CIMTYPE_UINT64:
3013                     case CIMTYPE_SINT64:
3014                     case CIMTYPE_REAL32:
3015                     case CIMTYPE_REAL64:
3016 thilo.boehm 1.3     case CIMTYPE_CHAR16:
3017                         {
3018                             if (isArray)
3019                             {
3020                                 _setBinary(pInVal,size*sizeof(SCMBUnion),
3021                                            u.arrayValue,
3022                                            &inst.mem );
3023                             }
3024                             else
3025                             {
3026                                 memcpy(&u,pInVal,sizeof(SCMBUnion));
3027                                 u.simple.hasValue=true;
3028                             }
3029                             break;
3030                         }
3031                     case CIMTYPE_DATETIME:
3032                         {
3033                             if (isArray)
3034                             {
3035                                 _setBinary(pInVal,size*sizeof(SCMBUnion),
3036                                            u.arrayValue,
3037 thilo.boehm 1.3                            &inst.mem );
3038                             }
3039                             else
3040                             {
3041                                 memcpy(&u,pInVal,sizeof(SCMBUnion));
3042                 
3043                             }
3044                             break;
3045                         }
3046                     case CIMTYPE_STRING:
3047                         {
3048                             if (isArray)
3049                             {
3050                                 SCMBUnion* ptr;
3051                                 Uint64 startPtr;
3052                 
3053                                 startPtr = _getFreeSpace(
3054                                     u.arrayValue,
3055                                     size*sizeof(SCMBUnion),
3056                                     &inst.mem);
3057                 
3058 thilo.boehm 1.3                 for (Uint32 i = 0; i < size; i++)
3059                                 {
3060                                     ptr = (SCMBUnion*)&(inst.base[startPtr]);
3061                                     // Copy the sting including the trailing '\0'
3062                                     _setBinary(
3063                                         pInVal[i].extString.pchar,
3064                                         pInVal[i].extString.length+1,
3065                                         ptr[i].stringValue,
3066                                         &inst.mem );
3067                                 }
3068                             }
3069                             else
3070                             {
3071                                 // Copy the sting including the trailing '\0'
3072                                 _setBinary(
3073                                     pInVal->extString.pchar,
3074                                     pInVal->extString.length+1,
3075                                     u.stringValue,
3076                                     &inst.mem );
3077                             }
3078                             break;
3079 thilo.boehm 1.3         }
3080                 
3081                     case CIMTYPE_REFERENCE:
3082                     case CIMTYPE_OBJECT:
3083                     case CIMTYPE_INSTANCE:
3084                         {
3085                             if(isArray)
3086                             {
3087                                 SCMBUnion* ptr;
3088                                 Uint64 startPtr;
3089                 
3090                                 // if the array was previously set, delete the references !
3091                                 _deleteArrayExtReference(u.arrayValue,&inst.mem);
3092                 
3093                                 // get new array
3094                                 startPtr = _getFreeSpace(
3095                                     u.arrayValue,
3096                                     size*sizeof(SCMBUnion),
3097                                     &inst.mem);
3098                 
3099                                 ptr = (SCMBUnion*)&(inst.base[startPtr]);
3100 thilo.boehm 1.3 
3101                                 for (Uint32 i = 0 ; i < size ; i++)
3102                                 {
3103                                     if(pInVal[i].extRefPtr)
3104                                     {
3105                                         ptr[i].extRefPtr=
3106                                             new SCMOInstance(*(pInVal[i].extRefPtr));
3107                 
3108                                         // This function can cause a reallocation !
3109                                         // Pointers can be invalid after the call.
3110                                         _setExtRefIndex(&(ptr[i]),&inst.mem);
3111                                     }
3112                                     else
3113                                     {
3114                                         ptr[i].extRefPtr = 0;
3115                                     }
3116                                 }
3117                 
3118                             }
3119                             else
3120                             {
3121 thilo.boehm 1.3                 if(0 != u.extRefPtr)
3122                                 {
3123                                     delete u.extRefPtr;
3124                                 }
3125                 
3126                                 if(pInVal->extRefPtr)
3127                                 {
3128                                     u.extRefPtr = new SCMOInstance(*(pInVal->extRefPtr));
3129                                     // This function can cause a reallocation !
3130                                     // Pointers can be invalid after the call.
3131                                     _setExtRefIndex(&u,&inst.mem);
3132                 
3133                                 }
3134                                 else
3135                                 {
3136                                     u.extRefPtr = 0;
3137                                 }
3138                             }
3139                             break;
3140                         }
3141                     default:
3142 thilo.boehm 1.3         {
3143                             PEGASUS_ASSERT(false);
3144                             break;
3145                         }
3146                     }
3147                 }
3148                 
3149                 void SCMOInstance::_setUnionArrayValue(
3150                     Uint64 start,
3151                     SCMBMgmt_Header** pmem,
3152                     CIMType type,
3153                     Uint32& n,
3154                     Uint64 startNS,
3155                     Uint32 sizeNS,
3156                     Union& u)
3157                 {
3158                     SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);
3159                     SCMBUnion* ptargetUnion;
3160                     Uint64 arrayStart;
3161                     Uint32 loop;
3162                 
3163 thilo.boehm 1.3     switch (type)
3164                     {
3165                     case CIMTYPE_BOOLEAN:
3166                         {
3167                             Array<Boolean> *x = reinterpret_cast<Array<Boolean>*>(&u);
3168                             // n can be invalid after re-allocation in _getFreeSpace !
3169                             loop = n = x->size();
3170                             arrayStart = _getFreeSpace(
3171                                 scmoUnion->arrayValue,
3172                                 loop*sizeof(SCMBUnion),
3173                                 pmem);
3174                 
3175                             ConstArrayIterator<Boolean> iterator(*x);
3176                 
3177                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3178                             for (Uint32 i = 0; i < loop; i++)
3179                             {
3180                                 ptargetUnion[i].simple.val.bin  = iterator[i];
3181                                 ptargetUnion[i].simple.hasValue = true;
3182                             }
3183                             break;
3184 thilo.boehm 1.3         }
3185                 
3186                     case CIMTYPE_UINT8:
3187                         {
3188                             Array<Uint8> *x = reinterpret_cast<Array<Uint8>*>(&u);
3189                             // n can be invalid after re-allocation in _getFreeSpace !
3190                             loop = n = x->size();
3191                             arrayStart = _getFreeSpace(
3192                                 scmoUnion->arrayValue,
3193                                 loop*sizeof(SCMBUnion),
3194                                 pmem);
3195                 
3196                             ConstArrayIterator<Uint8> iterator(*x);
3197                 
3198                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3199                             for (Uint32 i = 0; i < loop; i++)
3200                             {
3201                                 ptargetUnion[i].simple.val.u8  = iterator[i];
3202                                 ptargetUnion[i].simple.hasValue = true;
3203                             }
3204                             break;
3205 thilo.boehm 1.3         }
3206                 
3207                     case CIMTYPE_SINT8:
3208                         {
3209                             Array<Sint8> *x = reinterpret_cast<Array<Sint8>*>(&u);
3210                             // n can be invalid after re-allocation in _getFreeSpace !
3211                             loop = n = x->size();
3212                             arrayStart = _getFreeSpace(
3213                                 scmoUnion->arrayValue,
3214                                 loop*sizeof(SCMBUnion),
3215                                 pmem);
3216                 
3217                             ConstArrayIterator<Sint8> iterator(*x);
3218                 
3219                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3220                             for (Uint32 i = 0; i < loop; i++)
3221                             {
3222                                 ptargetUnion[i].simple.val.s8  = iterator[i];
3223                                 ptargetUnion[i].simple.hasValue = true;
3224                             }
3225                             break;
3226 thilo.boehm 1.3         }
3227                 
3228                     case CIMTYPE_UINT16:
3229                         {
3230                             Array<Uint16> *x = reinterpret_cast<Array<Uint16>*>(&u);
3231                             // n can be invalid after re-allocation in _getFreeSpace !
3232                             loop = n = x->size();
3233                             arrayStart = _getFreeSpace(
3234                                 scmoUnion->arrayValue,
3235                                 loop*sizeof(SCMBUnion),
3236                                 pmem);
3237                 
3238                             ConstArrayIterator<Uint16> iterator(*x);
3239                 
3240                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3241                             for (Uint32 i = 0; i < loop; i++)
3242                             {
3243                                 ptargetUnion[i].simple.val.u16  = iterator[i];
3244                                 ptargetUnion[i].simple.hasValue = true;
3245                             }
3246                             break;
3247 thilo.boehm 1.3         }
3248                 
3249                     case CIMTYPE_SINT16:
3250                         {
3251                             Array<Sint16> *x = reinterpret_cast<Array<Sint16>*>(&u);
3252                             // n can be invalid after re-allocation in _getFreeSpace !
3253                             loop = n = x->size();
3254                             arrayStart = _getFreeSpace(
3255                                 scmoUnion->arrayValue,
3256                                 loop*sizeof(SCMBUnion),
3257                                 pmem);
3258                 
3259                             ConstArrayIterator<Sint16> iterator(*x);
3260                 
3261                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3262                             for (Uint32 i = 0; i < loop; i++)
3263                             {
3264                                 ptargetUnion[i].simple.val.s16  = iterator[i];
3265                                 ptargetUnion[i].simple.hasValue = true;
3266                             }
3267                             break;
3268 thilo.boehm 1.3         }
3269                 
3270                     case CIMTYPE_UINT32:
3271                         {
3272                             Array<Uint32> *x = reinterpret_cast<Array<Uint32>*>(&u);
3273                             // n can be invalid after re-allocation in _getFreeSpace !
3274                             loop = n = x->size();
3275                             arrayStart = _getFreeSpace(
3276                                 scmoUnion->arrayValue,
3277                                 loop*sizeof(SCMBUnion),
3278                                 pmem);
3279                 
3280                             ConstArrayIterator<Uint32> iterator(*x);
3281                 
3282                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3283                             for (Uint32 i = 0; i < loop; i++)
3284                             {
3285                                 ptargetUnion[i].simple.val.u32  = iterator[i];
3286                                 ptargetUnion[i].simple.hasValue = true;
3287                             }
3288                             break;
3289 thilo.boehm 1.3         }
3290                 
3291                     case CIMTYPE_SINT32:
3292                         {
3293                             Array<Sint32> *x = reinterpret_cast<Array<Sint32>*>(&u);
3294                             // n can be invalid after re-allocation in _getFreeSpace !
3295                             loop = n = x->size();
3296                             arrayStart = _getFreeSpace(
3297                                 scmoUnion->arrayValue,
3298                                 loop*sizeof(SCMBUnion),
3299                                 pmem);
3300                 
3301                             ConstArrayIterator<Sint32> iterator(*x);
3302                 
3303                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3304                             for (Uint32 i = 0; i < loop; i++)
3305                             {
3306                                 ptargetUnion[i].simple.val.s32  = iterator[i];
3307                                 ptargetUnion[i].simple.hasValue = true;
3308                             }
3309                             break;
3310 thilo.boehm 1.3         }
3311                 
3312                     case CIMTYPE_UINT64:
3313                         {
3314                             Array<Uint64> *x = reinterpret_cast<Array<Uint64>*>(&u);
3315                             // n can be invalid after re-allocation in _getFreeSpace !
3316                             loop = n = x->size();
3317                             arrayStart = _getFreeSpace(
3318                                 scmoUnion->arrayValue,
3319                                 loop*sizeof(SCMBUnion),
3320                                 pmem);
3321                 
3322                             ConstArrayIterator<Uint64> iterator(*x);
3323                 
3324                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3325                             for (Uint32 i = 0; i < loop; i++)
3326                             {
3327                                 ptargetUnion[i].simple.val.u64  = iterator[i];
3328                                 ptargetUnion[i].simple.hasValue = true;
3329                             }
3330                             break;
3331 thilo.boehm 1.3         }
3332                 
3333                     case CIMTYPE_SINT64:
3334                         {
3335                             Array<Sint64> *x = reinterpret_cast<Array<Sint64>*>(&u);
3336                             // n can be invalid after re-allocation in _getFreeSpace !
3337                             loop = n = x->size();
3338                             arrayStart = _getFreeSpace(
3339                                 scmoUnion->arrayValue,
3340                                 loop*sizeof(SCMBUnion),
3341                                 pmem);
3342                 
3343                             ConstArrayIterator<Sint64> iterator(*x);
3344                 
3345                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3346                             for (Uint32 i = 0; i < loop; i++)
3347                             {
3348                                 ptargetUnion[i].simple.val.s64  = iterator[i];
3349                                 ptargetUnion[i].simple.hasValue = true;
3350                             }
3351                             break;
3352 thilo.boehm 1.3         }
3353                 
3354                     case CIMTYPE_REAL32:
3355                         {
3356                             Array<Real32> *x = reinterpret_cast<Array<Real32>*>(&u);
3357                             // n can be invalid after re-allocation in _getFreeSpace !
3358                             loop = n = x->size();
3359                             arrayStart = _getFreeSpace(
3360                                 scmoUnion->arrayValue,
3361                                 loop*sizeof(SCMBUnion),
3362                                 pmem);
3363                 
3364                             ConstArrayIterator<Real32> iterator(*x);
3365                 
3366                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3367                             for (Uint32 i = 0; i < loop; i++)
3368                             {
3369                                 ptargetUnion[i].simple.val.r32  = iterator[i];
3370                                 ptargetUnion[i].simple.hasValue = true;
3371                             }
3372                             break;
3373 thilo.boehm 1.3         }
3374                 
3375                     case CIMTYPE_REAL64:
3376                         {
3377                             Array<Real64> *x = reinterpret_cast<Array<Real64>*>(&u);
3378                             // n can be invalid after re-allocation in _getFreeSpace !
3379                             loop = n = x->size();
3380                             arrayStart = _getFreeSpace(
3381                                 scmoUnion->arrayValue,
3382                                 loop*sizeof(SCMBUnion),
3383                                 pmem);
3384                 
3385                             ConstArrayIterator<Real64> iterator(*x);
3386                 
3387                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3388                             for (Uint32 i = 0; i < loop; i++)
3389                             {
3390                                 ptargetUnion[i].simple.val.r64  = iterator[i];
3391                                 ptargetUnion[i].simple.hasValue = true;
3392                             }
3393                             break;
3394 thilo.boehm 1.3         }
3395                 
3396                     case CIMTYPE_CHAR16:
3397                         {
3398                             Array<Char16> *x = reinterpret_cast<Array<Char16>*>(&u);
3399                             // n can be invalid after re-allocation in _getFreeSpace !
3400                             loop = n = x->size();
3401                             arrayStart = _getFreeSpace(
3402                                 scmoUnion->arrayValue,
3403                                 loop*sizeof(SCMBUnion),
3404                                 pmem);
3405                 
3406                             ConstArrayIterator<Char16> iterator(*x);
3407                 
3408                             ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
3409                             for (Uint32 i = 0; i < loop; i++)
3410                             {
3411                                 ptargetUnion[i].simple.val.c16  = iterator[i];
3412                                 ptargetUnion[i].simple.hasValue = true;
3413                             }
3414                             break;
3415 thilo.boehm 1.3         }
3416                 
3417                     case CIMTYPE_STRING:
3418                         {
3419                             Array<String> *x = reinterpret_cast<Array<String>*>(&u);
3420                             // n can be invalid after re-allocation in _getFreeSpace !
3421                             loop = n = x->size();
3422                 
3423                             arrayStart = _getFreeSpace(
3424                                 scmoUnion->arrayValue,
3425                                 loop*sizeof(SCMBUnion),
3426                                 pmem);
3427                 
3428                             ConstArrayIterator<String> iterator(*x);
3429                 
3430                             for (Uint32 i = 0; i < loop ; i++)
3431                             {
3432                                 // the pointer has to be set eache loop,
3433                                 // because a reallocation may take place.
3434                                 ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
3435                                 _setString( iterator[i],ptargetUnion[i].stringValue, pmem );
3436 thilo.boehm 1.3             }
3437                 
3438                             break;
3439                         }
3440                 
3441                     case CIMTYPE_DATETIME:
3442                         {
3443                             Array<CIMDateTime> *x = reinterpret_cast<Array<CIMDateTime>*>(&u);
3444                             // n can be invalid after reallocation in _getFreeSpace !
3445                             loop = n = x->size();
3446                 
3447                             arrayStart = _getFreeSpace(
3448                                 scmoUnion->arrayValue,
3449                                 loop*sizeof(SCMBUnion),
3450                                 pmem);
3451                 
3452                             ConstArrayIterator<CIMDateTime> iterator(*x);
3453                 
3454                             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
3455                 
3456                             for (Uint32 i = 0; i < loop ; i++)
3457 thilo.boehm 1.3             {
3458                                 memcpy(
3459                                     &(ptargetUnion[i].dateTimeValue),
3460                                     iterator[i]._rep,
3461                                     sizeof(SCMBDateTime));
3462                             }
3463                             break;
3464                         }
3465                 
3466                     case CIMTYPE_REFERENCE:
3467                         {
3468                             Array<CIMObjectPath> *x =
3469                                 reinterpret_cast<Array<CIMObjectPath>*>(&u);
3470                 
3471                             // if the array was previously set, delete the references !
3472                             _deleteArrayExtReference(scmoUnion->arrayValue,pmem);
3473                 
3474                             // n can be invalid after reallocation in _getFreeSpace !
3475                             loop = n = x->size();
3476                 
3477                             arrayStart = _getFreeSpace(
3478 thilo.boehm 1.3                 scmoUnion->arrayValue,
3479                                 loop*sizeof(SCMBUnion),
3480                                 pmem);
3481                 
3482                             ConstArrayIterator<CIMObjectPath> iterator(*x);
3483                 
3484                             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
3485                 
3486                             for (Uint32 i = 0; i < loop ; i++)
3487                             {
3488                 
3489                                 ptargetUnion[i].extRefPtr =
3490                                     new SCMOInstance(
3491                                         iterator[i],
3492                                         &(((const char*)*pmem)[startNS]),
3493                                         sizeNS-1);
3494                                 // Was the conversion successful?
3495                                 if (ptargetUnion[i].extRefPtr->isEmpty())
3496                                 {
3497                                     // N0, delete the SCMOInstance.
3498                                     delete ptargetUnion[i].extRefPtr;
3499 thilo.boehm 1.3                     ptargetUnion[i].extRefPtr = 0;
3500                                 }
3501                                 else
3502                                 {
3503                                     _setExtRefIndex(&(ptargetUnion[i]),pmem);
3504                                 }
3505                             }
3506                 
3507                             break;
3508                         }
3509                     case CIMTYPE_OBJECT:
3510                         {
3511                             Array<CIMObject> *x =
3512                                 reinterpret_cast<Array<CIMObject>*>(&u);
3513                 
3514                             // if the array was previously set, delete the references !
3515                             _deleteArrayExtReference(scmoUnion->arrayValue,pmem);
3516                 
3517                             // n can be invalid after reallocation in _getFreeSpace !
3518                             loop = n = x->size();
3519                 
3520 thilo.boehm 1.3             arrayStart = _getFreeSpace(
3521                                 scmoUnion->arrayValue,
3522                                 loop*sizeof(SCMBUnion),
3523                                 pmem);
3524                 
3525                             ConstArrayIterator<CIMObject> iterator(*x);
3526                 
3527                             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
3528                 
3529                             for (Uint32 i = 0; i < loop ; i++)
3530                             {
3531                                 if (iterator[i].isUninitialized())
3532                                 {
3533                                     // the Object was empty.
3534                                     ptargetUnion[i].extRefPtr = 0;
3535                                 }
3536                                 else
3537                                 {
3538                                     if (iterator[i].isClass())
3539                                     {
3540                                         CIMClass cimClass(iterator[i]);
3541 thilo.boehm 1.3 
3542                                         ptargetUnion[i].extRefPtr =
3543                                             new SCMOInstance(
3544                                                 cimClass,
3545                                                 (&((const char*)*pmem)[startNS]));
3546                                         // marke as class only !
3547                                         ptargetUnion[i].extRefPtr->
3548                                             inst.hdr->flags.isClassOnly=true;
3549                 
3550                                         // This function can cause a reallocation !
3551                                         // Pointers can be invalid after the call.
3552                                         _setExtRefIndex(&(ptargetUnion[i]),pmem);
3553                                     }
3554                                     else
3555                                     {
3556                                         CIMInstance theInst(iterator[i]);
3557                 
3558                                         ptargetUnion[i].extRefPtr =
3559                                             new SCMOInstance(
3560                                                 theInst,
3561                                                 &(((const char*)*pmem)[startNS]),
3562 thilo.boehm 1.3                                 sizeNS-1);
3563                                          // Was the conversion successful?
3564                                          if (ptargetUnion[i].extRefPtr->isEmpty())
3565                                          {
3566                                              // N0, delete the SCMOInstance.
3567                                              delete ptargetUnion[i].extRefPtr;
3568                                              ptargetUnion[i].extRefPtr = 0;
3569                                          }
3570                                          else
3571                                          {
3572                                              // This function can cause a reallocation !
3573                                              // Pointers can be invalid after the call.
3574                                              _setExtRefIndex(&(ptargetUnion[i]),pmem);
3575                                          }
3576                                     }
3577                                 }
3578                             }
3579                 
3580                             break;
3581                         }
3582                     case CIMTYPE_INSTANCE:
3583 thilo.boehm 1.3         {
3584                             Array<CIMInstance> *x =
3585                                 reinterpret_cast<Array<CIMInstance>*>(&u);
3586                 
3587                             // if the array was previously set, delete the references !
3588                             _deleteArrayExtReference(scmoUnion->arrayValue,pmem);
3589                 
3590                             // n can be invalid after reallocation in _getFreeSpace !
3591                             loop = n = x->size();
3592                 
3593                             arrayStart = _getFreeSpace(
3594                                 scmoUnion->arrayValue,
3595                                 loop*sizeof(SCMBUnion),
3596                                 pmem);
3597                 
3598                             ConstArrayIterator<CIMInstance> iterator(*x);
3599                 
3600                             ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
3601                 
3602                             for (Uint32 i = 0; i < loop ; i++)
3603                             {
3604 thilo.boehm 1.3                 if (iterator[i].isUninitialized())
3605                                 {
3606                                     // the Instance was empty.
3607                                     ptargetUnion[i].extRefPtr = 0;
3608                                 }
3609                                 else
3610                                 {
3611                                     ptargetUnion[i].extRefPtr =
3612                                         new SCMOInstance(
3613                                             iterator[i],
3614                                             &(((const char*)*pmem)[startNS]),
3615                                             sizeNS-1);
3616                                     // Was the conversion successful?
3617                                     if (ptargetUnion[i].extRefPtr->isEmpty())
3618                                     {
3619                                         // N0, delete the SCMOInstance.
3620                                         delete ptargetUnion[i].extRefPtr;
3621                                         ptargetUnion[i].extRefPtr = 0;
3622                                     }
3623                                     else
3624                                     {
3625 thilo.boehm 1.3                         // This function can cause a reallocation !
3626                                         // Pointers can be invalid after the call.
3627                                         _setExtRefIndex(&(ptargetUnion[i]),pmem);
3628                                     }
3629                 
3630                                 }
3631                             }
3632                 
3633                             break;
3634                         }
3635                     default:
3636                         {
3637                             PEGASUS_ASSERT(false);
3638                             break;
3639                         }
3640                     }
3641                 }
3642                 
3643                 
3644                 void SCMOInstance::_setUnionValue(
3645                     Uint64 start,
3646 thilo.boehm 1.3     SCMBMgmt_Header** pmem,
3647                     CIMType type,
3648                     Uint64 startNS,
3649                     Uint32 sizeNS,
3650                     Union& u)
3651                 {
3652                     SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);
3653                 
3654                     switch (type)
3655                     {
3656                     case CIMTYPE_BOOLEAN:
3657                         {
3658                             scmoUnion->simple.val.bin = u._booleanValue;
3659                             scmoUnion->simple.hasValue=true;
3660                             break;
3661                         }
3662                 
3663                     case CIMTYPE_UINT8:
3664                         {
3665                             scmoUnion->simple.val.u8 = u._uint8Value;
3666                             scmoUnion->simple.hasValue=true;
3667 thilo.boehm 1.3             break;
3668                         }
3669                 
3670                     case CIMTYPE_SINT8:
3671                         {
3672                             scmoUnion->simple.val.s8 = u._sint8Value;
3673                             scmoUnion->simple.hasValue=true;
3674                             break;
3675                         }
3676                 
3677                     case CIMTYPE_UINT16:
3678                         {
3679                             scmoUnion->simple.val.u16 = u._uint16Value;
3680                             scmoUnion->simple.hasValue=true;
3681                             break;
3682                         }
3683                 
3684                     case CIMTYPE_SINT16:
3685                         {
3686                             scmoUnion->simple.val.s16 = u._sint16Value;
3687                             scmoUnion->simple.hasValue=true;
3688 thilo.boehm 1.3             break;
3689                         }
3690                 
3691                     case CIMTYPE_UINT32:
3692                         {
3693                             scmoUnion->simple.val.u32 = u._uint32Value;
3694                             scmoUnion->simple.hasValue=true;
3695                             break;
3696                         }
3697                 
3698                     case CIMTYPE_SINT32:
3699                         {
3700                             scmoUnion->simple.val.s32 = u._sint32Value;
3701                             scmoUnion->simple.hasValue=true;
3702                             break;
3703                         }
3704                 
3705                     case CIMTYPE_UINT64:
3706                         {
3707                             scmoUnion->simple.val.u64 = u._uint64Value;
3708                             scmoUnion->simple.hasValue=true;
3709 thilo.boehm 1.3             break;
3710                         }
3711                 
3712                     case CIMTYPE_SINT64:
3713                         {
3714                             scmoUnion->simple.val.s64 = u._sint64Value;
3715                             scmoUnion->simple.hasValue=true;
3716                             break;
3717                         }
3718                 
3719                     case CIMTYPE_REAL32:
3720                         {
3721                             scmoUnion->simple.val.r32 = u._real32Value;
3722                             scmoUnion->simple.hasValue=true;
3723                             break;
3724                         }
3725                 
3726                     case CIMTYPE_REAL64:
3727                         {
3728                             scmoUnion->simple.val.r64 = u._real64Value;
3729                             scmoUnion->simple.hasValue=true;
3730 thilo.boehm 1.3             break;
3731                         }
3732                 
3733                     case CIMTYPE_CHAR16:
3734                         {
3735                             scmoUnion->simple.val.c16 = u._char16Value;
3736                             scmoUnion->simple.hasValue=true;
3737                             break;
3738                         }
3739                 
3740                     case CIMTYPE_STRING:
3741                         {
3742                             _setString(*((String*)((void*)&u)),
3743                                        scmoUnion->stringValue,
3744                                        pmem );
3745                             break;
3746                         }
3747                 
3748                     case CIMTYPE_DATETIME:
3749                         {
3750                             memcpy(
3751 thilo.boehm 1.3                 &scmoUnion->dateTimeValue,
3752                                 (*((CIMDateTime*)((void*)&u)))._rep,
3753                                 sizeof(SCMBDateTime));
3754                             break;
3755                         }
3756                 
3757                     case CIMTYPE_REFERENCE:
3758                         {
3759                             if (0 != scmoUnion->extRefPtr)
3760                             {
3761                                 delete scmoUnion->extRefPtr;
3762                                 scmoUnion->extRefPtr = 0;
3763                             }
3764                 
3765                             if (0 == u._referenceValue)
3766                             {
3767                               scmoUnion->extRefPtr = 0;
3768                               return;
3769                             }
3770                 
3771                             CIMObjectPath* theCIMObj =
3772 thilo.boehm 1.3                 (CIMObjectPath*)((void*)&u._referenceValue);
3773                 
3774                             scmoUnion->extRefPtr =
3775                                 new SCMOInstance(
3776                                     *theCIMObj,
3777                                     &(((const char*)*pmem)[startNS]),
3778                                     sizeNS-1);
3779                 
3780                             // Was the conversion successful?
3781                             if (scmoUnion->extRefPtr->isEmpty())
3782                             {
3783                                 // N0, delete the SCMOInstance.
3784                                 delete scmoUnion->extRefPtr;
3785                                 scmoUnion->extRefPtr = 0;
3786                             }
3787                             else
3788                             {
3789                                 // This function can cause a reallocation !
3790                                 // Pointers can be invalid after the call.
3791                                 _setExtRefIndex(scmoUnion,pmem);
3792                             }
3793 thilo.boehm 1.3 
3794                             break;
3795                         }
3796                     case CIMTYPE_OBJECT:
3797                         {
3798                             if (0 != scmoUnion->extRefPtr)
3799                             {
3800                                 delete scmoUnion->extRefPtr;
3801                                 scmoUnion->extRefPtr = 0;
3802                             }
3803                 
3804                             if (0 == u._referenceValue)
3805                             {
3806                               scmoUnion->extRefPtr=0;
3807                               return;
3808                             }
3809                 
3810                             CIMObject* theCIMObject =(CIMObject*)((void*)&u._objectValue);
3811                 
3812                             if (theCIMObject->isUninitialized())
3813                             {
3814 thilo.boehm 1.3                 // the Object was empty.
3815                                 scmoUnion->extRefPtr = 0;
3816                             }
3817                             else
3818                             {
3819                                 if (theCIMObject->isClass())
3820                                 {
3821                                     CIMClass cimClass(*theCIMObject);
3822                 
3823                                     scmoUnion->extRefPtr =
3824                                         new SCMOInstance(
3825                                             cimClass,
3826                                             (&((const char*)*pmem)[startNS]));
3827                                     // marke as class only !
3828                                     scmoUnion->extRefPtr->inst.hdr->flags.isClassOnly=true;
3829                 
3830                                     // This function can cause a reallocation !
3831                                     // Pointers can be invalid after the call.
3832                                     _setExtRefIndex(scmoUnion,pmem);
3833                                 }
3834                                 else
3835 thilo.boehm 1.3                 {
3836                                     CIMInstance theCIMInst(*theCIMObject);
3837                 
3838                                     scmoUnion->extRefPtr =
3839                                         new SCMOInstance(
3840                                             theCIMInst,
3841                                             &(((const char*)*pmem)[startNS]),
3842                                             sizeNS-1);
3843                 
3844                                      // Was the conversion successful?
3845                                      if (scmoUnion->extRefPtr->isEmpty())
3846                                      {
3847                                          // N0, delete the SCMOInstance.
3848                                          delete scmoUnion->extRefPtr;
3849                                          scmoUnion->extRefPtr = 0;
3850                                      }
3851                                      else
3852                                      {
3853                                          // This function can cause a reallocation !
3854                                          // Pointers can be invalid after the call.
3855                                          _setExtRefIndex(scmoUnion,pmem);
3856 thilo.boehm 1.3                      }
3857                                 }
3858                             }
3859                             break;
3860                         }
3861                     case CIMTYPE_INSTANCE:
3862                         {
3863                             if (0 != scmoUnion->extRefPtr)
3864                             {
3865                                 delete scmoUnion->extRefPtr;
3866                                 scmoUnion->extRefPtr = 0;
3867                             }
3868                 
3869                             if (0 == u._referenceValue)
3870                             {
3871                               scmoUnion->extRefPtr=0;
3872                               return;
3873                             }
3874                 
3875                             CIMInstance* theCIMInst =
3876                                 (CIMInstance*)((void*)&u._instanceValue);
3877 thilo.boehm 1.3 
3878                             if (theCIMInst->isUninitialized())
3879                             {
3880                                 // the Instance was empty.
3881                                 scmoUnion->extRefPtr = 0;
3882                             }
3883                             else
3884                             {
3885                                 scmoUnion->extRefPtr =
3886                                     new SCMOInstance(
3887                                         *theCIMInst,
3888                                         &(((const char*)*pmem)[startNS]),
3889                                         sizeNS-1);
3890                 
3891                                  // Was the conversion successful?
3892                                  if (scmoUnion->extRefPtr->isEmpty())
3893                                  {
3894                                      // N0, delete the SCMOInstance.
3895                                      delete scmoUnion->extRefPtr;
3896                                      scmoUnion->extRefPtr = 0;
3897                                  }
3898 thilo.boehm 1.3                  else
3899                                  {
3900                                      // This function can cause a reallocation !
3901                                      // Pointers can be invalid after the call.
3902                                      _setExtRefIndex(scmoUnion,pmem);
3903                                  }
3904                             }
3905                             break;
3906                         }
3907                     default:
3908                         {
3909                             PEGASUS_ASSERT(false);
3910                             break;
3911                         }
3912                     }
3913                 }
3914                 
3915                 SCMO_RC SCMOInstance::_getPropertyAtNodeIndex(
3916                         Uint32 node,
3917                         const char** pname,
3918                         CIMType& type,
3919 thilo.boehm 1.3         const SCMBUnion** pvalue,
3920                         Boolean& isArray,
3921                         Uint32& size ) const
3922                 {
3923                     SCMBValue* theInstPropNodeArray =
3924                         (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
3925                 
3926                     // create a pointer to property node array of the class.
3927                     Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->propertySet.nodeArray.start;
3928                     SCMBClassPropertyNode* theClassPropNodeArray =
3929                         (SCMBClassPropertyNode*)&(inst.hdr->theClass.ptr->cls.base)[idx];
3930                 
3931                     // the property name is always from the class.
3932                     // return the absolut pointer to the property name,
3933                     // the caller has to copy the name!
3934                     *pname=_getCharString(
3935                         theClassPropNodeArray[node].theProperty.name,
3936                         inst.hdr->theClass.ptr->cls.base);
3937                 
3938                     // the property was set by the provider.
3939                     if (theInstPropNodeArray[node].flags.isSet)
3940 thilo.boehm 1.3     {
3941                 
3942                         type = theInstPropNodeArray[node].valueType;
3943                         isArray = theInstPropNodeArray[node].flags.isArray;
3944                         if (isArray)
3945                         {
3946                             size = theInstPropNodeArray[node].valueArraySize;
3947                         }
3948                 
3949                         if (theInstPropNodeArray[node].flags.isNull)
3950                         {
3951                             return SCMO_NULL_VALUE;
3952                         }
3953                 
3954                         // calculate the relative index for the value.
3955                         Uint64 start =
3956                             (const char*)&(theInstPropNodeArray[node].value) -
3957                             inst.base;
3958                 
3959                         // the caller has to copy the value !
3960                         *pvalue = _resolveSCMBUnion(type,isArray,size,start,inst.base);
3961 thilo.boehm 1.3 
3962                         return SCMO_OK;
3963                     }
3964                 
3965                     // the get the defaults out of the class.
3966                     type = theClassPropNodeArray[node].theProperty.defaultValue.valueType;
3967                     isArray =
3968                         theClassPropNodeArray[node].theProperty.defaultValue.flags.isArray;
3969                     if (isArray)
3970                     {
3971                         size = theClassPropNodeArray[node].
3972                                    theProperty.defaultValue.valueArraySize;
3973                     }
3974                 
3975                     if (theClassPropNodeArray[node].theProperty.defaultValue.flags.isNull)
3976                     {
3977                         return SCMO_NULL_VALUE;
3978                     }
3979                 
3980                     // calcutate the relativ start address of the value
3981                     Uint64 start =
3982 thilo.boehm 1.3         (const char*)
3983                                &(theClassPropNodeArray[node].theProperty.defaultValue.value) -
3984                         (inst.hdr->theClass.ptr->cls.base);
3985                 
3986                     *pvalue = _resolveSCMBUnion(
3987                         type,
3988                         isArray,
3989                         size,
3990                         start,
3991                         (inst.hdr->theClass.ptr->cls.base)
3992                         );
3993                 
3994                     return SCMO_OK;
3995                 
3996                 }
3997                 
3998                 SCMOInstance SCMOInstance::clone(Boolean objectPathOnly) const
3999                 {
4000                     if (objectPathOnly)
4001                     {
4002                         // Create a new, empty SCMOInstance
4003 thilo.boehm 1.3         SCMOInstance newInst(*(this->inst.hdr->theClass.ptr));
4004                 
4005                         // Copy the host name to tha new instance-
4006                         _setBinary(
4007                             _resolveDataPtr(this->inst.hdr->hostName,this->inst.base),
4008                             this->inst.hdr->hostName.size,
4009                             newInst.inst.hdr->hostName,
4010                             &newInst.inst.mem);
4011                 
4012                         newInst.inst.hdr->flags.isCompromised =
4013                             this->inst.hdr->flags.isCompromised;
4014                 
4015                         // If the instance contains a user set class and/or name space name
4016                         if (this->inst.hdr->flags.isCompromised)
4017                         {
4018                             // Copy the class name to tha new instance-
4019                             _setBinary(
4020                                 _resolveDataPtr(this->inst.hdr->instClassName,this->inst.base),
4021                                 this->inst.hdr->instClassName.size,
4022                                 newInst.inst.hdr->instClassName,
4023                                 &newInst.inst.mem);
4024 thilo.boehm 1.3 
4025                             // Copy the name space name to tha new instance-
4026                             _setBinary(
4027                                 _resolveDataPtr(this->inst.hdr->instNameSpace,this->inst.base),
4028                                 this->inst.hdr->instNameSpace.size,
4029                                 newInst.inst.hdr->instNameSpace,
4030                                 &newInst.inst.mem);
4031                         }
4032                 
4033                         // Copy the key bindings to that new instance.
4034                         this->_copyKeyBindings(newInst);
4035                 
4036                         return newInst;
4037                     }
4038                 
4039                     SCMOInstance newInst;
4040                     newInst.inst.base = inst.base;
4041                     newInst._clone();
4042                 
4043                     return newInst;
4044                 }
4045 thilo.boehm 1.3 
4046                 void SCMOInstance::_clone()
4047                 {
4048                     char* newBase;
4049                     newBase = (char*)malloc((size_t)inst.mem->totalSize);
4050                     if (0 == newBase )
4051                     {
4052                         throw PEGASUS_STD(bad_alloc)();
4053                     }
4054                 
4055                     memcpy( newBase,inst.base,(size_t)inst.mem->totalSize);
4056                 
4057                     // make new new memory block to mine.
4058                     inst.base = newBase;
4059                     // reset the refcounter of this instance
4060                     inst.hdr->refCount = 1;
4061                     // keep the ref counter of the class correct !
4062                     inst.hdr->theClass.ptr = new SCMOClass(*(inst.hdr->theClass.ptr));
4063                     // keep the ref count for external references
4064                     _copyExternalReferences();
4065                 
4066 thilo.boehm 1.3 }
4067                 
4068                 void SCMOInstance::_copyKeyBindings(SCMOInstance& targetInst) const
4069                 {
4070                     Uint32 noBindings = inst.hdr->numberKeyBindings;
4071                 
4072                     SCMBKeyBindingValue* sourceArray =
4073                         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
4074                 
4075                     // Address the class keybinding information
4076                     const SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
4077                     const char * clsbase = inst.hdr->theClass.ptr->cls.base;
4078                     SCMBKeyBindingNode* scmoClassArray =
4079                         (SCMBKeyBindingNode*)&(clsbase[clshdr->keyBindingSet.nodeArray.start]);
4080                 
4081                     SCMBKeyBindingValue* targetArray;
4082                 
4083                     for (Uint32 i = 0; i < noBindings; i++)
4084                     {
4085                         // hast to be set every time, because of reallocation.
4086                         targetArray=(SCMBKeyBindingValue*)&(targetInst.inst.base)
4087 thilo.boehm 1.3                              [targetInst.inst.hdr->keyBindingArray.start];
4088                         if(sourceArray[i].isSet)
4089                         {
4090                             // this has to be done on the target instance to keep constantness.
4091                             targetInst._setKeyBindingFromSCMBUnion(
4092                                 scmoClassArray[i].type,
4093                                 sourceArray[i].data,
4094                                 inst.base,
4095                                 targetArray[i]);
4096                         }
4097                     }
4098                 
4099                     // Are there user defined key bindings ?
4100                     if (0 != inst.hdr->numberUserKeyBindings)
4101                     {
4102                         SCMBUserKeyBindingElement* theUserDefKBElement =
4103                             (SCMBUserKeyBindingElement*)
4104                                  &(inst.base[inst.hdr->userKeyBindingElement.start]);
4105                 
4106                         for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
4107                         {
4108 thilo.boehm 1.3             if (theUserDefKBElement->value.isSet)
4109                             {
4110                                 targetInst._setUserDefinedKeyBinding(*theUserDefKBElement,
4111                                                                         inst.base);
4112                             }
4113                 
4114                             theUserDefKBElement =
4115                                 (SCMBUserKeyBindingElement*)
4116                                      &(inst.base[theUserDefKBElement->nextElement.start]);
4117                         } // for all user def. key bindings.
4118                     }
4119                 }
4120                 
4121                 
4122                 void SCMOInstance::_setUserDefinedKeyBinding(
4123                         SCMBUserKeyBindingElement& theInsertElement,
4124                         char* elementBase)
4125                 {
4126                 
4127                     SCMBUserKeyBindingElement* ptrNewElement;
4128                 
4129 thilo.boehm 1.3     // get an exsiting or new user defined key binding
4130                     ptrNewElement = _getUserDefinedKeyBinding(
4131                         _getCharString(theInsertElement.name,elementBase),
4132                         // lenght is without the trailing '\0'
4133                         theInsertElement.name.size-1,
4134                         theInsertElement.type);
4135                 
4136                     // Copy the data
4137                     _setKeyBindingFromSCMBUnion(
4138                                 theInsertElement.type,
4139                                 theInsertElement.value.data,
4140                                 elementBase,
4141                                 ptrNewElement->value);
4142                 
4143                 }
4144                 
4145                 
4146                 SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBindingAt(
4147                     Uint32 index ) const
4148                 {
4149                 
4150 thilo.boehm 1.3     // Get the start element
4151                     SCMBUserKeyBindingElement *ptrNewElement =
4152                         (SCMBUserKeyBindingElement*)
4153                              &(inst.base[inst.hdr->userKeyBindingElement.start]);
4154                 
4155                     // calculate the index within the user defined key bindings
4156                     index = index - inst.hdr->numberKeyBindings;
4157                 
4158                     // traverse trough the user defindes key binding nodes.
4159                     for (Uint32 i = 0; i < index; i ++)
4160                     {
4161                         PEGASUS_ASSERT(ptrNewElement->nextElement.start != 0);
4162                         ptrNewElement = (SCMBUserKeyBindingElement*)
4163                               &(inst.base[ptrNewElement->nextElement.start]);
4164                     }
4165                 
4166                     return ptrNewElement;
4167                 }
4168                 
4169                 SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBinding(
4170                     const char* name,
4171 thilo.boehm 1.3     Uint32 nameLen,
4172                     CIMType type)
4173                 {
4174                     SCMBDataPtr newElement;
4175                     SCMBUserKeyBindingElement* ptrNewElement;
4176                     Uint32 node;
4177                 
4178                     // is the key binding already stored as user defind in the instance ?
4179                     if (SCMO_OK == _getUserKeyBindingNodeIndex(node,name))
4180                     {
4181                        ptrNewElement = _getUserDefinedKeyBindingAt(node);
4182                     }
4183                     else // Not found, create a new user defined key binding.
4184                     {
4185                 
4186                         _getFreeSpace(newElement,
4187                                       sizeof(SCMBUserKeyBindingElement),
4188                                       &inst.mem);
4189                 
4190                         ptrNewElement =
4191                             (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);
4192 thilo.boehm 1.3 
4193                         // link new first user defined key binding element into chain:
4194                         // - Assing the start point of user key binding element chain
4195                         //   to the next element of the new element.
4196                         ptrNewElement->nextElement.start =
4197                             inst.hdr->userKeyBindingElement.start;
4198                         ptrNewElement->nextElement.size =
4199                             inst.hdr->userKeyBindingElement.size;
4200                         // - Assing the the new element
4201                         //   to the  start point of user key binding element chain
4202                         inst.hdr->userKeyBindingElement.start = newElement.start;
4203                         inst.hdr->userKeyBindingElement.size = newElement.size;
4204                         // Adjust the couter of user defined key bindings.
4205                         inst.hdr->numberUserKeyBindings++;
4206                 
4207                 
4208                         // Copy the type
4209                         ptrNewElement->type = type;
4210                         ptrNewElement->value.isSet=false;
4211                 
4212                         // Copy the key binding name including the trailing '\0'
4213 thilo.boehm 1.3         _setBinary(name,nameLen+1,ptrNewElement->name,&inst.mem);
4214                 
4215                         // reset the pointer. May the instance was reallocated.
4216                         ptrNewElement =
4217                             (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);
4218                 
4219                     }
4220                 
4221                 
4222                     return ptrNewElement;
4223                 
4224                 }
4225                 
4226                 Uint32 SCMOInstance::getPropertyCount() const
4227                 {
4228                     if (inst.hdr->flags.isFiltered)
4229                     {
4230                         return(inst.hdr->filterProperties);
4231                     }
4232                 
4233                     return(inst.hdr->numberProperties);
4234 thilo.boehm 1.3 }
4235                 
4236                 SCMBUnion * SCMOInstance::_resolveSCMBUnion(
4237                     CIMType type,
4238                     Boolean isArray,
4239                     Uint32 size,
4240                     Uint64 start,
4241                     char* base) const
4242                 {
4243                 
4244                     SCMBUnion* u = (SCMBUnion*)&(base[start]);
4245                 
4246                     SCMBUnion* av = 0;
4247                 
4248                     if (isArray)
4249                     {
4250                         if (size == 0)
4251                         {
4252                             return 0;
4253                         }
4254                         av = (SCMBUnion*)&(base[u->arrayValue.start]);
4255 thilo.boehm 1.3     }
4256                 
4257                     switch (type)
4258                     {
4259                     case CIMTYPE_BOOLEAN:
4260                     case CIMTYPE_UINT8:
4261                     case CIMTYPE_SINT8:
4262                     case CIMTYPE_UINT16:
4263                     case CIMTYPE_SINT16:
4264                     case CIMTYPE_UINT32:
4265                     case CIMTYPE_SINT32:
4266                     case CIMTYPE_UINT64:
4267                     case CIMTYPE_SINT64:
4268                     case CIMTYPE_REAL32:
4269                     case CIMTYPE_REAL64:
4270                     case CIMTYPE_CHAR16:
4271                     case CIMTYPE_DATETIME:
4272                     case CIMTYPE_REFERENCE:
4273                     case CIMTYPE_OBJECT:
4274                     case CIMTYPE_INSTANCE:
4275                         {
4276 thilo.boehm 1.3             if(isArray)
4277                             {
4278                                 return (av);
4279                             }
4280                             else
4281                             {
4282                                 return(u);
4283                             }
4284                             break;
4285                         }
4286                 
4287                     case CIMTYPE_STRING:
4288                         {
4289                             SCMBUnion *ptr;
4290                 
4291                             if (isArray)
4292                             {
4293                 
4294                                 ptr = (SCMBUnion*)malloc(size*sizeof(SCMBUnion));
4295                                 if (ptr == 0 )
4296                                 {
4297 thilo.boehm 1.3                     throw PEGASUS_STD(bad_alloc)();
4298                                 }
4299                 
4300                                 for(Uint32 i = 0; i < size; i++)
4301                                 {
4302                                     // resolv relative pointer to absolute pointer
4303                                     ptr[i].extString.pchar =
4304                                         (char*)_getCharString(av[i].stringValue,base);
4305                                     // lenght with out the trailing /0 !
4306                                     ptr[i].extString.length = av[i].stringValue.size-1;
4307                                 }
4308                             }
4309                             else
4310                             {
4311                                 ptr = (SCMBUnion*)malloc(sizeof(SCMBUnion));
4312                                 ptr->extString.pchar =
4313                                     (char*)_getCharString(u->stringValue,base);
4314                                 // lenght with out the trailing /0 !
4315                                 ptr->extString.length = u->stringValue.size-1;
4316                             }
4317                 
4318 thilo.boehm 1.3              return(ptr);
4319                             break;
4320                         }
4321                     default:
4322                         {
4323                             PEGASUS_ASSERT(false);
4324                             break;
4325                         }
4326                     }
4327                     return 0;
4328                 }
4329                 
4330                 void SCMOInstance::clearKeyBindings()
4331                 {
4332                     _copyOnWrite();
4333                 
4334                     // First destroy all external references in the key bindings
4335                     _destroyExternalKeyBindings();
4336                 
4337                     // reset user keybindings
4338                     inst.hdr->numberUserKeyBindings = 0;
4339 thilo.boehm 1.3     inst.hdr->userKeyBindingElement.start = 0;
4340                     inst.hdr->userKeyBindingElement.size = 0;
4341                 
4342                     // Allocate a clean the SCMOInstanceKeyBindingArray
4343                     _getFreeSpace(
4344                           inst.hdr->keyBindingArray,
4345                           sizeof(SCMBKeyBindingValue)*inst.hdr->numberKeyBindings,
4346                           &inst.mem);
4347                 }
4348                 
4349                 Uint32 SCMOInstance::getKeyBindingCount() const
4350                 {
4351                     // count of class keys + user definded keys
4352                     return(inst.hdr->numberKeyBindings+
4353                            inst.hdr->numberUserKeyBindings);
4354                 }
4355                 
4356                 
4357                 SCMO_RC SCMOInstance::getKeyBindingAt(
4358                         Uint32 node,
4359                         const char** pname,
4360 thilo.boehm 1.3         CIMType& type,
4361                         const SCMBUnion** pvalue) const
4362                 {
4363                     SCMO_RC rc;
4364                     const SCMBUnion* pdata=0;
4365                     Uint32 pnameLen=0;
4366                 
4367                     *pname = 0;
4368                     *pvalue = 0;
4369                 
4370                     // count of class keys + user definded keys
4371                     if (node >= (inst.hdr->numberKeyBindings+
4372                                  inst.hdr->numberUserKeyBindings))
4373                     {
4374                         return SCMO_INDEX_OUT_OF_BOUND;
4375                     }
4376                 
4377                     rc = _getKeyBindingDataAtNodeIndex(node,pname,pnameLen,type,&pdata);
4378                     if (rc != SCMO_OK)
4379                     {
4380                         return rc;
4381 thilo.boehm 1.3     }
4382                 
4383                     *pvalue = _resolveSCMBUnion(
4384                         type,
4385                         false,  // A key binding can never be an array.
4386                         0,
4387                         (char*)pdata-inst.base,
4388                         inst.base);
4389                 
4390                     return SCMO_OK;
4391                 
4392                 }
4393                 
4394                 SCMO_RC SCMOInstance::getKeyBinding(
4395                     const char* name,
4396                     CIMType& type,
4397                     const SCMBUnion** pvalue) const
4398                 {
4399                     SCMO_RC rc;
4400                     Uint32 node;
4401                     const char* pname=0;
4402 thilo.boehm 1.3     const SCMBUnion* pdata=0;
4403                     Uint32 pnameLen=0;
4404                 
4405                     *pvalue = 0;
4406                 
4407                     rc = inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name);
4408                     if (rc != SCMO_OK)
4409                     {
4410                         // look at the user defined key bindings.
4411                         rc = _getUserKeyBindingNodeIndex(node,name);
4412                         if (rc != SCMO_OK)
4413                         {
4414                             return rc;
4415                         }
4416                     }
4417                 
4418                     rc = _getKeyBindingDataAtNodeIndex(node,&pname,pnameLen,type,&pdata);
4419                 
4420                     if (rc != SCMO_OK)
4421                     {
4422                         return rc;
4423 thilo.boehm 1.3     }
4424                 
4425                     *pvalue = _resolveSCMBUnion(
4426                         type,
4427                         false,  // A key binding can never be an array.
4428                         0,
4429                         (char*)pdata-inst.base,
4430                         inst.base);
4431                 
4432                     return SCMO_OK;
4433                 }
4434                 
4435                 
4436                 SCMO_RC SCMOInstance::_getKeyBindingDataAtNodeIndex(
4437                     Uint32 node,
4438                     const char** pname,
4439                     Uint32 & pnameLen,
4440                     CIMType & type,
4441                     const SCMBUnion** pdata) const
4442                 {
4443                     if (node < inst.hdr->numberKeyBindings)
4444 thilo.boehm 1.3     {
4445                         SCMBKeyBindingValue* theInstKeyBindValueArray =
4446                             (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
4447                 
4448                         // create a pointer to key binding node array of the class.
4449                         Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
4450                             keyBindingSet.nodeArray.start;
4451                         SCMBKeyBindingNode* theClassKeyBindNodeArray =
4452                             (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
4453                 
4454                         type = theClassKeyBindNodeArray[node].type;
4455                 
4456                         // First resolve pointer to the key binding name
4457                         pnameLen = theClassKeyBindNodeArray[node].name.size;
4458                         *pname = _getCharString(
4459                             theClassKeyBindNodeArray[node].name,
4460                             inst.hdr->theClass.ptr->cls.base);
4461                 
4462                         // There is no value set in the instance
4463                         if (!theInstKeyBindValueArray[node].isSet)
4464                         {
4465 thilo.boehm 1.3             return SCMO_NULL_VALUE;
4466                         }
4467                 
4468                         *pdata = &(theInstKeyBindValueArray[node].data);
4469                     }
4470                     else // look at the user defined key bindings
4471                     {
4472                 
4473                         SCMBUserKeyBindingElement* theElem = _getUserDefinedKeyBindingAt(node);
4474                 
4475                         type = theElem->type;
4476                 
4477                         pnameLen = theElem->name.size;
4478                         *pname = _getCharString(theElem->name,inst.base);
4479                 
4480                         // There is no value set in the instance
4481                         if (!theElem->value.isSet)
4482                         {
4483                             return SCMO_NULL_VALUE;
4484                         }
4485                 
4486 thilo.boehm 1.3         *pdata = &(theElem->value.data);
4487                 
4488                     }
4489                 
4490                     return SCMO_OK;
4491                 }
4492                 
4493                 SCMO_RC SCMOInstance::_getUserKeyBindingNodeIndex(
4494                     Uint32& node,
4495                     const char* name) const
4496                 {
4497                 
4498                     Uint32 len = strlen(name);
4499                     node = 0;
4500                 
4501                     Uint64 elementStart = inst.hdr->userKeyBindingElement.start;
4502                 
4503                     while (elementStart != 0)
4504                     {
4505                         SCMBUserKeyBindingElement* theUserDefKBElement =
4506                             (SCMBUserKeyBindingElement*)&(inst.base[elementStart]);
4507 thilo.boehm 1.3 
4508                         if (_equalNoCaseUTF8Strings(
4509                             theUserDefKBElement->name,inst.base,name,len))
4510                         {
4511                             // the node index of a user defined key binding has an offset
4512                             // by the number of key bindings defined in the class
4513                             node = node + inst.hdr->numberKeyBindings;
4514                             return SCMO_OK;
4515                         }
4516                         node = node + 1;
4517                         elementStart = theUserDefKBElement->nextElement.start;
4518                     }
4519                 
4520                     return SCMO_NOT_FOUND;
4521                 
4522                 }
4523                 
4524                 CIMType SCMOInstance::_CIMTypeFromKeyBindingType(
4525                     const char* key,
4526                     CIMKeyBinding::Type t)
4527                 {
4528 thilo.boehm 1.3     switch( t )
4529                     {
4530                         case CIMKeyBinding::NUMERIC:
4531                             {
4532                                 if( *(key)=='-' )
4533                                 {
4534                                    Sint64 x;
4535                                    // check if it is realy an integer
4536                                    if (StringConversion::stringToSignedInteger(key, x))
4537                                    {
4538                                        return CIMTYPE_SINT64;
4539                                    }
4540                                    else
4541                                    {
4542                                        return CIMTYPE_REAL64;
4543                                    }
4544                                 }
4545                                 else
4546                                 {
4547                                     Uint64 x;
4548                                     // check if it is realy an integer
4549 thilo.boehm 1.3                     if (StringConversion::stringToUnsignedInteger(key, x))
4550                                     {
4551                                         return CIMTYPE_UINT64;
4552                                     }
4553                                     else
4554                                     {
4555                                         return CIMTYPE_REAL64;
4556                                     }
4557                                 }
4558                                 break;
4559                             }
4560                 
4561                 
4562                         case CIMKeyBinding::STRING:
4563                         {
4564                             return CIMTYPE_STRING;
4565                             break;
4566                         }
4567                 
4568                         case CIMKeyBinding::BOOLEAN:
4569                         {
4570 thilo.boehm 1.3             return CIMTYPE_BOOLEAN;
4571                             break;
4572                         }
4573                 
4574                         case CIMKeyBinding::REFERENCE:
4575                         {
4576                             return CIMTYPE_REFERENCE;
4577                             break;
4578                         }
4579                 
4580                         default:
4581                             return CIMTYPE_UINT64;
4582                     }
4583                     return CIMTYPE_UINT64;
4584                 }
4585                 
4586                 Boolean SCMOInstance::_setCimKeyBindingStringToSCMOKeyBindingValue(
4587                     const String& kbs,
4588                     CIMType type,
4589                     SCMBKeyBindingValue& scmoKBV
4590                     )
4591 thilo.boehm 1.3 {
4592                     scmoKBV.isSet=false;
4593                     // If it not a simple value, it will be over written.
4594                     scmoKBV.data.simple.hasValue=false;
4595                 
4596                     if ( kbs.size() == 0 && type != CIMTYPE_STRING)
4597                     {
4598                         // The string is empty ! Do nothing.
4599                         return false;
4600                     }
4601                 
4602                     CString a = kbs.getCString();
4603                     const char* v = a;
4604                 
4605                     switch (type)
4606                     {
4607                     case CIMTYPE_UINT8:
4608                         {
4609                             Uint64 x;
4610                             if (StringConversion::stringToUnsignedInteger(v, x) &&
4611                                 StringConversion::checkUintBounds(x, type))
4612 thilo.boehm 1.3             {
4613                               scmoKBV.data.simple.val.u8 = Uint8(x);
4614                               scmoKBV.data.simple.hasValue=true;
4615                               scmoKBV.isSet=true;
4616                             }
4617                             break;
4618                         }
4619                     case CIMTYPE_UINT16:
4620                         {
4621                             Uint64 x;
4622                             if (StringConversion::stringToUnsignedInteger(v, x) &&
4623                                 StringConversion::checkUintBounds(x, type))
4624                             {
4625                               scmoKBV.data.simple.val.u16 = Uint16(x);
4626                               scmoKBV.data.simple.hasValue=true;
4627                               scmoKBV.isSet=true;
4628                             }
4629                             break;
4630                         }
4631                 
4632                     case CIMTYPE_UINT32:
4633 thilo.boehm 1.3         {
4634                             Uint64 x;
4635                             if (StringConversion::stringToUnsignedInteger(v, x) &&
4636                                 StringConversion::checkUintBounds(x, type))
4637                             {
4638                               scmoKBV.data.simple.val.u32 = Uint32(x);
4639                               scmoKBV.data.simple.hasValue=true;
4640                               scmoKBV.isSet=true;
4641                             }
4642                             break;
4643                         }
4644                 
4645                     case CIMTYPE_UINT64:
4646                         {
4647                             Uint64 x;
4648                             if (StringConversion::stringToUnsignedInteger(v, x))
4649                             {
4650                               scmoKBV.data.simple.val.u64 = x;
4651                               scmoKBV.data.simple.hasValue=true;
4652                               scmoKBV.isSet=true;
4653                             }
4654 thilo.boehm 1.3             break;
4655                         }
4656                 
4657                     case CIMTYPE_SINT8:
4658                         {
4659                             Sint64 x;
4660                             if (StringConversion::stringToSignedInteger(v, x) &&
4661                                 StringConversion::checkSintBounds(x, type))
4662                             {
4663                               scmoKBV.data.simple.val.s8 = Sint8(x);
4664                               scmoKBV.data.simple.hasValue=true;
4665                               scmoKBV.isSet=true;
4666                             }
4667                             break;
4668                         }
4669                 
4670                     case CIMTYPE_SINT16:
4671                         {
4672                             Sint64 x;
4673                             if (StringConversion::stringToSignedInteger(v, x) &&
4674                                 StringConversion::checkSintBounds(x, type))
4675 thilo.boehm 1.3             {
4676                               scmoKBV.data.simple.val.s16 = Sint16(x);
4677                               scmoKBV.data.simple.hasValue=true;
4678                               scmoKBV.isSet=true;
4679                             }
4680                             break;
4681                         }
4682                 
4683                     case CIMTYPE_SINT32:
4684                         {
4685                             Sint64 x;
4686                             if (StringConversion::stringToSignedInteger(v, x) &&
4687                                 StringConversion::checkSintBounds(x, type))
4688                             {
4689                               scmoKBV.data.simple.val.s32 = Sint32(x);
4690                               scmoKBV.data.simple.hasValue=true;
4691                               scmoKBV.isSet=true;
4692                             }
4693                             break;
4694                         }
4695                 
4696 thilo.boehm 1.3     case CIMTYPE_SINT64:
4697                         {
4698                             Sint64 x;
4699                             if (StringConversion::stringToSignedInteger(v, x))
4700                             {
4701                               scmoKBV.data.simple.val.s64 = x;
4702                               scmoKBV.data.simple.hasValue=true;
4703                               scmoKBV.isSet=true;
4704                             }
4705                             break;
4706                         }
4707                 
4708                     case CIMTYPE_DATETIME:
4709                         {
4710                             CIMDateTime tmp;
4711                 
4712                             try
4713                             {
4714                                 tmp.set(v);
4715                             }
4716                             catch (InvalidDateTimeFormatException&)
4717 thilo.boehm 1.3             {
4718                                 return false;
4719                             }
4720                 
4721                             memcpy(
4722                                 &(scmoKBV.data.dateTimeValue),
4723                                 tmp._rep,
4724                                 sizeof(SCMBDateTime));
4725                             scmoKBV.isSet=true;
4726                             break;
4727                         }
4728                 
4729                     case CIMTYPE_REAL32:
4730                         {
4731                             Real64 x;
4732                 
4733                             if (StringConversion::stringToReal64(v, x))
4734                             {
4735                               scmoKBV.data.simple.val.r32 = Real32(x);
4736                               scmoKBV.data.simple.hasValue=true;
4737                               scmoKBV.isSet=true;
4738 thilo.boehm 1.3             }
4739                             break;
4740                         }
4741                 
4742                     case CIMTYPE_REAL64:
4743                         {
4744                             Real64 x;
4745                 
4746                             if (StringConversion::stringToReal64(v, x))
4747                             {
4748                               scmoKBV.data.simple.val.r64 = x;
4749                               scmoKBV.data.simple.hasValue=true;
4750                               scmoKBV.isSet=true;
4751                             }
4752                             break;
4753                         }
4754                 
4755                     case CIMTYPE_CHAR16:
4756                         {
4757                             if (kbs.size() == 1)
4758                             {
4759 thilo.boehm 1.3                 scmoKBV.data.simple.val.c16 = kbs[0];
4760                                 scmoKBV.data.simple.hasValue=true;
4761                                 scmoKBV.isSet=true;
4762                             }
4763                             break;
4764                         }
4765                     case CIMTYPE_BOOLEAN:
4766                         {
4767                             if (String::equalNoCase(kbs,"TRUE"))
4768                             {
4769                                 scmoKBV.data.simple.val.bin = true;
4770                                 scmoKBV.data.simple.hasValue=true;
4771                                 scmoKBV.isSet=true;
4772                             }
4773                             else if (String::equalNoCase(kbs,"FALSE"))
4774                                  {
4775                                      scmoKBV.data.simple.val.bin = false;
4776                                      scmoKBV.data.simple.hasValue=true;
4777                                      scmoKBV.isSet=true;
4778                                  }
4779                             break;
4780 thilo.boehm 1.3         }
4781                 
4782                     case CIMTYPE_STRING:
4783                         {
4784                             scmoKBV.isSet=true;
4785                             // Can cause reallocation !
4786                             _setString(kbs,scmoKBV.data.stringValue,&inst.mem);
4787                             return true;
4788                             break;
4789                         }
4790                     case CIMTYPE_REFERENCE:
4791                         {
4792                             if (0 != scmoKBV.data.extRefPtr)
4793                             {
4794                                 delete scmoKBV.data.extRefPtr;
4795                                 scmoKBV.data.extRefPtr = 0;
4796                                 scmoKBV.isSet=false;
4797                             }
4798                             // TBD: Optimize parsing and SCMOInstance creation.
4799                             CIMObjectPath theCIMObj(kbs);
4800                 
4801 thilo.boehm 1.3             scmoKBV.data.extRefPtr = new SCMOInstance(theCIMObj);
4802                             scmoKBV.isSet=true;
4803                 
4804                             // Was the conversion successful?
4805                             if (scmoKBV.data.extRefPtr->isEmpty())
4806                             {
4807                                 // N0, delete the SCMOInstance.
4808                                 delete scmoKBV.data.extRefPtr;
4809                                 scmoKBV.data.extRefPtr = 0;
4810                                 scmoKBV.isSet=false;
4811                             }
4812                             else
4813                             {
4814                                 // This function can cause a reallocation !
4815                                 // Pointers can be invalid after the call.
4816                                 _setExtRefIndex(&(scmoKBV.data),&inst.mem);
4817                             }
4818                             break;
4819                         }
4820                     case CIMTYPE_OBJECT:
4821                     case CIMTYPE_INSTANCE:
4822 thilo.boehm 1.3         {
4823                             // From PEP 194: EmbeddedObjects cannot be keys.
4824                             throw TypeMismatchException();
4825                             break;
4826                         }
4827                     default:
4828                         {
4829                             PEGASUS_ASSERT(false);
4830                             break;
4831                         }
4832                     }
4833                 
4834                     return scmoKBV.isSet;
4835                 }
4836                 
4837                 SCMO_RC SCMOInstance::_setKeyBindingFromString(
4838                     const char* name,
4839                     CIMType type,
4840                     String cimKeyBinding)
4841                 {
4842                     Uint32 node;
4843 thilo.boehm 1.3 
4844                     if (0 == name)
4845                     {
4846                         return SCMO_INVALID_PARAMETER;
4847                     }
4848                 
4849                     if (SCMO_OK == inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name))
4850                     {
4851                         // create a pointer to keybinding node array of the class.
4852                         Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
4853                             keyBindingSet.nodeArray.start;
4854                         SCMBKeyBindingNode* theClassKeyBindNodeArray =
4855                             (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
4856                 
4857                         // create a pointer to instance keybinding values
4858                         SCMBKeyBindingValue* theInstKeyBindValueArray =
4859                             (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
4860                 
4861                         // If the set was not successful, the conversion was not successful
4862                         if ( !_setCimKeyBindingStringToSCMOKeyBindingValue(
4863                                 cimKeyBinding,
4864 thilo.boehm 1.3                 theClassKeyBindNodeArray[node].type,
4865                                 theInstKeyBindValueArray[node]))
4866                         {
4867                             return SCMO_TYPE_MISSMATCH;
4868                         }
4869                 
4870                         return SCMO_OK;
4871                     }
4872                 
4873                     // the key binig does not belong to the associated class
4874                     // add/set it as user defined key binding.
4875                     SCMBUserKeyBindingElement* ptrNewElement;
4876                 
4877                     ptrNewElement = _getUserDefinedKeyBinding( name,strlen(name),type);
4878                 
4879                     // Copy the data.
4880                     // If the set was not successful, the conversion was not successful
4881                     if ( !_setCimKeyBindingStringToSCMOKeyBindingValue(
4882                             cimKeyBinding,
4883                             type,
4884                             ptrNewElement->value))
4885 thilo.boehm 1.3     {
4886                         return SCMO_TYPE_MISSMATCH;
4887                     }
4888                 
4889                     return SCMO_OK;
4890                 }
4891                 
4892                 SCMO_RC SCMOInstance::setKeyBinding(
4893                     const char* name,
4894                     CIMType type,
4895                     const SCMBUnion* keyvalue)
4896                 {
4897                     SCMO_RC rc;
4898                     Uint32 node;
4899                 
4900                     if (0 == name)
4901                     {
4902                         return SCMO_INVALID_PARAMETER;
4903                     }
4904                 
4905                     if (0 == keyvalue)
4906 thilo.boehm 1.3     {
4907                         return SCMO_INVALID_PARAMETER;
4908                     }
4909                 
4910                     _copyOnWrite();
4911                 
4912                     rc = inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name);
4913                     if (rc != SCMO_OK)
4914                     {
4915                         // the key bindig does not belong to the associated class
4916                         // add/set it as user defined key binding.
4917                         SCMBUserKeyBindingElement *theNode;
4918                 
4919                         theNode = _getUserDefinedKeyBinding( name,strlen(name),type);
4920                 
4921                         // Is this a new node or an existing user key binding?
4922                         if (theNode->value.isSet && (theNode->type != type))
4923                         {
4924                             return SCMO_TYPE_MISSMATCH;
4925                 
4926                         }
4927 thilo.boehm 1.3 
4928                         theNode->value.isSet=true;
4929                 
4930                         _setSCMBUnion(
4931                             keyvalue,
4932                             type,
4933                             false, // a key binding can never be an array.
4934                             0,
4935                             theNode->value.data);
4936                 
4937                          return SCMO_OK;
4938                     }
4939                 
4940                     return setKeyBindingAt(node, type, keyvalue);
4941                 }
4942                 
4943                 SCMO_RC SCMOInstance::setKeyBindingAt(
4944                         Uint32 node,
4945                         CIMType type,
4946                         const SCMBUnion* keyvalue)
4947                 {
4948 thilo.boehm 1.3     if (0 == keyvalue)
4949                     {
4950                         return SCMO_INVALID_PARAMETER;
4951                     }
4952                 
4953                     // count of class keys + user definded keys
4954                     if (node >= (inst.hdr->numberKeyBindings+
4955                                  inst.hdr->numberUserKeyBindings))
4956                     {
4957                         return SCMO_INDEX_OUT_OF_BOUND;
4958                     }
4959                 
4960                     _copyOnWrite();
4961                 
4962                    // create a pointer to keybinding node array of the class.
4963                     Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
4964                         keyBindingSet.nodeArray.start;
4965                     SCMBKeyBindingNode* theClassKeyBindNodeArray =
4966                         (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
4967                 
4968                     // is the node a user defined key binding ?
4969 thilo.boehm 1.3     if (node >= inst.hdr->numberKeyBindings)
4970                     {
4971                         SCMBUserKeyBindingElement* theNode = _getUserDefinedKeyBindingAt(node);
4972                 
4973                         // Does the new value for the user defined keybinding match?
4974                         if (theNode->type != type)
4975                         {
4976                             return SCMO_TYPE_MISSMATCH;
4977                         }
4978                 
4979                         _setSCMBUnion(
4980                             keyvalue,
4981                             type,
4982                             false, // a key binding can never be an array.
4983                             0,
4984                             theNode->value.data);
4985                 
4986                          return SCMO_OK;
4987                 
4988                     }
4989                 
4990 thilo.boehm 1.3     SCMBKeyBindingValue* theInstKeyBindValueArray =
4991                         (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
4992                 
4993                 
4994                     if (theClassKeyBindNodeArray[node].type == type)
4995                     {
4996                 
4997                         // Has to be set first,
4998                         // because reallocaton can take place in _setSCMBUnion()
4999                         theInstKeyBindValueArray[node].isSet=true;
5000                 
5001                         _setSCMBUnion(
5002                             keyvalue,
5003                             type,
5004                             false, // a key binding can never be an array.
5005                             0,
5006                             theInstKeyBindValueArray[node].data);
5007                 
5008                         return SCMO_OK;
5009                 
5010                     }
5011 thilo.boehm 1.3 
5012                     // The type does not match.
5013                     return _setKeyBindingTypeTolerate(
5014                         theClassKeyBindNodeArray[node].type,
5015                         type,
5016                         keyvalue,
5017                         theInstKeyBindValueArray[node]);
5018                 
5019                 }
5020                 
5021                 /**
5022                  * Set a SCMO user defined key binding using the class CIM type tolerating
5023                  * CIM key binding types converted to CIM types by fuction
5024                  *  _CIMTypeFromKeyBindingType().
5025                  *
5026                  * @parm classType The type of the key binding in the class definition
5027                  * @parm setType The type of the key binding to be set.
5028                  * @param keyValue A pointer to the key binding to be set.
5029                  * @param kbValue Out parameter, the SCMO keybinding to be set.
5030                  *
5031                  **/
5032 thilo.boehm 1.3 SCMO_RC SCMOInstance::_setKeyBindingTypeTolerate(
5033                     CIMType classType,
5034                     CIMType setType,
5035                     const SCMBUnion* keyValue,
5036                     SCMBKeyBindingValue& kbValue)
5037                 {
5038                     if (setType == CIMTYPE_UINT64 )
5039                     {
5040                         switch (classType)
5041                         {
5042                 
5043                         case CIMTYPE_UINT8:
5044                             {
5045                                 kbValue.isSet=true;
5046                                 kbValue.data.simple.hasValue=true;
5047                                 kbValue.data.simple.val.u8=Uint8(keyValue->simple.val.u64);
5048                                 return SCMO_OK;
5049                                 break;
5050                             }
5051                         case CIMTYPE_UINT16:
5052                             {
5053 thilo.boehm 1.3                 kbValue.isSet=true;
5054                                 kbValue.data.simple.hasValue=true;
5055                                 kbValue.data.simple.val.u16=Uint16(keyValue->simple.val.u64);
5056                                 return SCMO_OK;
5057                                 break;
5058                             }
5059                         case CIMTYPE_UINT32:
5060                             {
5061                                 kbValue.isSet=true;
5062                                 kbValue.data.simple.hasValue=true;
5063                                 kbValue.data.simple.val.u32=Uint32(keyValue->simple.val.u64);
5064                                 return SCMO_OK;
5065                                 break;
5066                             }
5067                         case CIMTYPE_UINT64:
5068                             {
5069                                 kbValue.isSet=true;
5070                                 kbValue.data.simple.hasValue=true;
5071                                 kbValue.data.simple.val.u64=keyValue->simple.val.u64;
5072                                 return SCMO_OK;
5073                                 break;
5074 thilo.boehm 1.3             }
5075                         default:
5076                             {
5077                                 return SCMO_TYPE_MISSMATCH;
5078                                 break;
5079                             }
5080                         }
5081                     }
5082                 
5083                     if (setType == CIMTYPE_SINT64)
5084                     {
5085                         switch (classType)
5086                         {
5087                 
5088                         case CIMTYPE_SINT8:
5089                             {
5090                                 kbValue.isSet=true;
5091                                 kbValue.data.simple.hasValue=true;
5092                                 kbValue.data.simple.val.s8=Sint8(keyValue->simple.val.s64);
5093                                 return SCMO_OK;
5094                                 break;
5095 thilo.boehm 1.3             }
5096                         case CIMTYPE_SINT16:
5097                             {
5098                                 kbValue.isSet=true;
5099                                 kbValue.data.simple.hasValue=true;
5100                                 kbValue.data.simple.val.s16=Sint16(keyValue->simple.val.s64);
5101                                 return SCMO_OK;
5102                                 break;
5103                             }
5104                         case CIMTYPE_SINT32:
5105                             {
5106                                 kbValue.isSet=true;
5107                                 kbValue.data.simple.hasValue=true;
5108                                 kbValue.data.simple.val.s32=Sint32(keyValue->simple.val.s64);
5109                                 return SCMO_OK;
5110                                 break;
5111                             }
5112                         case CIMTYPE_SINT64:
5113                             {
5114                                 kbValue.isSet=true;
5115                                 kbValue.data.simple.hasValue=true;
5116 thilo.boehm 1.3                 kbValue.data.simple.val.s64=keyValue->simple.val.s64;
5117                                 return SCMO_OK;
5118                                 break;
5119                             }
5120                         default:
5121                             {
5122                                 return SCMO_TYPE_MISSMATCH;
5123                                 break;
5124                             }
5125                         }
5126                     }
5127                 
5128                     if (setType == CIMTYPE_REAL64)
5129                     {
5130                         switch (classType)
5131                         {
5132                         case CIMTYPE_REAL32:
5133                             {
5134                                 kbValue.isSet=true;
5135                                 kbValue.data.simple.hasValue=true;
5136                                 kbValue.data.simple.val.r32=Real32(keyValue->simple.val.r64);
5137 thilo.boehm 1.3                 return SCMO_OK;
5138                                 break;
5139                             }
5140                         case CIMTYPE_REAL64:
5141                             {
5142                                 kbValue.isSet=true;
5143                                 kbValue.data.simple.hasValue=true;
5144                                 kbValue.data.simple.val.r64=keyValue->simple.val.r64;
5145                                 return SCMO_OK;
5146                                 break;
5147                             }
5148                         default:
5149                             {
5150                                 return SCMO_TYPE_MISSMATCH;
5151                                 break;
5152                             }
5153                         }
5154                     }
5155                     else
5156                     {
5157                         // If type defined in the class and the provided type does not match
5158 thilo.boehm 1.3         // at this point, no convertaion can be done and the provided type
5159                         // is handlend as type missmatch.
5160                         if (classType != setType)
5161                         {
5162                             return SCMO_TYPE_MISSMATCH;
5163                         }
5164                 
5165                         switch (classType)
5166                         {
5167                         case CIMTYPE_DATETIME:
5168                         case CIMTYPE_BOOLEAN:
5169                         case CIMTYPE_UINT64:
5170                         case CIMTYPE_SINT64:
5171                         case CIMTYPE_REAL64:
5172                         case CIMTYPE_STRING:
5173                         case CIMTYPE_REFERENCE:
5174                             {
5175                                 kbValue.isSet=true;
5176                                 _setSCMBUnion(keyValue,classType,false, 0,kbValue.data);
5177                                 return SCMO_OK;
5178                                 break;
5179 thilo.boehm 1.3             }
5180                         default:
5181                             {
5182                                 return SCMO_TYPE_MISSMATCH;
5183                                 break;
5184                             }
5185                         }
5186                     }
5187                 
5188                     return SCMO_TYPE_MISSMATCH;
5189                 
5190                 }
5191                 
5192                 static int _indexComp(const void* left, const void* right)
5193                 {
5194                     return((*(Uint32 *)left)-(*(Uint32 *)right));
5195                 }
5196                 
5197                 void SCMOInstance::setPropertyFilter(const char **propertyList)
5198                 {
5199                     SCMO_RC rc;
5200 thilo.boehm 1.3     Uint32 node,i = 0;
5201                 
5202                     _copyOnWrite();
5203                 
5204                     if (inst.hdr->propertyFilter.start == 0)
5205                     {
5206                         // Allocate the SCMBPropertyFilter
5207                         _getFreeSpace(
5208                             inst.hdr->propertyFilter,
5209                             sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1),
5210                             &inst.mem);
5211                 
5212                         // Allocate the SCMBPropertyFilterIndexMap
5213                         _getFreeSpace(
5214                             inst.hdr->propertyFilterIndexMap,
5215                             sizeof(Uint32)*inst.hdr->numberProperties,
5216                             &inst.mem);
5217                     }
5218                     // Get absolut pointer to property filter index map of the instance
5219                     Uint32* propertyFilterIndexMap =
5220                         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);
5221 thilo.boehm 1.3 
5222                     // All properties are accepted
5223                     if (propertyList == 0)
5224                     {
5225                         // Clear filtering:
5226                         // Switch filtering off.
5227                         inst.hdr->flags.isFiltered = false;
5228                 
5229                         // Clear filter index map
5230                         memset(
5231                             propertyFilterIndexMap,
5232                             0,
5233                             sizeof(Uint32)*inst.hdr->numberProperties);
5234 thilo.boehm 1.1 
5235 thilo.boehm 1.2         //reset number filter properties to all
5236 thilo.boehm 1.3         inst.hdr->filterProperties = inst.hdr->numberProperties;
5237                 
5238                         return;
5239                     }
5240                 
5241                     // Switch filtering on.
5242                     inst.hdr->flags.isFiltered = true;
5243                 
5244                     // intit the filter with the key properties
5245                     inst.hdr->filterProperties=_initPropFilterWithKeys();
5246                 
5247                     // add the properties to the filter.
5248                     while (propertyList[i] != 0)
5249                     {
5250                         // the hash index of the property if the property name is found
5251                         rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(node,propertyList[i]);
5252                 
5253                         // if property is already in the filter
5254                         // ( eg. key properties ) do not add them !
5255                         if (rc == SCMO_OK && !_isPropertyInFilter(node))
5256                         {
5257 thilo.boehm 1.3             // The property name was found. Otherwise ignore this property name.
5258                             // insert the hash index into the filter index map
5259                             propertyFilterIndexMap[inst.hdr->filterProperties]=node;
5260                             // increase number of properties in filter.
5261                             inst.hdr->filterProperties++;
5262                             // set bit in the property filter
5263                             _setPropertyInPropertyFilter(node);
5264                         }
5265                         // Proceed with the next property name.
5266                         i++;
5267                     }
5268                 
5269                     // sort the filter index to be in order as properties stored in the class.
5270                     qsort(
5271                         propertyFilterIndexMap,
5272                         inst.hdr->filterProperties,
5273                         sizeof(Uint32),
5274                         _indexComp);
5275                 }
5276                 
5277                 Uint32 SCMOInstance::_initPropFilterWithKeys()
5278 thilo.boehm 1.3 {
5279                 
5280                     // Get absolut pointer to the key property mask of the class.
5281                     Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->keyPropertyMask.start;
5282                     Uint64* keyMask =(Uint64*)&(inst.hdr->theClass.ptr->cls.base)[idx];
5283                 
5284                     // Get absolut pointer to property filter mask
5285                     Uint64* propertyFilterMask =
5286                         (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);
5287                 
5288                     // copy the key mask to the property filter mask
5289                     memcpy(
5290                         propertyFilterMask,
5291                         keyMask,
5292                         sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1));
5293                 
5294                     // Get absolut pointer to key index list of the class
5295                     idx=inst.hdr->theClass.ptr->cls.hdr->keyIndexList.start;
5296                     Uint32* keyIndex = (Uint32*)&(inst.hdr->theClass.ptr->cls.base)[idx];
5297                 
5298                     // Get absolut pointer to property filter index map of the instance
5299 thilo.boehm 1.3     Uint32* propertyFilterIndexMap =
5300                         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);
5301                 
5302                     Uint32 noKeys = inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
5303                     memcpy(propertyFilterIndexMap,keyIndex,sizeof(Uint32)*noKeys);
5304                 
5305                     // return the number of properties already in the filter index map
5306                     return noKeys;
5307                 
5308                 }
5309                 
5310                 void SCMOInstance::_clearPropertyFilter()
5311                 {
5312                     Uint64 *propertyFilter;
5313                 
5314                     // Calculate the real pointer to the Uint64 array
5315                     propertyFilter = (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);
5316                 
5317                     // the number of Uint64 in the key mask is :
5318                     // Decrease the number of properties by 1
5319                     // since the array is starting at index 0!
5320 thilo.boehm 1.3     // Divide with the number of bits in a Uint64.
5321                     // e.g. number of Properties = 68
5322                     // (68 - 1) / 64 = 1 --> The mask consists of 2 Uint64
5323                 
5324                     memset(propertyFilter,
5325                            0,
5326                            sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1));
5327                 
5328                 }
5329                 void SCMOInstance::_setPropertyInPropertyFilter(Uint32 i)
5330                 {
5331                     Uint64 *propertyFilter;
5332                 
5333                     // In which Uint64 of key mask is the bit for property i ?
5334                     // Divide with the number of bits in a Uint64.
5335                     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].
5336                     Uint32 idx = i/64 ;
5337                 
5338                     // Create a filter to set the bit.
5339                     // Modulo division with 64. Shift left a bit by the remainder.
5340                     Uint64 filter = ( (Uint64)1 << (i%64));
5341 thilo.boehm 1.3 
5342                     // Calculate the real pointer to the Uint64 array
5343                     propertyFilter = (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);
5344                 
5345                     propertyFilter[idx] = propertyFilter[idx] | filter ;
5346                 }
5347                 
5348                 Boolean SCMOInstance::_isPropertyInFilter(Uint32 i) const
5349                 {
5350                     Uint64 *propertyFilter;
5351                 
5352                     // In which Uint64 of key mask is the bit for property i ?
5353                     // Divide with the number of bits in a Uint64.
5354                     // e.g. number of Properties = 68
5355                     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].
5356                     Uint32 idx = i/64 ;
5357                 
5358                     // Create a filter to check if the bit is set:
5359                     // Modulo division with 64. Shift left a bit by the remainder.
5360                     Uint64 filter = ( (Uint64)1 << (i%64));
5361                 
5362 thilo.boehm 1.3     // Calculate the real pointer to the Uint64 array
5363                     propertyFilter = (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);
5364                 
5365                     // If the bit is set the property is NOT filtered.
5366                     // So the result has to be negated!
5367                     return propertyFilter[idx] & filter ;
5368                 
5369                 }
5370                 
5371                 /******************************************************************************
5372                  * SCMODump Print and Dump functions
5373                  *****************************************************************************/
5374                 SCMODump::SCMODump()
5375                 {
5376 r.kieninger 1.7     _out = stderr;
5377 thilo.boehm 1.3     _fileOpen = false;
5378                 
5379                 #ifdef PEGASUS_OS_ZOS
5380                     setEBCDICEncoding(fileno(_out));
5381                 #endif
5382                 
5383                 }
5384                 
5385                 SCMODump::SCMODump(const char* filename)
5386                 {
5387                     openFile(filename);
5388                 }
5389                 
5390                 void SCMODump::openFile(const char* filename)
5391                 {
5392                     const char* pegasusHomeDir = getenv("PEGASUS_HOME");
5393                 
5394                     if (pegasusHomeDir == 0)
5395                     {
5396                         pegasusHomeDir = ".";
5397                     }
5398 thilo.boehm 1.3 
5399                     _filename = pegasusHomeDir;
5400                     _filename.append("/");
5401                     _filename.append(filename);
5402                 
5403                     _out = fopen((const char*)_filename.getCString(),"w+");
5404                 
5405                     _fileOpen = true;
5406                 
5407                 #ifdef PEGASUS_OS_ZOS
5408                     setEBCDICEncoding(fileno(_out));
5409                 #endif
5410                 
5411                 }
5412                 
5413                 void SCMODump::deleteFile()
5414                 {
5415                     if(_fileOpen)
5416                     {
5417                         closeFile();
5418                     }
5419 thilo.boehm 1.3 
5420                     System::removeFile((const char*)_filename.getCString());
5421                 
5422                 }
5423                 void SCMODump::closeFile()
5424                 {
5425                     if (_fileOpen)
5426                     {
5427                         fclose(_out);
5428                         _fileOpen=false;
5429                         _out = stdout;
5430                     }
5431                 }
5432                 
5433                 SCMODump::~SCMODump()
5434                 {
5435                     if (_fileOpen)
5436                     {
5437                         fclose(_out);
5438                         _fileOpen=false;
5439                     }
5440 thilo.boehm 1.3 }
5441                 
5442                 Boolean SCMODump::compareFile(String master)
5443                 {
5444                     if (!_fileOpen)
5445                     {
5446                         return false;
5447                     }
5448                     closeFile();
5449                 
5450                     ifstream isMaster;
5451                     ifstream isDumpFile;
5452                 
5453                     Open(isDumpFile, _filename);
5454                     Open(isMaster, master);
5455                 
5456                     String aLine;
5457                     String bLine;
5458                 
5459                     while (GetLine(isDumpFile, aLine) && GetLine(isMaster, bLine))
5460                     {
5461 thilo.boehm 1.3         if (aLine != bLine)
5462                         {
5463                             cout << "|" << aLine << "|" << endl;
5464                             cout << "|" << bLine << "|" << endl;
5465                             isDumpFile.close();
5466                             isMaster.close();
5467                             return false;
5468                         }
5469                     };
5470                     isDumpFile.close();
5471                     isMaster.close();
5472                     return true;
5473                 }
5474                 
5475 r.kieninger 1.7 void SCMODump::dumpSCMOInstance(SCMOInstance& testInst, Boolean inclMemHdr)const
5476 thilo.boehm 1.3 {
5477                     SCMBInstance_Main* insthdr = testInst.inst.hdr;
5478                     char* instbase = testInst.inst.base;
5479                 
5480                     fprintf(_out,"\n\nDump of SCMOInstance\n");
5481 r.kieninger 1.7 
5482                     if (inclMemHdr)
5483                     {
5484                         _dumpSCMBMgmt_Header(insthdr->header,instbase);
5485                     }
5486                 
5487 thilo.boehm 1.3     // The reference counter for this c++ class
5488                     fprintf(_out,"\nrefCount=%i",insthdr->refCount.get());
5489                     fprintf(_out,"\ntheClass: %p",insthdr->theClass.ptr);
5490                     fprintf(_out,"\n\nThe Flags:");
5491                     fprintf(_out,"\n   includeQualifiers: %s",
5492                            (insthdr->flags.includeQualifiers ? "True" : "False"));
5493                     fprintf(_out,"\n   includeClassOrigin: %s",
5494                            (insthdr->flags.includeClassOrigin ? "True" : "False"));
5495                     fprintf(_out,"\n   isFiltered: %s",
5496                            (insthdr->flags.isFiltered ? "True" : "False"));
5497                     fprintf(_out,"\n   isClassOnly: %s",
5498                            (insthdr->flags.isClassOnly ? "True" : "False"));
5499                     fprintf(_out,"\n   isCompromised: %s",
5500                            (insthdr->flags.isCompromised ? "True" : "False"));
5501                     fprintf(_out,"\n   exportSetOnly: %s",
5502                            (insthdr->flags.exportSetOnly ? "True" : "False"));
5503                     fprintf(_out,"\n\ninstNameSpace: \'%s\'",
5504                            NULLSTR(_getCharString(insthdr->instNameSpace,instbase)));
5505                     fprintf(_out,"\n\ninstClassName: \'%s\'",
5506                            NULLSTR(_getCharString(insthdr->instClassName,instbase)));
5507                     fprintf(_out,"\n\nhostName: \'%s\'",
5508 thilo.boehm 1.3            NULLSTR(_getCharString(insthdr->hostName,instbase)));
5509                 
5510                     dumpSCMOInstanceKeyBindings(testInst);
5511                 
5512                     dumpSCMOInstancePropertyFilter(testInst);
5513                 
5514                     dumpInstanceProperties(testInst);
5515                     fprintf(_out,"\n\n");
5516                 
5517                 }
5518                 
5519                 void SCMODump::dumpSCMOInstancePropertyFilter(SCMOInstance& testInst) const
5520                 {
5521                     SCMBInstance_Main* insthdr = testInst.inst.hdr;
5522                     char* instbase = testInst.inst.base;
5523                 
5524                     if (!insthdr->flags.isFiltered)
5525                     {
5526                         fprintf(_out,"\n\nNo propterty filter!\n\n");
5527                         return;
5528                     }
5529 thilo.boehm 1.3 
5530                     fprintf(_out,"\n\nInstance Property Filter :");
5531                     fprintf(_out,"\n==========================");
5532                     fprintf(_out,"\n\nNumber of properties in the filter : %u\n"
5533                         ,insthdr->filterProperties);
5534                 
5535                     dumpPropertyFilter(testInst);
5536                 
5537                     dumpPropertyFilterIndexMap(testInst);
5538                 
5539                 }
5540 thilo.boehm 1.1 
5541 thilo.boehm 1.3 void SCMODump::dumpInstanceProperties(
5542                     SCMOInstance& testInst,
5543                     Boolean verbose) const
5544                 {
5545                     SCMBInstance_Main* insthdr = testInst.inst.hdr;
5546                     char* instbase = testInst.inst.base;
5547 thilo.boehm 1.2 
5548 thilo.boehm 1.3     SCMBValue* val =
5549                         (SCMBValue*)_resolveDataPtr(insthdr->propertyArray,instbase);
5550 thilo.boehm 1.2 
5551 thilo.boehm 1.3     fprintf(_out,"\n\nInstance Properties :");
5552                     fprintf(_out,"\n=====================");
5553                     fprintf(_out,"\n\nNumber of properties in instance : %u",
5554                            insthdr->numberProperties);
5555 thilo.boehm 1.2 
5556 thilo.boehm 1.3     for (Uint32 i = 0, k = insthdr->numberProperties; i < k; i++)
5557 thilo.boehm 1.1     {
5558 thilo.boehm 1.3         fprintf(_out,"\n\nInstance property (#%3u) %s\n",i,
5559                                 NULLSTR(insthdr->theClass.ptr->_getPropertyNameAtNode(i)));
5560                         if(insthdr->flags.isFiltered && !testInst._isPropertyInFilter(i))
5561                         {
5562                             fprintf(_out,"\nProperty is filtered out!");
5563                         }
5564                         else
5565 thilo.boehm 1.1         {
5566 thilo.boehm 1.3             printSCMOValue(val[i],instbase,verbose);
5567 thilo.boehm 1.1         }
5568                     }
5569                 
5570                 }
5571                 
5572 thilo.boehm 1.3 void SCMODump::dumpPropertyFilterIndexMap(SCMOInstance& testInst) const
5573 thilo.boehm 1.2 {
5574                 
5575 thilo.boehm 1.3     SCMBInstance_Main* insthdr = testInst.inst.hdr;
5576                     char* instbase = testInst.inst.base;
5577 thilo.boehm 1.2 
5578 thilo.boehm 1.3     if (!insthdr->flags.isFiltered)
5579                     {
5580                         fprintf(_out,"\n\nNo propterty filter!\n\n");
5581                         return;
5582                     }
5583 thilo.boehm 1.2 
5584 thilo.boehm 1.3     fprintf(_out,"\n\nProperty Filter Index Max:");
5585                     fprintf(_out,"\n==========================\n");
5586 thilo.boehm 1.2 
5587                     // Get absolut pointer to key index list of the class
5588 thilo.boehm 1.3     Uint32* keyIndex =
5589                         (Uint32*)&(instbase)[insthdr->propertyFilterIndexMap.start];
5590                 
5591                     Uint32 line,j,i,k = insthdr->filterProperties;
5592                 
5593                     for (j = 0; j < k; j = j + line)
5594                     {
5595                         if ((insthdr->filterProperties-j)/16)
5596                         {
5597                             line = 16 ;
5598                         }
5599                         else
5600                         {
5601                             line = insthdr->filterProperties%16;
5602                         }
5603                 
5604 thilo.boehm 1.2 
5605 thilo.boehm 1.3         fprintf(_out,"Index :");
5606                         for (i = 0; i < line; i++)
5607                         {
5608                             fprintf(_out," %3u",j+i);
5609                         }
5610                 
5611                         fprintf(_out,"\nNode  :");
5612                         for (i = 0; i < line; i++)
5613                         {
5614                             fprintf(_out," %3u",keyIndex[j+i]);
5615                         }
5616 thilo.boehm 1.2 
5617 thilo.boehm 1.3         fprintf(_out,"\n\n");
5618 thilo.boehm 1.2 
5619 thilo.boehm 1.3     }
5620 thilo.boehm 1.2 
5621                 }
5622                 
5623 thilo.boehm 1.3 void SCMODump::dumpPropertyFilter(SCMOInstance& testInst) const
5624 thilo.boehm 1.2 {
5625                 
5626 thilo.boehm 1.3     SCMBInstance_Main* insthdr = testInst.inst.hdr;
5627                     char* instbase = testInst.inst.base;
5628                 
5629                     if (!insthdr->flags.isFiltered)
5630                     {
5631                         fprintf(_out,"\n\nNo propterty filter!");
5632                         return;
5633                     }
5634                 
5635                     Uint64 *thePropertyFilter =
5636                         (Uint64*)&(instbase[insthdr->propertyFilter.start]);
5637                      Uint32 end, noProperties = insthdr->numberProperties;
5638                      Uint32 noMasks = (noProperties-1)/64;
5639                      Uint64 printMask = 1;
5640                 
5641                      for (Uint32 i = 0; i <= noMasks; i++ )
5642                      {
5643                          printMask = 1;
5644                          if (i < noMasks)
5645                          {
5646                              end = 64;
5647 thilo.boehm 1.3          }
5648                          else
5649                          {
5650                              end = noProperties%64;
5651                          }
5652                 
5653                          fprintf(_out,"\npropertyFilter[%02u]= ",i);
5654 thilo.boehm 1.2 
5655 thilo.boehm 1.3          for (Uint32 j = 0; j < end; j++)
5656                          {
5657                              if (j > 0 && !(j%8))
5658                              {
5659                                  fprintf(_out," ");
5660                              }
5661 thilo.boehm 1.2 
5662 thilo.boehm 1.3              if (thePropertyFilter[i] & printMask)
5663                              {
5664                                  fprintf(_out,"1");
5665                              }
5666                              else
5667                              {
5668                                  fprintf(_out,"0");
5669                              }
5670 thilo.boehm 1.2 
5671 thilo.boehm 1.3              printMask = printMask << 1;
5672                          }
5673                          fprintf(_out,"\n");
5674                      }
5675 thilo.boehm 1.2 }
5676 thilo.boehm 1.3 
5677                 void SCMODump::dumpSCMOInstanceKeyBindings(
5678                     SCMOInstance& testInst,
5679                     Boolean verbose) const
5680 thilo.boehm 1.1 {
5681 thilo.boehm 1.3     SCMBInstance_Main* insthdr = testInst.inst.hdr;
5682                     char* instbase = testInst.inst.base;
5683 thilo.boehm 1.2 
5684 thilo.boehm 1.3     // create a pointer to keybinding node array of the class.
5685                     Uint64 idx = insthdr->theClass.ptr->cls.hdr->keyBindingSet.nodeArray.start;
5686                     SCMBKeyBindingNode* theClassKeyBindNodeArray =
5687                         (SCMBKeyBindingNode*)&((insthdr->theClass.ptr->cls.base)[idx]);
5688 thilo.boehm 1.2 
5689 thilo.boehm 1.3     SCMBKeyBindingValue* ptr =
5690                         (SCMBKeyBindingValue*)
5691                              _resolveDataPtr(insthdr->keyBindingArray,instbase);
5692                 
5693                     fprintf(_out,"\n\nInstance Key Bindings :");
5694                     fprintf(_out,"\n=======================");
5695                     fprintf(_out,"\n\nNumber of Key Bindings defined in the Class: %u",
5696                             insthdr->numberKeyBindings);
5697                 
5698                     for (Uint32 i = 0, k = insthdr->numberKeyBindings; i < k; i++)
5699                     {
5700                         if (ptr[i].isSet)
5701                         {
5702                             fprintf(_out,"\n\nName: '%s'\nType: '%s'",
5703                                 NULLSTR(_getCharString(
5704                                     theClassKeyBindNodeArray[i].name,
5705                                     insthdr->theClass.ptr->cls.base)),
5706                                 cimTypeToString(theClassKeyBindNodeArray[i].type));
5707                             printUnionValue(
5708                                 theClassKeyBindNodeArray[i].type,
5709                                 ptr[i].data,
5710 thilo.boehm 1.3                 instbase,
5711                                 verbose);
5712                         }
5713                         else
5714                         {
5715                             fprintf(_out,"\n\nName: '%s': Not Set",
5716                                 NULLSTR(_getCharString(
5717                                     theClassKeyBindNodeArray[i].name,
5718                                     insthdr->theClass.ptr->cls.base)));
5719                         }
5720                     }
5721 thilo.boehm 1.2 
5722 thilo.boehm 1.3     fprintf(_out,"\n\nNumber of User Defined Key Bindings: %u",
5723                             insthdr->numberUserKeyBindings);
5724 thilo.boehm 1.1 
5725 thilo.boehm 1.2 
5726 thilo.boehm 1.3     SCMBUserKeyBindingElement* theUserDefKBElement;
5727 thilo.boehm 1.1 
5728 thilo.boehm 1.3     Uint64 start = insthdr->userKeyBindingElement.start;
5729                     while (start != 0)
5730                     {
5731                         theUserDefKBElement = (SCMBUserKeyBindingElement*)&(instbase[start]);
5732 thilo.boehm 1.1 
5733 thilo.boehm 1.3         if (theUserDefKBElement->value.isSet)
5734                         {
5735                             fprintf(_out,"\n\nName: '%s'\nType: '%s'",
5736                                 NULLSTR(_getCharString(theUserDefKBElement->name,instbase)),
5737                                 cimTypeToString(theUserDefKBElement->type));
5738                             printUnionValue(
5739                                 theUserDefKBElement->type,
5740                                 theUserDefKBElement->value.data,
5741                                 instbase,
5742                                 verbose);
5743                         }
5744                         else
5745                         {
5746                             fprintf(_out,"\n\n    %s : Not Set",
5747                                 NULLSTR(_getCharString(theUserDefKBElement->name,instbase)));
5748 thilo.boehm 1.1 
5749 thilo.boehm 1.3         }
5750                         start = theUserDefKBElement->nextElement.start;
5751                     } // for all user def. key bindings.
5752 thilo.boehm 1.1 
5753 thilo.boehm 1.3     fprintf(_out,"\n\n");
5754 thilo.boehm 1.1 
5755                 }
5756                 
5757 r.kieninger 1.7 void SCMODump::_dumpSCMBMgmt_Header(SCMBMgmt_Header& header,char* base) const
5758                 {
5759                     fprintf(_out,"\nThe Management Header:");
5760                     // The magic number
5761                     fprintf(_out,"\n   magic=%08X",header.magic);
5762                     // Total size of the memory block( # bytes )
5763                     fprintf(_out,"\n   totalSize=%llu",header.totalSize);
5764                     // Free bytes in the block
5765                     fprintf(_out,"\n   freeBytes=%llu",header.freeBytes);
5766                     // Index to the start of the free space in this SCMB memory block.
5767                     fprintf(_out,"\n   startOfFreeSpace=%llu",header.startOfFreeSpace);
5768                     // Number of external references in this instance.
5769                     fprintf(_out,"\n   numberExtRef=%u",header.numberExtRef);
5770                     // Size of external reference index array;
5771                     fprintf(_out,"\n   sizeExtRefIndexArray=%u",header.sizeExtRefIndexArray);
5772                 
5773                     if (header.numberExtRef > 0)
5774                     {
5775                         fprintf(_out,"\n   extRefIndexArray=[");
5776                         Uint64* extRefIndexArray =
5777                             (Uint64*)&(base[header.extRefIndexArray.start]);
5778 r.kieninger 1.7 
5779                         for (Uint32 i = 0; i < header.numberExtRef;)
5780                         {
5781                             fprintf(_out,"%llu",extRefIndexArray[i]);
5782                             i++;
5783                             if (i != header.numberExtRef)
5784                             {
5785                                 fprintf(_out,", ");
5786                             }
5787                         }
5788                         fprintf(_out,"\n");
5789                     }
5790                     else
5791                     {
5792                            fprintf(_out,"\n   extRefIndexArray=[NO INDEX]\n");
5793                     }
5794                 }
5795                 
5796                 void SCMODump::dumpSCMOClass(SCMOClass& testCls, Boolean inclMemHdr) const
5797 thilo.boehm 1.2 {
5798                     SCMBClass_Main* clshdr = testCls.cls.hdr;
5799 thilo.boehm 1.3     char* clsbase = testCls.cls.base;
5800 thilo.boehm 1.1 
5801 thilo.boehm 1.3     fprintf(_out,"\n\nDump of SCMOClass\n");
5802 r.kieninger 1.7 
5803                     if (inclMemHdr)
5804                     {
5805                         _dumpSCMBMgmt_Header(clshdr->header,clsbase);
5806                     }
5807                 
5808 thilo.boehm 1.3     // The reference counter for this c++ class
5809                     fprintf(_out,"\nrefCount=%i",clshdr->refCount.get());
5810                     fprintf(_out,"\n\nThe Flags:");
5811                     fprintf(_out,"\n   isEmpty: %s",
5812                            (clshdr->flags.isEmpty ? "True" : "False"));
5813                     fprintf(_out,"\n\nsuperClassName: \'%s\'",
5814                            NULLSTR(_getCharString(clshdr->superClassName,clsbase)));
5815                     fprintf(_out,"\nnameSpace: \'%s\'",
5816                             NULLSTR(_getCharString(clshdr->nameSpace,clsbase)));
5817                     fprintf(_out,"\nclassName: \'%s\'",
5818                             NULLSTR(_getCharString(clshdr->className,clsbase)));
5819                     fprintf(_out,"\n\nTheClass qualfiers:");
5820 thilo.boehm 1.2     _dumpQualifierArray(
5821                         clshdr->qualifierArray.start,
5822                         clshdr->numberOfQualifiers,
5823                         clsbase);
5824 thilo.boehm 1.3     fprintf(_out,"\n");
5825 thilo.boehm 1.2     dumpKeyPropertyMask(testCls);
5826 thilo.boehm 1.3     fprintf(_out,"\n");
5827 thilo.boehm 1.2     dumpKeyIndexList(testCls);
5828 thilo.boehm 1.3     fprintf(_out,"\n");
5829 thilo.boehm 1.2     dumpClassProperties(testCls);
5830 thilo.boehm 1.3     fprintf(_out,"\n");
5831 thilo.boehm 1.2     dumpKeyBindingSet(testCls);
5832 thilo.boehm 1.3     fprintf(_out,"\n");
5833 thilo.boehm 1.2     /*
5834                     */
5835 thilo.boehm 1.3     fprintf(_out,"\n");
5836                 
5837                 }
5838                 
5839                 void SCMODump::dumpSCMOClassQualifiers(SCMOClass& testCls) const
5840                 {
5841                     SCMBClass_Main* clshdr = testCls.cls.hdr;
5842                     char* clsbase = testCls.cls.base;
5843                 
5844                     fprintf(_out,"\n\nTheClass qualfiers:");
5845                     _dumpQualifierArray(
5846                         clshdr->qualifierArray.start,
5847                         clshdr->numberOfQualifiers,
5848                         clsbase);
5849                     fprintf(_out,"\n\n\n");
5850 thilo.boehm 1.1 
5851 thilo.boehm 1.2 }
5852 thilo.boehm 1.1 
5853 thilo.boehm 1.2 void SCMODump::hexDumpSCMOClass(SCMOClass& testCls) const
5854 thilo.boehm 1.1 {
5855 thilo.boehm 1.2     SCMBClass_Main* clshdr = testCls.cls.hdr;
5856 thilo.boehm 1.3     char* clsbase = testCls.cls.base;
5857 thilo.boehm 1.1 
5858 thilo.boehm 1.3     fprintf(_out,"\n\nHex dump of a SCMBClass:");
5859                     fprintf(_out,"\n========================");
5860                     fprintf(_out,"\n\n Size of SCMBClass: %llu\n\n",clshdr->header.totalSize);
5861 thilo.boehm 1.1 
5862 thilo.boehm 1.2     _hexDump(clsbase,clshdr->header.totalSize);
5863 thilo.boehm 1.1 
5864                 }
5865 thilo.boehm 1.2 void SCMODump::dumpKeyIndexList(SCMOClass& testCls) const
5866                 {
5867                     SCMBClass_Main* clshdr = testCls.cls.hdr;
5868 thilo.boehm 1.3     char* clsbase = testCls.cls.base;
5869 thilo.boehm 1.1 
5870 thilo.boehm 1.3     fprintf(_out,"\n\nKey Index List:");
5871                     fprintf(_out,"\n===============\n");
5872 thilo.boehm 1.1 
5873 thilo.boehm 1.2     // Get absolut pointer to key index list of the class
5874                     Uint32* keyIndex = (Uint32*)&(clsbase)[clshdr->keyIndexList.start];
5875 thilo.boehm 1.3     Uint32 line,j,i,k = clshdr->propertySet.number;
5876                     for (j = 0; j < k; j = j + line)
5877 thilo.boehm 1.1     {
5878 thilo.boehm 1.2         if ((clshdr->propertySet.number-j)/16)
5879 thilo.boehm 1.1         {
5880 thilo.boehm 1.2             line = 16 ;
5881 thilo.boehm 1.1         }
5882 thilo.boehm 1.2         else
5883 thilo.boehm 1.1         {
5884 thilo.boehm 1.2             line = clshdr->propertySet.number%16;
5885 thilo.boehm 1.1         }
5886                 
5887 thilo.boehm 1.2 
5888 thilo.boehm 1.3         fprintf(_out,"Index :");
5889 thilo.boehm 1.2         for (i = 0; i < line; i++)
5890 thilo.boehm 1.1         {
5891 thilo.boehm 1.3             fprintf(_out," %3u",j+i);
5892 thilo.boehm 1.1         }
5893                 
5894 thilo.boehm 1.3         fprintf(_out,"\nNode  :");
5895 thilo.boehm 1.2         for (i = 0; i < line; i++)
5896 thilo.boehm 1.1         {
5897 thilo.boehm 1.3             fprintf(_out," %3u",keyIndex[j+i]);
5898 thilo.boehm 1.1         }
5899                 
5900 thilo.boehm 1.3         fprintf(_out,"\n\n");
5901 thilo.boehm 1.2 
5902                     }
5903                 
5904                 }
5905                 
5906                 void SCMODump::dumpKeyBindingSet(SCMOClass& testCls) const
5907                 {
5908                     SCMBClass_Main* clshdr = testCls.cls.hdr;
5909 thilo.boehm 1.3     char* clsbase = testCls.cls.base;
5910 thilo.boehm 1.2 
5911 thilo.boehm 1.3     fprintf(_out,"\n\nKey Binding Set:");
5912                     fprintf(_out,"\n=================\n");
5913                     fprintf(_out,"\nNumber of key bindings: %3u",clshdr->keyBindingSet.number);
5914 thilo.boehm 1.2     dumpHashTable(
5915                         clshdr->keyBindingSet.hashTable,
5916                         PEGASUS_KEYBINDIG_SCMB_HASHSIZE);
5917 thilo.boehm 1.1 
5918 thilo.boehm 1.2     dumpClassKeyBindingNodeArray(testCls);
5919 thilo.boehm 1.1 
5920 thilo.boehm 1.2 }
5921 thilo.boehm 1.1 
5922 thilo.boehm 1.2 void SCMODump::dumpClassKeyBindingNodeArray(SCMOClass& testCls) const
5923                 {
5924                     SCMBClass_Main* clshdr = testCls.cls.hdr;
5925 thilo.boehm 1.3     char* clsbase = testCls.cls.base;
5926 thilo.boehm 1.1 
5927 thilo.boehm 1.2     SCMBKeyBindingNode* nodeArray =
5928                         (SCMBKeyBindingNode*)
5929                              &(clsbase[clshdr->keyBindingSet.nodeArray.start]);
5930 thilo.boehm 1.1 
5931 thilo.boehm 1.3     for (Uint32 i = 0, k = clshdr->keyBindingSet.number; i < k; i++)
5932 thilo.boehm 1.2     {
5933 thilo.boehm 1.3         fprintf(_out,"\n\n===================");
5934                         fprintf(_out,"\nKey Binding #%3u",i);
5935                         fprintf(_out,"\n===================");
5936 thilo.boehm 1.1 
5937 thilo.boehm 1.3         fprintf(_out,"\nHas next: %s",(nodeArray[i].hasNext?"TRUE":"FALSE"));
5938 thilo.boehm 1.2         if (nodeArray[i].hasNext)
5939 thilo.boehm 1.1         {
5940 thilo.boehm 1.3             fprintf(_out,"\nNext Node: %3u",nodeArray[i].nextNode);
5941 thilo.boehm 1.1         }
5942 thilo.boehm 1.2         else
5943 thilo.boehm 1.1         {
5944 thilo.boehm 1.3             fprintf(_out,"\nNext Node: N/A");
5945 thilo.boehm 1.1         }
5946                 
5947 thilo.boehm 1.3         fprintf(_out,"\nKey Property name: %s",
5948                                NULLSTR(_getCharString(nodeArray[i].name,clsbase)));
5949 thilo.boehm 1.2 
5950 thilo.boehm 1.3         fprintf(_out,"\nHash Tag %3u Hash Index %3u",
5951 thilo.boehm 1.2                nodeArray[i].nameHashTag,
5952                                nodeArray[i].nameHashTag%PEGASUS_KEYBINDIG_SCMB_HASHSIZE);
5953                 
5954 thilo.boehm 1.3         fprintf(_out,"\nType: %s",cimTypeToString(nodeArray[i].type));
5955 thilo.boehm 1.2 
5956                     }
5957                 
5958                 }
5959                 
5960                 void SCMODump::dumpClassProperties(SCMOClass& testCls) const
5961                 {
5962                     SCMBClass_Main* clshdr = testCls.cls.hdr;
5963 thilo.boehm 1.3     char* clsbase = testCls.cls.base;
5964 thilo.boehm 1.2 
5965 thilo.boehm 1.3     fprintf(_out,"\n\nClass Properties:");
5966                     fprintf(_out,"\n=================\n");
5967                     fprintf(_out,"\nNumber of properties: %3u",clshdr->propertySet.number);
5968 thilo.boehm 1.2     dumpHashTable(
5969                         clshdr->propertySet.hashTable,
5970                         PEGASUS_PROPERTY_SCMB_HASHSIZE);
5971                     dumpClassPropertyNodeArray(testCls);
5972                 
5973                 }
5974                 
5975                 void SCMODump::dumpClassPropertyNodeArray(SCMOClass& testCls) const
5976                 {
5977                     SCMBClass_Main* clshdr = testCls.cls.hdr;
5978 thilo.boehm 1.3     char* clsbase = testCls.cls.base;
5979 thilo.boehm 1.2 
5980                     SCMBClassPropertyNode* nodeArray =
5981                         (SCMBClassPropertyNode*)
5982                             &(clsbase[clshdr->propertySet.nodeArray.start]);
5983                 
5984 thilo.boehm 1.3     for (Uint32 i = 0, k =  clshdr->propertySet.number; i < k; i++)
5985 thilo.boehm 1.2     {
5986 thilo.boehm 1.1 
5987 thilo.boehm 1.3         fprintf(_out,"\nClass property #%3u",i);
5988                         fprintf(_out,"\n===================");
5989 thilo.boehm 1.1 
5990 thilo.boehm 1.3         fprintf(_out,"\nHas next: %s",(nodeArray[i].hasNext?"TRUE":"FALSE"));
5991 thilo.boehm 1.2         if (nodeArray[i].hasNext)
5992                         {
5993 thilo.boehm 1.3             fprintf(_out,"\nNext Node: %3u",nodeArray[i].nextNode);
5994 thilo.boehm 1.1         }
5995 thilo.boehm 1.2         else
5996 thilo.boehm 1.1         {
5997 thilo.boehm 1.3             fprintf(_out,"\nNext Node: N/A");
5998 thilo.boehm 1.1         }
5999                 
6000 thilo.boehm 1.2         _dumpClassProperty(nodeArray[i].theProperty,clsbase);
6001                     }
6002                 }
6003                 
6004                 void SCMODump::_dumpClassProperty(
6005                     const SCMBClassProperty& prop,
6006 thilo.boehm 1.3     char* clsbase) const
6007 thilo.boehm 1.2 {
6008 thilo.boehm 1.3     fprintf(_out,"\nProperty name: %s",
6009                             NULLSTR(_getCharString(prop.name,clsbase)));
6010 thilo.boehm 1.2 
6011 thilo.boehm 1.3     fprintf(_out,"\nHash Tag %3u Hash Index %3u",
6012 thilo.boehm 1.2            prop.nameHashTag,
6013                            prop.nameHashTag%PEGASUS_PROPERTY_SCMB_HASHSIZE);
6014 thilo.boehm 1.3     fprintf(_out,"\nPropagated: %s isKey: %s",
6015 thilo.boehm 1.2            (prop.flags.propagated?"TRUE":"FALSE"),
6016                            (prop.flags.isKey?"TRUE":"FALSE")
6017                            );
6018 thilo.boehm 1.1 
6019 thilo.boehm 1.3     fprintf(_out,"\nOrigin class name: %s",
6020                            NULLSTR(_getCharString(prop.originClassName,clsbase)));
6021                     fprintf(_out,"\nReference class name: %s",
6022                            NULLSTR(_getCharString(prop.refClassName,clsbase)));
6023 thilo.boehm 1.1 
6024 thilo.boehm 1.2     printSCMOValue(prop.defaultValue,clsbase);
6025 thilo.boehm 1.1 
6026 thilo.boehm 1.2     _dumpQualifierArray(
6027                         prop.qualifierArray.start,
6028                         prop.numberOfQualifiers,
6029                         clsbase);
6030 thilo.boehm 1.1 
6031                 }
6032                 
6033 thilo.boehm 1.2 void SCMODump::dumpHashTable(Uint32* hashTable,Uint32 size) const
6034 thilo.boehm 1.1 {
6035 thilo.boehm 1.2     Uint32 i,j,line;
6036 thilo.boehm 1.3     fprintf(_out,"\n\nHash table:\n");
6037 thilo.boehm 1.1 
6038                 
6039 thilo.boehm 1.2     for (j = 0; j < size; j = j + line)
6040                     {
6041                         if ((size-j)/16)
6042                         {
6043                             line = 16 ;
6044                         }
6045                         else
6046                         {
6047                             line = size%16;
6048                         }
6049 thilo.boehm 1.1 
6050                 
6051 thilo.boehm 1.3         fprintf(_out,"Index    :");
6052 thilo.boehm 1.2         for (i = 0; i < line; i++)
6053 thilo.boehm 1.1         {
6054 thilo.boehm 1.3             fprintf(_out," %3u",j+i);
6055 thilo.boehm 1.1         }
6056                 
6057 thilo.boehm 1.3         fprintf(_out,"\nHashTable:");
6058 thilo.boehm 1.2         for (i = 0; i < line; i++)
6059 thilo.boehm 1.1         {
6060 thilo.boehm 1.3             fprintf(_out," %3u",hashTable[j+i]);
6061 thilo.boehm 1.1         }
6062                 
6063 thilo.boehm 1.3         fprintf(_out,"\n\n");
6064 thilo.boehm 1.1 
6065                     }
6066                 
6067 thilo.boehm 1.2 
6068                 }
6069                 
6070                 void SCMODump::_dumpQualifierArray(
6071 thilo.boehm 1.3     Uint64 start,
6072 thilo.boehm 1.2     Uint32 size,
6073 thilo.boehm 1.3     char* clsbase
6074 thilo.boehm 1.2     ) const
6075                 {
6076                 
6077                     SCMBQualifier *theArray = (SCMBQualifier*)&(clsbase[start]);
6078                 
6079                     for(Uint32 i = 0; i < size; i++)
6080 thilo.boehm 1.1     {
6081 thilo.boehm 1.2         _dumpQualifier(theArray[i],clsbase);
6082 thilo.boehm 1.1     }
6083 thilo.boehm 1.2 }
6084 thilo.boehm 1.1 
6085 thilo.boehm 1.2 void SCMODump::_dumpQualifier(
6086                     const SCMBQualifier& theQualifier,
6087 thilo.boehm 1.3     char* clsbase
6088 thilo.boehm 1.2     ) const
6089                 {
6090                      if(theQualifier.name == QUALNAME_USERDEFINED)
6091                      {
6092 thilo.boehm 1.3          fprintf(_out,"\n\nQualifier user defined name: \'%s\'",
6093                                 NULLSTR(_getCharString(theQualifier.userDefName,clsbase)));
6094 thilo.boehm 1.2      }
6095                      else
6096 thilo.boehm 1.3      {
6097                          fprintf(_out,"\n\nQualifier DMTF defined name: \'%s\'",
6098                                 SCMOClass::qualifierNameStrLit(theQualifier.name).str);
6099                      }
6100                 
6101                      fprintf(_out,"\nPropagated : %s",
6102                             (theQualifier.propagated ? "True" : "False"));
6103                      fprintf(_out,"\nFlavor : %s",
6104                          (const char*)(CIMFlavor(theQualifier.flavor).toString().getCString()));
6105                 
6106                      printSCMOValue(theQualifier.value,clsbase);
6107                 
6108                 }
6109                 
6110                 void SCMODump::printSCMOValue(
6111                     const SCMBValue& theValue,
6112                     char* base,
6113                     Boolean verbose) const
6114                 {
6115                    fprintf(_out,"\nValueType : %s",cimTypeToString(theValue.valueType));
6116                    fprintf(_out,"\nValue was set: %s",
6117 thilo.boehm 1.3        (theValue.flags.isSet ? "True" : "False"));
6118                    if (theValue.flags.isNull)
6119                    {
6120                        fprintf(_out,"\nIt's a NULL value.");
6121                        return;
6122                    }
6123                    if (theValue.flags.isArray)
6124                    {
6125                        fprintf(
6126                            _out,
6127                            "\nThe value is an Array of size: %u",
6128                            theValue.valueArraySize);
6129                        printArrayValue(
6130                            theValue.valueType,
6131                            theValue.valueArraySize,
6132                            theValue.value,
6133                            base,
6134                            verbose);
6135                    }
6136                    else
6137                    {
6138 thilo.boehm 1.3        printUnionValue(theValue.valueType,theValue.value,base,verbose);
6139                    }
6140                 
6141                    return;
6142                 
6143                 }
6144                 
6145                 void SCMODump::dumpKeyPropertyMask(SCMOClass& testCls ) const
6146                 {
6147                 
6148                     SCMBClass_Main* clshdr = testCls.cls.hdr;
6149                     char* clsbase = testCls.cls.base;
6150                 
6151                      Uint64 *theKeyMask = (Uint64*)&(clsbase[clshdr->keyPropertyMask.start]);
6152                      Uint32 end, noProperties = clshdr->propertySet.number;
6153                      Uint32 noMasks = (noProperties-1)/64;
6154                      Uint64 printMask = 1;
6155                 
6156                      for (Uint32 i = 0; i <= noMasks; i++ )
6157                      {
6158                          printMask = 1;
6159 thilo.boehm 1.3          if (i < noMasks)
6160                          {
6161                              end = 64;
6162                          }
6163                          else
6164                          {
6165                              end = noProperties%64;
6166                          }
6167                 
6168                          fprintf(_out,"\nkeyPropertyMask[%02u]= ",i);
6169                 
6170                          for (Uint32 j = 0; j < end; j++)
6171                          {
6172                              if (j > 0 && !(j%8))
6173                              {
6174                                  fprintf(_out," ");
6175                              }
6176                 
6177                              if (theKeyMask[i] & printMask)
6178                              {
6179                                  fprintf(_out,"1");
6180 thilo.boehm 1.3              }
6181                              else
6182                              {
6183                                  fprintf(_out,"0");
6184                              }
6185                 
6186                              printMask = printMask << 1;
6187                          }
6188                          fprintf(_out,"\n");
6189                      }
6190                 }
6191                 
6192                 void SCMODump::_hexDump(char* buffer,Uint64 length) const
6193                 {
6194                 
6195                     unsigned char printLine[3][80];
6196                     int p;
6197                     int len;
6198                     unsigned char item;
6199                 
6200                     for (Uint64 i = 0; i < length;i=i+1)
6201 thilo.boehm 1.3     {
6202                         p = (int)i%80;
6203                 
6204                         if ((p == 0 && i > 0) || i == length-1 )
6205                         {
6206                             for (int y = 0; y < 3; y=y+1)
6207                             {
6208                                 if (p == 0)
6209                                 {
6210                                     len = 80;
6211                                 } else
6212                                 {
6213                                     len = p;
6214                                 }
6215 thilo.boehm 1.1 
6216 thilo.boehm 1.3                 for (int x = 0; x < len; x=x+1)
6217                                 {
6218                                     if (y == 0)
6219                                     {
6220                                         fprintf(_out,"%c",printLine[y][x]);
6221                                     }
6222                                     else
6223                                     {
6224                                         fprintf(_out,"%1X",printLine[y][x]);
6225                                     }
6226                                 }
6227                                 fprintf(_out,"\n");
6228                             }
6229                             fprintf(_out,"\n");
6230                         }
6231 thilo.boehm 1.1 
6232 thilo.boehm 1.3         item = (unsigned char)buffer[i];
6233 thilo.boehm 1.1 
6234 thilo.boehm 1.3         if (item < 32 || item > 125 )
6235                         {
6236                             printLine[0][p] = '.';
6237                         } else
6238                         {
6239                             printLine[0][p] = item;
6240                         }
6241 thilo.boehm 1.1 
6242 thilo.boehm 1.3         printLine[1][p] = item/16;
6243                         printLine[2][p] = item%16;
6244 thilo.boehm 1.1 
6245 thilo.boehm 1.3     }
6246 thilo.boehm 1.1 }
6247                 
6248 thilo.boehm 1.3 void SCMODump::printArrayValue(
6249 thilo.boehm 1.1     CIMType type,
6250 thilo.boehm 1.3     Uint32 size,
6251 thilo.boehm 1.2     SCMBUnion u,
6252 thilo.boehm 1.3     char* base,
6253                     Boolean verbose) const
6254 thilo.boehm 1.1 {
6255 thilo.boehm 1.2     Buffer out;
6256 thilo.boehm 1.1 
6257 thilo.boehm 1.3     SCMBUnion* p;
6258                     p = (SCMBUnion*)&(base[u.arrayValue.start]);
6259                 
6260 thilo.boehm 1.1     switch (type)
6261                     {
6262                     case CIMTYPE_BOOLEAN:
6263 thilo.boehm 1.2         {
6264                             for (Uint32 i = 0; i < size; i++)
6265                             {
6266 thilo.boehm 1.3                 out.append('\'');
6267                                 _toString(out,p[i].simple.val.bin);
6268                                 out << STRLIT("\'(hasValue=");
6269                                 out << (p[i].simple.hasValue ?
6270                                           STRLIT("TRUE)"):
6271                                           STRLIT("FALSE)"));
6272                                 out.append(';');
6273 thilo.boehm 1.2             }
6274 thilo.boehm 1.3             fprintf(_out,"\nThe values are: %s",out.getData());
6275 thilo.boehm 1.2             break;
6276                         }
6277                 
6278 thilo.boehm 1.1     case CIMTYPE_UINT8:
6279 thilo.boehm 1.2         {
6280 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6281                             {
6282                                 out.append('\'');
6283                                 _toString(out,p[i].simple.val.u8);
6284                                 out << STRLIT("\'(hasValue=");
6285                                 out << (p[i].simple.hasValue ?
6286                                           STRLIT("TRUE)"):
6287                                           STRLIT("FALSE)"));
6288                                 out.append(';');
6289                             }
6290                             fprintf(_out,"\nThe values are: %s",out.getData());
6291 thilo.boehm 1.2             break;
6292                         }
6293                 
6294 thilo.boehm 1.1     case CIMTYPE_SINT8:
6295 thilo.boehm 1.2         {
6296 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6297                             {
6298                                 out.append('\'');
6299                                 _toString(out,p[i].simple.val.s8);
6300                                 out << STRLIT("\'(hasValue=");
6301                                 out << (p[i].simple.hasValue ?
6302                                           STRLIT("TRUE)"):
6303                                           STRLIT("FALSE)"));
6304                                 out.append(';');
6305                             }
6306                             fprintf(_out,"\nThe values are: %s",out.getData());
6307 thilo.boehm 1.2             break;
6308                         }
6309                 
6310 thilo.boehm 1.1     case CIMTYPE_UINT16:
6311 thilo.boehm 1.2         {
6312 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6313                             {
6314                                 out.append('\'');
6315                                 _toString(out,p[i].simple.val.u16);
6316                                 out << STRLIT("\'(hasValue=");
6317                                 out << (p[i].simple.hasValue ?
6318                                           STRLIT("TRUE)"):
6319                                           STRLIT("FALSE)"));
6320                                 out.append(';');
6321                             }
6322                             fprintf(_out,"\nThe values are: %s",out.getData());
6323 thilo.boehm 1.2             break;
6324                         }
6325                 
6326 thilo.boehm 1.1     case CIMTYPE_SINT16:
6327 thilo.boehm 1.2         {
6328 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6329                             {
6330                                 out.append('\'');
6331                                 _toString(out,p[i].simple.val.s16);
6332                                 out << STRLIT("\'(hasValue=");
6333                                 out << (p[i].simple.hasValue ?
6334                                           STRLIT("TRUE)"):
6335                                           STRLIT("FALSE)"));
6336                                 out.append(';');
6337                             }
6338                             fprintf(_out,"\nThe values are: %s",out.getData());
6339 thilo.boehm 1.2             break;
6340                         }
6341                 
6342 thilo.boehm 1.1     case CIMTYPE_UINT32:
6343 thilo.boehm 1.2         {
6344 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6345                             {
6346                                 out.append('\'');
6347                                 _toString(out,p[i].simple.val.u32);
6348                                 out << STRLIT("\'(hasValue=");
6349                                 out << (p[i].simple.hasValue ?
6350                                           STRLIT("TRUE)"):
6351                                           STRLIT("FALSE)"));
6352                                 out.append(';');
6353                             }
6354                             fprintf(_out,"\nThe values are: %s",out.getData());
6355 thilo.boehm 1.2             break;
6356                         }
6357                 
6358 thilo.boehm 1.1     case CIMTYPE_SINT32:
6359 thilo.boehm 1.2         {
6360 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6361                             {
6362                                 out.append('\'');
6363                                 _toString(out,p[i].simple.val.s32);
6364                                 out << STRLIT("\'(hasValue=");
6365                                 out << (p[i].simple.hasValue ?
6366                                           STRLIT("TRUE)"):
6367                                           STRLIT("FALSE)"));
6368                                 out.append(';');
6369                             }
6370                             fprintf(_out,"\nThe values are: %s",out.getData());
6371 thilo.boehm 1.2             break;
6372                         }
6373                 
6374 thilo.boehm 1.1     case CIMTYPE_UINT64:
6375 thilo.boehm 1.2         {
6376 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6377                             {
6378                                 out.append('\'');
6379                                 _toString(out,p[i].simple.val.u64);
6380                                 out << STRLIT("\'(hasValue=");
6381                                 out << (p[i].simple.hasValue ?
6382                                           STRLIT("TRUE)"):
6383                                           STRLIT("FALSE)"));
6384                                 out.append(';');
6385                             }
6386                             fprintf(_out,"\nThe values are: %s",out.getData());
6387 thilo.boehm 1.2             break;
6388                         }
6389                 
6390 thilo.boehm 1.1     case CIMTYPE_SINT64:
6391 thilo.boehm 1.2         {
6392 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6393                             {
6394                                 out.append('\'');
6395                                 _toString(out,p[i].simple.val.s64);
6396                                 out << STRLIT("\'(hasValue=");
6397                                 out << (p[i].simple.hasValue ?
6398                                           STRLIT("TRUE)"):
6399                                           STRLIT("FALSE)"));
6400                                 out.append(';');
6401                             }
6402                             fprintf(_out,"\nThe values are: %s",out.getData());
6403 thilo.boehm 1.2             break;
6404                         }
6405                 
6406 thilo.boehm 1.1     case CIMTYPE_REAL32:
6407 thilo.boehm 1.2         {
6408 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6409                             {
6410                                 out.append('\'');
6411                                 _toString(out,p[i].simple.val.r32);
6412                                 out << STRLIT("\'(hasValue=");
6413                                 out << (p[i].simple.hasValue ?
6414                                           STRLIT("TRUE)"):
6415                                           STRLIT("FALSE)"));
6416                                 out.append(';');
6417                             }
6418                             fprintf(_out,"\nThe values are: %s",out.getData());
6419 thilo.boehm 1.2             break;
6420                         }
6421                 
6422 thilo.boehm 1.1     case CIMTYPE_REAL64:
6423 thilo.boehm 1.2         {
6424 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6425                             {
6426                                 out.append('\'');
6427                                 _toString(out,p[i].simple.val.r64);
6428                                 out << STRLIT("\'(hasValue=");
6429                                 out << (p[i].simple.hasValue ?
6430                                           STRLIT("TRUE)"):
6431                                           STRLIT("FALSE)"));
6432                                 out.append(';');
6433                             }
6434                             fprintf(_out,"\nThe values are: %s",out.getData());
6435 thilo.boehm 1.2             break;
6436                         }
6437                 
6438 thilo.boehm 1.1     case CIMTYPE_CHAR16:
6439                         {
6440 thilo.boehm 1.3             for (Uint32 i = 0; i < size; i++)
6441                             {
6442                                 out.append('\'');
6443                                 _toString(out,p[i].simple.val.c16);
6444                                 out << STRLIT("\'(hasValue=");
6445                                 out << (p[i].simple.hasValue ?
6446                                           STRLIT("TRUE)"):
6447                                           STRLIT("FALSE)"));
6448                                 out.append(';');
6449                             }
6450                             fprintf(_out,"\nThe values are: %s",out.getData());
6451 thilo.boehm 1.1             break;
6452                         }
6453                 
6454                     case CIMTYPE_STRING:
6455                         {
6456 thilo.boehm 1.2             for (Uint32 i = 0; i < size; i++)
6457 thilo.boehm 1.1             {
6458 thilo.boehm 1.3                 if ( 0 != p[i].stringValue.size)
6459                                 {
6460                                     out.append('\'');
6461                                     out.append(
6462                                         (const char*)_getCharString(p[i].stringValue,base),
6463                                         p[i].stringValue.size-1);
6464                                     out.append('\'');
6465                                 }
6466                                 else
6467                                 {
6468                                   out << STRLIT("NULL;");
6469                                 }
6470                                 out.append(';');
6471 thilo.boehm 1.2             }
6472 thilo.boehm 1.3             fprintf(_out,"\nThe values are: %s",out.getData());
6473 thilo.boehm 1.2             break;
6474                         }
6475 thilo.boehm 1.1 
6476 thilo.boehm 1.2     case CIMTYPE_DATETIME:
6477                         {
6478                             CIMDateTime x;
6479                             for (Uint32 i = 0; i < size; i++)
6480 thilo.boehm 1.1             {
6481 thilo.boehm 1.3                 memcpy(x._rep,&(p[i].dateTimeValue),sizeof(SCMBDateTime));
6482 thilo.boehm 1.2                 _toString(out,x);
6483 thilo.boehm 1.3                 out.append(' ');
6484 thilo.boehm 1.1             }
6485 thilo.boehm 1.3             fprintf(_out,"\nThe values are: %s",out.getData());
6486 thilo.boehm 1.1             break;
6487                         }
6488                 
6489                     case CIMTYPE_REFERENCE:
6490 thilo.boehm 1.3     case CIMTYPE_OBJECT:
6491                     case CIMTYPE_INSTANCE:
6492 thilo.boehm 1.2         {
6493 thilo.boehm 1.3             if (verbose)
6494                             {
6495                                 for (Uint32 i = 0; i < size; i++)
6496                                 {
6497                                     fprintf(_out,"\n-----------> "
6498                                                   "Start of embedded external reference [%d]"
6499                                                   " <-----------\n\n",i);
6500                                     dumpSCMOInstance(*(p[i].extRefPtr));
6501                                     fprintf(_out,"\n-----------> "
6502                                                   "End of embedded external reference [%d]"
6503                                                   " <-----------\n\n",i);
6504                                 }
6505                 
6506                             } else
6507                             {
6508                                 fprintf(_out,"\nThe values are: ");
6509                 
6510                                 for (Uint32 i = 0; i < size; i++)
6511                                 {
6512                                     fprintf(
6513                                         _out,
6514 thilo.boehm 1.3                         "Pointer to external Reference[%d] : \'%p\';",
6515                                         i,p[i].extRefPtr);
6516                                 }
6517                             }
6518 thilo.boehm 1.1 
6519 thilo.boehm 1.2             break;
6520 thilo.boehm 1.1 
6521 thilo.boehm 1.2         }
6522 thilo.boehm 1.1     default:
6523 thilo.boehm 1.2         {
6524 thilo.boehm 1.3             PEGASUS_ASSERT(false);
6525                             break;
6526 thilo.boehm 1.2         }
6527 thilo.boehm 1.1     }
6528                 
6529 thilo.boehm 1.3     return;
6530 thilo.boehm 1.1 }
6531                 
6532 thilo.boehm 1.3 void SCMODump::printUnionValue(
6533                     CIMType type,
6534 thilo.boehm 1.2     SCMBUnion u,
6535 thilo.boehm 1.3     char* base,
6536                     Boolean verbose) const
6537 thilo.boehm 1.1 {
6538 thilo.boehm 1.3 
6539 thilo.boehm 1.2     Buffer out;
6540 thilo.boehm 1.1 
6541 thilo.boehm 1.2     switch (type)
6542 thilo.boehm 1.1     {
6543 thilo.boehm 1.2     case CIMTYPE_BOOLEAN:
6544                         {
6545 thilo.boehm 1.3             _toString(out,u.simple.val.bin);
6546                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6547 thilo.boehm 1.2             break;
6548                         }
6549 thilo.boehm 1.1 
6550 thilo.boehm 1.2     case CIMTYPE_UINT8:
6551                         {
6552 thilo.boehm 1.3             _toString(out,u.simple.val.u8);
6553                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6554 thilo.boehm 1.2             break;
6555                         }
6556 thilo.boehm 1.1 
6557 thilo.boehm 1.2     case CIMTYPE_SINT8:
6558                         {
6559 thilo.boehm 1.3             _toString(out,u.simple.val.s8);
6560                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6561 thilo.boehm 1.2             break;
6562                         }
6563 thilo.boehm 1.1 
6564 thilo.boehm 1.2     case CIMTYPE_UINT16:
6565                         {
6566 thilo.boehm 1.3             _toString(out,(Uint32)u.simple.val.u16);
6567                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6568 thilo.boehm 1.2             break;
6569                         }
6570 thilo.boehm 1.1 
6571 thilo.boehm 1.2     case CIMTYPE_SINT16:
6572                         {
6573 thilo.boehm 1.3             _toString(out,u.simple.val.s16);
6574                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6575 thilo.boehm 1.2             break;
6576                         }
6577 thilo.boehm 1.1 
6578 thilo.boehm 1.2     case CIMTYPE_UINT32:
6579                         {
6580 thilo.boehm 1.3             _toString(out,u.simple.val.u32);
6581                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6582 thilo.boehm 1.2             break;
6583                         }
6584 thilo.boehm 1.1 
6585 thilo.boehm 1.2     case CIMTYPE_SINT32:
6586                         {
6587 thilo.boehm 1.3             _toString(out,u.simple.val.s32);
6588                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6589 thilo.boehm 1.2             break;
6590                         }
6591 thilo.boehm 1.1 
6592 thilo.boehm 1.2     case CIMTYPE_UINT64:
6593 thilo.boehm 1.1         {
6594 thilo.boehm 1.3             _toString(out,u.simple.val.u64);
6595                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6596 thilo.boehm 1.2             break;
6597 thilo.boehm 1.1         }
6598                 
6599 thilo.boehm 1.2     case CIMTYPE_SINT64:
6600                         {
6601 thilo.boehm 1.3             _toString(out,u.simple.val.s64);
6602                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6603 thilo.boehm 1.2             break;
6604                         }
6605 thilo.boehm 1.1 
6606 thilo.boehm 1.2     case CIMTYPE_REAL32:
6607                         {
6608 thilo.boehm 1.3             _toString(out,u.simple.val.r32);
6609                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6610 thilo.boehm 1.2             break;
6611                         }
6612 thilo.boehm 1.1 
6613 thilo.boehm 1.2     case CIMTYPE_REAL64:
6614                         {
6615 thilo.boehm 1.3             _toString(out,u.simple.val.r32);
6616                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6617 thilo.boehm 1.2             break;
6618                         }
6619 thilo.boehm 1.1 
6620 thilo.boehm 1.2     case CIMTYPE_CHAR16:
6621                         {
6622 thilo.boehm 1.3             _toString(out,u.simple.val.c16);
6623                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6624 thilo.boehm 1.2             break;
6625                         }
6626 thilo.boehm 1.1 
6627 thilo.boehm 1.2     case CIMTYPE_STRING:
6628                         {
6629 thilo.boehm 1.3             if ( 0 != u.stringValue.size)
6630                             {
6631                                 out.append((const char*)_getCharString(u.stringValue,base),
6632                                            u.stringValue.size-1);
6633                             }
6634                             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6635 thilo.boehm 1.2             break;
6636                         }
6637 thilo.boehm 1.1 
6638 thilo.boehm 1.2     case CIMTYPE_DATETIME:
6639                         {
6640                             CIMDateTime x;
6641 thilo.boehm 1.3             memcpy(x._rep,&(u.dateTimeValue),sizeof(SCMBDateTime));
6642 thilo.boehm 1.2             _toString(out,x);
6643 thilo.boehm 1.3             fprintf(_out,"\nThe Value is: '%s'",out.getData());
6644 thilo.boehm 1.2             break;
6645                         }
6646 thilo.boehm 1.1 
6647 thilo.boehm 1.2     case CIMTYPE_REFERENCE:
6648                     case CIMTYPE_OBJECT:
6649 thilo.boehm 1.3     case CIMTYPE_INSTANCE:
6650 thilo.boehm 1.2         {
6651 thilo.boehm 1.3             if (verbose)
6652                             {
6653                                 fprintf(_out,"\n-----------> "
6654                                               "Start of embedded external reference"
6655                                               " <-----------\n\n");
6656                                 dumpSCMOInstance(*u.extRefPtr);
6657                                 fprintf(_out,"\n-----------> "
6658                                              "End of embedded external reference"
6659                                              " <-----------\n\n");
6660                             } else
6661                             {
6662                                 fprintf(
6663                                     _out,
6664                                     "Pointer to external Reference : \'%p\'",
6665                                     u.extRefPtr);
6666                             }
6667 thilo.boehm 1.1 
6668 thilo.boehm 1.2             break;
6669                         }
6670                     default:
6671                         {
6672 thilo.boehm 1.3             PEGASUS_ASSERT(false);
6673                             break;
6674 thilo.boehm 1.2         }
6675                     }
6676 thilo.boehm 1.1 
6677 thilo.boehm 1.3   return;
6678 thilo.boehm 1.1 }
6679                 
6680                 
6681 thilo.boehm 1.2 /*****************************************************************************
6682                  * The constant functions
6683                  *****************************************************************************/
6684                 
6685 thilo.boehm 1.3 #ifdef PEGASUS_HAS_ICU
6686                 Uint32 _utf8ICUncasecmp(
6687                     const char* a,
6688                     const char* b,
6689                     Uint32 len)
6690 thilo.boehm 1.1 {
6691 thilo.boehm 1.3     UErrorCode errorCode=U_ZERO_ERROR;
6692                 
6693                     Uint32 rc, a16len,b16len,utf16BufLen;
6694                     utf16BufLen = (len*sizeof(UChar))+2;
6695 thilo.boehm 1.1 
6696 thilo.boehm 1.3     UChar* a_UTF16 = (UChar*)malloc(utf16BufLen);
6697                     UChar* b_UTF16 = (UChar*)malloc(utf16BufLen);
6698 thilo.boehm 1.1 
6699 thilo.boehm 1.3     UConverter *conv = ucnv_open(0, &errorCode);
6700                     if(U_FAILURE(errorCode))
6701                     {
6702                         free(a_UTF16);
6703                         free(b_UTF16);
6704                         String message("SCMO::_utf8ICUncasecmp() ICUError: ");
6705                         message.append(u_errorName(errorCode));
6706                         message.append(" Can not open ICU default converter!");
6707                         throw CIMException(CIM_ERR_FAILED,message );
6708                     }
6709 thilo.boehm 1.1 
6710 thilo.boehm 1.3     a16len = ucnv_toUChars(conv,a_UTF16,utf16BufLen,a,len,&errorCode);
6711 thilo.boehm 1.1 
6712 thilo.boehm 1.3     if(U_FAILURE(errorCode))
6713 thilo.boehm 1.1     {
6714 thilo.boehm 1.3         free(a_UTF16);
6715                         free(b_UTF16);
6716                         ucnv_close(conv);
6717                         String message("SCMO::_utf8ICUncasecmp() ICUError: ");
6718                         message.append(u_errorName(errorCode));
6719                         message.append(" Can not convert string a:'");
6720                         message.append(String(a,len));
6721                         message.append('\'');
6722                         throw CIMException(CIM_ERR_FAILED,message );
6723 thilo.boehm 1.1     }
6724                 
6725 thilo.boehm 1.3     b16len = ucnv_toUChars(conv,b_UTF16,utf16BufLen,b,len,&errorCode);
6726                 
6727                     if(U_FAILURE(errorCode))
6728 thilo.boehm 1.1     {
6729 thilo.boehm 1.3         free(a_UTF16);
6730                         free(b_UTF16);
6731                         ucnv_close(conv);
6732                         String message("SCMO::_utf8ICUncasecmp() ICUError: ");
6733                         message.append(u_errorName(errorCode));
6734                         message.append(" Can not convert string b:'");
6735                         message.append(String(b,len));
6736                         message.append('\'');
6737                         throw CIMException(CIM_ERR_FAILED,message );
6738 thilo.boehm 1.1     }
6739                 
6740 thilo.boehm 1.3     rc = u_strCaseCompare(
6741                         a_UTF16,a16len,
6742                         b_UTF16,b16len,
6743                         U_FOLD_CASE_DEFAULT,
6744                         &errorCode);
6745 thilo.boehm 1.2 
6746 thilo.boehm 1.3     if(U_FAILURE(errorCode))
6747 thilo.boehm 1.1     {
6748 thilo.boehm 1.3         free(a_UTF16);
6749                         free(b_UTF16);
6750                         ucnv_close(conv);
6751                         String message("SCMO::_utf8ICUncasecmp() ICUError: ");
6752                         message.append(u_errorName(errorCode));
6753                         message.append(" Can not compare string a:'");
6754                         message.append(String(a,len));
6755                         message.append("' with b: '");
6756                         message.append(String(b,len));
6757                         message.append('\'');
6758                         throw CIMException(CIM_ERR_FAILED,message );
6759 thilo.boehm 1.1     }
6760                 
6761 thilo.boehm 1.3     free(a_UTF16);
6762                     free(b_UTF16);
6763                     ucnv_close(conv);
6764 thilo.boehm 1.1 
6765 thilo.boehm 1.3     return(rc);
6766 thilo.boehm 1.1 }
6767 thilo.boehm 1.3 #endif
6768 thilo.boehm 1.1 
6769                 /**
6770                  * This function calcutates a free memory slot in the single chunk memory block.
6771 thilo.boehm 1.2  * Warning: In this routine a reallocation may take place.
6772 thilo.boehm 1.1  * @param ptr A reference to a data SCMB data pointer. The values to the free
6773 thilo.boehm 1.2  *            block is written into this pointer. If the provided ptr is
6774                  *            located in the single chunk memory block, this pointer may be
6775                  *            invalid after this call. You have to recalcuate the pointer
6776 thilo.boehm 1.1  *            after calling this function.
6777                  * @parm size The requested free memory slot.
6778                  * @parm pmem A reference to the pointer of the single chunk memory block.
6779                  *            e.g. &cls.mem
6780                  * @return The relaive index of the free memory slot.
6781                  */
6782 thilo.boehm 1.3 Uint64 _getFreeSpace(
6783 thilo.boehm 1.2     SCMBDataPtr& ptr,
6784 thilo.boehm 1.3     Uint32 size,
6785                     SCMBMgmt_Header** pmem)
6786 thilo.boehm 1.1 {
6787                     Uint64 oldSize, start;
6788 marek       1.4     Uint64 alignedStart, reqAlignSize;
6789 thilo.boehm 1.1 
6790                     if (size == 0)
6791                     {
6792                         ptr.start = 0;
6793 thilo.boehm 1.3         ptr.size = 0;
6794 thilo.boehm 1.1         return 0;
6795                     }
6796                 
6797 thilo.boehm 1.2     // The SCMBDataPtr has to be set before any reallocation.
6798 thilo.boehm 1.1     start = (*pmem)->startOfFreeSpace;
6799 marek       1.4 
6800                     // Need to align the start of freespace to 8 byte
6801                     // boundaries to avoid alignment issues on some architectures
6802                     // Round up to nearest multiple of 8
6803                     alignedStart = (start + 7) & ~7;
6804                     // due to the alignment, a little more room is needed in the SCMB
6805                     reqAlignSize = (size + alignedStart - start);
6806                 
6807                     ptr.start = alignedStart;
6808 thilo.boehm 1.3     ptr.size = size;
6809 marek       1.4     // add 8 bytes of size for later alignment on the next pointer
6810                     while ((*pmem)->freeBytes < reqAlignSize)
6811 thilo.boehm 1.1     {
6812                         // save old size of buffer
6813                         oldSize = (*pmem)->totalSize;
6814                         // reallocate the buffer, double the space !
6815                         // This is a working approach until a better algorithm is found.
6816 thilo.boehm 1.3         void* newBlockPtr = realloc((*pmem),(size_t)oldSize*2);
6817                         if ((newBlockPtr) == 0)
6818 thilo.boehm 1.1         {
6819 thilo.boehm 1.2             // Not enough memory!
6820 thilo.boehm 1.1             throw PEGASUS_STD(bad_alloc)();
6821                         }
6822 thilo.boehm 1.3         (*pmem) = (SCMBMgmt_Header*)newBlockPtr;
6823 thilo.boehm 1.2         // increase the total size and free space
6824 thilo.boehm 1.3         (*pmem)->freeBytes+=oldSize;
6825                         (*pmem)->totalSize+=oldSize;
6826 thilo.boehm 1.2     }
6827 thilo.boehm 1.1 
6828 marek       1.4     (*pmem)->freeBytes -= reqAlignSize;
6829                     (*pmem)->startOfFreeSpace = alignedStart + size;
6830 thilo.boehm 1.3 
6831 marek       1.4     // Init memory from unaligned start up to the size required with alignment
6832                     // to zero.
6833                     memset(&((char*)(*pmem))[start],0,(size_t)reqAlignSize);
6834 thilo.boehm 1.1 
6835 marek       1.4     return alignedStart;
6836 thilo.boehm 1.1 }
6837                 
6838 thilo.boehm 1.3 void _setString(
6839 thilo.boehm 1.2     const String& theString,
6840                     SCMBDataPtr& ptr,
6841 thilo.boehm 1.1     SCMBMgmt_Header** pmem)
6842                 {
6843                 
6844                     // Get the UTF8 CString
6845                     CString theCString=theString.getCString();
6846 thilo.boehm 1.2     // Get the real size of the UTF8 sting + \0.
6847                     // It maybe greater then the length in the String due to
6848 thilo.boehm 1.1     // 4 byte encoding of non ASCII chars.
6849 thilo.boehm 1.3     Uint64 start;
6850                     Uint32 length = strlen((const char*)theCString)+1;
6851 thilo.boehm 1.1 
6852                     // If the string is not empty.
6853                     if (length != 1)
6854                     {
6855                 
6856                        // Attention ! In this function a reallocation may take place.
6857 thilo.boehm 1.2        // The reference ptr may be unusable after the call to _getFreeSpace
6858 thilo.boehm 1.1        // --> use the returned start index.
6859 thilo.boehm 1.2        start = _getFreeSpace(ptr , length, pmem);
6860 thilo.boehm 1.1        // Copy string including trailing \0
6861 thilo.boehm 1.3        memcpy(&((char*)(*pmem))[start],(const char*)theCString,length);
6862 thilo.boehm 1.2     }
6863 thilo.boehm 1.1     else
6864                     {
6865                         ptr.start = 0;
6866 thilo.boehm 1.3         ptr.size = 0;
6867 thilo.boehm 1.1     }
6868                 }
6869                 
6870 thilo.boehm 1.3 void _setBinary(
6871 thilo.boehm 1.2     const void* theBuffer,
6872 thilo.boehm 1.3     Uint32 bufferSize,
6873 thilo.boehm 1.2     SCMBDataPtr& ptr,
6874 thilo.boehm 1.1     SCMBMgmt_Header** pmem)
6875                 {
6876                 
6877                     // If buffer is not empty.
6878 thilo.boehm 1.3     if (bufferSize != 0 && theBuffer != 0)
6879 thilo.boehm 1.1     {
6880                 
6881                         Uint64 start;
6882                         // Attention ! In this function a reallocation may take place.
6883 thilo.boehm 1.2         // The reference ptr may be unusable after the call to _getFreeSpace
6884 thilo.boehm 1.1         // --> use the returned start index.
6885 thilo.boehm 1.2         start = _getFreeSpace(ptr , bufferSize, pmem);
6886 thilo.boehm 1.1         // Copy buffer into SCMB
6887                         memcpy(
6888 thilo.boehm 1.3             &((char*)(*pmem))[start],
6889 thilo.boehm 1.1             (const char*)theBuffer,
6890 thilo.boehm 1.2             bufferSize);
6891                     }
6892 thilo.boehm 1.1     else
6893                     {
6894                         ptr.start = 0;
6895 thilo.boehm 1.3         ptr.size = 0;
6896 thilo.boehm 1.1     }
6897                 }
6898                 
6899 thilo.boehm 1.3 void _destroyExternalReferencesInternal(SCMBMgmt_Header* memHdr)
6900                 {
6901                 
6902                     Uint32 number = memHdr->numberExtRef;
6903                 
6904                     if (0 != number)
6905                     {
6906                         char * base = ((char*)memHdr);
6907                         Uint64* array =
6908                             (Uint64*)&(base[memHdr->extRefIndexArray.start]);
6909                         for (Uint32 i = 0; i < number; i++)
6910                         {
6911                              delete ((SCMBUnion*)(&(base[array[i]])))->extRefPtr;
6912                         }
6913                 
6914                     }
6915                 }
6916 thilo.boehm 1.1 
6917                 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2