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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2