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

   1 mike  1.1.2.1 //%2006////////////////////////////////////////////////////////////////////////
   2               //
   3               // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   4               // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   5               // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   6               // IBM Corp.; EMC Corporation, The Open Group.
   7               // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   8               // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   9               // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10               // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11               // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12               // EMC Corporation; Symantec Corporation; The Open Group.
  13               //
  14               // Permission is hereby granted, free of charge, to any person obtaining a copy
  15               // of this software and associated documentation files (the "Software"), to
  16               // deal in the Software without restriction, including without limitation the
  17               // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18               // sell copies of the Software, and to permit persons to whom the Software is
  19               // furnished to do so, subject to the following conditions:
  20               //
  21               // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22 mike  1.1.2.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  23               // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  24               // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  25               // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26               // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27               // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28               // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29               //
  30               //==============================================================================
  31               //
  32               //%/////////////////////////////////////////////////////////////////////////////
  33               
  34               #include <cstdarg>
  35               #include <cassert>
  36               #include "SourceRepository.h"
  37               #include <Pegasus/Common/System.h>
  38               
  39 mike  1.1.2.2 /*
  40               ATTN-MEB: take these out!
  41               */
  42               #include "root_cimv2_namespace.h"
  43               #include "root_PG_Internal_namespace.h"
  44               #include "root_PG_InterOp_namespace.h"
  45               
  46 mike  1.1.2.1 PEGASUS_NAMESPACE_BEGIN
  47               
  48               static const size_t _MAX_NAMESPACES = 32;
  49               static const SourceNameSpace* _nameSpaces[_MAX_NAMESPACES];
  50               static size_t _nameSpacesSize = 0;
  51               
  52 mike  1.1.2.2 static const size_t _MAX_FEATURES = 1024;
  53               static const size_t _MAX_QUALIFIERS = 1024;
  54               
  55               /*
  56               ATTN-MEB: take this out!
  57               */
  58               static void _init()
  59               {
  60                   if (_nameSpacesSize == 0)
  61                   {
  62                       SourceRepository::addNameSpace(&root_PG_InterOp_namespace);
  63                       SourceRepository::addNameSpace(&root_cimv2_namespace);
  64                       SourceRepository::addNameSpace(&root_PG_Internal_namespace);
  65                   }
  66               }
  67               
  68               static bool _eqi(const char* s1, const char* s2)
  69               {
  70                   return System::strcasecmp(s1, s2) == 0;
  71               }
  72               
  73 mike  1.1.2.1 //==============================================================================
  74               //
  75               // Local definitions:
  76               //
  77               //==============================================================================
  78               
  79               class Str
  80               {
  81               public:
  82                   Str(const String& s) : _cstr(s.getCString()) { }
  83                   Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
  84                   Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
  85                   Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
  86                   Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
  87                   Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
  88                   const char* operator*() const { return (const char*)_cstr; }
  89                   operator const char*() const { return (const char*)_cstr; }
  90               private:
  91                   CString _cstr;
  92               };
  93               
  94 mike  1.1.2.1 PEGASUS_FORMAT(2, 3)
  95               static void _throw(CIMStatusCode code, const char* format, ...)
  96               {
  97                   char buffer[4096];
  98               
  99                   va_list ap;
 100                   va_start(ap, format);
 101                   vsprintf(buffer, format, ap);
 102                   va_end(ap);
 103 mike  1.1.2.2     throw CIMException(code, buffer);
 104 mike  1.1.2.1 }
 105               
 106               static const SourceNameSpace* _findNameSpace(const char* name)
 107               {
 108                   for (size_t i = 0; i < _nameSpacesSize; i++)
 109                   {
 110 mike  1.1.2.2         if (_eqi(_nameSpaces[i]->name, name))
 111 mike  1.1.2.1             return _nameSpaces[i];
 112                   }
 113               
 114                   // Not found!
 115                   return 0;
 116               }
 117               
 118               static bool _isSubClass(const SourceClass* super, const SourceClass* sub)
 119               {
 120                   if (!super)
 121                       return true;
 122               
 123                   for (SourceClass* p = sub->super; p; p = p->super)
 124                   {
 125                       if (p == super)
 126                           return true;
 127                   }
 128               
 129                   return false;
 130               }
 131               
 132 mike  1.1.2.1 static inline bool _isDirectSubClass(
 133                   const SourceClass* super, 
 134                   const SourceClass* sub)
 135               {
 136                   return sub->super == super;
 137               }
 138               
 139               static const SourceClass* _findClass(
 140                   const SourceNameSpace* ns, 
 141                   const char* name)
 142               {
 143                   for (size_t i = 0; ns->classes[i]; i++)
 144                   {
 145                       const SourceClass* sc = ns->classes[i];
 146               
 147 mike  1.1.2.2         if (_eqi(sc->name, name))
 148 mike  1.1.2.1             return sc;
 149                   }
 150               
 151                   // Not found!
 152                   return 0;
 153               }
 154               
 155               static inline void _readBoolean(const char*& value, Boolean& x)
 156               {
 157                   unsigned const char* p = (unsigned const char*)value;
 158                   x = Boolean(p[0]);
 159                   value++;
 160               }
 161               
 162               static inline void _readUint8(const char*& value, Uint8& x)
 163               {
 164                   unsigned const char* p = (unsigned const char*)value;
 165                   x = Uint8(p[0]);
 166                   value += sizeof(x);
 167               }
 168               
 169 mike  1.1.2.1 static inline void _readSint8(const char*& value, Sint8& x)
 170               {
 171                   _readUint8(value, *((Uint8*)&x));
 172               }
 173               
 174               static inline void _readUint16(const char*& value, Uint16& x)
 175               {
 176                   unsigned const char* p = (unsigned const char*)value;
 177                   Uint16 x0 = Uint16(p[0]) << 8;
 178                   Uint16 x1 = Uint16(p[1]) << 0;
 179                   x = Uint16(x0 | x1);
 180                   value += sizeof(x);
 181               }
 182               
 183               static inline void _readSint16(const char*& value, Sint16& x)
 184               {
 185                   _readUint16(value, *((Uint16*)&x));
 186                   value += sizeof(x);
 187               }
 188               
 189               static inline void _readUint32(const char*& value, Uint32& x)
 190 mike  1.1.2.1 {
 191                   unsigned const char* p = (unsigned const char*)value;
 192                   Uint32 x0 = Uint32(p[0]) << 24;
 193                   Uint32 x1 = Uint32(p[1]) << 16;
 194                   Uint32 x2 = Uint32(p[0]) <<  8;
 195                   Uint32 x3 = Uint32(p[1]) <<  0;
 196                   x = Uint32(x0 | x1 | x2 | x3);
 197                   value += sizeof(x);
 198               }
 199               
 200               static inline void _readSint32(const char*& value, Sint32& x)
 201               {
 202                   _readUint32(value, *((Uint32*)&x));
 203                   value += sizeof(x);
 204               }
 205               
 206               static inline void _readUint64(const char*& value, Uint64& x)
 207               {
 208                   unsigned const char* p = (unsigned const char*)value;
 209                   Uint64 x0 = Uint64(p[0]) << 56;
 210                   Uint64 x1 = Uint64(p[1]) << 48;
 211 mike  1.1.2.1     Uint64 x2 = Uint64(p[2]) << 40;
 212                   Uint64 x3 = Uint64(p[3]) << 32;
 213                   Uint64 x4 = Uint64(p[4]) << 24;
 214                   Uint64 x5 = Uint64(p[5]) << 16;
 215                   Uint64 x6 = Uint64(p[6]) <<  8;
 216                   Uint64 x7 = Uint64(p[7]) <<  0;
 217                   x = Uint64(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7);
 218                   value += sizeof(x);
 219               }
 220               
 221               static inline void _readSint64(const char*& value, Sint64& x)
 222               {
 223                   _readUint64(value, *((Uint64*)&x));
 224                   value += sizeof(x);
 225               }
 226               
 227               static inline void _readReal32(const char*& value, Real32& x)
 228               {
 229                   _readUint32(value, *((Uint32*)&x));
 230                   value += sizeof(x);
 231               }
 232 mike  1.1.2.1 
 233               static inline void _readReal64(const char*& value, Real64& x)
 234               {
 235                   _readUint64(value, *((Uint64*)&x));
 236                   value += sizeof(x);
 237               }
 238               
 239               static inline void _readChar16(const char*& value, Char16& x)
 240               {
 241                   _readUint16(value, *((Uint16*)&x));
 242                   value += sizeof(x);
 243               }
 244               
 245               static inline void _readString(const char*& value, String& x)
 246               {
 247                   size_t n = strlen(value);
 248                   x.assign(value, n);
 249                   value += n + 1;
 250               }
 251               
 252               static inline void _readDateTime(const char*& value, CIMDateTime& x)
 253 mike  1.1.2.1 {
 254                   size_t n = strlen(value);
 255                   x.set(value);
 256                   value += n + 1;
 257               }
 258               
 259               static int _makeValue(
 260                   CIMValue& cv, 
 261                   Uint16 type, 
 262                   Sint16 subscript, 
 263                   const char* value)
 264               {
 265                   // If null value:
 266               
 267                   if (value == 0)
 268                   {
 269                       if (subscript == -1)
 270                           cv.setNullValue(CIMType(type), false);
 271                       else
 272                           cv.setNullValue(CIMType(type), true, subscript);
 273               
 274 mike  1.1.2.1         return 0;
 275                   }
 276               
 277                   // If scalar, else array:
 278               
 279                   if (subscript == -1)
 280                   {
 281                       switch (CIMType(type))
 282                       {
 283                           case CIMTYPE_BOOLEAN:
 284                           {
 285                               Boolean x;
 286                               _readBoolean(value, x);
 287                               cv.set(x);
 288                               return 0;
 289                           }
 290                           case CIMTYPE_UINT8:
 291                           {
 292                               Uint8 x;
 293                               _readUint8(value, x);
 294                               cv.set(x);
 295 mike  1.1.2.1                 return 0;
 296                           }
 297                           case CIMTYPE_SINT8:
 298                           {
 299                               Sint8 x;
 300                               _readSint8(value, x);
 301                               cv.set(x);
 302                               return 0;
 303                           }
 304                           case CIMTYPE_UINT16:
 305                           {
 306                               Uint16 x;
 307                               _readUint16(value, x);
 308                               cv.set(x);
 309                               return 0;
 310                           }
 311                           case CIMTYPE_SINT16:
 312                           {
 313                               Sint16 x;
 314                               _readSint16(value, x);
 315                               cv.set(x);
 316 mike  1.1.2.1                 return 0;
 317                           }
 318                           case CIMTYPE_UINT32:
 319                           {
 320                               Uint32 x;
 321                               _readUint32(value, x);
 322                               cv.set(x);
 323                               return 0;
 324                           }
 325                           case CIMTYPE_SINT32:
 326                           {
 327                               Sint32 x;
 328                               _readSint32(value, x);
 329                               cv.set(x);
 330                               return 0;
 331                           }
 332                           case CIMTYPE_UINT64:
 333                           {
 334                               Uint64 x;
 335                               _readUint64(value, x);
 336                               cv.set(x);
 337 mike  1.1.2.1                 return 0;
 338                           }
 339                           case CIMTYPE_SINT64:
 340                           {
 341                               Sint64 x;
 342                               _readSint64(value, x);
 343                               cv.set(x);
 344                               return 0;
 345                           }
 346                           case CIMTYPE_REAL32:
 347                           {
 348                               Real32 x;
 349                               _readReal32(value, x);
 350                               cv.set(x);
 351                               return 0;
 352                           }
 353                           case CIMTYPE_REAL64:
 354                           {
 355                               Real64 x;
 356                               _readReal64(value, x);
 357                               cv.set(x);
 358 mike  1.1.2.1                 return 0;
 359                           }
 360                           case CIMTYPE_CHAR16:
 361                           {
 362                               Char16 x;
 363                               _readChar16(value, x);
 364                               cv.set(x);
 365                               return 0;
 366                           }
 367                           case CIMTYPE_STRING:
 368                           {
 369                               String x;
 370                               _readString(value, x);
 371                               cv.set(x);
 372                               return 0;
 373                           }
 374                           case CIMTYPE_DATETIME:
 375                           {
 376                               CIMDateTime x;
 377                               _readDateTime(value, x);
 378                               cv.set(x);
 379 mike  1.1.2.1                 return 0;
 380                           }
 381               
 382                           default:
 383 mike  1.1.2.2                 printf("T[%u]\n", __LINE__);
 384 mike  1.1.2.1                 return -1;
 385                       }
 386                   }
 387                   else
 388                   {
 389                       // Read array size:
 390               
 391                       Uint16 size;
 392                       _readUint16(value, size);
 393               
 394                       // Read array elements:
 395               
 396                       switch (CIMType(type))
 397                       {
 398                           case CIMTYPE_BOOLEAN:
 399                           {
 400                               Array<Boolean> a;
 401               
 402                               for (Uint16 i = 0; i < size; i++)
 403                               {
 404                                   Boolean x;
 405 mike  1.1.2.1                     _readBoolean(value, x);
 406                                   a.append(x);
 407                               }
 408               
 409                               cv.set(a);
 410                               return 0;
 411                           }
 412                           case CIMTYPE_UINT8:
 413                           {
 414                               Array<Uint8> a;
 415               
 416                               for (Uint16 i = 0; i < size; i++)
 417                               {
 418                                   Uint8 x;
 419                                   _readUint8(value, x);
 420                                   a.append(x);
 421                               }
 422               
 423                               cv.set(a);
 424                               return 0;
 425                           }
 426 mike  1.1.2.1             case CIMTYPE_SINT8:
 427                           {
 428                               Array<Sint8> a;
 429               
 430                               for (Uint16 i = 0; i < size; i++)
 431                               {
 432                                   Sint8 x;
 433                                   _readSint8(value, x);
 434                                   a.append(x);
 435                               }
 436               
 437                               cv.set(a);
 438                               return 0;
 439                           }
 440                           case CIMTYPE_UINT16:
 441                           {
 442                               Array<Uint16> a;
 443               
 444                               for (Uint16 i = 0; i < size; i++)
 445                               {
 446                                   Uint16 x;
 447 mike  1.1.2.1                     _readUint16(value, x);
 448                                   a.append(x);
 449                               }
 450               
 451                               cv.set(a);
 452                               return 0;
 453                           }
 454                           case CIMTYPE_SINT16:
 455                           {
 456                               Array<Sint16> a;
 457               
 458                               for (Uint16 i = 0; i < size; i++)
 459                               {
 460                                   Sint16 x;
 461                                   _readSint16(value, x);
 462                                   a.append(x);
 463                               }
 464               
 465                               cv.set(a);
 466                               return 0;
 467                           }
 468 mike  1.1.2.1             case CIMTYPE_UINT32:
 469                           {
 470                               Array<Uint32> a;
 471               
 472                               for (Uint16 i = 0; i < size; i++)
 473                               {
 474                                   Uint32 x;
 475                                   _readUint32(value, x);
 476                                   a.append(x);
 477                               }
 478               
 479                               cv.set(a);
 480                               return 0;
 481                           }
 482                           case CIMTYPE_SINT32:
 483                           {
 484                               Array<Sint32> a;
 485               
 486                               for (Uint16 i = 0; i < size; i++)
 487                               {
 488                                   Sint32 x;
 489 mike  1.1.2.1                     _readSint32(value, x);
 490                                   a.append(x);
 491                               }
 492               
 493                               cv.set(a);
 494                               return 0;
 495                           }
 496                           case CIMTYPE_UINT64:
 497                           {
 498                               Array<Uint64> a;
 499               
 500                               for (Uint16 i = 0; i < size; i++)
 501                               {
 502                                   Uint64 x;
 503                                   _readUint64(value, x);
 504                                   a.append(x);
 505                               }
 506               
 507                               cv.set(a);
 508                               return 0;
 509                           }
 510 mike  1.1.2.1             case CIMTYPE_SINT64:
 511                           {
 512                               Array<Sint64> a;
 513               
 514                               for (Uint16 i = 0; i < size; i++)
 515                               {
 516                                   Sint64 x;
 517                                   _readSint64(value, x);
 518                                   a.append(x);
 519                               }
 520               
 521                               cv.set(a);
 522                               return 0;
 523                           }
 524                           case CIMTYPE_REAL32:
 525                           {
 526                               Array<Real32> a;
 527               
 528                               for (Uint16 i = 0; i < size; i++)
 529                               {
 530                                   Real32 x;
 531 mike  1.1.2.1                     _readReal32(value, x);
 532                                   a.append(x);
 533                               }
 534               
 535                               cv.set(a);
 536                               return 0;
 537                           }
 538                           case CIMTYPE_REAL64:
 539                           {
 540                               Array<Real64> a;
 541               
 542                               for (Uint16 i = 0; i < size; i++)
 543                               {
 544                                   Real64 x;
 545                                   _readReal64(value, x);
 546                                   a.append(x);
 547                               }
 548               
 549                               cv.set(a);
 550                               return 0;
 551                           }
 552 mike  1.1.2.1             case CIMTYPE_CHAR16:
 553                           {
 554                               Array<Char16> a;
 555               
 556                               for (Uint16 i = 0; i < size; i++)
 557                               {
 558                                   Char16 x;
 559                                   _readChar16(value, x);
 560                                   a.append(x);
 561                               }
 562               
 563                               cv.set(a);
 564                               return 0;
 565                           }
 566                           case CIMTYPE_STRING:
 567                           {
 568                               Array<String> a;
 569               
 570                               for (Uint16 i = 0; i < size; i++)
 571                               {
 572                                   String x;
 573 mike  1.1.2.1                     _readString(value, x);
 574                                   a.append(x);
 575                               }
 576               
 577                               cv.set(a);
 578                               return 0;
 579                           }
 580                           case CIMTYPE_DATETIME:
 581                           {
 582                               Array<CIMDateTime> a;
 583               
 584                               for (Uint16 i = 0; i < size; i++)
 585                               {
 586                                   CIMDateTime x;
 587                                   _readDateTime(value, x);
 588                                   a.append(x);
 589                               }
 590               
 591                               cv.set(a);
 592                               return 0;
 593                           }
 594 mike  1.1.2.1 
 595                           default:
 596 mike  1.1.2.2                 printf("T[%u]\n", __LINE__);
 597 mike  1.1.2.1                 return -1;
 598                       }
 599                   }
 600               
 601                   // Unreachable!
 602 mike  1.1.2.2     printf("T[%u]\n", __LINE__);
 603 mike  1.1.2.1     return -1;
 604               }
 605               
 606 mike  1.1.2.2 struct FeatureInfo
 607               {
 608                   const SourceFeature* sf;
 609                   const SourceClass* sc;
 610               };
 611               
 612               static int _mergeFeatures(
 613                   const SourceClass* sc,
 614                   FeatureInfo features[_MAX_FEATURES],
 615                   size_t& numFeatures)
 616               {
 617                   if (sc->super)
 618                   {
 619                       if (_mergeFeatures(sc->super, features, numFeatures) != 0)
 620                       {
 621                           printf("T[%u]\n", __LINE__);
 622                           return -1;
 623                       }
 624                   }
 625               
 626                   // Process all features of this class:
 627 mike  1.1.2.2 
 628                   for (size_t i = 0; sc->features[i]; i++)
 629                   {
 630                       const SourceFeature* sf = sc->features[i];
 631               
 632                       // Override feature if defined by ancestor class:
 633               
 634                       bool found = false;
 635               
 636                       for (size_t j = 0; j < numFeatures; j++)
 637                       {
 638                           const SourceFeature* tmp = features[j].sf;
 639               
 640                           if (_eqi(sf->name, tmp->name))
 641                           {
 642                               features[j].sf = sf;
 643                               features[j].sc = sc;
 644                               found = true;
 645                               break;
 646                           }
 647                       }
 648 mike  1.1.2.2 
 649                       // Add new feature if not not defined by ancestor class:
 650               
 651                       if (!found)
 652                       {
 653                           if (numFeatures == _MAX_FEATURES)
 654                           {
 655                               printf("T[%u]\n", __LINE__);
 656                               return -1;
 657                           }
 658               
 659                           features[numFeatures].sf = sf;
 660                           features[numFeatures].sc = sc;
 661                           numFeatures++;
 662                       }
 663                   }
 664               
 665                   return 0;
 666               }
 667               
 668               struct QualifierInfo
 669 mike  1.1.2.2 {
 670                   const char* qualifier;
 671                   const SourceClass* sc;
 672               };
 673               
 674               static const SourceFeature* _findFeature(
 675                   const SourceClass* sc, 
 676                   const char* name)
 677               {
 678                   for (size_t i = 0; sc->features[i]; i++)
 679                   {
 680                       const SourceFeature* sf = sc->features[i];
 681               
 682                       if (_eqi(sf->name, name))
 683                           return sf;
 684                   }
 685               
 686                   // Not found!
 687                   return 0;
 688               }
 689               
 690 mike  1.1.2.2 static const SourceFeature* _findParameter(
 691                   const SourceMethod* sm, 
 692                   const char* name)
 693               {
 694                   for (size_t i = 0; sm->parameters[i]; i++)
 695                   {
 696                       const SourceFeature* sf = sm->parameters[i];
 697               
 698                       if (_eqi(sm->name, name))
 699                           return sf;
 700                   }
 701               
 702                   // Not found!
 703                   return 0;
 704               }
 705               
 706               static int _mergeQualifiers(
 707                   const SourceNameSpace* ns,
 708                   const SourceClass* sc,
 709                   const char* featureName,
 710                   const char* parameterName,
 711 mike  1.1.2.2     bool depth,
 712                   QualifierInfo qualifiers[_MAX_QUALIFIERS],
 713                   size_t& numQualifiers)
 714               {
 715                   // Merge super-class qualifiers:
 716               
 717                   if (sc->super)
 718                   {
 719                       _mergeQualifiers(ns, sc->super, featureName, parameterName, depth + 1,
 720                           qualifiers, numQualifiers);
 721                   }
 722               
 723                   const char** quals = 0;
 724               
 725                   // Find qualifiers of the given object:
 726               
 727                   if (!featureName && !parameterName)
 728                   {
 729                       // Case 1: get class qualifiers:
 730                       quals = sc->qualifiers;
 731                   }
 732 mike  1.1.2.2     else if (featureName && !parameterName)
 733                   {
 734                       // Case 2: get feature qualifiers:
 735               
 736                       const SourceFeature* sf = _findFeature(sc, featureName);
 737               
 738                       if (sf)
 739                           quals = sf->qualifiers;
 740                   }
 741                   else if (featureName && parameterName)
 742                   {
 743                       // Case 3: get parameter qualifiers:
 744               
 745                       const SourceFeature* sf = _findFeature(sc, featureName);
 746               
 747                       if (sf && (sf->flags & PEGASUS_FLAG_METHOD))
 748                       {
 749                           const SourceMethod* sm = (const SourceMethod*)sf;
 750                           const SourceFeature* p = _findParameter(sm, parameterName);
 751               
 752                           if (p)
 753 mike  1.1.2.2                 quals = p->qualifiers;
 754                       }
 755                   }
 756               
 757                   // Merge quals into the qualifiers array:
 758               
 759                   if (!quals)
 760                       return 0;
 761               
 762                   for (size_t i = 0; quals[i]; i++)
 763                   {
 764                       const char* qi = quals[i];
 765               
 766                       // Override existing qualifier if any:
 767               
 768                       bool found = false;
 769               
 770                       for (size_t j = 0; j < numQualifiers; j++)
 771                       {
 772                           const char* qj = qualifiers[j].qualifier;
 773               
 774 mike  1.1.2.2             if (qi[0] == qj[0])
 775                           {
 776                               qualifiers[j].qualifier = qi;
 777                               qualifiers[j].sc = sc;
 778                               found = true;
 779                               break;
 780                           }
 781                       }
 782               
 783                       // Inject this qualifier not found:
 784               
 785                       if (!found)
 786                       {
 787                           SourceQualifierDecl* qd = ns->qualifiers[qi[0]];
 788               
 789                           if (depth == 0 || !(qd->flavor & PEGASUS_FLAVOR_RESTRICTED))
 790                           {
 791                               if (numQualifiers == _MAX_QUALIFIERS)
 792                               {
 793                                   printf("T[%u]\n", __LINE__);
 794                                   return -1;
 795 mike  1.1.2.2                 }
 796               
 797                               qualifiers[numQualifiers].qualifier = qi;
 798                               qualifiers[numQualifiers].sc = sc;
 799                               numQualifiers++;
 800                           }
 801                       }
 802                   }
 803               
 804                   return 0;
 805               }
 806               
 807 mike  1.1.2.1 template<class C>
 808 mike  1.1.2.2 static int _addQualifiers(
 809 mike  1.1.2.1     const SourceNameSpace* ns,
 810 mike  1.1.2.2     const SourceClass* sc,
 811                   const char* featureName,
 812                   const char* parameterName,
 813                   C& c)
 814               {
 815                   QualifierInfo qualifiers[_MAX_QUALIFIERS];
 816                   size_t numQualifiers = 0;
 817 mike  1.1.2.1 
 818 mike  1.1.2.2     if (_mergeQualifiers(
 819                       ns, sc, featureName, parameterName, 0, qualifiers, numQualifiers) != 0)
 820 mike  1.1.2.1     {
 821 mike  1.1.2.2         printf("T[%u]\n", __LINE__);
 822                       return -1;
 823                   }
 824               
 825                   // Add qualifiers to container:
 826               
 827                   for (size_t i = 0; i < numQualifiers; i++)
 828                   {
 829                       const char* q = qualifiers[i].qualifier;
 830 mike  1.1.2.1 
 831 mike  1.1.2.2         // Get qualifier id:
 832 mike  1.1.2.1 
 833 mike  1.1.2.2         Uint8 qid = Uint8(q[0]);
 834 mike  1.1.2.1 
 835                       // Get qualifier declaration:
 836               
 837                       SourceQualifierDecl* qd = ns->qualifiers[qid];
 838               
 839                       // Make CIMValue:
 840               
 841                       CIMValue cv;
 842 mike  1.1.2.2 
 843                       if (_makeValue(cv, qd->type, qd->subscript, q + 1) != 0)
 844                       {
 845                           printf("T[%u]\n", __LINE__);
 846                           return -1;
 847                       }
 848 mike  1.1.2.1 
 849                       // Add qualifier:
 850               
 851                       c.addQualifier(CIMQualifier(qd->name, cv));
 852                   }
 853 mike  1.1.2.2 
 854                   return 0;
 855 mike  1.1.2.1 }
 856               
 857 mike  1.1.2.2 static int _addProperty(
 858 mike  1.1.2.1     const SourceNameSpace* ns,
 859 mike  1.1.2.2     const SourceClass* sc,
 860                   const SourceProperty* sp,
 861                   const char* classOrigin,
 862                   bool propagated,
 863                   CIMClass& cc)
 864 mike  1.1.2.1 {
 865                   // Make CIMvalue:
 866               
 867                   CIMValue cv;
 868 mike  1.1.2.2 
 869                   if (_makeValue(cv, sp->type, sp->subscript, sp->value) != 0)
 870                   {
 871                       printf("T[%u]\n", __LINE__);
 872                       return -1;
 873                   }
 874 mike  1.1.2.1 
 875                   // Create property:
 876               
 877                   CIMProperty cp(sp->name, cv);
 878 mike  1.1.2.2     cp.setClassOrigin(classOrigin);
 879                   cp.setPropagated(propagated);
 880 mike  1.1.2.1 
 881                   // Add qualifiers:
 882               
 883 mike  1.1.2.2     if (_addQualifiers(ns, sc, sp->name, 0, cp) != 0)
 884                   {
 885                       printf("T[%u]\n", __LINE__);
 886                       return -1;
 887                   }
 888 mike  1.1.2.1 
 889                   // Add to class:
 890               
 891                   cc.addProperty(cp);
 892 mike  1.1.2.2     return 0;
 893 mike  1.1.2.1 }
 894               
 895 mike  1.1.2.2 static int _addReference(
 896 mike  1.1.2.1     const SourceNameSpace* ns,
 897 mike  1.1.2.2     const SourceClass* sc,
 898                   const SourceReference* sr,
 899                   const char* classOrigin,
 900                   bool propagated,
 901                   CIMClass& cc)
 902 mike  1.1.2.1 {
 903 mike  1.1.2.2     // Set isArray and arraySize:
 904 mike  1.1.2.1 
 905 mike  1.1.2.2     Boolean isArray;
 906                   Uint32 arraySize;
 907 mike  1.1.2.1     
 908                   if (sr->subscript == -1)
 909 mike  1.1.2.2     {
 910                       isArray = false;
 911                       arraySize = 0;
 912                   }
 913 mike  1.1.2.1     else
 914 mike  1.1.2.2     {
 915                       isArray = true;
 916                       arraySize = sr->subscript;
 917                   }
 918               
 919                   // Set referenceClassName:
 920               
 921                   CIMName rcn = sr->ref->name;
 922               
 923                   // Create value:
 924               
 925                   CIMValue cv(CIMTYPE_REFERENCE, isArray, arraySize);
 926               
 927                   // Create property:
 928 mike  1.1.2.1 
 929 mike  1.1.2.2     CIMProperty cp(sr->name, cv, arraySize, rcn, classOrigin, propagated);
 930 mike  1.1.2.1 
 931                   // Add qualifiers:
 932               
 933 mike  1.1.2.2     if (_addQualifiers(ns, sc, sr->name, 0, cp) != 0)
 934                   {
 935                       printf("T[%u]\n", __LINE__);
 936                       return -1;
 937                   }
 938 mike  1.1.2.1 
 939                   // Add to class:
 940               
 941                   cc.addProperty(cp);
 942 mike  1.1.2.2     return 0;
 943 mike  1.1.2.1 }
 944               
 945 mike  1.1.2.2 static int _addPropertyParameter(
 946 mike  1.1.2.1     const SourceNameSpace* ns,
 947 mike  1.1.2.2     const SourceClass* sc,
 948                   const SourceMethod* sm,
 949                   const SourceProperty* sp,
 950                   CIMMethod& cm)
 951 mike  1.1.2.1 {
 952                   // Create property:
 953               
 954                   bool isArray;
 955                   Uint32 arraySize;
 956               
 957                   if (sp->subscript == -1)
 958                   {
 959                       isArray = false;
 960                       arraySize = 0;
 961                   }
 962                   else 
 963                   {
 964                       isArray = true;
 965                       arraySize = Uint32(sp->subscript);
 966                   }
 967               
 968                   CIMParameter cp(sp->name, CIMType(sp->type), isArray, arraySize);
 969               
 970                   // Add qualifiers:
 971               
 972 mike  1.1.2.2     if (_addQualifiers(ns, sc, sm->name, sp->name, cm) != 0)
 973                   {
 974                       printf("T[%u]\n", __LINE__);
 975                       return -1;
 976                   }
 977 mike  1.1.2.1 
 978                   // Add to method:
 979               
 980                   cm.addParameter(cp);
 981 mike  1.1.2.2     return 0;
 982 mike  1.1.2.1 }
 983               
 984 mike  1.1.2.2 static int _addReferenceParameter(
 985 mike  1.1.2.1     const SourceNameSpace* ns,
 986 mike  1.1.2.2     const SourceClass* sc,
 987                   const SourceMethod* sm,
 988                   const SourceReference* sr,
 989                   CIMMethod& cm)
 990 mike  1.1.2.1 {
 991                   // Create property:
 992               
 993                   bool isArray;
 994                   Uint32 arraySize;
 995               
 996 mike  1.1.2.2     if (sr->subscript == -1)
 997 mike  1.1.2.1     {
 998                       isArray = false;
 999                       arraySize = 0;
1000                   }
1001                   else 
1002                   {
1003                       isArray = true;
1004 mike  1.1.2.2         arraySize = Uint32(sr->subscript);
1005 mike  1.1.2.1     }
1006               
1007 mike  1.1.2.2     CIMName rcn = sr->ref->name;
1008                   CIMParameter cp(sr->name, CIMTYPE_REFERENCE, isArray, arraySize, rcn);
1009 mike  1.1.2.1 
1010                   // Add qualifiers:
1011               
1012 mike  1.1.2.2     if (_addQualifiers(ns, sc, sm->name, sr->name, cm) != 0)
1013                   {
1014                       printf("T[%u]\n", __LINE__);
1015                       return -1;
1016                   }
1017 mike  1.1.2.1 
1018                   // Add to method:
1019               
1020                   cm.addParameter(cp);
1021 mike  1.1.2.2     return 0;
1022 mike  1.1.2.1 }
1023               
1024 mike  1.1.2.2 static int _addMethod(
1025 mike  1.1.2.1     const SourceNameSpace* ns,
1026 mike  1.1.2.2     const SourceClass* sc,
1027                   const SourceMethod* sm,
1028                   const char* classOrigin,
1029                   bool propagated,
1030                   CIMClass& cc)
1031 mike  1.1.2.1 {
1032                   // Create method:
1033               
1034                   CIMMethod cm(sm->name, CIMType(sm->type));
1035 mike  1.1.2.2     cm.setClassOrigin(classOrigin);
1036                   cm.setPropagated(propagated);
1037 mike  1.1.2.1 
1038                   // Add parameters:
1039               
1040 mike  1.1.2.2     for (size_t i = 0; sm->parameters[i]; i++)
1041 mike  1.1.2.1     {
1042 mike  1.1.2.2         SourceFeature* sf = sm->parameters[i];
1043 mike  1.1.2.1 
1044                       if (sf->flags & PEGASUS_FLAG_PROPERTY)
1045                       {
1046                           SourceProperty* sp = (SourceProperty*)sf;
1047 mike  1.1.2.2             _addPropertyParameter(ns, sc, sm, sp, cm);
1048 mike  1.1.2.1         }
1049                       else if (sf->flags & PEGASUS_FLAG_REFERENCE)
1050                       {
1051                           SourceReference* sr = (SourceReference*)sf;
1052 mike  1.1.2.2             _addReferenceParameter(ns, sc, sm, sr, cm);
1053 mike  1.1.2.1         }
1054                   }
1055               
1056                   // Add qualifiers:
1057               
1058 mike  1.1.2.2     if (_addQualifiers(ns, sc, sm->name, 0, cm) != 0)
1059                   {
1060                       printf("T[%u]\n", __LINE__);
1061                       return -1;
1062                   }
1063 mike  1.1.2.1 
1064                   // Add to class:
1065               
1066                   cc.addMethod(cm);
1067 mike  1.1.2.2     return 0;
1068 mike  1.1.2.1 }
1069               
1070 mike  1.1.2.2 static int _addFeatures(
1071 mike  1.1.2.1     const SourceNameSpace* ns,
1072 mike  1.1.2.2     const SourceClass* sc,
1073                   CIMClass& cc)
1074 mike  1.1.2.1 {
1075               
1076 mike  1.1.2.2     // Merge features from all inheritance levels into a single array:
1077 mike  1.1.2.1 
1078 mike  1.1.2.2     FeatureInfo features[_MAX_FEATURES];
1079                   size_t numFeatures = 0;
1080               
1081                   if (_mergeFeatures(sc, features, numFeatures) != 0)
1082                   {
1083                       printf("T[%u]\n", __LINE__);
1084                       return -1;
1085                   }
1086 mike  1.1.2.1 
1087                   // For each feature:
1088               
1089 mike  1.1.2.2     for (size_t i = 0; i < numFeatures; i++)
1090 mike  1.1.2.1     {
1091 mike  1.1.2.2         const FeatureInfo& fi = features[i];
1092               
1093                       // Set propagated flag:
1094               
1095                       bool propagated = fi.sc != sc;
1096               
1097                       // Set classOrigin:
1098               
1099                       const char* classOrigin = fi.sc->name;
1100               
1101                       // Add the feature:
1102               
1103                       const SourceFeature* sf = fi.sf;
1104 mike  1.1.2.1 
1105                       if (sf->flags & PEGASUS_FLAG_PROPERTY)
1106                       {
1107                           SourceProperty* sp = (SourceProperty*)sf;
1108 mike  1.1.2.2 
1109                           if (_addProperty(ns, sc, sp, classOrigin, propagated, cc) != 0)
1110                           {
1111                               printf("T[%u]\n", __LINE__);
1112                               return -1;
1113                           }
1114 mike  1.1.2.1         }
1115                       else if (sf->flags & PEGASUS_FLAG_REFERENCE)
1116                       {
1117                           SourceReference* sr = (SourceReference*)sf;
1118 mike  1.1.2.2 
1119                           if (_addReference(ns, sc, sr, classOrigin, propagated, cc) != 0)
1120                           {
1121                               printf("T[%u]\n", __LINE__);
1122                               return -1;
1123                           }
1124 mike  1.1.2.1         }
1125                       else if (sf->flags & PEGASUS_FLAG_METHOD)
1126                       {
1127                           SourceMethod* sm = (SourceMethod*)sf;
1128 mike  1.1.2.2 
1129                           if (_addMethod(ns, sc, sm, classOrigin, propagated, cc) != 0)
1130                           {
1131                               printf("T[%u]\n", __LINE__);
1132                               return -1;
1133                           }
1134 mike  1.1.2.1         }
1135                   }
1136 mike  1.1.2.2 
1137                   return 0;
1138 mike  1.1.2.1 }
1139               
1140 mike  1.1.2.2 static int _makeClass(
1141 mike  1.1.2.1     const SourceNameSpace* ns,
1142                   CIMClass& cc, 
1143                   const SourceClass* sc)
1144               {
1145                   try
1146                   {
1147                       // Create class:
1148 mike  1.1.2.2         {
1149                           CIMName scn;
1150 mike  1.1.2.1 
1151 mike  1.1.2.2             if (sc->super)
1152                               scn = sc->super->name;
1153 mike  1.1.2.1 
1154 mike  1.1.2.2             cc = CIMClass(sc->name, scn);
1155                   }
1156 mike  1.1.2.1 
1157                       // Add qualifiers:
1158               
1159 mike  1.1.2.2         if (_addQualifiers(ns, sc, 0, 0, cc) != 0)
1160                       {
1161                           printf("T[%u]\n", __LINE__);
1162                           return -1;
1163                       }
1164 mike  1.1.2.1 
1165                       // Features:
1166               
1167 mike  1.1.2.2         if (_addFeatures(ns, sc, cc) != 0)
1168                       {
1169                           printf("T[%u]\n", __LINE__);
1170                           return -1;
1171                       }
1172                   }
1173                   catch (Exception& e)
1174                   {
1175                       printf("EXCEPTION[%s]\n", *Str(e));
1176                       return -1;
1177 mike  1.1.2.1     }
1178                   catch (...)
1179                   {
1180 mike  1.1.2.2         printf("T[%u]\n", __LINE__);
1181                       return -1;
1182 mike  1.1.2.1     }
1183               
1184 mike  1.1.2.2     return 0;
1185 mike  1.1.2.1 }
1186               
1187               //==============================================================================
1188               //
1189               // class SourceRepository
1190               //
1191               //==============================================================================
1192               
1193               SourceRepository::SourceRepository()
1194               {
1195               }
1196               
1197               SourceRepository::~SourceRepository()
1198               {
1199               }
1200               
1201               bool SourceRepository::addNameSpace(const SourceNameSpace* nameSpace)
1202               {
1203                   if (_nameSpacesSize == _MAX_NAMESPACES || !nameSpace)
1204                       return false;
1205               
1206 mike  1.1.2.1     for (size_t i = 0; i < _nameSpacesSize; i++)
1207                   {
1208 mike  1.1.2.2         if (_eqi(_nameSpaces[i]->name, nameSpace->name))
1209 mike  1.1.2.1             return false;
1210                   }
1211               
1212                   _nameSpaces[_nameSpacesSize++] = nameSpace;
1213                   return true;
1214               }
1215               
1216               CIMClass SourceRepository::getClass(
1217                   const CIMNamespaceName& nameSpace,
1218                   const CIMName& className,
1219                   Boolean localOnly,
1220                   Boolean includeQualifiers,
1221                   Boolean includeClassOrigin,
1222                   const CIMPropertyList& propertyList)
1223               {
1224                   return CIMClass();
1225               }
1226               
1227 mike  1.1.2.2 Array<CIMClass> SourceRepository::enumerateClasses(
1228 mike  1.1.2.1     const CIMNamespaceName& nameSpace,
1229                   const CIMName& className,
1230                   Boolean deepInheritance,
1231                   Boolean localOnly,
1232                   Boolean includeQualifiers,
1233                   Boolean includeClassOrigin)
1234               {
1235 mike  1.1.2.2     _init();
1236               
1237                   printf("SourceRepository::enumerateClasses()\n");
1238               
1239                   // Lookup namespace:
1240               
1241                   const SourceNameSpace* ns = _findNameSpace(*Str(nameSpace));
1242               
1243                   if (!ns)
1244                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
1245               
1246                   // Lookup class:
1247               
1248                   const SourceClass* super = 0;
1249                   
1250                   if (!className.isNull())
1251                   {
1252                       super = _findClass(ns, *Str(className));
1253               
1254                       if (!super)
1255                           _throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className));
1256 mike  1.1.2.2     }
1257               
1258                   // Iterate all classes looking for matches:
1259               
1260                   Array<CIMClass> result;
1261               
1262                   for (size_t i = 0; ns->classes[i]; i++)
1263                   {
1264                       SourceClass* sc = ns->classes[i];
1265               
1266               // printf("CLASSNAME[%s]\n", sc->name);
1267               
1268                       if (deepInheritance)
1269                       {
1270                           if (_isSubClass(super, sc))
1271                           {
1272                               CIMClass cc;
1273               
1274                               if (_makeClass(ns, cc, sc) != 0)
1275                                   _throw(CIM_ERR_FAILED, "conversion failed: %s", sc->name);
1276                               else
1277 mike  1.1.2.2                     result.append(cc);
1278                           }
1279                       }
1280                       else
1281                       {
1282                           if (_isDirectSubClass(super, sc))
1283                           {
1284                               CIMClass cc;
1285               
1286                               if (_makeClass(ns, cc, sc) != 0)
1287                                   _throw(CIM_ERR_FAILED, "conversion failed: %s", sc->name);
1288                               else
1289                                   result.append(cc);
1290                           }
1291                       }
1292                   }
1293               
1294                   return result;
1295 mike  1.1.2.1 }
1296               
1297 mike  1.1.2.2 Array<CIMName> SourceRepository::enumerateClassNames(
1298 mike  1.1.2.1     const CIMNamespaceName& nameSpace,
1299                   const CIMName& className,
1300                   Boolean deepInheritance)
1301               {
1302                   // Lookup namespace:
1303               
1304                   const SourceNameSpace* ns = _findNameSpace(*Str(nameSpace));
1305               
1306                   if (!ns)
1307                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
1308               
1309                   // Lookup class:
1310               
1311                   const SourceClass* super = 0;
1312                   
1313 mike  1.1.2.2     if (!className.isNull())
1314 mike  1.1.2.1     {
1315                       super = _findClass(ns, *Str(className));
1316               
1317                       if (!super)
1318                           _throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className));
1319                   }
1320               
1321                   // Iterate all classes looking for matches:
1322               
1323                   Array<CIMName> result;
1324               
1325                   for (size_t i = 0; ns->classes[i]; i++)
1326                   {
1327                       SourceClass* sc = ns->classes[i];
1328               
1329                       if (deepInheritance)
1330                       {
1331                           if (_isSubClass(super, sc))
1332                               result.append(sc->name);
1333                       }
1334                       else
1335 mike  1.1.2.1         {
1336                           if (_isDirectSubClass(super, sc))
1337                               result.append(sc->name);
1338                       }
1339                   }
1340               
1341                   return result;
1342               }
1343               
1344               void SourceRepository::deleteClass(
1345                   const CIMNamespaceName& nameSpace,
1346                   const CIMName& className)
1347               {
1348                   _throw(CIM_ERR_NOT_SUPPORTED, "deleteClass()");
1349               }
1350               
1351               void SourceRepository::createClass(
1352                   const CIMNamespaceName& nameSpace,
1353                   const CIMClass& newClass)
1354               {
1355                   _throw(CIM_ERR_NOT_SUPPORTED, "createClass()");
1356 mike  1.1.2.1 }
1357               
1358               void SourceRepository::modifyClass(
1359                   const CIMNamespaceName& nameSpace,
1360                   const CIMClass& newClass)
1361               {
1362                   _throw(CIM_ERR_NOT_SUPPORTED, "modifyClass()");
1363               }
1364               
1365               PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2