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