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