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

   1 martin 1.3 //%LICENSE////////////////////////////////////////////////////////////////
   2 martin 1.4 //
   3 martin 1.3 // Licensed to The Open Group (TOG) under one or more contributor license
   4            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   5            // this work for additional information regarding copyright ownership.
   6            // Each contributor licenses this file to you under the OpenPegasus Open
   7            // Source License; you may not use this file except in compliance with the
   8            // License.
   9 martin 1.4 //
  10 martin 1.3 // 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.4 //
  17 martin 1.3 // The above copyright notice and this permission notice shall be included
  18            // in all copies or substantial portions of the Software.
  19 martin 1.4 //
  20 martin 1.3 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21 martin 1.4 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22 martin 1.3 // 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.4 //
  28 martin 1.3 //////////////////////////////////////////////////////////////////////////
  29 mike   1.1 //
  30            //%/////////////////////////////////////////////////////////////////////////////
  31            
  32            #include "MRRSerialization.h"
  33            
  34            #define RETURN_FAILURE \
  35                do \
  36                { \
  37                    printf("***** RETURN_FAILURE: %s(%d)\n", __FILE__, __LINE__); \
  38                    return -1; \
  39                } \
  40                while (0)
  41            
  42            PEGASUS_NAMESPACE_BEGIN
  43            
  44            //==============================================================================
  45            //
  46            // Limitations:
  47            //
  48            //     1. Does not handle CIMObjects that contain CIMClass.
  49            //
  50 mike   1.1 //==============================================================================
  51            
  52            static Uint32 _INSTANCE_MAGIC = 0x20D54A36;
  53            static Uint32 _NAMESPACE_MAGIC = 0x06979333;
  54            
  55            class Str
  56            {
  57            public:
  58                Str(const String& s) : _cstr(s.getCString()) { }
  59                Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
  60                Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
  61                Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
  62                Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
  63                Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
  64                const char* operator*() const { return (const char*)_cstr; }
  65                operator const char*() const { return (const char*)_cstr; }
  66            private:
  67                CString _cstr;
  68            };
  69            
  70            static void _PutUint8(Buffer& out, Uint8 x)
  71 mike   1.1 {
  72                out.append(x);
  73            }
  74            
  75            static void _PutBoolean(Buffer& out, Boolean x)
  76            {
  77                _PutUint8(out, x ? 1 : 0);
  78            }
  79            
  80            static void _PutUint16(Buffer& out, Uint16 x)
  81            {
  82                Uint8 x0 = Uint8((x >> 8) & 0x00FF);
  83                Uint8 x1 = Uint8((x >> 0) & 0x00FF);
  84                out.append(x0);
  85                out.append(x1);
  86            }
  87            
  88            static void _PutUint32(Buffer& out, Uint32 x)
  89            {
  90                Uint8 x0 = Uint8((x >> 24) & 0x000000FF);
  91                Uint8 x1 = Uint8((x >> 16) & 0x000000FF);
  92 mike   1.1     Uint8 x2 = Uint8((x >>  8) & 0x000000FF);
  93                Uint8 x3 = Uint8((x >>  0) & 0x000000FF);
  94                out.append(x0, x1, x2, x3);
  95            }
  96            
  97            static void _PutUint64(Buffer& out, Uint64 x)
  98            {
  99                Uint8 x0 = Uint8((x >> 56) & 0x00000000000000FF);
 100                Uint8 x1 = Uint8((x >> 48) & 0x00000000000000FF);
 101                Uint8 x2 = Uint8((x >> 40) & 0x00000000000000FF);
 102                Uint8 x3 = Uint8((x >> 32) & 0x00000000000000FF);
 103                Uint8 x4 = Uint8((x >> 24) & 0x00000000000000FF);
 104                Uint8 x5 = Uint8((x >> 16) & 0x00000000000000FF);
 105                Uint8 x6 = Uint8((x >>  8) & 0x00000000000000FF);
 106                Uint8 x7 = Uint8((x >>  0) & 0x00000000000000FF);
 107                out.append(x0, x1, x2, x3, x4, x5, x6, x7);
 108            }
 109            
 110            static void _PutSint8(Buffer& out, Sint8 x)
 111            {
 112                return _PutUint8(out, Uint8(x));
 113 mike   1.1 }
 114            
 115            static void _PutSint16(Buffer& out, Sint16 x)
 116            {
 117                return _PutUint16(out, Uint16(x));
 118            }
 119            
 120            static void _PutSint32(Buffer& out, Sint32 x)
 121            {
 122                return _PutUint32(out, Uint32(x));
 123            }
 124            
 125            static void _PutSint64(Buffer& out, Sint64 x)
 126            {
 127                return _PutUint64(out, Uint64(x));
 128            }
 129            
 130            static void _PutReal32(Buffer& out, Real32 x)
 131            {
 132                return _PutUint32(out, *((Uint32*)(void*)&x));
 133            }
 134 mike   1.1 
 135            static void _PutReal64(Buffer& out, Real64 x)
 136            {
 137                return _PutUint64(out, *((Uint64*)(void*)&x));
 138            }
 139            
 140            static void _PutChar16(Buffer& out, Char16 x)
 141            {
 142                return _PutUint16(out, Uint16(x));
 143            }
 144            
 145            static int _GetUint8(const Buffer& in, size_t& pos, Uint8& x)
 146            {
 147                if (in.size() < 1)
 148                    RETURN_FAILURE;
 149            
 150                const Uint8* p = (const Uint8*)(in.getData() + pos);
 151                x = p[0];
 152                pos++;
 153            
 154                return 0;
 155 mike   1.1 }
 156            
 157            static int _GetBoolean(const Buffer& in, size_t& pos, Boolean& x)
 158            {
 159                Uint8 tmp;
 160            
 161                if (_GetUint8(in, pos, tmp) != 0)
 162                    RETURN_FAILURE;
 163            
 164                if (tmp != 0 && tmp != 1)
 165                    RETURN_FAILURE;
 166            
 167                x = Boolean(tmp);
 168                return 0;
 169            }
 170            
 171            static int _GetUint16(const Buffer& in, size_t& pos, Uint16& x)
 172            {
 173                if (in.size() < 2)
 174                    RETURN_FAILURE;
 175            
 176 mike   1.1     const Uint8* p = (const Uint8*)(in.getData() + pos);
 177                Uint16 x0 = p[0];
 178                Uint16 x1 = p[1];
 179                x = (x0 << 8) | x1;
 180                pos += 2;
 181            
 182                return 0;
 183            }
 184            
 185            static int _GetUint32(const Buffer& in, size_t& pos, Uint32& x)
 186            {
 187                if (in.size() < 4)
 188                    RETURN_FAILURE;
 189            
 190                const Uint8* p = (const Uint8*)(in.getData() + pos);
 191                Uint32 x0 = p[0];
 192                Uint32 x1 = p[1];
 193                Uint32 x2 = p[2];
 194                Uint32 x3 = p[3];
 195                x = (x0 << 24) | (x1 << 16) | (x2 << 8) | x3;
 196                pos += 4;
 197 mike   1.1 
 198                return 0;
 199            }
 200            
 201            static int _GetUint64(const Buffer& in, size_t& pos, Uint64& x)
 202            {
 203                if (in.size() < 8)
 204                    RETURN_FAILURE;
 205            
 206                const Uint8* p = (const Uint8*)(in.getData() + pos);
 207                Uint64 x0 = p[0];
 208                Uint64 x1 = p[1];
 209                Uint64 x2 = p[2];
 210                Uint64 x3 = p[3];
 211                Uint64 x4 = p[4];
 212                Uint64 x5 = p[5];
 213                Uint64 x6 = p[6];
 214                Uint64 x7 = p[7];
 215                x = (x0 << 56) | (x1 << 48) | (x2 << 40) | (x3 << 32) |
 216                    (x4 << 24) | (x5 << 16) | (x6 << 8) | x7;
 217                pos += 8;
 218 mike   1.1 
 219                return 0;
 220            }
 221            
 222            static int _GetSint8(const Buffer& in, size_t& pos, Sint8& x)
 223            {
 224                return _GetUint8(in, pos, *((Uint8*)&x));
 225            }
 226            
 227            static int _GetSint16(const Buffer& in, size_t& pos, Sint16& x)
 228            {
 229                return _GetUint16(in, pos, *((Uint16*)&x));
 230            }
 231            
 232            static int _GetSint32(const Buffer& in, size_t& pos, Sint32& x)
 233            {
 234                return _GetUint32(in, pos, *((Uint32*)&x));
 235            }
 236            
 237            static int _GetSint64(const Buffer& in, size_t& pos, Sint64& x)
 238            {
 239 mike   1.1     return _GetUint64(in, pos, *((Uint64*)&x));
 240            }
 241            
 242            static int _GetReal32(const Buffer& in, size_t& pos, Real32& x)
 243            {
 244                return _GetUint32(in, pos, *((Uint32*)&x));
 245            }
 246            
 247            static int _GetReal64(const Buffer& in, size_t& pos, Real64& x)
 248            {
 249                return _GetUint64(in, pos, *((Uint64*)&x));
 250            }
 251            
 252            static int _GetChar16(const Buffer& in, size_t& pos, Char16& x)
 253            {
 254                return _GetUint16(in, pos, *((Uint16*)&x));
 255            }
 256            
 257            static void _PutString(Buffer& out, const String& str)
 258            {
 259                CString cstr(str.getCString());
 260 mike   1.1     Uint32 size = strlen(cstr);
 261            
 262                // Pack size:
 263                _PutUint32(out, size);
 264            
 265                // Pack UTF8 characters:
 266                out.append(cstr, size);
 267            }
 268            
 269            static void _PutDateTime(Buffer& out, const CIMDateTime& x)
 270            {
 271                _PutString(out, x.toString());
 272            }
 273            
 274            static void _PutObjectPath(Buffer& out, const CIMObjectPath& x)
 275            {
 276                // Serialize host:
 277            
 278                _PutString(out, x.getHost());
 279            
 280                //  Serialize namespace:
 281 mike   1.1 
 282                _PutString(out, x.getNameSpace().getString());
 283            
 284                // Serialize class name:
 285            
 286                _PutString(out, x.getClassName().getString());
 287            
 288                // Serialize key bindings:
 289            
 290                const Array<CIMKeyBinding>& kbs = x.getKeyBindings();
 291                _PutUint32(out, kbs.size());
 292            
 293                for (Uint32 i = 0, n = kbs.size(); i < n; i++)
 294                {
 295                    const CIMKeyBinding& kb = kbs[i];
 296            
 297                    // Serialize name:
 298            
 299                    _PutString(out, kb.getName().getString());
 300            
 301                    // Serialize type:
 302 mike   1.1 
 303                    _PutUint8(out, kb.getType());
 304            
 305                    // Serialize value:
 306            
 307                    _PutString(out, kb.getValue());
 308                }
 309            }
 310            
 311            static int _PutValue(Buffer& out, const CIMValue& cv)
 312            {
 313                // Serialize type (set MSB if array).
 314            
 315                Uint8 type = Uint8(cv.getType());
 316            
 317                if (cv.isArray())
 318                    type |= 0x80;
 319            
 320                _PutUint8(out, type);
 321            
 322                // Serialize the value itself:
 323 mike   1.1 
 324                if (cv.isArray())
 325                {
 326                    switch (cv.getType())
 327                    {
 328                        case CIMTYPE_BOOLEAN:
 329                        {
 330                            Array<Boolean> x;
 331                            cv.get(x);
 332                            _PutUint32(out, x.size());
 333            
 334                            for (Uint32 i = 0; i < x.size(); i++)
 335                                _PutBoolean(out, x[i]);
 336                            break;
 337                        }
 338                        case CIMTYPE_UINT8:
 339                        {
 340                            Array<Uint8> x;
 341                            cv.get(x);
 342                            _PutUint32(out, x.size());
 343            
 344 mike   1.1                 for (Uint32 i = 0; i < x.size(); i++)
 345                                _PutUint8(out, x[i]);
 346                            break;
 347                        }
 348                        case CIMTYPE_SINT8:
 349                        {
 350                            Array<Sint8> x;
 351                            cv.get(x);
 352                            _PutUint32(out, x.size());
 353            
 354                            for (Uint32 i = 0; i < x.size(); i++)
 355                                _PutSint8(out, x[i]);
 356                            break;
 357                        }
 358                        case CIMTYPE_UINT16:
 359                        {
 360                            Array<Uint16> x;
 361                            cv.get(x);
 362                            _PutUint32(out, x.size());
 363            
 364                            for (Uint32 i = 0; i < x.size(); i++)
 365 mike   1.1                     _PutUint16(out, x[i]);
 366                            break;
 367                        }
 368                        case CIMTYPE_SINT16:
 369                        {
 370                            Array<Sint16> x;
 371                            cv.get(x);
 372                            _PutUint32(out, x.size());
 373            
 374                            for (Uint32 i = 0; i < x.size(); i++)
 375                                _PutSint16(out, x[i]);
 376                            break;
 377                        }
 378                        case CIMTYPE_UINT32:
 379                        {
 380                            Array<Uint32> x;
 381                            cv.get(x);
 382                            _PutUint32(out, x.size());
 383            
 384                            for (Uint32 i = 0; i < x.size(); i++)
 385                                _PutUint32(out, x[i]);
 386 mike   1.1                 break;
 387                        }
 388                        case CIMTYPE_SINT32:
 389                        {
 390                            Array<Sint32> x;
 391                            cv.get(x);
 392                            _PutUint32(out, x.size());
 393            
 394                            for (Uint32 i = 0; i < x.size(); i++)
 395                                _PutSint32(out, x[i]);
 396                            break;
 397                        }
 398                        case CIMTYPE_UINT64:
 399                        {
 400                            Array<Uint64> x;
 401                            cv.get(x);
 402                            _PutUint32(out, x.size());
 403            
 404                            for (Uint32 i = 0; i < x.size(); i++)
 405                                _PutUint64(out, x[i]);
 406                            break;
 407 mike   1.1             }
 408                        case CIMTYPE_SINT64:
 409                        {
 410                            Array<Sint64> x;
 411                            cv.get(x);
 412                            _PutUint32(out, x.size());
 413            
 414                            for (Uint32 i = 0; i < x.size(); i++)
 415                                _PutSint64(out, x[i]);
 416                            break;
 417                        }
 418                        case CIMTYPE_REAL32:
 419                        {
 420                            Array<Real32> x;
 421                            cv.get(x);
 422                            _PutUint32(out, x.size());
 423            
 424                            for (Uint32 i = 0; i < x.size(); i++)
 425                                _PutReal32(out, x[i]);
 426                            break;
 427                        }
 428 mike   1.1             case CIMTYPE_REAL64:
 429                        {
 430                            Array<Real64> x;
 431                            cv.get(x);
 432                            _PutUint32(out, x.size());
 433            
 434                            for (Uint32 i = 0; i < x.size(); i++)
 435                                _PutReal64(out, x[i]);
 436                            break;
 437                        }
 438                        case CIMTYPE_CHAR16:
 439                        {
 440                            Array<Char16> x;
 441                            cv.get(x);
 442                            _PutUint32(out, x.size());
 443            
 444                            for (Uint32 i = 0; i < x.size(); i++)
 445                                _PutChar16(out, x[i]);
 446                            break;
 447                        }
 448                        case CIMTYPE_STRING:
 449 mike   1.1             {
 450                            Array<String> x;
 451                            cv.get(x);
 452                            _PutUint32(out, x.size());
 453            
 454                            for (Uint32 i = 0; i < x.size(); i++)
 455                                _PutString(out, x[i]);
 456                            break;
 457                        }
 458                        case CIMTYPE_DATETIME:
 459                        {
 460                            Array<CIMDateTime> x;
 461                            cv.get(x);
 462                            _PutUint32(out, x.size());
 463            
 464                            for (Uint32 i = 0; i < x.size(); i++)
 465                                _PutDateTime(out, x[i]);
 466                            break;
 467                        }
 468                        case CIMTYPE_REFERENCE:
 469                        {
 470 mike   1.1                 Array<CIMObjectPath> x;
 471                            cv.get(x);
 472                            _PutUint32(out, x.size());
 473            
 474                            for (Uint32 i = 0; i < x.size(); i++)
 475                                _PutObjectPath(out, x[i]);
 476                            break;
 477                        }
 478                        case CIMTYPE_OBJECT:
 479                        {
 480                            Array<CIMObject> x;
 481                            cv.get(x);
 482                            _PutUint32(out, x.size());
 483            
 484                            for (Uint32 i = 0; i < x.size(); i++)
 485                            {
 486                                if (!x[i].isInstance())
 487                                    RETURN_FAILURE;
 488            
 489                                CIMInstance ci(x[i]);
 490            
 491 mike   1.1                     MRRSerializeInstance(out, ci);
 492                            }
 493                            break;
 494                        }
 495                        case CIMTYPE_INSTANCE:
 496                        {
 497                            Array<CIMInstance> x;
 498                            cv.get(x);
 499                            _PutUint32(out, x.size());
 500            
 501                            for (Uint32 i = 0; i < x.size(); i++)
 502                                MRRSerializeInstance(out, x[i]);
 503                            break;
 504                        }
 505                    }
 506                }
 507                else
 508                {
 509                    switch (cv.getType())
 510                    {
 511                        case CIMTYPE_BOOLEAN:
 512 mike   1.1             {
 513                            Boolean x;
 514                            cv.get(x);
 515                            _PutBoolean(out, x);
 516                            break;
 517                        }
 518                        case CIMTYPE_UINT8:
 519                        {
 520                            Uint8 x;
 521                            cv.get(x);
 522                            _PutUint8(out, x);
 523                            break;
 524                        }
 525                        case CIMTYPE_SINT8:
 526                        {
 527                            Sint8 x;
 528                            cv.get(x);
 529                            _PutSint8(out, x);
 530                            break;
 531                        }
 532                        case CIMTYPE_UINT16:
 533 mike   1.1             {
 534                            Uint16 x;
 535                            cv.get(x);
 536                            _PutUint16(out, x);
 537                            break;
 538                        }
 539                        case CIMTYPE_SINT16:
 540                        {
 541                            Sint16 x;
 542                            cv.get(x);
 543                            _PutSint16(out, x);
 544                            break;
 545                        }
 546                        case CIMTYPE_UINT32:
 547                        {
 548                            Uint32 x;
 549                            cv.get(x);
 550                            _PutUint32(out, x);
 551                            break;
 552                        }
 553                        case CIMTYPE_SINT32:
 554 mike   1.1             {
 555                            Sint32 x;
 556                            cv.get(x);
 557                            _PutSint32(out, x);
 558                            break;
 559                        }
 560                        case CIMTYPE_UINT64:
 561                        {
 562                            Uint64 x;
 563                            cv.get(x);
 564                            _PutUint64(out, x);
 565                            break;
 566                        }
 567                        case CIMTYPE_SINT64:
 568                        {
 569                            Sint64 x;
 570                            cv.get(x);
 571                            _PutSint64(out, x);
 572                            break;
 573                        }
 574                        case CIMTYPE_REAL32:
 575 mike   1.1             {
 576                            Real32 x;
 577                            cv.get(x);
 578                            _PutReal32(out, x);
 579                            break;
 580                        }
 581                        case CIMTYPE_REAL64:
 582                        {
 583                            Real64 x;
 584                            cv.get(x);
 585                            _PutReal64(out, x);
 586                            break;
 587                        }
 588                        case CIMTYPE_CHAR16:
 589                        {
 590                            Char16 x;
 591                            cv.get(x);
 592                            _PutChar16(out, x);
 593                            break;
 594                        }
 595                        case CIMTYPE_STRING:
 596 mike   1.1             {
 597                            String x;
 598                            cv.get(x);
 599                            _PutString(out, x);
 600                            break;
 601                        }
 602                        case CIMTYPE_DATETIME:
 603                        {
 604                            CIMDateTime x;
 605                            cv.get(x);
 606                            _PutDateTime(out, x);
 607                            break;
 608                        }
 609                        case CIMTYPE_REFERENCE:
 610                        {
 611                            CIMObjectPath x;
 612                            cv.get(x);
 613                            _PutObjectPath(out, x);
 614                            break;
 615                        }
 616                        case CIMTYPE_OBJECT:
 617 mike   1.1             {
 618                            CIMObject co;
 619                            cv.get(co);
 620            
 621                            if (!co.isInstance())
 622                                RETURN_FAILURE;
 623            
 624                            CIMInstance ci(co);
 625            
 626                            MRRSerializeInstance(out, ci);
 627                            break;
 628                        }
 629                        case CIMTYPE_INSTANCE:
 630                        {
 631                            CIMInstance ci;
 632                            cv.get(ci);
 633                            MRRSerializeInstance(out, ci);
 634                            break;
 635                        }
 636                    }
 637                }
 638 mike   1.1 
 639                return 0;
 640            }
 641            
 642            static int _GetString(
 643                const Buffer& in, size_t& pos, String& str)
 644            {
 645                // Deserialize size:
 646            
 647                Uint32 size;
 648            
 649                if (_GetUint32(in, pos, size) != 0)
 650                    RETURN_FAILURE;
 651            
 652                // Read string:
 653            
 654                str.append(&in[pos], size);
 655                pos += size;
 656            
 657                return 0;
 658            }
 659 mike   1.1 
 660            static int _GetDateTime(const Buffer& in, size_t& pos, CIMDateTime& x)
 661            {
 662                String str;
 663            
 664                if (_GetString(in, pos, str) != 0)
 665                    RETURN_FAILURE;
 666            
 667                try
 668                {
 669                    x.set(str);
 670                }
 671                catch (...)
 672                {
 673                    RETURN_FAILURE;
 674                }
 675                return 0;
 676            }
 677            
 678            static int _GetObjectPath(
 679 kumpf  1.5     const Buffer& in,
 680                size_t& pos,
 681 mike   1.1     CIMObjectPath& cop)
 682            {
 683                // Deserialize host:
 684            
 685                String host;
 686            
 687                if (_GetString(in, pos, host) != 0)
 688                    RETURN_FAILURE;
 689            
 690                // Deserialize namespace:
 691            
 692                CIMNamespaceName nameSpace;
 693                {
 694                    String nameSpaceString;
 695            
 696                    if (_GetString(in, pos, nameSpaceString) != 0)
 697                        RETURN_FAILURE;
 698            
 699                    if (nameSpaceString.size() != 0)
 700                        nameSpace = nameSpaceString;
 701                }
 702 mike   1.1 
 703                // Deserialize className:
 704            
 705                CIMName className;
 706                {
 707                    String classNameString;
 708            
 709                    if (_GetString(in, pos, classNameString) != 0)
 710                        RETURN_FAILURE;
 711            
 712                    if (classNameString.size() != 0)
 713                        className = classNameString;
 714                }
 715            
 716                // Deserialize the number of key bindings:
 717            
 718                Uint32 size;
 719            
 720                if (_GetUint32(in, pos, size) != 0)
 721                    RETURN_FAILURE;
 722            
 723 mike   1.1     // Deserialize the key bindings.
 724            
 725                Array<CIMKeyBinding> kbs;
 726            
 727                for (Uint32 i = 0; i < size; i++)
 728                {
 729                    // Deserialize name:
 730            
 731                    String name;
 732            
 733                    if (_GetString(in, pos, name) != 0)
 734                        RETURN_FAILURE;
 735            
 736                    // Deserialize and check type:
 737            
 738                    Uint8 type;
 739            
 740                    if (_GetUint8(in, pos, type) != 0)
 741                        RETURN_FAILURE;
 742            
 743                    if (type != CIMKeyBinding::BOOLEAN && type != CIMKeyBinding::STRING &&
 744 mike   1.1             type != CIMKeyBinding::NUMERIC && type != CIMKeyBinding::REFERENCE)
 745                    {
 746                        RETURN_FAILURE;
 747                    }
 748            
 749                    // Deserialize value:
 750            
 751                    String value;
 752            
 753                    if (_GetString(in, pos, value) != 0)
 754                        RETURN_FAILURE;
 755            
 756                    // Add key binding:
 757            
 758                    try
 759                    {
 760                        kbs.append(CIMKeyBinding(name, value, CIMKeyBinding::Type(type)));
 761                    }
 762                    catch (...)
 763                    {
 764                        RETURN_FAILURE;
 765 mike   1.1         }
 766                }
 767            
 768                // Create the object path:
 769            
 770                try
 771                {
 772                    cop = CIMObjectPath(host, nameSpace, className, kbs);
 773                }
 774                catch (...)
 775                {
 776                    RETURN_FAILURE;
 777                }
 778            
 779                return 0;
 780            }
 781            
 782            static int _GetValue(
 783 kumpf  1.5     const Buffer& in,
 784 mike   1.1     size_t& pos,
 785                CIMValue& value)
 786            {
 787                value.clear();
 788            
 789                // Deserialize type and isArray:
 790            
 791                Boolean isArray;
 792                Uint32 type;
 793                {
 794                    Uint8 tmp;
 795 kumpf  1.5 
 796 mike   1.1         if (_GetUint8(in, pos, tmp) != 0)
 797                        RETURN_FAILURE;
 798            
 799                    isArray = tmp & 0x80;
 800                    type = CIMType(tmp & 0x7F);
 801                }
 802            
 803                // Deserialize the value itself:
 804            
 805                if (isArray)
 806                {
 807                    Uint32 size;
 808            
 809                    if (_GetUint32(in, pos, size) != 0)
 810                        RETURN_FAILURE;
 811            
 812                    switch (type)
 813                    {
 814                        case CIMTYPE_BOOLEAN:
 815                        {
 816                            Array<Boolean> a;
 817 mike   1.1 
 818                            for (Uint32 i = 0; i < size; i++)
 819                            {
 820                                Boolean x;
 821            
 822                                if (_GetBoolean(in, pos, x) != 0)
 823                                    RETURN_FAILURE;
 824            
 825                                a.append(x);
 826                            }
 827                            value.set(a);
 828                            break;
 829                        }
 830                        case CIMTYPE_UINT8:
 831                        {
 832                            Array<Uint8> a;
 833            
 834                            for (Uint32 i = 0; i < size; i++)
 835                            {
 836                                Uint8 x;
 837            
 838 mike   1.1                     if (_GetUint8(in, pos, x) != 0)
 839                                    RETURN_FAILURE;
 840            
 841                                a.append(x);
 842                            }
 843                            value.set(a);
 844                            break;
 845                        }
 846                        case CIMTYPE_SINT8:
 847                        {
 848                            Array<Sint8> a;
 849            
 850                            for (Uint32 i = 0; i < size; i++)
 851                            {
 852                                Sint8 x;
 853            
 854                                if (_GetSint8(in, pos, x) != 0)
 855                                    RETURN_FAILURE;
 856            
 857                                a.append(x);
 858                            }
 859 mike   1.1                 value.set(a);
 860                            break;
 861                        }
 862                        case CIMTYPE_UINT16:
 863                        {
 864                            Array<Uint16> a;
 865            
 866                            for (Uint32 i = 0; i < size; i++)
 867                            {
 868                                Uint16 x;
 869            
 870                                if (_GetUint16(in, pos, x) != 0)
 871                                    RETURN_FAILURE;
 872            
 873                                a.append(x);
 874                            }
 875                            value.set(a);
 876                            break;
 877                        }
 878                        case CIMTYPE_SINT16:
 879                        {
 880 mike   1.1                 Array<Sint16> a;
 881            
 882                            for (Uint32 i = 0; i < size; i++)
 883                            {
 884                                Sint16 x;
 885            
 886                                if (_GetSint16(in, pos, x) != 0)
 887                                    RETURN_FAILURE;
 888            
 889                                a.append(x);
 890                            }
 891                            value.set(a);
 892                            break;
 893                        }
 894                        case CIMTYPE_UINT32:
 895                        {
 896                            Array<Uint32> a;
 897            
 898                            for (Uint32 i = 0; i < size; i++)
 899                            {
 900                                Uint32 x;
 901 mike   1.1 
 902                                if (_GetUint32(in, pos, x) != 0)
 903                                    RETURN_FAILURE;
 904            
 905                                a.append(x);
 906                            }
 907                            value.set(a);
 908                            break;
 909                        }
 910                        case CIMTYPE_SINT32:
 911                        {
 912                            Array<Sint32> a;
 913            
 914                            for (Uint32 i = 0; i < size; i++)
 915                            {
 916                                Sint32 x;
 917            
 918                                if (_GetSint32(in, pos, x) != 0)
 919                                    RETURN_FAILURE;
 920            
 921                                a.append(x);
 922 mike   1.1                 }
 923                            value.set(a);
 924                            break;
 925                        }
 926                        case CIMTYPE_UINT64:
 927                        {
 928                            Array<Uint64> a;
 929            
 930                            for (Uint32 i = 0; i < size; i++)
 931                            {
 932                                Uint64 x;
 933            
 934                                if (_GetUint64(in, pos, x) != 0)
 935                                    RETURN_FAILURE;
 936            
 937                                a.append(x);
 938                            }
 939                            value.set(a);
 940                            break;
 941                        }
 942                        case CIMTYPE_SINT64:
 943 mike   1.1             {
 944                            Array<Sint64> a;
 945            
 946                            for (Uint32 i = 0; i < size; i++)
 947                            {
 948                                Sint64 x;
 949            
 950                                if (_GetSint64(in, pos, x) != 0)
 951                                    RETURN_FAILURE;
 952            
 953                                a.append(x);
 954                            }
 955                            value.set(a);
 956                            break;
 957                        }
 958                        case CIMTYPE_REAL32:
 959                        {
 960                            Array<Real32> a;
 961            
 962                            for (Uint32 i = 0; i < size; i++)
 963                            {
 964 mike   1.1                     Real32 x;
 965            
 966                                if (_GetReal32(in, pos, x) != 0)
 967                                    RETURN_FAILURE;
 968            
 969                                a.append(x);
 970                            }
 971                            value.set(a);
 972                            break;
 973                        }
 974                        case CIMTYPE_REAL64:
 975                        {
 976                            Array<Real64> a;
 977            
 978                            for (Uint32 i = 0; i < size; i++)
 979                            {
 980                                Real64 x;
 981            
 982                                if (_GetReal64(in, pos, x) != 0)
 983                                    RETURN_FAILURE;
 984            
 985 mike   1.1                     a.append(x);
 986                            }
 987                            value.set(a);
 988                            break;
 989                        }
 990                        case CIMTYPE_CHAR16:
 991                        {
 992                            Array<Char16> a;
 993            
 994                            for (Uint32 i = 0; i < size; i++)
 995                            {
 996                                Char16 x;
 997            
 998                                if (_GetChar16(in, pos, x) != 0)
 999                                    RETURN_FAILURE;
1000            
1001                                a.append(x);
1002                            }
1003                            value.set(a);
1004                            break;
1005                        }
1006 mike   1.1             case CIMTYPE_STRING:
1007                        {
1008                            Array<String> a;
1009            
1010                            for (Uint32 i = 0; i < size; i++)
1011                            {
1012                                String x;
1013            
1014                                if (_GetString(in, pos, x) != 0)
1015                                    RETURN_FAILURE;
1016            
1017                                a.append(x);
1018                            }
1019                            value.set(a);
1020                            break;
1021                        }
1022                        case CIMTYPE_DATETIME:
1023                        {
1024                            Array<CIMDateTime> a;
1025            
1026                            for (Uint32 i = 0; i < size; i++)
1027 mike   1.1                 {
1028                                CIMDateTime x;
1029            
1030                                if (_GetDateTime(in, pos, x) != 0)
1031                                    RETURN_FAILURE;
1032            
1033                                a.append(x);
1034                            }
1035                            value.set(a);
1036                            break;
1037                        }
1038                        case CIMTYPE_REFERENCE:
1039                        {
1040                            Array<CIMObjectPath> a;
1041            
1042                            for (Uint32 i = 0; i < size; i++)
1043                            {
1044                                CIMObjectPath x;
1045            
1046                                if (_GetObjectPath(in, pos, x) != 0)
1047                                    RETURN_FAILURE;
1048 mike   1.1 
1049                                a.append(x);
1050                            }
1051                            value.set(a);
1052                            break;
1053                        }
1054                        case CIMTYPE_OBJECT:
1055                        {
1056                            Array<CIMObject> a;
1057            
1058                            for (Uint32 i = 0; i < size; i++)
1059                            {
1060                                CIMInstance x;
1061            
1062                                if (MRRDeserializeInstance(in, pos, x) != 0)
1063                                    RETURN_FAILURE;
1064            
1065                                a.append(CIMObject(x));
1066                            }
1067                            value.set(a);
1068                            break;
1069 mike   1.1             }
1070                        case CIMTYPE_INSTANCE:
1071                        {
1072                            Array<CIMInstance> a;
1073            
1074                            for (Uint32 i = 0; i < size; i++)
1075                            {
1076                                CIMInstance x;
1077            
1078                                if (MRRDeserializeInstance(in, pos, x) != 0)
1079                                    RETURN_FAILURE;
1080            
1081                                a.append(x);
1082                            }
1083                            value.set(a);
1084                            break;
1085                        }
1086                        default:
1087                            RETURN_FAILURE;
1088                    }
1089                }
1090 mike   1.1     else
1091                {
1092                    switch (type)
1093                    {
1094                        case CIMTYPE_BOOLEAN:
1095                        {
1096                            Boolean x;
1097            
1098                            if (_GetBoolean(in, pos, x) != 0)
1099                                RETURN_FAILURE;
1100            
1101                            value.set(x);
1102                            break;
1103                        }
1104                        case CIMTYPE_UINT8:
1105                        {
1106                            Uint8 x;
1107            
1108                            if (_GetUint8(in, pos, x) != 0)
1109                                RETURN_FAILURE;
1110            
1111 mike   1.1                 value.set(x);
1112                            break;
1113                        }
1114                        case CIMTYPE_SINT8:
1115                        {
1116                            Sint8 x;
1117            
1118                            if (_GetSint8(in, pos, x) != 0)
1119                                RETURN_FAILURE;
1120            
1121                            value.set(x);
1122                            break;
1123                        }
1124                        case CIMTYPE_UINT16:
1125                        {
1126                            Uint16 x;
1127            
1128                            if (_GetUint16(in, pos, x) != 0)
1129                                RETURN_FAILURE;
1130            
1131                            value.set(x);
1132 mike   1.1                 break;
1133                        }
1134                        case CIMTYPE_SINT16:
1135                        {
1136                            Sint16 x;
1137            
1138                            if (_GetSint16(in, pos, x) != 0)
1139                                RETURN_FAILURE;
1140            
1141                            value.set(x);
1142                            break;
1143                        }
1144                        case CIMTYPE_UINT32:
1145                        {
1146                            Uint32 x;
1147            
1148                            if (_GetUint32(in, pos, x) != 0)
1149                                RETURN_FAILURE;
1150            
1151                            value.set(x);
1152                            break;
1153 mike   1.1             }
1154                        case CIMTYPE_SINT32:
1155                        {
1156                            Sint32 x;
1157            
1158                            if (_GetSint32(in, pos, x) != 0)
1159                                RETURN_FAILURE;
1160            
1161                            value.set(x);
1162                            break;
1163                        }
1164                        case CIMTYPE_UINT64:
1165                        {
1166                            Uint64 x;
1167            
1168                            if (_GetUint64(in, pos, x) != 0)
1169                                RETURN_FAILURE;
1170            
1171                            value.set(x);
1172                            break;
1173                        }
1174 mike   1.1             case CIMTYPE_SINT64:
1175                        {
1176                            Sint64 x;
1177            
1178                            if (_GetSint64(in, pos, x) != 0)
1179                                RETURN_FAILURE;
1180            
1181                            value.set(x);
1182                            break;
1183                        }
1184                        case CIMTYPE_REAL32:
1185                        {
1186                            Real32 x;
1187            
1188                            if (_GetReal32(in, pos, x) != 0)
1189                                RETURN_FAILURE;
1190            
1191                            value.set(x);
1192                            break;
1193                        }
1194                        case CIMTYPE_REAL64:
1195 mike   1.1             {
1196                            Real64 x;
1197            
1198                            if (_GetReal64(in, pos, x) != 0)
1199                                RETURN_FAILURE;
1200            
1201                            value.set(x);
1202                            break;
1203                        }
1204                        case CIMTYPE_CHAR16:
1205                        {
1206                            Char16 x;
1207            
1208                            if (_GetChar16(in, pos, x) != 0)
1209                                RETURN_FAILURE;
1210            
1211                            value.set(x);
1212                            break;
1213                        }
1214                        case CIMTYPE_STRING:
1215                        {
1216 mike   1.1                 String x;
1217            
1218                            if (_GetString(in, pos, x) != 0)
1219                                RETURN_FAILURE;
1220            
1221                            value.set(x);
1222                            break;
1223                        }
1224                        case CIMTYPE_DATETIME:
1225                        {
1226                            CIMDateTime x;
1227            
1228                            if (_GetDateTime(in, pos, x) != 0)
1229                                RETURN_FAILURE;
1230            
1231                            value.set(x);
1232                            break;
1233                        }
1234                        case CIMTYPE_REFERENCE:
1235                        {
1236                            CIMObjectPath x;
1237 mike   1.1 
1238                            if (_GetObjectPath(in, pos, x) != 0)
1239                                RETURN_FAILURE;
1240            
1241                            value.set(x);
1242                            break;
1243                        }
1244                        case CIMTYPE_OBJECT:
1245                        {
1246                            CIMInstance x;
1247            
1248                            if (MRRDeserializeInstance(in, pos, x) != 0)
1249                                RETURN_FAILURE;
1250            
1251                            value.set(CIMObject(x));
1252                            break;
1253                        }
1254                        case CIMTYPE_INSTANCE:
1255                        {
1256                            CIMInstance x;
1257            
1258 mike   1.1                 if (MRRDeserializeInstance(in, pos, x) != 0)
1259                                RETURN_FAILURE;
1260            
1261                            value.set(x);
1262                            break;
1263                        }
1264                        default:
1265                            RETURN_FAILURE;
1266                    }
1267                }
1268            
1269                return 0;
1270            }
1271            
1272            void MRRSerializeInstance(Buffer& out, const CIMInstance& ci)
1273            {
1274                // Serialize magic number:
1275            
1276                _PutUint32(out, _INSTANCE_MAGIC);
1277            
1278                // Serialize object path:
1279 mike   1.1 
1280                _PutObjectPath(out, ci.getPath());
1281            
1282                // Serialize properties:
1283            
1284                _PutUint32(out, ci.getPropertyCount());
1285            
1286                for (Uint32 i = 0, n = ci.getPropertyCount(); i < n; i++)
1287                {
1288                    const CIMConstProperty cp = ci.getProperty(i);
1289            
1290                    // Serialize property name:
1291            
1292                    _PutString(out, cp.getName().getString());
1293            
1294                    // Serialize the value:
1295            
1296                    _PutValue(out, cp.getValue());
1297                }
1298            }
1299            
1300 mike   1.1 int MRRDeserializeInstance(
1301 kumpf  1.5     const Buffer& in,
1302 mike   1.1     size_t& pos,
1303                CIMInstance& ci)
1304            {
1305                // Deserialize magic number:
1306            
1307                Uint32 magic;
1308            
1309                if (_GetUint32(in, pos, magic) != 0 || magic != _INSTANCE_MAGIC)
1310                    RETURN_FAILURE;
1311            
1312                // Deserialize object path:
1313            
1314                CIMObjectPath cop;
1315            
1316                if (_GetObjectPath(in, pos, cop) != 0)
1317                    RETURN_FAILURE;
1318            
1319                // Create the instance:
1320            
1321                try
1322                {
1323 mike   1.1         ci = CIMInstance(cop.getClassName());
1324                    ci.setPath(cop);
1325                }
1326                catch (...)
1327                {
1328                    RETURN_FAILURE;
1329                }
1330            
1331                // Get property count:
1332            
1333                Uint32 propertyCount = 0;
1334            
1335                if (_GetUint32(in, pos, propertyCount) != 0)
1336                    RETURN_FAILURE;
1337            
1338                // Deserialize properties:
1339            
1340                for (Uint32 i = 0; i < propertyCount; i++)
1341                {
1342                    // Deserialize property name:
1343            
1344 mike   1.1         String name;
1345            
1346                    if (_GetString(in, pos, name) != 0)
1347                        RETURN_FAILURE;
1348            
1349                    // Deserialize property value:
1350            
1351                    CIMValue value;
1352            
1353                    if (_GetValue(in, pos, value) != 0)
1354                        RETURN_FAILURE;
1355            
1356                    // Add property to instance.
1357            
1358                    try
1359                    {
1360                        ci.addProperty(CIMProperty(name, value));
1361                    }
1362                    catch (Exception& e)
1363                    {
1364                        RETURN_FAILURE;
1365 mike   1.1         }
1366                }
1367            
1368                return 0;
1369            }
1370            
1371            void MRRSerializeNameSpace(
1372 kumpf  1.5     Buffer& out,
1373 mike   1.1     const CIMNamespaceName& nameSpace)
1374            {
1375                // Serialize magic number:
1376            
1377                _PutUint32(out, _NAMESPACE_MAGIC);
1378            
1379                // Serialize namespace string:
1380            
1381                _PutString(out, nameSpace.getString());
1382            }
1383            
1384            int MRRDeserializeNameSpace(
1385 kumpf  1.5     const Buffer& in,
1386 mike   1.1     size_t& pos,
1387                CIMNamespaceName& nameSpace)
1388            {
1389                // Deserialize magic number:
1390            
1391                Uint32 magic;
1392            
1393                if (_GetUint32(in, pos, magic) != 0 || magic != _NAMESPACE_MAGIC)
1394                    RETURN_FAILURE;
1395            
1396                // Deserialize namespace string:
1397            
1398                String tmp;
1399            
1400                if (_GetString(in, pos, tmp) != 0)
1401                    RETURN_FAILURE;
1402            
1403                try
1404                {
1405                    nameSpace = tmp;
1406                }
1407 mike   1.1     catch (...)
1408                {
1409                    return -1;
1410                }
1411                return 0;
1412            }
1413            
1414            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2