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