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 "SchemaTypes.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.1 }
506 }
507
508 // Unreachable!
509 return -1;
510 }
511
512 int MergeFeatures(
|
513 mike 1.1.2.2 const SchemaClass* sc,
|
514 mike 1.1.2.1 bool localOnly,
515 Uint32 flags,
516 SchemaFeatureInfo features[SCHEMA_MAX_FEATURES],
517 size_t& numFeatures)
518 {
|
519 mike 1.1.2.2 if (!localOnly && sc->super)
|
520 mike 1.1.2.1 {
521 if (MergeFeatures(
|
522 mike 1.1.2.2 sc->super, localOnly, 0xFFFFFFFF, features, numFeatures) != 0)
|
523 mike 1.1.2.1 {
524 return -1;
525 }
526 }
527
528 // Process all features of this class:
529
|
530 mike 1.1.2.2 for (size_t i = 0; sc->features[i]; i++)
|
531 mike 1.1.2.1 {
|
532 mike 1.1.2.2 const SchemaFeature* sf = sc->features[i];
|
533 mike 1.1.2.1
|
534 mike 1.1.2.2 if (!(sf->flags & flags))
|
535 mike 1.1.2.1 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 mike 1.1.2.2 const SchemaFeature* tmp = features[j].sf;
|
544 mike 1.1.2.1
|
545 mike 1.1.2.2 if (_eqi(sf->name, tmp->name))
|
546 mike 1.1.2.1 {
|
547 mike 1.1.2.2 features[j].sf = sf;
548 features[j].sc = sc;
|
549 mike 1.1.2.1 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 == SCHEMA_MAX_FEATURES)
559 {
560 return -1;
561 }
562
|
563 mike 1.1.2.2 features[numFeatures].sf = sf;
564 features[numFeatures].sc = sc;
|
565 mike 1.1.2.1 numFeatures++;
566 }
567 }
568
569 return 0;
570 }
571
572 struct QualifierInfo
573 {
574 const char* qualifier;
|
575 mike 1.1.2.2 const SchemaClass* sc;
|
576 mike 1.1.2.1 };
577
578 static const SchemaFeature* _findFeature(
|
579 mike 1.1.2.2 const SchemaClass* sc,
|
580 mike 1.1.2.1 const char* name)
581 {
|
582 mike 1.1.2.2 for (size_t i = 0; sc->features[i]; i++)
|
583 mike 1.1.2.1 {
|
584 mike 1.1.2.2 const SchemaFeature* sf = sc->features[i];
|
585 mike 1.1.2.1
|
586 mike 1.1.2.2 if (_eqi(sf->name, name))
587 return sf;
|
588 mike 1.1.2.1 }
589
590 // Not found!
591 return 0;
592 }
593
594 static const SchemaFeature* _findParameter(
|
595 mike 1.1.2.2 const SchemaMethod* sm,
|
596 mike 1.1.2.1 const char* name)
597 {
|
598 mike 1.1.2.2 for (size_t i = 0; sm->parameters[i]; i++)
|
599 mike 1.1.2.1 {
|
600 mike 1.1.2.2 const SchemaFeature* sf = sm->parameters[i];
|
601 mike 1.1.2.1
|
602 mike 1.1.2.2 if (_eqi(sm->name, name))
603 return sf;
|
604 mike 1.1.2.1 }
605
606 // Not found!
607 return 0;
608 }
609
610 static int _mergeQualifiers(
611 const SchemaNameSpace* ns,
|
612 mike 1.1.2.2 const SchemaClass* sc,
|
613 mike 1.1.2.1 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 mike 1.1.2.2 if (sc->super)
|
622 mike 1.1.2.1 {
|
623 mike 1.1.2.2 _mergeQualifiers(ns, sc->super, featureName, parameterName, depth + 1,
|
624 mike 1.1.2.1 qualifiers, numQualifiers);
625 }
626
627 const char** quals = 0;
628
629 // Find qualifiers of the given object:
630
631 if (!featureName && !parameterName)
632 {
633 // Case 1: get class qualifiers:
|
634 mike 1.1.2.2 quals = sc->qualifiers;
|
635 mike 1.1.2.1 }
636 else if (featureName && !parameterName)
637 {
638 // Case 2: get feature qualifiers:
639
|
640 mike 1.1.2.2 const SchemaFeature* sf = _findFeature(sc, featureName);
|
641 mike 1.1.2.1
|
642 mike 1.1.2.2 if (sf)
643 quals = sf->qualifiers;
|
644 mike 1.1.2.1 }
645 else if (featureName && parameterName)
646 {
647 // Case 3: get parameter qualifiers:
648
|
649 mike 1.1.2.2 const SchemaFeature* sf = _findFeature(sc, featureName);
|
650 mike 1.1.2.1
|
651 mike 1.1.2.2 if (sf && (sf->flags & SCHEMA_FLAG_METHOD))
|
652 mike 1.1.2.1 {
|
653 mike 1.1.2.2 const SchemaMethod* sm = (const SchemaMethod*)sf;
654 const SchemaFeature* p = _findParameter(sm, parameterName);
|
655 mike 1.1.2.1
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
674 for (size_t j = 0; j < numQualifiers; j++)
675 {
676 mike 1.1.2.1 const char* qj = qualifiers[j].qualifier;
677
678 if (qi[0] == qj[0])
679 {
680 qualifiers[j].qualifier = qi;
|
681 mike 1.1.2.2 qualifiers[j].sc = sc;
|
682 mike 1.1.2.1 found = true;
683 break;
684 }
685 }
686
687 // Inject this qualifier not found:
688
689 if (!found)
690 {
691 SchemaQualifierDecl* qd = ns->qualifiers[qi[0]];
692
693 if (depth == 0 || !(qd->flavor & SCHEMA_FLAVOR_RESTRICTED))
694 {
695 if (numQualifiers == _MAX_QUALIFIERS)
696 {
697 return -1;
698 }
699
700 qualifiers[numQualifiers].qualifier = qi;
|
701 mike 1.1.2.2 qualifiers[numQualifiers].sc = sc;
|
702 mike 1.1.2.1 numQualifiers++;
703 }
704 }
705 }
706
707 return 0;
708 }
709
710 template<class C>
711 static int _addQualifiers(
712 const SchemaNameSpace* ns,
|
713 mike 1.1.2.2 const SchemaClass* sc,
|
714 mike 1.1.2.1 const char* featureName,
715 const char* parameterName,
716 C& c)
717 {
718 QualifierInfo qualifiers[_MAX_QUALIFIERS];
719 size_t numQualifiers = 0;
720
721 if (_mergeQualifiers(
|
722 mike 1.1.2.2 ns, sc, featureName, parameterName, 0, qualifiers, numQualifiers) != 0)
|
723 mike 1.1.2.1 {
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
737 // Get qualifier declaration:
738
739 SchemaQualifierDecl* qd = ns->qualifiers[qid];
740
741 // Make CIMValue:
742
743 CIMValue cv;
744 mike 1.1.2.1
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
758 static int _addProperty(
759 const SchemaNameSpace* ns,
|
760 mike 1.1.2.2 const SchemaClass* sc,
761 const SchemaProperty* sp,
|
762 mike 1.1.2.1 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 mike 1.1.2.2 if (_makeValue(cv, sp->type, sp->subscript, sp->value) != 0)
|
773 mike 1.1.2.1 {
774 return -1;
775 }
776
777 // Create property:
778
|
779 mike 1.1.2.2 CIMProperty cp(sp->name, cv);
|
780 mike 1.1.2.1
781 if (includeClassOrigin)
782 cp.setClassOrigin(classOrigin);
783
784 cp.setPropagated(propagated);
785
786 // Add qualifiers:
787
788 if (includeQualifiers)
789 {
|
790 mike 1.1.2.2 if (_addQualifiers(ns, sc, sp->name, 0, cp) != 0)
|
791 mike 1.1.2.1 {
792 return -1;
793 }
794 }
795
796 // Add to class:
797
798 cc.addProperty(cp);
799 return 0;
800 }
801
802 static int _addReference(
803 const SchemaNameSpace* ns,
|
804 mike 1.1.2.2 const SchemaClass* sc,
805 const SchemaReference* sr,
|
806 mike 1.1.2.1 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 mike 1.1.2.2 if (sr->subscript == -1)
|
818 mike 1.1.2.1 {
819 isArray = false;
820 arraySize = 0;
821 }
822 else
823 {
824 isArray = true;
|
825 mike 1.1.2.2 arraySize = sr->subscript;
|
826 mike 1.1.2.1 }
827
828 // Set referenceClassName:
829
|
830 mike 1.1.2.2 CIMName rcn = sr->ref->name;
|
831 mike 1.1.2.1
832 // Create value:
833
834 CIMValue cv(CIMTYPE_REFERENCE, isArray, arraySize);
835
836 // Create property:
837
|
838 mike 1.1.2.2 CIMProperty cp(sr->name, cv, arraySize, rcn);
|
839 mike 1.1.2.1
840 if (includeClassOrigin)
841 cp.setClassOrigin(classOrigin);
842
843 cp.setPropagated(propagated);
844
845 // Add qualifiers:
846
847 if (includeQualifiers)
848 {
|
849 mike 1.1.2.2 if (_addQualifiers(ns, sc, sr->name, 0, cp) != 0)
|
850 mike 1.1.2.1 {
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 const SchemaNameSpace* ns,
|
863 mike 1.1.2.2 const SchemaClass* sc,
864 const SchemaMethod* sm,
865 const SchemaProperty* sp,
|
866 mike 1.1.2.1 bool includeQualifiers,
867 CIMMethod& cm)
868 {
869 // Create property:
870
871 bool isArray;
872 Uint32 arraySize;
873
|
874 mike 1.1.2.2 if (sp->subscript == -1)
|
875 mike 1.1.2.1 {
876 isArray = false;
877 arraySize = 0;
878 }
879 else
880 {
881 isArray = true;
|
882 mike 1.1.2.2 arraySize = Uint32(sp->subscript);
|
883 mike 1.1.2.1 }
884
|
885 mike 1.1.2.2 CIMParameter cp(sp->name, CIMType(sp->type), isArray, arraySize);
|
886 mike 1.1.2.1
887 // Add qualifiers:
888
889 if (includeQualifiers)
890 {
|
891 mike 1.1.2.2 if (_addQualifiers(ns, sc, sm->name, sp->name, cm) != 0)
|
892 mike 1.1.2.1 {
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 const SchemaNameSpace* ns,
|
905 mike 1.1.2.2 const SchemaClass* sc,
906 const SchemaMethod* sm,
907 const SchemaReference* sr,
|
908 mike 1.1.2.1 bool includeQualifiers,
909 CIMMethod& cm)
910 {
911 // Create property:
912
913 bool isArray;
914 Uint32 arraySize;
915
|
916 mike 1.1.2.2 if (sr->subscript == -1)
|
917 mike 1.1.2.1 {
918 isArray = false;
919 arraySize = 0;
920 }
921 else
922 {
923 isArray = true;
|
924 mike 1.1.2.2 arraySize = Uint32(sr->subscript);
|
925 mike 1.1.2.1 }
926
|
927 mike 1.1.2.2 CIMName rcn = sr->ref->name;
928 CIMParameter cp(sr->name, CIMTYPE_REFERENCE, isArray, arraySize, rcn);
|
929 mike 1.1.2.1
930 // Add qualifiers:
931
932 if (includeQualifiers)
933 {
|
934 mike 1.1.2.2 if (_addQualifiers(ns, sc, sm->name, sr->name, cm) != 0)
|
935 mike 1.1.2.1 {
936 return -1;
937 }
938 }
939
940 // Add to method:
941
942 cm.addParameter(cp);
943 return 0;
944 }
945
946 static int _addMethod(
947 const SchemaNameSpace* ns,
|
948 mike 1.1.2.2 const SchemaClass* sc,
949 const SchemaMethod* sm,
|
950 mike 1.1.2.1 const char* classOrigin,
951 bool propagated,
952 bool includeQualifiers,
953 bool includeClassOrigin,
954 CIMClass& cc)
955 {
956 // Create method:
957
|
958 mike 1.1.2.2 CIMMethod cm(sm->name, CIMType(sm->type));
|
959 mike 1.1.2.1
960 if (includeClassOrigin)
961 cm.setClassOrigin(classOrigin);
962
963 cm.setPropagated(propagated);
964
965 // Add parameters:
966
|
967 mike 1.1.2.2 for (size_t i = 0; sm->parameters[i]; i++)
|
968 mike 1.1.2.1 {
|
969 mike 1.1.2.2 SchemaFeature* sf = sm->parameters[i];
|
970 mike 1.1.2.1
|
971 mike 1.1.2.2 if (sf->flags & SCHEMA_FLAG_PROPERTY)
|
972 mike 1.1.2.1 {
|
973 mike 1.1.2.2 SchemaProperty* sp = (SchemaProperty*)sf;
974 _addPropertyParameter(ns, sc, sm, sp, includeQualifiers, cm);
|
975 mike 1.1.2.1 }
|
976 mike 1.1.2.2 else if (sf->flags & SCHEMA_FLAG_REFERENCE)
|
977 mike 1.1.2.1 {
|
978 mike 1.1.2.2 SchemaReference* sr = (SchemaReference*)sf;
979 _addReferenceParameter(ns, sc, sm, sr, includeQualifiers, cm);
|
980 mike 1.1.2.1 }
981 }
982
983 // Add qualifiers:
984
985 if (includeQualifiers)
986 {
|
987 mike 1.1.2.2 if (_addQualifiers(ns, sc, sm->name, 0, cm) != 0)
|
988 mike 1.1.2.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.2.1
1010 static int _addFeatures(
1011 const SchemaNameSpace* ns,
|
1012 mike 1.1.2.2 const SchemaClass* sc,
|
1013 mike 1.1.2.1 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 SchemaFeatureInfo features[SCHEMA_MAX_FEATURES];
1022 size_t numFeatures = 0;
1023
|
1024 mike 1.1.2.2 if (MergeFeatures(sc, localOnly, 0xFFFFFFFF, features, numFeatures) != 0)
|
1025 mike 1.1.2.1 {
1026 return -1;
1027 }
1028
1029 // For each feature:
1030
1031 for (size_t i = 0; i < numFeatures; i++)
1032 {
1033 const SchemaFeatureInfo& fi = features[i];
1034
1035 // Set propagated flag:
1036
|
1037 mike 1.1.2.2 bool propagated = fi.sc != sc;
|
1038 mike 1.1.2.1
1039 // Set classOrigin:
1040
|
1041 mike 1.1.2.2 const char* classOrigin = fi.sc->name;
|
1042 mike 1.1.2.1
1043 // Skip feature not in property list:
1044
|
1045 mike 1.1.2.2 const SchemaFeature* sf = fi.sf;
|
1046 mike 1.1.2.1
|
1047 mike 1.1.2.2 if (propertyList && !_hasProperty(propertyList, sf->name))
|
1048 mike 1.1.2.1 continue;
1049
1050 // Add the feature:
1051
|
1052 mike 1.1.2.2 if (sf->flags & SCHEMA_FLAG_PROPERTY)
|
1053 mike 1.1.2.1 {
|
1054 mike 1.1.2.2 SchemaProperty* sp = (SchemaProperty*)sf;
|
1055 mike 1.1.2.1
|
1056 mike 1.1.2.2 if (_addProperty(ns, sc, sp, classOrigin, propagated,
|
1057 mike 1.1.2.1 includeQualifiers, includeClassOrigin, cc) != 0)
1058 {
1059 return -1;
1060 }
1061 }
|
1062 mike 1.1.2.2 else if (sf->flags & SCHEMA_FLAG_REFERENCE)
|
1063 mike 1.1.2.1 {
|
1064 mike 1.1.2.2 SchemaReference* sr = (SchemaReference*)sf;
|
1065 mike 1.1.2.1
|
1066 mike 1.1.2.2 if (_addReference(ns, sc, sr, classOrigin, propagated,
|
1067 mike 1.1.2.1 includeQualifiers, includeClassOrigin, cc) != 0)
1068 {
1069 return -1;
1070 }
1071 }
|
1072 mike 1.1.2.2 else if (sf->flags & SCHEMA_FLAG_METHOD)
|
1073 mike 1.1.2.1 {
|
1074 mike 1.1.2.2 SchemaMethod* sm = (SchemaMethod*)sf;
|
1075 mike 1.1.2.1
|
1076 mike 1.1.2.2 if (_addMethod(ns, sc, sm, classOrigin, propagated,
|
1077 mike 1.1.2.1 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 SchemaNameSpace* ns,
|
1090 mike 1.1.2.2 const SchemaClass* sc,
|
1091 mike 1.1.2.1 Boolean localOnly,
1092 Boolean includeQualifiers,
1093 Boolean includeClassOrigin,
1094 const char* const* propertyList,
1095 CIMClass& cc)
1096 {
1097 try
1098 {
1099 // Create class:
1100 {
1101 CIMName scn;
1102
|
1103 mike 1.1.2.2 if (sc->super)
1104 scn = sc->super->name;
|
1105 mike 1.1.2.1
|
1106 mike 1.1.2.2 cc = CIMClass(sc->name, scn);
|
1107 mike 1.1.2.1 }
1108
1109 // Add qualifiers:
1110
1111 if (includeQualifiers)
1112 {
|
1113 mike 1.1.2.2 if (_addQualifiers(ns, sc, 0, 0, cc) != 0)
|
1114 mike 1.1.2.1 {
1115 return -1;
1116 }
1117 }
1118
1119 // Features:
1120
|
1121 mike 1.1.2.2 if (_addFeatures(ns, sc, localOnly, includeQualifiers,
|
1122 mike 1.1.2.1 includeClassOrigin, propertyList, cc) != 0)
1123 {
1124 return -1;
1125 }
1126
1127 // Object path:
1128
|
1129 mike 1.1.2.2 cc.setPath(CIMObjectPath(hostName, ns->name, sc->name));
|
1130 mike 1.1.2.1 }
1131 catch (Exception& e)
1132 {
1133 printf("EXCEPTION[%s]\n", *Str(e));
1134 return -1;
1135 }
1136 catch (...)
1137 {
1138 return -1;
1139 }
1140
1141 return 0;
1142 }
1143
1144 int MakeQualifierDecl(
1145 const SchemaNameSpace* ns,
1146 const SchemaQualifierDecl* mqd,
1147 class CIMQualifierDecl& cqd)
1148 {
1149 // Value:
1150
1151 mike 1.1.2.1 CIMValue cv;
1152
1153 if (_makeValue(cv, mqd->type, mqd->subscript, mqd->value) != 0)
1154 {
1155 return -1;
1156 }
1157
1158 // Scope:
1159
1160 CIMScope scope;
1161
1162 if (mqd->scope & SCHEMA_SCOPE_CLASS)
1163 scope.addScope(CIMScope::CLASS);
1164 if (mqd->scope & SCHEMA_SCOPE_ASSOCIATION)
1165 scope.addScope(CIMScope::ASSOCIATION);
1166 if (mqd->scope & SCHEMA_SCOPE_INDICATION)
1167 scope.addScope(CIMScope::INDICATION);
1168 if (mqd->scope & SCHEMA_SCOPE_PROPERTY)
1169 scope.addScope(CIMScope::PROPERTY);
1170 if (mqd->scope & SCHEMA_SCOPE_REFERENCE)
1171 scope.addScope(CIMScope::REFERENCE);
1172 mike 1.1.2.1 if (mqd->scope & SCHEMA_SCOPE_METHOD)
1173 scope.addScope(CIMScope::METHOD);
|
1174 mike 1.1.2.3 if (mqd->scope & SCHEMA_SCOPE_PARAMETER)
|
1175 mike 1.1.2.1 scope.addScope(CIMScope::PARAMETER);
1176
1177 // Flavor:
1178
1179 CIMFlavor flavor;
1180
1181 if (mqd->flavor & SCHEMA_FLAVOR_OVERRIDABLE)
1182 flavor.addFlavor(CIMFlavor::OVERRIDABLE);
1183 if (mqd->flavor & SCHEMA_FLAVOR_TOSUBCLASS)
1184 flavor.addFlavor(CIMFlavor::TOSUBCLASS);
1185 if (mqd->flavor & SCHEMA_FLAVOR_TOINSTANCE)
1186 flavor.addFlavor(CIMFlavor::TOINSTANCE);
1187 if (mqd->flavor & SCHEMA_FLAVOR_TRANSLATABLE)
1188 flavor.addFlavor(CIMFlavor::TRANSLATABLE);
1189 if (mqd->flavor & SCHEMA_FLAVOR_DISABLEOVERRIDE)
1190 flavor.addFlavor(CIMFlavor::DISABLEOVERRIDE);
1191 if (mqd->flavor & SCHEMA_FLAVOR_RESTRICTED)
1192 flavor.addFlavor(CIMFlavor::RESTRICTED);
1193
1194 // Array size:
1195
1196 mike 1.1.2.1 Uint32 arraySize;
1197
1198 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 SchemaClass* FindClass(const SchemaNameSpace* ns, const char* name)
1209 {
1210 for (size_t i = 0; ns->classes[i]; i++)
1211 {
|
1212 mike 1.1.2.2 const SchemaClass* sc = ns->classes[i];
|
1213 mike 1.1.2.1
|
1214 mike 1.1.2.2 if (_eqi(sc->name, name))
1215 return sc;
|
1216 mike 1.1.2.1 }
1217
1218 // Not found!
1219 return 0;
1220 }
1221
1222 const SchemaQualifierDecl* FindQualifierDecl(
1223 const SchemaNameSpace* ns,
1224 const char* name)
1225 {
1226 for (size_t i = 0; ns->classes[i]; i++)
1227 {
1228 const SchemaQualifierDecl* mqd = ns->qualifiers[i];
1229
1230 if (_eqi(mqd->name, name))
1231 return mqd;
1232 }
1233
1234 // Not found!
1235 return 0;
1236 }
1237 mike 1.1.2.1
1238 bool IsSubClass(const SchemaClass* super, const SchemaClass* sub)
1239 {
1240 if (!super)
1241 return true;
1242
1243 for (SchemaClass* p = sub->super; p; p = p->super)
1244 {
1245 if (p == super)
1246 return true;
1247 }
1248
1249 return false;
1250 }
1251
1252 const SchemaFeature* FindFeature(
|
1253 mike 1.1.2.2 const SchemaClass* sc,
|
1254 mike 1.1.2.1 const char* name,
1255 Uint32 flags)
1256 {
|
1257 mike 1.1.2.2 for (size_t i = 0; sc->features[i]; i++)
|
1258 mike 1.1.2.1 {
|
1259 mike 1.1.2.2 const SchemaFeature* sf = sc->features[i];
|
1260 mike 1.1.2.1
|
1261 mike 1.1.2.2 if (sf->flags & flags && _eqi(sf->name, name))
1262 return sf;
|
1263 mike 1.1.2.1 }
1264
1265 // Not found!
1266 return 0;
1267 }
1268
1269 PEGASUS_NAMESPACE_END
|