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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2