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