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