29 mike 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "MRRTypes.h"
33 #include <Pegasus/Common/System.h>
34 #include <Pegasus/Common/CIMClass.h>
35 #include <Pegasus/Common/CIMQualifierDecl.h>
36 #include <Pegasus/Common/System.h>
37
38 PEGASUS_NAMESPACE_BEGIN
39
40 static const size_t _MAX_QUALIFIERS = 32;
41
42 static bool _eqi(const char* s1, const char* s2)
43 {
44 return System::strcasecmp(s1, s2) == 0;
45 }
46
47 class Str
48 {
49 public:
50 mike 1.1 Str(const String& s) : _cstr(s.getCString()) { }
51 Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
52 Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
53 Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
54 Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
55 Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
56 const char* operator*() const { return (const char*)_cstr; }
57 operator const char*() const { return (const char*)_cstr; }
58 private:
59 CString _cstr;
60 };
61
62 static inline void _readBoolean(const char*& value, Boolean& x)
63 {
64 unsigned const char* p = (unsigned const char*)value;
65 x = Boolean(p[0]);
66 value++;
67 }
68
69 static inline void _readUint8(const char*& value, Uint8& x)
70 {
71 mike 1.1 unsigned const char* p = (unsigned const char*)value;
72 x = Uint8(p[0]);
73 value += sizeof(x);
74 }
75
76 static inline void _readSint8(const char*& value, Sint8& x)
77 {
78 _readUint8(value, *((Uint8*)&x));
79 }
80
81 static inline void _readUint16(const char*& value, Uint16& x)
82 {
83 unsigned const char* p = (unsigned const char*)value;
84 Uint16 x0 = Uint16(p[0]) << 8;
85 Uint16 x1 = Uint16(p[1]) << 0;
86 x = Uint16(x0 | x1);
87 value += sizeof(x);
88 }
89
90 static inline void _readSint16(const char*& value, Sint16& x)
91 {
92 mike 1.1 _readUint16(value, *((Uint16*)&x));
93 value += sizeof(x);
94 }
95
96 static inline void _readUint32(const char*& value, Uint32& x)
97 {
98 unsigned const char* p = (unsigned const char*)value;
99 Uint32 x0 = Uint32(p[0]) << 24;
100 Uint32 x1 = Uint32(p[1]) << 16;
101 Uint32 x2 = Uint32(p[0]) << 8;
102 Uint32 x3 = Uint32(p[1]) << 0;
103 x = Uint32(x0 | x1 | x2 | x3);
104 value += sizeof(x);
105 }
106
107 static inline void _readSint32(const char*& value, Sint32& x)
108 {
109 _readUint32(value, *((Uint32*)&x));
110 value += sizeof(x);
111 }
112
113 mike 1.1 static inline void _readUint64(const char*& value, Uint64& x)
114 {
115 unsigned const char* p = (unsigned const char*)value;
116 Uint64 x0 = Uint64(p[0]) << 56;
117 Uint64 x1 = Uint64(p[1]) << 48;
118 Uint64 x2 = Uint64(p[2]) << 40;
119 Uint64 x3 = Uint64(p[3]) << 32;
120 Uint64 x4 = Uint64(p[4]) << 24;
121 Uint64 x5 = Uint64(p[5]) << 16;
122 Uint64 x6 = Uint64(p[6]) << 8;
123 Uint64 x7 = Uint64(p[7]) << 0;
124 x = Uint64(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7);
125 value += sizeof(x);
126 }
127
128 static inline void _readSint64(const char*& value, Sint64& x)
129 {
130 _readUint64(value, *((Uint64*)&x));
131 value += sizeof(x);
132 }
133
134 mike 1.1 static inline void _readReal32(const char*& value, Real32& x)
135 {
136 _readUint32(value, *((Uint32*)&x));
137 value += sizeof(x);
138 }
139
140 static inline void _readReal64(const char*& value, Real64& x)
141 {
142 _readUint64(value, *((Uint64*)&x));
143 value += sizeof(x);
144 }
145
146 static inline void _readChar16(const char*& value, Char16& x)
147 {
148 _readUint16(value, *((Uint16*)&x));
149 value += sizeof(x);
150 }
151
152 static inline void _readString(const char*& value, String& x)
153 {
154 size_t n = strlen(value);
155 mike 1.1 x.assign(value, n);
156 value += n + 1;
157 }
158
159 static inline void _readDateTime(const char*& value, CIMDateTime& x)
160 {
161 size_t n = strlen(value);
162 x.set(value);
163 value += n + 1;
164 }
165
166 static int _makeValue(
167 CIMValue& cv,
168 Uint16 type,
169 Sint16 subscript,
170 const char* value)
171 {
172 // If null value:
173
174 if (value == 0)
175 {
176 mike 1.1 if (subscript == -1)
177 cv.setNullValue(CIMType(type), false);
178 else
179 cv.setNullValue(CIMType(type), true, subscript);
180
181 return 0;
182 }
183
184 // If scalar, else array:
185
186 if (subscript == -1)
187 {
188 switch (CIMType(type))
189 {
190 case CIMTYPE_BOOLEAN:
191 {
192 Boolean x;
193 _readBoolean(value, x);
194 cv.set(x);
195 return 0;
196 }
197 mike 1.1 case CIMTYPE_UINT8:
198 {
199 Uint8 x;
200 _readUint8(value, x);
201 cv.set(x);
202 return 0;
203 }
204 case CIMTYPE_SINT8:
205 {
206 Sint8 x;
207 _readSint8(value, x);
208 cv.set(x);
209 return 0;
210 }
211 case CIMTYPE_UINT16:
212 {
213 Uint16 x;
214 _readUint16(value, x);
215 cv.set(x);
216 return 0;
217 }
218 mike 1.1 case CIMTYPE_SINT16:
219 {
220 Sint16 x;
221 _readSint16(value, x);
222 cv.set(x);
223 return 0;
224 }
225 case CIMTYPE_UINT32:
226 {
227 Uint32 x;
228 _readUint32(value, x);
229 cv.set(x);
230 return 0;
231 }
232 case CIMTYPE_SINT32:
233 {
234 Sint32 x;
235 _readSint32(value, x);
236 cv.set(x);
237 return 0;
238 }
239 mike 1.1 case CIMTYPE_UINT64:
240 {
241 Uint64 x;
242 _readUint64(value, x);
243 cv.set(x);
244 return 0;
245 }
246 case CIMTYPE_SINT64:
247 {
248 Sint64 x;
249 _readSint64(value, x);
250 cv.set(x);
251 return 0;
252 }
253 case CIMTYPE_REAL32:
254 {
255 Real32 x;
256 _readReal32(value, x);
257 cv.set(x);
258 return 0;
259 }
260 mike 1.1 case CIMTYPE_REAL64:
261 {
262 Real64 x;
263 _readReal64(value, x);
264 cv.set(x);
265 return 0;
266 }
267 case CIMTYPE_CHAR16:
268 {
269 Char16 x;
270 _readChar16(value, x);
271 cv.set(x);
272 return 0;
273 }
274 case CIMTYPE_STRING:
275 {
276 String x;
277 _readString(value, x);
278 cv.set(x);
279 return 0;
280 }
281 mike 1.1 case CIMTYPE_DATETIME:
282 {
283 CIMDateTime x;
284 _readDateTime(value, x);
285 cv.set(x);
286 return 0;
287 }
288
289 default:
290 return -1;
291 }
292 }
293 else
294 {
295 // Read array size:
296
297 Uint16 size;
298 _readUint16(value, size);
299
300 // Read array elements:
301
302 mike 1.1 switch (CIMType(type))
303 {
304 case CIMTYPE_BOOLEAN:
305 {
306 Array<Boolean> a;
307
308 for (Uint16 i = 0; i < size; i++)
309 {
310 Boolean x;
311 _readBoolean(value, x);
312 a.append(x);
313 }
314
315 cv.set(a);
316 return 0;
317 }
318 case CIMTYPE_UINT8:
319 {
320 Array<Uint8> a;
321
322 for (Uint16 i = 0; i < size; i++)
323 mike 1.1 {
324 Uint8 x;
325 _readUint8(value, x);
326 a.append(x);
327 }
328
329 cv.set(a);
330 return 0;
331 }
332 case CIMTYPE_SINT8:
333 {
334 Array<Sint8> a;
335
336 for (Uint16 i = 0; i < size; i++)
337 {
338 Sint8 x;
339 _readSint8(value, x);
340 a.append(x);
341 }
342
343 cv.set(a);
344 mike 1.1 return 0;
345 }
346 case CIMTYPE_UINT16:
347 {
348 Array<Uint16> a;
349
350 for (Uint16 i = 0; i < size; i++)
351 {
352 Uint16 x;
353 _readUint16(value, x);
354 a.append(x);
355 }
356
357 cv.set(a);
358 return 0;
359 }
360 case CIMTYPE_SINT16:
361 {
362 Array<Sint16> a;
363
364 for (Uint16 i = 0; i < size; i++)
365 mike 1.1 {
366 Sint16 x;
367 _readSint16(value, x);
368 a.append(x);
369 }
370
371 cv.set(a);
372 return 0;
373 }
374 case CIMTYPE_UINT32:
375 {
376 Array<Uint32> a;
377
378 for (Uint16 i = 0; i < size; i++)
379 {
380 Uint32 x;
381 _readUint32(value, x);
382 a.append(x);
383 }
384
385 cv.set(a);
386 mike 1.1 return 0;
387 }
388 case CIMTYPE_SINT32:
389 {
390 Array<Sint32> a;
391
392 for (Uint16 i = 0; i < size; i++)
393 {
394 Sint32 x;
395 _readSint32(value, x);
396 a.append(x);
397 }
398
399 cv.set(a);
400 return 0;
401 }
402 case CIMTYPE_UINT64:
403 {
404 Array<Uint64> a;
405
406 for (Uint16 i = 0; i < size; i++)
407 mike 1.1 {
408 Uint64 x;
409 _readUint64(value, x);
410 a.append(x);
411 }
412
413 cv.set(a);
414 return 0;
415 }
416 case CIMTYPE_SINT64:
417 {
418 Array<Sint64> a;
419
420 for (Uint16 i = 0; i < size; i++)
421 {
422 Sint64 x;
423 _readSint64(value, x);
424 a.append(x);
425 }
426
427 cv.set(a);
428 mike 1.1 return 0;
429 }
430 case CIMTYPE_REAL32:
431 {
432 Array<Real32> a;
433
434 for (Uint16 i = 0; i < size; i++)
435 {
436 Real32 x;
437 _readReal32(value, x);
438 a.append(x);
439 }
440
441 cv.set(a);
442 return 0;
443 }
444 case CIMTYPE_REAL64:
445 {
446 Array<Real64> a;
447
448 for (Uint16 i = 0; i < size; i++)
449 mike 1.1 {
450 Real64 x;
451 _readReal64(value, x);
452 a.append(x);
453 }
454
455 cv.set(a);
456 return 0;
457 }
458 case CIMTYPE_CHAR16:
459 {
460 Array<Char16> a;
461
462 for (Uint16 i = 0; i < size; i++)
463 {
464 Char16 x;
465 _readChar16(value, x);
466 a.append(x);
467 }
468
469 cv.set(a);
470 mike 1.1 return 0;
471 }
472 case CIMTYPE_STRING:
473 {
474 Array<String> a;
475
476 for (Uint16 i = 0; i < size; i++)
477 {
478 String x;
479 _readString(value, x);
480 a.append(x);
481 }
482
483 cv.set(a);
484 return 0;
485 }
486 case CIMTYPE_DATETIME:
487 {
488 Array<CIMDateTime> a;
489
490 for (Uint16 i = 0; i < size; i++)
491 mike 1.1 {
492 CIMDateTime x;
493 _readDateTime(value, x);
494 a.append(x);
495 }
496
497 cv.set(a);
498 return 0;
499 }
500
501 default:
502 return -1;
503 }
504 }
505
506 // Unreachable!
507 return -1;
508 }
509
510 int MergeFeatures(
511 const MRRClass* sc,
512 mike 1.1 bool localOnly,
513 Uint32 flags,
514 MRRFeatureInfo features[MRR_MAX_FEATURES],
515 size_t& numFeatures)
516 {
517 if (!localOnly && sc->super)
518 {
519 if (MergeFeatures(
520 sc->super, localOnly, 0xFFFFFFFF, features, numFeatures) != 0)
521 {
522 return -1;
523 }
524 }
525
526 // Process all features of this class:
527
528 for (size_t i = 0; sc->features[i]; i++)
529 {
530 const MRRFeature* sf = sc->features[i];
531
532 if (!(sf->flags & flags))
533 mike 1.1 continue;
534
535 // Override feature if defined by ancestor class:
536
537 bool found = false;
538
539 for (size_t j = 0; j < numFeatures; j++)
540 {
541 const MRRFeature* tmp = features[j].sf;
542
543 if (_eqi(sf->name, tmp->name))
544 {
545 features[j].sf = sf;
546 features[j].sc = sc;
547 found = true;
548 break;
549 }
550 }
551
552 // Add new feature if not not defined by ancestor class:
553
554 mike 1.1 if (!found)
555 {
556 if (numFeatures == MRR_MAX_FEATURES)
557 {
558 return -1;
559 }
560
561 features[numFeatures].sf = sf;
562 features[numFeatures].sc = sc;
563 numFeatures++;
564 }
565 }
566
567 return 0;
568 }
569
570 struct QualifierInfo
571 {
572 const char* qualifier;
573 const MRRClass* sc;
574 };
575 mike 1.1
576 static const MRRFeature* _findFeature(
577 const MRRClass* sc,
578 const char* name)
579 {
580 for (size_t i = 0; sc->features[i]; i++)
581 {
582 const MRRFeature* sf = sc->features[i];
583
584 if (_eqi(sf->name, name))
585 return sf;
586 }
587
588 // Not found!
589 return 0;
590 }
591
592 static const MRRFeature* _findParameter(
593 const MRRMethod* sm,
594 const char* name)
595 {
596 mike 1.1 for (size_t i = 0; sm->parameters[i]; i++)
597 {
598 const MRRFeature* sf = sm->parameters[i];
599
600 if (_eqi(sm->name, name))
601 return sf;
602 }
603
604 // Not found!
605 return 0;
606 }
607
608 static int _mergeQualifiers(
609 const MRRNameSpace* ns,
610 const MRRClass* sc,
611 const char* featureName,
612 const char* parameterName,
613 bool depth,
614 QualifierInfo qualifiers[_MAX_QUALIFIERS],
615 size_t& numQualifiers)
616 {
617 mike 1.1 // Merge super-class qualifiers:
618
619 if (sc->super)
620 {
621 _mergeQualifiers(ns, sc->super, featureName, parameterName, depth + 1,
622 qualifiers, numQualifiers);
623 }
624
625 const char** quals = 0;
626
627 // Find qualifiers of the given object:
628
629 if (!featureName && !parameterName)
630 {
631 // Case 1: get class qualifiers:
632 quals = sc->qualifiers;
633 }
634 else if (featureName && !parameterName)
635 {
636 // Case 2: get feature qualifiers:
637
638 mike 1.1 const MRRFeature* sf = _findFeature(sc, featureName);
639
640 if (sf)
641 quals = sf->qualifiers;
642 }
643 else if (featureName && parameterName)
644 {
645 // Case 3: get parameter qualifiers:
646
647 const MRRFeature* sf = _findFeature(sc, featureName);
648
649 if (sf && (sf->flags & MRR_FLAG_METHOD))
650 {
651 const MRRMethod* sm = (const MRRMethod*)sf;
652 const MRRFeature* p = _findParameter(sm, parameterName);
653
654 if (p)
655 quals = p->qualifiers;
656 }
657 }
658
659 mike 1.1 // Merge quals into the qualifiers array:
660
661 if (!quals)
662 return 0;
663
664 for (size_t i = 0; quals[i]; i++)
665 {
666 const char* qi = quals[i];
667
668 // Override existing qualifier if any:
669
670 bool found = false;
671
672 for (size_t j = 0; j < numQualifiers; j++)
673 {
674 const char* qj = qualifiers[j].qualifier;
675
676 if (qi[0] == qj[0])
677 {
678 qualifiers[j].qualifier = qi;
679 qualifiers[j].sc = sc;
680 mike 1.1 found = true;
681 break;
682 }
683 }
684
685 // Inject this qualifier not found:
686
687 if (!found)
688 {
689 MRRQualifierDecl* qd = ns->qualifiers[qi[0]];
690
691 if (depth == 0 || !(qd->flavor & MRR_FLAVOR_RESTRICTED))
692 {
693 if (numQualifiers == _MAX_QUALIFIERS)
694 {
695 return -1;
696 }
697
698 qualifiers[numQualifiers].qualifier = qi;
699 qualifiers[numQualifiers].sc = sc;
700 numQualifiers++;
701 mike 1.1 }
702 }
703 }
704
705 return 0;
706 }
707
708 template<class C>
709 static int _addQualifiers(
710 const MRRNameSpace* ns,
711 const MRRClass* sc,
712 const char* featureName,
713 const char* parameterName,
714 C& c)
715 {
716 QualifierInfo qualifiers[_MAX_QUALIFIERS];
717 size_t numQualifiers = 0;
718
719 if (_mergeQualifiers(
720 ns, sc, featureName, parameterName, 0, qualifiers, numQualifiers) != 0)
721 {
722 mike 1.1 return -1;
723 }
724
725 // Add qualifiers to container:
726
727 for (size_t i = 0; i < numQualifiers; i++)
728 {
729 const char* q = qualifiers[i].qualifier;
730
731 // Get qualifier id:
732
733 Uint8 qid = Uint8(q[0]);
734
735 // Get qualifier declaration:
736
737 MRRQualifierDecl* qd = ns->qualifiers[qid];
738
739 // Make CIMValue:
740
741 CIMValue cv;
742
743 mike 1.1 if (_makeValue(cv, qd->type, qd->subscript, q + 1) != 0)
744 {
745 return -1;
746 }
747
748 // Add qualifier:
749
750 c.addQualifier(CIMQualifier(qd->name, cv));
751 }
752
753 return 0;
754 }
755
756 static int _addProperty(
757 const MRRNameSpace* ns,
758 const MRRClass* sc,
759 const MRRProperty* sp,
760 const char* classOrigin,
761 bool propagated,
762 bool includeQualifiers,
763 bool includeClassOrigin,
764 mike 1.1 CIMClass& cc)
765 {
766 // Make CIMvalue:
767
768 CIMValue cv;
769
770 if (_makeValue(cv, sp->type, sp->subscript, sp->value) != 0)
771 {
772 return -1;
773 }
774
775 // Create property:
776
777 CIMProperty cp(sp->name, cv);
778
779 if (includeClassOrigin)
780 cp.setClassOrigin(classOrigin);
781
782 cp.setPropagated(propagated);
783
784 // Add qualifiers:
785 mike 1.1
786 if (includeQualifiers)
787 {
788 if (_addQualifiers(ns, sc, sp->name, 0, cp) != 0)
789 {
790 return -1;
791 }
792 }
793
794 // Add to class:
795
796 cc.addProperty(cp);
797 return 0;
798 }
799
800 static int _addReference(
801 const MRRNameSpace* ns,
802 const MRRClass* sc,
803 const MRRReference* sr,
804 const char* classOrigin,
805 bool propagated,
806 mike 1.1 bool includeQualifiers,
807 bool includeClassOrigin,
808 CIMClass& cc)
809 {
810 // Set isArray and arraySize:
811
812 Boolean isArray;
813 Uint32 arraySize;
814
815 if (sr->subscript == -1)
816 {
817 isArray = false;
818 arraySize = 0;
819 }
820 else
821 {
822 isArray = true;
823 arraySize = sr->subscript;
824 }
825
826 // Set referenceClassName:
827 mike 1.1
828 CIMName rcn = sr->ref->name;
829
830 // Create value:
831
832 CIMValue cv(CIMTYPE_REFERENCE, isArray, arraySize);
833
834 // Create property:
835
836 CIMProperty cp(sr->name, cv, arraySize, rcn);
837
838 if (includeClassOrigin)
839 cp.setClassOrigin(classOrigin);
840
841 cp.setPropagated(propagated);
842
843 // Add qualifiers:
844
845 if (includeQualifiers)
846 {
847 if (_addQualifiers(ns, sc, sr->name, 0, cp) != 0)
848 mike 1.1 {
849 return -1;
850 }
851 }
852
853 // Add to class:
854
855 cc.addProperty(cp);
856 return 0;
857 }
858
859 static int _addPropertyParameter(
860 const MRRNameSpace* ns,
861 const MRRClass* sc,
862 const MRRMethod* sm,
863 const MRRProperty* sp,
864 bool includeQualifiers,
865 CIMMethod& cm)
866 {
867 // Create property:
868
869 mike 1.1 bool isArray;
870 Uint32 arraySize;
871
872 if (sp->subscript == -1)
873 {
874 isArray = false;
875 arraySize = 0;
876 }
877 else
878 {
879 isArray = true;
880 arraySize = Uint32(sp->subscript);
881 }
882
883 CIMParameter cp(sp->name, CIMType(sp->type), isArray, arraySize);
884
885 // Add qualifiers:
886
887 if (includeQualifiers)
888 {
889 if (_addQualifiers(ns, sc, sm->name, sp->name, cm) != 0)
890 mike 1.1 {
891 return -1;
892 }
893 }
894
895 // Add to method:
896
897 cm.addParameter(cp);
898 return 0;
899 }
900
901 static int _addReferenceParameter(
902 const MRRNameSpace* ns,
903 const MRRClass* sc,
904 const MRRMethod* sm,
905 const MRRReference* sr,
906 bool includeQualifiers,
907 CIMMethod& cm)
908 {
909 // Create property:
910
911 mike 1.1 bool isArray;
912 Uint32 arraySize;
913
914 if (sr->subscript == -1)
915 {
916 isArray = false;
917 arraySize = 0;
918 }
919 else
920 {
921 isArray = true;
922 arraySize = Uint32(sr->subscript);
923 }
924
925 CIMName rcn = sr->ref->name;
926 CIMParameter cp(sr->name, CIMTYPE_REFERENCE, isArray, arraySize, rcn);
927
928 // Add qualifiers:
929
930 if (includeQualifiers)
931 {
932 mike 1.1 if (_addQualifiers(ns, sc, sm->name, sr->name, cm) != 0)
933 {
934 return -1;
935 }
936 }
937
938 // Add to method:
939
940 cm.addParameter(cp);
941 return 0;
942 }
943
944 static int _addMethod(
945 const MRRNameSpace* ns,
946 const MRRClass* sc,
947 const MRRMethod* sm,
948 const char* classOrigin,
949 bool propagated,
950 bool includeQualifiers,
951 bool includeClassOrigin,
952 CIMClass& cc)
953 mike 1.1 {
954 // Create method:
955
956 CIMMethod cm(sm->name, CIMType(sm->type));
957
958 if (includeClassOrigin)
959 cm.setClassOrigin(classOrigin);
960
961 cm.setPropagated(propagated);
962
963 // Add parameters:
964
965 for (size_t i = 0; sm->parameters[i]; i++)
966 {
967 MRRFeature* sf = sm->parameters[i];
968
969 if (sf->flags & MRR_FLAG_PROPERTY)
970 {
971 MRRProperty* sp = (MRRProperty*)sf;
972 _addPropertyParameter(ns, sc, sm, sp, includeQualifiers, cm);
973 }
974 mike 1.1 else if (sf->flags & MRR_FLAG_REFERENCE)
975 {
976 MRRReference* sr = (MRRReference*)sf;
977 _addReferenceParameter(ns, sc, sm, sr, includeQualifiers, cm);
978 }
979 }
980
981 // Add qualifiers:
982
983 if (includeQualifiers)
984 {
985 if (_addQualifiers(ns, sc, sm->name, 0, cm) != 0)
986 {
987 return -1;
988 }
989 }
990
991 // Add to class:
992
993 cc.addMethod(cm);
994 return 0;
995 mike 1.1 }
996
997 static bool _hasProperty(const char* const* propertyList, const char* name)
998 {
999 for (size_t i = 0; propertyList[i]; i++)
1000 {
1001 if (_eqi(propertyList[i], name))
1002 return true;
1003 }
1004
1005 return false;
1006 }
1007
1008 static int _addFeatures(
1009 const MRRNameSpace* ns,
1010 const MRRClass* sc,
1011 bool localOnly,
1012 bool includeQualifiers,
1013 bool includeClassOrigin,
1014 const char* const* propertyList,
1015 CIMClass& cc)
1016 mike 1.1 {
1017 // Merge features from all inheritance levels into a single array:
1018
1019 MRRFeatureInfo features[MRR_MAX_FEATURES];
1020 size_t numFeatures = 0;
1021
1022 if (MergeFeatures(sc, localOnly, 0xFFFFFFFF, features, numFeatures) != 0)
1023 {
1024 return -1;
1025 }
1026
1027 // For each feature:
1028
1029 for (size_t i = 0; i < numFeatures; i++)
1030 {
1031 const MRRFeatureInfo& fi = features[i];
1032
1033 // Set propagated flag:
1034
1035 bool propagated = fi.sc != sc;
1036
1037 mike 1.1 // Set classOrigin:
1038
1039 const char* classOrigin = fi.sc->name;
1040
1041 // Skip feature not in property list:
1042
1043 const MRRFeature* sf = fi.sf;
1044
1045 if (propertyList && !_hasProperty(propertyList, sf->name))
1046 continue;
1047
1048 // Add the feature:
1049
1050 if (sf->flags & MRR_FLAG_PROPERTY)
1051 {
1052 MRRProperty* sp = (MRRProperty*)sf;
1053
1054 if (_addProperty(ns, sc, sp, classOrigin, propagated,
1055 includeQualifiers, includeClassOrigin, cc) != 0)
1056 {
1057 return -1;
1058 mike 1.1 }
1059 }
1060 else if (sf->flags & MRR_FLAG_REFERENCE)
1061 {
1062 MRRReference* sr = (MRRReference*)sf;
1063
1064 if (_addReference(ns, sc, sr, classOrigin, propagated,
1065 includeQualifiers, includeClassOrigin, cc) != 0)
1066 {
1067 return -1;
1068 }
1069 }
1070 else if (sf->flags & MRR_FLAG_METHOD)
1071 {
1072 MRRMethod* sm = (MRRMethod*)sf;
1073
1074 if (_addMethod(ns, sc, sm, classOrigin, propagated,
1075 includeQualifiers, includeClassOrigin, cc) != 0)
1076 {
1077 return -1;
1078 }
1079 mike 1.1 }
1080 }
1081
1082 return 0;
1083 }
1084
1085 int MakeClass(
1086 const char* hostName,
1087 const MRRNameSpace* ns,
1088 const MRRClass* sc,
1089 Boolean localOnly,
1090 Boolean includeQualifiers,
1091 Boolean includeClassOrigin,
1092 const char* const* propertyList,
1093 CIMClass& cc)
1094 {
1095 try
1096 {
1097 // Create class:
1098 {
1099 CIMName scn;
1100 mike 1.1
1101 if (sc->super)
1102 scn = sc->super->name;
1103
1104 cc = CIMClass(sc->name, scn);
1105 }
1106
1107 // Add qualifiers:
1108
1109 if (includeQualifiers)
1110 {
1111 if (_addQualifiers(ns, sc, 0, 0, cc) != 0)
1112 {
1113 return -1;
1114 }
1115 }
1116
1117 // Features:
1118
1119 if (_addFeatures(ns, sc, localOnly, includeQualifiers,
1120 includeClassOrigin, propertyList, cc) != 0)
1121 mike 1.1 {
1122 return -1;
1123 }
1124
1125 // Object path:
1126
1127 cc.setPath(CIMObjectPath(hostName, ns->name, sc->name));
1128 }
1129 catch (Exception& e)
1130 {
1131 printf("EXCEPTION[%s]\n", *Str(e));
1132 return -1;
1133 }
1134 catch (...)
1135 {
1136 return -1;
1137 }
1138
1139 return 0;
1140 }
1141
1142 mike 1.1 int MakeQualifierDecl(
1143 const MRRNameSpace* ns,
1144 const MRRQualifierDecl* mqd,
1145 class CIMQualifierDecl& cqd)
1146 {
1147 // Value:
1148
1149 CIMValue cv;
1150
1151 if (_makeValue(cv, mqd->type, mqd->subscript, mqd->value) != 0)
1152 {
1153 return -1;
1154 }
1155
1156 // Scope:
1157
1158 CIMScope scope;
1159
1160 if (mqd->scope & MRR_SCOPE_CLASS)
1161 scope.addScope(CIMScope::CLASS);
1162 if (mqd->scope & MRR_SCOPE_ASSOCIATION)
1163 mike 1.1 scope.addScope(CIMScope::ASSOCIATION);
1164 if (mqd->scope & MRR_SCOPE_INDICATION)
1165 scope.addScope(CIMScope::INDICATION);
1166 if (mqd->scope & MRR_SCOPE_PROPERTY)
1167 scope.addScope(CIMScope::PROPERTY);
1168 if (mqd->scope & MRR_SCOPE_REFERENCE)
1169 scope.addScope(CIMScope::REFERENCE);
1170 if (mqd->scope & MRR_SCOPE_METHOD)
1171 scope.addScope(CIMScope::METHOD);
1172 if (mqd->scope & MRR_SCOPE_PARAMETER)
1173 scope.addScope(CIMScope::PARAMETER);
1174
1175 // Flavor:
1176
1177 CIMFlavor flavor;
1178
1179 if (mqd->flavor & MRR_FLAVOR_OVERRIDABLE)
1180 flavor.addFlavor(CIMFlavor::OVERRIDABLE);
1181 if (mqd->flavor & MRR_FLAVOR_TOSUBCLASS)
1182 flavor.addFlavor(CIMFlavor::TOSUBCLASS);
1183 if (mqd->flavor & MRR_FLAVOR_TOINSTANCE)
1184 mike 1.1 flavor.addFlavor(CIMFlavor::TOINSTANCE);
1185 if (mqd->flavor & MRR_FLAVOR_TRANSLATABLE)
1186 flavor.addFlavor(CIMFlavor::TRANSLATABLE);
1187 if (mqd->flavor & MRR_FLAVOR_DISABLEOVERRIDE)
1188 flavor.addFlavor(CIMFlavor::DISABLEOVERRIDE);
1189 if (mqd->flavor & MRR_FLAVOR_RESTRICTED)
1190 flavor.addFlavor(CIMFlavor::RESTRICTED);
1191
1192 // Array size:
1193
1194 Uint32 arraySize;
1195
1196 if (mqd->subscript == -1)
1197 arraySize = 0;
1198 else
1199 arraySize = mqd->subscript;
1200
1201 cqd = CIMQualifierDecl(mqd->name, cv, scope, flavor, arraySize);
1202
1203 return 0;
1204 }
1205 mike 1.1
1206 const MRRClass* FindClass(const MRRNameSpace* ns, const char* name)
1207 {
1208 for (size_t i = 0; ns->classes[i]; i++)
1209 {
1210 const MRRClass* sc = ns->classes[i];
1211
1212 if (_eqi(sc->name, name))
1213 return sc;
1214 }
1215
1216 // Not found!
1217 return 0;
1218 }
1219
1220 const MRRQualifierDecl* FindQualifierDecl(
1221 const MRRNameSpace* ns,
1222 const char* name)
1223 {
1224 for (size_t i = 0; ns->classes[i]; i++)
1225 {
1226 mike 1.1 const MRRQualifierDecl* mqd = ns->qualifiers[i];
1227
1228 if (_eqi(mqd->name, name))
1229 return mqd;
1230 }
1231
1232 // Not found!
1233 return 0;
1234 }
1235
1236 bool IsSubClass(const MRRClass* super, const MRRClass* sub)
1237 {
1238 if (!super)
1239 return true;
1240
1241 for (MRRClass* p = sub->super; p; p = p->super)
1242 {
1243 if (p == super)
1244 return true;
1245 }
1246
1247 mike 1.1 return false;
1248 }
1249
1250 const MRRFeature* FindFeature(
1251 const MRRClass* sc,
1252 const char* name,
1253 Uint32 flags)
1254 {
1255 for (size_t i = 0; sc->features[i]; i++)
1256 {
1257 const MRRFeature* sf = sc->features[i];
1258
1259 if (sf->flags & flags && _eqi(sf->name, name))
1260 return sf;
1261 }
1262
1263 // Not found!
1264 return 0;
1265 }
1266
1267 PEGASUS_NAMESPACE_END
|