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
56 class Str
57 {
58 public:
59 Str(const String& s) : _cstr(s.getCString()) { }
60 Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
61 Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
62 Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
63 Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
64 mike 1.1.2.1 Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
65 const char* operator*() const { return (const char*)_cstr; }
66 operator const char*() const { return (const char*)_cstr; }
67 private:
68 CString _cstr;
69 };
70
71 static void _PutUint8(Buffer& out, Uint8 x)
72 {
73 out.append(x);
74 }
75
76 static void _PutBoolean(Buffer& out, Boolean x)
77 {
78 _PutUint8(out, x ? 1 : 0);
79 }
80
81 static void _PutUint16(Buffer& out, Uint16 x)
82 {
83 Uint8 x0 = Uint8((x >> 8) & 0x00FF);
84 Uint8 x1 = Uint8((x >> 0) & 0x00FF);
85 mike 1.1.2.1 out.append(x0, 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 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 mike 1.1.2.1 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 }
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 mike 1.1.2.1 return _PutUint64(out, Uint64(x));
128 }
129
130 static void _PutReal32(Buffer& out, Real32 x)
131 {
132 return _PutUint32(out, *((Uint32*)&x));
133 }
134
135 static void _PutReal64(Buffer& out, Real64 x)
136 {
137 return _PutUint64(out, *((Uint64*)&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 mike 1.1.2.1 RETURN_FAILURE;
149
150 const Uint8* p = (const Uint8*)(in.getData() + pos);
151 x = p[0];
152 pos++;
153
154 return 0;
155 }
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 mike 1.1.2.1 }
170
171 static int _GetUint16(const Buffer& in, size_t& pos, Uint16& x)
172 {
173 if (in.size() < 2)
174 RETURN_FAILURE;
175
176 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 mike 1.1.2.1 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
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 mike 1.1.2.1 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
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 mike 1.1.2.1 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 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 mike 1.1.2.1 {
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 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 mike 1.1.2.1 static void _PutObjectPath(Buffer& out, const CIMObjectPath& x)
275 {
276 // Serialize host:
277
278 _PutString(out, x.getHost());
279
280 // Serialize namespace:
281
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 mike 1.1.2.1 const CIMKeyBinding& kb = kbs[i];
296
297 // Serialize name:
298
299 _PutString(out, kb.getName().getString());
300
301 // Serialize type:
302
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 mike 1.1.2.1
317 if (cv.isArray())
318 type |= 0x80;
319
320 _PutUint8(out, type);
321
322 // Serialize the value itself:
323
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 mike 1.1.2.1 }
338 case CIMTYPE_UINT8:
339 {
340 Array<Uint8> x;
341 cv.get(x);
342 _PutUint32(out, x.size());
343
344 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 mike 1.1.2.1 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 _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 mike 1.1.2.1 {
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 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 mike 1.1.2.1 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 }
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 mike 1.1.2.1 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 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 mike 1.1.2.1 _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 {
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 mike 1.1.2.1
464 for (Uint32 i = 0; i < x.size(); i++)
465 _PutDateTime(out, x[i]);
466 break;
467 }
468 case CIMTYPE_REFERENCE:
469 {
470 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 mike 1.1.2.1 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 SerializeInstance(out, ci);
492 }
493 break;
494 }
495 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
496 # ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
497 case CIMTYPE_INSTANCE:
498 {
499 Array<CIMInstance> x;
500 cv.get(x);
501 _PutUint32(out, x.size());
502
503 for (Uint32 i = 0; i < x.size(); i++)
504 SerializeInstance(out, x[i]);
505 mike 1.1.2.1 break;
506 }
507 # endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
508 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
509 }
510 }
511 else
512 {
513 switch (cv.getType())
514 {
515 case CIMTYPE_BOOLEAN:
516 {
517 Boolean x;
518 cv.get(x);
519 _PutBoolean(out, x);
520 break;
521 }
522 case CIMTYPE_UINT8:
523 {
524 Uint8 x;
525 cv.get(x);
526 mike 1.1.2.1 _PutUint8(out, x);
527 break;
528 }
529 case CIMTYPE_SINT8:
530 {
531 Sint8 x;
532 cv.get(x);
533 _PutSint8(out, x);
534 break;
535 }
536 case CIMTYPE_UINT16:
537 {
538 Uint16 x;
539 cv.get(x);
540 _PutUint16(out, x);
541 break;
542 }
543 case CIMTYPE_SINT16:
544 {
545 Sint16 x;
546 cv.get(x);
547 mike 1.1.2.1 _PutSint16(out, x);
548 break;
549 }
550 case CIMTYPE_UINT32:
551 {
552 Uint32 x;
553 cv.get(x);
554 _PutUint32(out, x);
555 break;
556 }
557 case CIMTYPE_SINT32:
558 {
559 Sint32 x;
560 cv.get(x);
561 _PutSint32(out, x);
562 break;
563 }
564 case CIMTYPE_UINT64:
565 {
566 Uint64 x;
567 cv.get(x);
568 mike 1.1.2.1 _PutUint64(out, x);
569 break;
570 }
571 case CIMTYPE_SINT64:
572 {
573 Sint64 x;
574 cv.get(x);
575 _PutSint64(out, x);
576 break;
577 }
578 case CIMTYPE_REAL32:
579 {
580 Real32 x;
581 cv.get(x);
582 _PutReal32(out, x);
583 break;
584 }
585 case CIMTYPE_REAL64:
586 {
587 Real64 x;
588 cv.get(x);
589 mike 1.1.2.1 _PutReal64(out, x);
590 break;
591 }
592 case CIMTYPE_CHAR16:
593 {
594 Char16 x;
595 cv.get(x);
596 _PutChar16(out, x);
597 break;
598 }
599 case CIMTYPE_STRING:
600 {
601 String x;
602 cv.get(x);
603 _PutString(out, x);
604 break;
605 }
606 case CIMTYPE_DATETIME:
607 {
608 CIMDateTime x;
609 cv.get(x);
610 mike 1.1.2.1 _PutDateTime(out, x);
611 break;
612 }
613 case CIMTYPE_REFERENCE:
614 {
615 CIMObjectPath x;
616 cv.get(x);
617 _PutObjectPath(out, x);
618 break;
619 }
620 case CIMTYPE_OBJECT:
621 {
622 CIMObject co;
623 cv.get(co);
624
625 if (!co.isInstance())
626 RETURN_FAILURE;
627
628 CIMInstance ci(co);
629
630 SerializeInstance(out, ci);
631 mike 1.1.2.1 break;
632 }
633 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
634 # ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
635 case CIMTYPE_INSTANCE:
636 {
637 CIMInstance ci;
638 cv.get(ci);
639 SerializeInstance(out, ci);
640 break;
641 }
642 # endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
643 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
644 }
645 }
646
647 return 0;
648 }
649
650 static int _GetString(
651 const Buffer& in, size_t& pos, String& str)
652 mike 1.1.2.1 {
653 // Deserialize size:
654
655 Uint32 size;
656
657 if (_GetUint32(in, pos, size) != 0)
658 RETURN_FAILURE;
659
660 // Read string:
661
662 str.append(&in[pos], size);
663 pos += size;
664
665 return 0;
666 }
667
668 static int _GetDateTime(const Buffer& in, size_t& pos, CIMDateTime& x)
669 {
670 String str;
671
672 if (_GetString(in, pos, str) != 0)
673 mike 1.1.2.1 RETURN_FAILURE;
674
675 try
676 {
677 x.set(str);
678 }
679 catch (...)
680 {
681 RETURN_FAILURE;
682 }
683 return 0;
684 }
685
686 static int _GetObjectPath(
687 const Buffer& in,
688 size_t& pos,
689 CIMObjectPath& cop)
690 {
691 // Deserialize host:
692
693 String host;
694 mike 1.1.2.1
695 if (_GetString(in, pos, host) != 0)
696 RETURN_FAILURE;
697
698 // Deserialize namespace:
699
700 CIMNamespaceName nameSpace;
701 {
702 String nameSpaceString;
703
704 if (_GetString(in, pos, nameSpaceString) != 0)
705 RETURN_FAILURE;
706
707 if (nameSpaceString.size() != 0)
708 nameSpace = nameSpaceString;
709 }
710
711 // Deserialize className:
712
713 CIMName className;
714 {
715 mike 1.1.2.1 String classNameString;
716
717 if (_GetString(in, pos, classNameString) != 0)
718 RETURN_FAILURE;
719
720 if (classNameString.size() != 0)
721 className = classNameString;
722 }
723
724 // Deserialize the number of key bindings:
725
726 Uint32 size;
727
728 if (_GetUint32(in, pos, size) != 0)
729 RETURN_FAILURE;
730
731 // Deserialize the key bindings.
732
733 Array<CIMKeyBinding> kbs;
734
735 for (Uint32 i = 0; i < size; i++)
736 mike 1.1.2.1 {
737 // Deserialize name:
738
739 String name;
740
741 if (_GetString(in, pos, name) != 0)
742 RETURN_FAILURE;
743
744 // Deserialize and check type:
745
746 Uint8 type;
747
748 if (_GetUint8(in, pos, type) != 0)
749 RETURN_FAILURE;
750
751 if (type != CIMKeyBinding::BOOLEAN && type != CIMKeyBinding::STRING &&
752 type != CIMKeyBinding::NUMERIC && type != CIMKeyBinding::REFERENCE)
753 {
754 RETURN_FAILURE;
755 }
756
757 mike 1.1.2.1 // Deserialize value:
758
759 String value;
760
761 if (_GetString(in, pos, value) != 0)
762 RETURN_FAILURE;
763
764 // Add key binding:
765
766 try
767 {
768 kbs.append(CIMKeyBinding(name, value, CIMKeyBinding::Type(type)));
769 }
770 catch (...)
771 {
772 RETURN_FAILURE;
773 }
774 }
775
776 // Create the object path:
777
778 mike 1.1.2.1 try
779 {
780 cop = CIMObjectPath(host, nameSpace, className, kbs);
781 }
782 catch (...)
783 {
784 RETURN_FAILURE;
785 }
786
787 return 0;
788 }
789
790 static int _GetValue(
791 const Buffer& in,
792 size_t& pos,
793 CIMValue& value)
794 {
795 value.clear();
796
797 // Deserialize type and isArray:
798
799 mike 1.1.2.1 Boolean isArray;
800 Uint32 type;
801 {
802 Uint8 tmp;
803
804 if (_GetUint8(in, pos, tmp) != 0)
805 RETURN_FAILURE;
806
807 isArray = tmp & 0x80;
808 type = CIMType(tmp & 0x7F);
809 }
810
811 // Deserialize the value itself:
812
813 if (isArray)
814 {
815 Uint32 size;
816
817 if (_GetUint32(in, pos, size) != 0)
818 RETURN_FAILURE;
819
820 mike 1.1.2.1 switch (type)
821 {
822 case CIMTYPE_BOOLEAN:
823 {
824 Array<Boolean> a;
825
826 for (Uint32 i = 0; i < size; i++)
827 {
828 Boolean x;
829
830 if (_GetBoolean(in, pos, x) != 0)
831 RETURN_FAILURE;
832
833 a.append(x);
834 }
835 value.set(a);
836 break;
837 }
838 case CIMTYPE_UINT8:
839 {
840 Array<Uint8> a;
841 mike 1.1.2.1
842 for (Uint32 i = 0; i < size; i++)
843 {
844 Uint8 x;
845
846 if (_GetUint8(in, pos, x) != 0)
847 RETURN_FAILURE;
848
849 a.append(x);
850 }
851 value.set(a);
852 break;
853 }
854 case CIMTYPE_SINT8:
855 {
856 Array<Sint8> a;
857
858 for (Uint32 i = 0; i < size; i++)
859 {
860 Sint8 x;
861
862 mike 1.1.2.1 if (_GetSint8(in, pos, x) != 0)
863 RETURN_FAILURE;
864
865 a.append(x);
866 }
867 value.set(a);
868 break;
869 }
870 case CIMTYPE_UINT16:
871 {
872 Array<Uint16> a;
873
874 for (Uint32 i = 0; i < size; i++)
875 {
876 Uint16 x;
877
878 if (_GetUint16(in, pos, x) != 0)
879 RETURN_FAILURE;
880
881 a.append(x);
882 }
883 mike 1.1.2.1 value.set(a);
884 break;
885 }
886 case CIMTYPE_SINT16:
887 {
888 Array<Sint16> a;
889
890 for (Uint32 i = 0; i < size; i++)
891 {
892 Sint16 x;
893
894 if (_GetSint16(in, pos, x) != 0)
895 RETURN_FAILURE;
896
897 a.append(x);
898 }
899 value.set(a);
900 break;
901 }
902 case CIMTYPE_UINT32:
903 {
904 mike 1.1.2.1 Array<Uint32> a;
905
906 for (Uint32 i = 0; i < size; i++)
907 {
908 Uint32 x;
909
910 if (_GetUint32(in, pos, x) != 0)
911 RETURN_FAILURE;
912
913 a.append(x);
914 }
915 value.set(a);
916 break;
917 }
918 case CIMTYPE_SINT32:
919 {
920 Array<Sint32> a;
921
922 for (Uint32 i = 0; i < size; i++)
923 {
924 Sint32 x;
925 mike 1.1.2.1
926 if (_GetSint32(in, pos, x) != 0)
927 RETURN_FAILURE;
928
929 a.append(x);
930 }
931 value.set(a);
932 break;
933 }
934 case CIMTYPE_UINT64:
935 {
936 Array<Uint64> a;
937
938 for (Uint32 i = 0; i < size; i++)
939 {
940 Uint64 x;
941
942 if (_GetUint64(in, pos, x) != 0)
943 RETURN_FAILURE;
944
945 a.append(x);
946 mike 1.1.2.1 }
947 value.set(a);
948 break;
949 }
950 case CIMTYPE_SINT64:
951 {
952 Array<Sint64> a;
953
954 for (Uint32 i = 0; i < size; i++)
955 {
956 Sint64 x;
957
958 if (_GetSint64(in, pos, x) != 0)
959 RETURN_FAILURE;
960
961 a.append(x);
962 }
963 value.set(a);
964 break;
965 }
966 case CIMTYPE_REAL32:
967 mike 1.1.2.1 {
968 Array<Real32> a;
969
970 for (Uint32 i = 0; i < size; i++)
971 {
972 Real32 x;
973
974 if (_GetReal32(in, pos, x) != 0)
975 RETURN_FAILURE;
976
977 a.append(x);
978 }
979 value.set(a);
980 break;
981 }
982 case CIMTYPE_REAL64:
983 {
984 Array<Real64> a;
985
986 for (Uint32 i = 0; i < size; i++)
987 {
988 mike 1.1.2.1 Real64 x;
989
990 if (_GetReal64(in, pos, x) != 0)
991 RETURN_FAILURE;
992
993 a.append(x);
994 }
995 value.set(a);
996 break;
997 }
998 case CIMTYPE_CHAR16:
999 {
1000 Array<Char16> a;
1001
1002 for (Uint32 i = 0; i < size; i++)
1003 {
1004 Char16 x;
1005
1006 if (_GetChar16(in, pos, x) != 0)
1007 RETURN_FAILURE;
1008
1009 mike 1.1.2.1 a.append(x);
1010 }
1011 value.set(a);
1012 break;
1013 }
1014 case CIMTYPE_STRING:
1015 {
1016 Array<String> a;
1017
1018 for (Uint32 i = 0; i < size; i++)
1019 {
1020 String x;
1021
1022 if (_GetString(in, pos, x) != 0)
1023 RETURN_FAILURE;
1024
1025 a.append(x);
1026 }
1027 value.set(a);
1028 break;
1029 }
1030 mike 1.1.2.1 case CIMTYPE_DATETIME:
1031 {
1032 Array<CIMDateTime> a;
1033
1034 for (Uint32 i = 0; i < size; i++)
1035 {
1036 CIMDateTime x;
1037
1038 if (_GetDateTime(in, pos, x) != 0)
1039 RETURN_FAILURE;
1040
1041 a.append(x);
1042 }
1043 value.set(a);
1044 break;
1045 }
1046 case CIMTYPE_REFERENCE:
1047 {
1048 Array<CIMObjectPath> a;
1049
1050 for (Uint32 i = 0; i < size; i++)
1051 mike 1.1.2.1 {
1052 CIMObjectPath x;
1053
1054 if (_GetObjectPath(in, pos, x) != 0)
1055 RETURN_FAILURE;
1056
1057 a.append(x);
1058 }
1059 value.set(a);
1060 break;
1061 }
1062 case CIMTYPE_OBJECT:
1063 {
1064 Array<CIMObject> a;
1065
1066 for (Uint32 i = 0; i < size; i++)
1067 {
1068 CIMInstance x;
1069
1070 if (DeserializeInstance(in, pos, x) != 0)
1071 RETURN_FAILURE;
1072 mike 1.1.2.1
1073 a.append(CIMObject(x));
1074 }
1075 value.set(a);
1076 break;
1077 }
1078 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
1079 # ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
1080 case CIMTYPE_INSTANCE:
1081 {
1082 Array<CIMInstance> a;
1083
1084 for (Uint32 i = 0; i < size; i++)
1085 {
1086 CIMInstance x;
1087
1088 if (DeserializeInstance(in, pos, x) != 0)
1089 RETURN_FAILURE;
1090
1091 a.append(x);
1092 }
1093 mike 1.1.2.1 value.set(a);
1094 break;
1095 }
1096 # endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
1097 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
1098 default:
1099 RETURN_FAILURE;
1100 }
1101 }
1102 else
1103 {
1104 switch (type)
1105 {
1106 case CIMTYPE_BOOLEAN:
1107 {
1108 Boolean x;
1109
1110 if (_GetBoolean(in, pos, x) != 0)
1111 RETURN_FAILURE;
1112
1113 value.set(x);
1114 mike 1.1.2.1 break;
1115 }
1116 case CIMTYPE_UINT8:
1117 {
1118 Uint8 x;
1119
1120 if (_GetUint8(in, pos, x) != 0)
1121 RETURN_FAILURE;
1122
1123 value.set(x);
1124 break;
1125 }
1126 case CIMTYPE_SINT8:
1127 {
1128 Sint8 x;
1129
1130 if (_GetSint8(in, pos, x) != 0)
1131 RETURN_FAILURE;
1132
1133 value.set(x);
1134 break;
1135 mike 1.1.2.1 }
1136 case CIMTYPE_UINT16:
1137 {
1138 Uint16 x;
1139
1140 if (_GetUint16(in, pos, x) != 0)
1141 RETURN_FAILURE;
1142
1143 value.set(x);
1144 break;
1145 }
1146 case CIMTYPE_SINT16:
1147 {
1148 Sint16 x;
1149
1150 if (_GetSint16(in, pos, x) != 0)
1151 RETURN_FAILURE;
1152
1153 value.set(x);
1154 break;
1155 }
1156 mike 1.1.2.1 case CIMTYPE_UINT32:
1157 {
1158 Uint32 x;
1159
1160 if (_GetUint32(in, pos, x) != 0)
1161 RETURN_FAILURE;
1162
1163 value.set(x);
1164 break;
1165 }
1166 case CIMTYPE_SINT32:
1167 {
1168 Sint32 x;
1169
1170 if (_GetSint32(in, pos, x) != 0)
1171 RETURN_FAILURE;
1172
1173 value.set(x);
1174 break;
1175 }
1176 case CIMTYPE_UINT64:
1177 mike 1.1.2.1 {
1178 Uint64 x;
1179
1180 if (_GetUint64(in, pos, x) != 0)
1181 RETURN_FAILURE;
1182
1183 value.set(x);
1184 break;
1185 }
1186 case CIMTYPE_SINT64:
1187 {
1188 Sint64 x;
1189
1190 if (_GetSint64(in, pos, x) != 0)
1191 RETURN_FAILURE;
1192
1193 value.set(x);
1194 break;
1195 }
1196 case CIMTYPE_REAL32:
1197 {
1198 mike 1.1.2.1 Real32 x;
1199
1200 if (_GetReal32(in, pos, x) != 0)
1201 RETURN_FAILURE;
1202
1203 value.set(x);
1204 break;
1205 }
1206 case CIMTYPE_REAL64:
1207 {
1208 Real64 x;
1209
1210 if (_GetReal64(in, pos, x) != 0)
1211 RETURN_FAILURE;
1212
1213 value.set(x);
1214 break;
1215 }
1216 case CIMTYPE_CHAR16:
1217 {
1218 Char16 x;
1219 mike 1.1.2.1
1220 if (_GetChar16(in, pos, x) != 0)
1221 RETURN_FAILURE;
1222
1223 value.set(x);
1224 break;
1225 }
1226 case CIMTYPE_STRING:
1227 {
1228 String x;
1229
1230 if (_GetString(in, pos, x) != 0)
1231 RETURN_FAILURE;
1232
1233 value.set(x);
1234 break;
1235 }
1236 case CIMTYPE_DATETIME:
1237 {
1238 CIMDateTime x;
1239
1240 mike 1.1.2.1 if (_GetDateTime(in, pos, x) != 0)
1241 RETURN_FAILURE;
1242
1243 value.set(x);
1244 break;
1245 }
1246 case CIMTYPE_REFERENCE:
1247 {
1248 CIMObjectPath x;
1249
1250 if (_GetObjectPath(in, pos, x) != 0)
1251 RETURN_FAILURE;
1252
1253 value.set(x);
1254 break;
1255 }
1256 case CIMTYPE_OBJECT:
1257 {
1258 CIMInstance x;
1259
1260 if (DeserializeInstance(in, pos, x) != 0)
1261 mike 1.1.2.1 RETURN_FAILURE;
1262
1263 value.set(CIMObject(x));
1264 break;
1265 }
1266 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
1267 # ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
1268 case CIMTYPE_INSTANCE:
1269 {
1270 CIMInstance x;
1271
1272 if (DeserializeInstance(in, pos, x) != 0)
1273 RETURN_FAILURE;
1274
1275 value.set(x);
1276 break;
1277 }
1278 # endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
1279 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
1280 default:
1281 RETURN_FAILURE;
1282 mike 1.1.2.1 }
1283 }
1284
1285 return 0;
1286 }
1287
1288 void SerializeInstance(Buffer& out, const CIMInstance& ci)
1289 {
1290 // Serialize magic number:
1291
1292 _PutUint32(out, _INSTANCE_MAGIC);
1293
1294 // Serialize object path:
1295
1296 _PutObjectPath(out, ci.getPath());
1297
1298 // Serialize properties:
1299
1300 _PutUint32(out, ci.getPropertyCount());
1301
1302 for (Uint32 i = 0, n = ci.getPropertyCount(); i < n; i++)
1303 mike 1.1.2.1 {
1304 const CIMConstProperty cp = ci.getProperty(i);
1305
1306 // Serialize property name:
1307
1308 _PutString(out, cp.getName().getString());
1309
1310 // Serialize the value:
1311
1312 _PutValue(out, cp.getValue());
1313 }
1314 }
1315
1316 int DeserializeInstance(
1317 const Buffer& in,
1318 size_t& pos,
1319 CIMInstance& ci)
1320 {
1321 // Deserialize magic number:
1322
1323 Uint32 magic;
1324 mike 1.1.2.1
1325 if (_GetUint32(in, pos, magic) != 0 || magic != _INSTANCE_MAGIC)
1326 RETURN_FAILURE;
1327
1328 // Deserialize object path:
1329
1330 CIMObjectPath cop;
1331
1332 if (_GetObjectPath(in, pos, cop) != 0)
1333 RETURN_FAILURE;
1334
1335 // Create the instance:
1336
1337 try
1338 {
1339 ci = CIMInstance(cop.getClassName());
1340 ci.setPath(cop);
1341 }
1342 catch (...)
1343 {
1344 RETURN_FAILURE;
1345 mike 1.1.2.1 }
1346
1347 // Get property count:
1348
1349 Uint32 propertyCount = 0;
1350
1351 if (_GetUint32(in, pos, propertyCount) != 0)
1352 RETURN_FAILURE;
1353
1354 // Deserialize properties:
1355
1356 for (Uint32 i = 0; i < propertyCount; i++)
1357 {
1358 // Deserialize property name:
1359
1360 String name;
1361
1362 if (_GetString(in, pos, name) != 0)
1363 RETURN_FAILURE;
1364
1365 // Deserialize property value:
1366 mike 1.1.2.1
1367 CIMValue value;
1368
1369 if (_GetValue(in, pos, value) != 0)
1370 RETURN_FAILURE;
1371
1372 // Add property to instance.
1373
1374 try
1375 {
1376 ci.addProperty(CIMProperty(name, value));
1377 }
1378 catch (Exception& e)
1379 {
1380 RETURN_FAILURE;
1381 }
1382 }
1383
1384 return 0;
1385 }
1386
1387 mike 1.1.2.1 void SerializeNameSpace(
1388 Buffer& out,
1389 const CIMNamespaceName& nameSpace)
1390 {
1391 _PutString(out, nameSpace.getString());
1392 }
1393
1394 int DeserializeNameSpace(
1395 const Buffer& in,
1396 size_t& pos,
1397 CIMNamespaceName& nameSpace)
1398 {
1399 String tmp;
1400
1401 if (_GetString(in, pos, tmp) != 0)
1402 RETURN_FAILURE;
1403
1404 nameSpace = tmp;
1405 return 0;
1406 }
1407
1408 mike 1.1.2.1 PEGASUS_NAMESPACE_END
|