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