1 martin 1.2 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.3 //
|
3 martin 1.2 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.3 //
|
10 martin 1.2 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.3 //
|
17 martin 1.2 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.3 //
|
20 martin 1.2 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.3 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.2 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.3 //
|
28 martin 1.2 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.1 //
30 // Local routines:
31 //
32 //==============================================================================
33
34 static size_t _indent = 0;
35
36 class Str
37 {
38 public:
39 Str(const String& s) : _cstr(s.getCString()) { }
|
40 kumpf 1.4 Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
41 Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
42 Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
|
43 mike 1.1 Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
|
44 kumpf 1.4 Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
|
45 mike 1.1 const char* operator*() const { return (const char*)_cstr; }
46 operator const char*() const { return (const char*)_cstr; }
47 private:
48 CString _cstr;
49 };
50
51 static void _vout(FILE* os, const char* format, va_list ap)
52 {
53 for (size_t i = 0; i < _indent; i++)
54 fprintf(os, " ");
55
56 vfprintf(os, format, ap);
57 }
58
59 PEGASUS_FORMAT(2, 3)
60 static void _throw(CIMStatusCode code, const char* format, ...)
61 {
62 char buffer[4096];
63
64 va_list ap;
65 va_start(ap, format);
66 mike 1.1 vsprintf(buffer, format, ap);
67 va_end(ap);
68 throw CIMException(code, format);
69 }
70
71 static void _line(FILE* os)
72 {
73 fprintf(os, "//");
74
75 for (size_t i = 0; i < 78; i++)
76 fputc('=', os);
77
78 fputc('\n', os);
79 }
80
81 PEGASUS_FORMAT(2, 3)
82 static void _box(FILE* os, const char* format, ...)
83 {
84 _line(os);
85
86 fprintf(os, "//\n");
87 mike 1.1
88 fprintf(os, "// ");
89
90 va_list ap;
91 va_start(ap, format);
92 vfprintf(os, format, ap);
93 va_end(ap);
94
95 fputc('\n', os);
96 fprintf(os, "//\n");
97
98 _line(os);
99 }
100
101 static void _writeHeaderFile(const String& ns)
102 {
103 const char format[] =
104 "\n"
105 "#ifndef _%s_namespace_h\n"
106 "#define _%s_namespace_h\n"
107 "\n"
108 mike 1.1 "#include <Pegasus/Repository/MRRTypes.h>\n"
109 "\n"
110 "PEGASUS_NAMESPACE_BEGIN\n"
111 "\n"
112 "extern const MRRNameSpace %s_namespace;\n"
113 "\n"
114 "PEGASUS_NAMESPACE_END\n"
115 "\n"
116 "#endif /* _%s_namespace_h */\n"
117 ;
118
119 String path = ns + "_namespace.h";
120 FILE* os = fopen(*Str(path), "wb");
121
122 if (!os)
123 {
|
124 kumpf 1.4 fprintf(stderr, "cimmofl: failed to open \"%s\" for write\n",
|
125 mike 1.1 *Str(path));
126 exit(1);
127 }
128
129 _box(os, "CAUTION: THIS FILE WAS GENERATED BY CIMMOFL; "
130 "PLEASE DO NOT EDIT IT.");
131 fprintf(stderr, "\n");
132
133 fprintf(os, format, *Str(ns), *Str(ns), *Str(ns), *Str(ns));
134
135 fclose(os);
136 }
137
138 static String _makeIdent(const String& str)
139 {
140 // Build a legal C identifier from str. Translate all illegal characters
141 // to underscores.
142
143 String r;
144
145 for (Uint32 i = 0; i < str.size(); i++)
146 mike 1.1 {
147 Uint16 c = str[i];
148
149 if (c < 127 && (isalnum(c) || c == '_'))
150 r.append(c);
151 else
152 r.append('_');
153 }
154
155 return r;
156 }
157
158
159 static const char* _typeNames[] =
160 {
161 "CIMTYPE_BOOLEAN",
162 "CIMTYPE_UINT8",
163 "CIMTYPE_SINT8",
164 "CIMTYPE_UINT16",
165 "CIMTYPE_SINT16",
166 "CIMTYPE_UINT32",
167 mike 1.1 "CIMTYPE_SINT32",
168 "CIMTYPE_UINT64",
169 "CIMTYPE_SINT64",
170 "CIMTYPE_REAL32",
171 "CIMTYPE_REAL64",
172 "CIMTYPE_CHAR16",
173 "CIMTYPE_STRING",
174 "CIMTYPE_DATETIME",
175 "CIMTYPE_REFERENCE",
176 "CIMTYPE_OBJECT",
177 "CIMTYPE_INSTANCE",
178 };
179
180 static bool _is_printable(const char* s)
181 {
182 for (; *s; s++)
183 {
184 if (!isprint(*s))
185 return false;
186 }
187
188 mike 1.1 return true;
189 }
190
191 template<class C>
192 static void _writeFlags(
|
193 kumpf 1.4 FILE* os,
194 const C& c,
|
195 mike 1.1 bool isProperty,
196 bool isParameter)
197 {
198 // Build up flags mask:
199
200 Uint32 flags = 0;
201
202 if (isProperty)
203 flags |= MRR_FLAG_READ;
204
205 if (isParameter)
206 flags |= MRR_FLAG_IN;
207
208 for (Uint32 i = 0; i < c.getQualifierCount(); i++)
209 {
210 CIMConstQualifier cq = c.getQualifier(i);
211 const CIMName& qn = cq.getName();
212
213 if (cq.getType() != CIMTYPE_BOOLEAN || cq.isArray())
214 continue;
215
216 mike 1.1 Boolean x;
217 cq.getValue().get(x);
218
219
220 if (System::strcasecmp(*Str(qn), "KEY") == 0)
221 {
222 if (x)
223 flags |= MRR_FLAG_KEY;
224 else
225 flags &= ~MRR_FLAG_KEY;
226 }
227 else if (System::strcasecmp(*Str(qn), "IN") == 0)
228 {
229 if (x)
230 flags |= MRR_FLAG_IN;
231 else
232 flags &= ~MRR_FLAG_IN;
233 }
234 else if (System::strcasecmp(*Str(qn), "OUT") == 0)
235 {
236 if (x)
237 mike 1.1 flags |= MRR_FLAG_OUT;
238 else
239 flags &= ~MRR_FLAG_OUT;
240 }
241 else if (System::strcasecmp(*Str(qn), "ABSTRACT") == 0)
242 {
243 if (x)
244 flags |= MRR_FLAG_ABSTRACT;
245 else
246 flags &= ~MRR_FLAG_ABSTRACT;
247 }
248 else if (System::strcasecmp(*Str(qn), "AGGREGATE") == 0)
249 {
250 if (x)
251 flags |= MRR_FLAG_AGGREGATE;
252 else
253 flags &= ~MRR_FLAG_AGGREGATE;
254 }
255 else if (System::strcasecmp(*Str(qn), "AGGREGATION") == 0)
256 {
257 if (x)
258 mike 1.1 flags |= MRR_FLAG_AGGREGATION;
259 else
260 flags &= ~MRR_FLAG_AGGREGATION;
261 }
262 else if (System::strcasecmp(*Str(qn), "COUNTER") == 0)
263 {
264 if (x)
265 flags |= MRR_FLAG_COUNTER;
266 else
267 flags &= ~MRR_FLAG_COUNTER;
268 }
269 else if (System::strcasecmp(*Str(qn), "DELETE") == 0)
270 {
271 if (x)
272 flags |= MRR_FLAG_DELETE;
273 else
274 flags &= ~MRR_FLAG_DELETE;
275 }
276 else if (System::strcasecmp(*Str(qn), "DN") == 0)
277 {
278 if (x)
279 mike 1.1 flags |= MRR_FLAG_DN;
280 else
281 flags &= ~MRR_FLAG_DN;
282 }
283 else if (System::strcasecmp(*Str(qn), "EMBEDDEDOBJECT") == 0)
284 {
285 if (x)
286 flags |= MRR_FLAG_EMBEDDEDOBJECT;
287 else
288 flags &= ~MRR_FLAG_EMBEDDEDOBJECT;
289 }
290 else if (System::strcasecmp(*Str(qn), "EXPENSIVE") == 0)
291 {
292 if (x)
293 flags |= MRR_FLAG_EXPENSIVE;
294 else
295 flags &= ~MRR_FLAG_EXPENSIVE;
296 }
297 else if (System::strcasecmp(*Str(qn), "EXPERIMENTAL") == 0)
298 {
299 if (x)
300 mike 1.1 flags |= MRR_FLAG_EXPERIMENTAL;
301 else
302 flags &= ~MRR_FLAG_EXPERIMENTAL;
303 }
304 else if (System::strcasecmp(*Str(qn), "GAUGE") == 0)
305 {
306 if (x)
307 flags |= MRR_FLAG_GAUGE;
308 else
309 flags &= ~MRR_FLAG_GAUGE;
310 }
311 else if (System::strcasecmp(*Str(qn), "IFDELETED") == 0)
312 {
313 if (x)
314 flags |= MRR_FLAG_IFDELETED;
315 else
316 flags &= ~MRR_FLAG_IFDELETED;
317 }
318 else if (System::strcasecmp(*Str(qn), "INVISIBLE") == 0)
319 {
320 if (x)
321 mike 1.1 flags |= MRR_FLAG_INVISIBLE;
322 else
323 flags &= ~MRR_FLAG_INVISIBLE;
324 }
325 else if (System::strcasecmp(*Str(qn), "LARGE") == 0)
326 {
327 if (x)
328 flags |= MRR_FLAG_LARGE;
329 else
330 flags &= ~MRR_FLAG_LARGE;
331 }
332 else if (System::strcasecmp(*Str(qn), "OCTETSTRING") == 0)
333 {
334 if (x)
335 flags |= MRR_FLAG_OCTETSTRING;
336 else
337 flags &= ~MRR_FLAG_OCTETSTRING;
338 }
339 else if (System::strcasecmp(*Str(qn), "READ") == 0)
340 {
341 if (x)
342 mike 1.1 flags |= MRR_FLAG_READ;
343 else
344 flags &= ~MRR_FLAG_READ;
345 }
346 else if (System::strcasecmp(*Str(qn), "REQUIRED") == 0)
347 {
348 if (x)
349 flags |= MRR_FLAG_REQUIRED;
350 else
351 flags &= ~MRR_FLAG_REQUIRED;
352 }
353 else if (System::strcasecmp(*Str(qn), "STATIC") == 0)
354 {
355 if (x)
356 flags |= MRR_FLAG_STATIC;
357 else
358 flags &= ~MRR_FLAG_STATIC;
359 }
360 else if (System::strcasecmp(*Str(qn), "TERMINAL") == 0)
361 {
362 if (x)
363 mike 1.1 flags |= MRR_FLAG_TERMINAL;
364 else
365 flags &= ~MRR_FLAG_TERMINAL;
366 }
367 else if (System::strcasecmp(*Str(qn), "WEAK") == 0)
368 {
369 if (x)
370 flags |= MRR_FLAG_WEAK;
371 else
372 flags &= ~MRR_FLAG_WEAK;
373 }
374 else if (System::strcasecmp(*Str(qn), "WRITE") == 0)
375 {
376 if (x)
377 flags |= MRR_FLAG_WRITE;
378 else
379 flags &= ~MRR_FLAG_WRITE;
380 }
381 else
382 {
383 // ATTN: Composition qualifier not handled (no more room in mask).
384 mike 1.1 }
385 }
386
387 // Write flags mask:
388
389 if (flags & MRR_FLAG_KEY)
390 fprintf(os, "|MRR_FLAG_KEY");
391 if (flags && (flags & MRR_FLAG_IN))
392 fprintf(os, "|MRR_FLAG_IN");
393 if (flags && (flags & MRR_FLAG_OUT))
394 fprintf(os, "|MRR_FLAG_OUT");
395 if (flags & MRR_FLAG_ABSTRACT)
396 fprintf(os, "|MRR_FLAG_ABSTRACT");
397 if (flags & MRR_FLAG_AGGREGATE)
398 fprintf(os, "|MRR_FLAG_AGGREGATE");
399 if (flags & MRR_FLAG_AGGREGATION)
400 fprintf(os, "|MRR_FLAG_AGGREGATION");
401 if (flags & MRR_FLAG_COUNTER)
402 fprintf(os, "|MRR_FLAG_COUNTER");
403 if (flags & MRR_FLAG_DELETE)
404 fprintf(os, "|MRR_FLAG_DELETE");
405 mike 1.1 if (flags & MRR_FLAG_DN)
406 fprintf(os, "|MRR_FLAG_DN");
407 if (flags & MRR_FLAG_EMBEDDEDOBJECT)
408 fprintf(os, "|MRR_FLAG_EMBEDDEDOBJECT");
409 if (flags & MRR_FLAG_EXPENSIVE)
410 fprintf(os, "|MRR_FLAG_EXPENSIVE");
411 if (flags & MRR_FLAG_EXPERIMENTAL)
412 fprintf(os, "|MRR_FLAG_EXPERIMENTAL");
413 if (flags & MRR_FLAG_GAUGE)
414 fprintf(os, "|MRR_FLAG_GAUGE");
415 if (flags & MRR_FLAG_IFDELETED)
416 fprintf(os, "|MRR_FLAG_IFDELETED");
417 if (flags & MRR_FLAG_INVISIBLE)
418 fprintf(os, "|MRR_FLAG_INVISIBLE");
419 if (flags & MRR_FLAG_LARGE)
420 fprintf(os, "|MRR_FLAG_LARGE");
421 if (flags & MRR_FLAG_OCTETSTRING)
422 fprintf(os, "|MRR_FLAG_OCTETSTRING");
423 if (flags & MRR_FLAG_READ)
424 fprintf(os, "|MRR_FLAG_READ");
425 if (flags & MRR_FLAG_REQUIRED)
426 mike 1.1 fprintf(os, "|MRR_FLAG_REQUIRED");
427 if (flags & MRR_FLAG_STATIC)
428 fprintf(os, "|MRR_FLAG_STATIC");
429 if (flags & MRR_FLAG_TERMINAL)
430 fprintf(os, "|MRR_FLAG_TERMINAL");
431 if (flags & MRR_FLAG_WEAK)
432 fprintf(os, "|MRR_FLAG_WEAK");
433 if (flags & MRR_FLAG_WRITE)
434 fprintf(os, "|MRR_FLAG_WRITE");
435 }
436
437 static bool _testBooleanQualifier(const CIMClass& cc, const CIMName& name)
438 {
439 Uint32 pos = cc.findQualifier(name);
440
441 if (pos == PEG_NOT_FOUND)
442 return false;
443
444 CIMConstQualifier cq = cc.getQualifier(pos);
445
446 if (cq.getType() != CIMTYPE_BOOLEAN || cq.isArray())
447 mike 1.1 return false;
448
449 Boolean x;
450 cq.getValue().get(x);
451 return x;
452 }
453
454 static void _writeBoolean(FILE* os, Boolean x)
455 {
456 fprintf(os, "\\%03o", (int)x);
457 }
458
459 static void _writeUint8(FILE* os, Uint8 x)
460 {
461 fprintf(os, "\\%03o", (int)x);
462 }
463
464 static void _writeSint8(FILE* os, Sint8 x)
465 {
466 _writeUint8(os, Uint8(x));
467 }
468 mike 1.1
469 static void _writeUint16(FILE* os, Uint16 x)
470 {
471 Uint16 x0 = (x >> 8) & 0x00FF;
472 Uint16 x1 = (x >> 0) & 0x00FF;
473 fprintf(os, "\\%03o", (int)x0);
474 fprintf(os, "\\%03o", (int)x1);
475 }
476
477 static void _writeSint16(FILE* os, Sint16 x)
478 {
479 _writeUint16(os, Uint16(x));
480 }
481
482 static void _writeUint32(FILE* os, Uint32 x)
483 {
484 Uint32 x0 = (x >> 24) & 0x000000FF;
485 Uint32 x1 = (x >> 16) & 0x000000FF;
486 Uint32 x2 = (x >> 8) & 0x000000FF;
487 Uint32 x3 = (x >> 0) & 0x000000FF;
488 fprintf(os, "\\%03o", (int)x0);
489 mike 1.1 fprintf(os, "\\%03o", (int)x1);
490 fprintf(os, "\\%03o", (int)x2);
491 fprintf(os, "\\%03o", (int)x3);
492 }
493
494 static void _writeSint32(FILE* os, Sint32 x)
495 {
496 _writeUint32(os, Uint32(x));
497 }
498
499 static void _writeUint64(FILE* os, Uint64 x)
500 {
501 Uint64 x0 = (x >> 56) & 0x00000000000000FF;
502 Uint64 x1 = (x >> 48) & 0x00000000000000FF;
503 Uint64 x2 = (x >> 40) & 0x00000000000000FF;
504 Uint64 x3 = (x >> 32) & 0x00000000000000FF;
505 Uint64 x4 = (x >> 24) & 0x00000000000000FF;
506 Uint64 x5 = (x >> 16) & 0x00000000000000FF;
507 Uint64 x6 = (x >> 8) & 0x00000000000000FF;
508 Uint64 x7 = (x >> 0) & 0x00000000000000FF;
509 fprintf(os, "\\%03o", (int)x0);
510 mike 1.1 fprintf(os, "\\%03o", (int)x1);
511 fprintf(os, "\\%03o", (int)x2);
512 fprintf(os, "\\%03o", (int)x3);
513 fprintf(os, "\\%03o", (int)x4);
514 fprintf(os, "\\%03o", (int)x5);
515 fprintf(os, "\\%03o", (int)x6);
516 fprintf(os, "\\%03o", (int)x7);
517 }
518
519 static void _writeSint64(FILE* os, Sint64 x)
520 {
521 _writeUint64(os, Uint64(x));
522 }
523
524 static void _writeReal32(FILE* os, Real32 x)
525 {
526 _writeUint32(os, *((Uint32*)(void*)&x));
527 }
528
529 static void _writeReal64(FILE* os, Real64 x)
530 {
531 mike 1.1 _writeUint64(os, *((Uint64*)(void*)&x));
532 }
533
534 static void _writeChar16(FILE* os, const Char16& x)
535 {
536 _writeUint16(os, x);
537 }
538
539 static void _writeString(FILE* os, const char* s)
540 {
541 size_t n = strlen(s);
542
543 for (size_t i = 0; i < n; i++)
544 {
545 char c = s[i];
546
547 if (isprint(c) && c != '"')
548 fprintf(os, "%c", c);
549 else
550 fprintf(os, "\\%03o", c);
551 }
552 mike 1.1 }
553
554 static void _writeString(FILE* os, const String& x)
555 {
556 _writeString(os, *Str(x));
557 }
558
559 static void _writeDateTime(FILE* os, const CIMDateTime& x)
560 {
561 _writeString(os, x.toString());
562 }
563
564 static int _writeValue(FILE* os, const CIMValue& cv, bool quote)
565 {
566 if (cv.isNull())
567 {
568 fprintf(os, "0");
569 return 0;
570 }
571
572 if (quote)
573 mike 1.1 fputc('"', os);
574
575 if (cv.isArray())
576 {
577 switch (cv.getType())
578 {
579 case CIMTYPE_BOOLEAN:
580 {
581 Array<Boolean> x;
582 cv.get(x);
583
584 _writeUint16(os, x.size());
585
586 for (Uint32 i = 0; i < x.size(); i++)
587 _writeBoolean(os, x[i]);
588 break;
589 }
590
591 case CIMTYPE_UINT8:
592 {
593 Array<Uint8> x;
594 mike 1.1 cv.get(x);
595
596 _writeUint16(os, x.size());
597
598 for (Uint32 i = 0; i < x.size(); i++)
599 _writeUint8(os, x[i]);
600 break;
601 }
602
603 case CIMTYPE_SINT8:
604 {
605 Array<Sint8> x;
606 cv.get(x);
607
608 _writeUint16(os, x.size());
609
610 for (Uint32 i = 0; i < x.size(); i++)
611 _writeSint8(os, x[i]);
612 break;
613 }
614
615 mike 1.1 case CIMTYPE_UINT16:
616 {
617 Array<Uint16> x;
618 cv.get(x);
619
620 _writeUint16(os, x.size());
621
622 for (Uint32 i = 0; i < x.size(); i++)
623 _writeUint16(os, x[i]);
624 break;
625 }
626
627 case CIMTYPE_SINT16:
628 {
629 Array<Sint16> x;
630 cv.get(x);
631
632 _writeUint16(os, x.size());
633
634 for (Uint32 i = 0; i < x.size(); i++)
635 _writeSint16(os, x[i]);
636 mike 1.1 break;
637 }
638
639 case CIMTYPE_UINT32:
640 {
641 Array<Uint32> x;
642 cv.get(x);
643
644 _writeUint16(os, x.size());
645
646 for (Uint32 i = 0; i < x.size(); i++)
647 _writeUint32(os, x[i]);
648 break;
649 }
650
651 case CIMTYPE_SINT32:
652 {
653 Array<Sint32> x;
654 cv.get(x);
655
656 _writeUint16(os, x.size());
657 mike 1.1
658 for (Uint32 i = 0; i < x.size(); i++)
659 _writeSint32(os, x[i]);
660 break;
661 }
662
663 case CIMTYPE_UINT64:
664 {
665 Array<Uint64> x;
666 cv.get(x);
667
668 _writeUint16(os, x.size());
669
670 for (Uint32 i = 0; i < x.size(); i++)
671 _writeUint64(os, x[i]);
672 break;
673 }
674
675 case CIMTYPE_SINT64:
676 {
677 Array<Sint64> x;
678 mike 1.1 cv.get(x);
679
680 _writeUint16(os, x.size());
681
682 for (Uint32 i = 0; i < x.size(); i++)
683 _writeSint64(os, x[i]);
684 break;
685 }
686
687 case CIMTYPE_REAL32:
688 {
689 Array<Real32> x;
690 cv.get(x);
691
692 _writeUint16(os, x.size());
693
694 for (Uint32 i = 0; i < x.size(); i++)
695 _writeReal32(os, x[i]);
696 break;
697 }
698
699 mike 1.1 case CIMTYPE_REAL64:
700 {
701 Array<Real64> x;
702 cv.get(x);
703
704 _writeUint16(os, x.size());
705
706 for (Uint32 i = 0; i < x.size(); i++)
707 _writeReal64(os, x[i]);
708 break;
709 }
710
711 case CIMTYPE_CHAR16:
712 {
713 Array<Char16> x;
714 cv.get(x);
715
716 _writeUint16(os, x.size());
717
718 for (Uint32 i = 0; i < x.size(); i++)
719 _writeChar16(os, x[i]);
720 mike 1.1 break;
721 }
722
723 case CIMTYPE_STRING:
724 {
725 Array<String> x;
726 cv.get(x);
727
728 _writeUint16(os, x.size());
729
730 for (Uint32 i = 0; i < x.size(); i++)
731 {
732 _writeString(os, x[i]);
733 _writeUint8(os, 0);
734 }
735 break;
736 }
737
738 case CIMTYPE_DATETIME:
739 {
740 Array<CIMDateTime> x;
741 mike 1.1 cv.get(x);
742
743 _writeUint16(os, x.size());
744
745 for (Uint32 i = 0; i < x.size(); i++)
746 _writeDateTime(os, x[i]);
747 break;
748 }
749
750 default:
751 return -1;
752 }
753 }
754 else
755 {
756 switch (cv.getType())
757 {
758 case CIMTYPE_BOOLEAN:
759 {
760 Boolean x;
761 cv.get(x);
762 mike 1.1 _writeBoolean(os, x);
763 break;
764 }
765
766 case CIMTYPE_UINT8:
767 {
768 Uint8 x;
769 cv.get(x);
770 _writeUint8(os, x);
771 break;
772 }
773
774 case CIMTYPE_SINT8:
775 {
776 Sint8 x;
777 cv.get(x);
778 _writeSint8(os, x);
779 break;
780 }
781
782 case CIMTYPE_UINT16:
783 mike 1.1 {
784 Uint16 x;
785 cv.get(x);
786 _writeUint16(os, x);
787 break;
788 }
789
790 case CIMTYPE_SINT16:
791 {
792 Sint16 x;
793 cv.get(x);
794 _writeSint16(os, x);
795 break;
796 }
797
798 case CIMTYPE_UINT32:
799 {
800 Uint32 x;
801 cv.get(x);
802 _writeUint32(os, x);
803 break;
804 mike 1.1 }
805
806 case CIMTYPE_SINT32:
807 {
808 Sint32 x;
809 cv.get(x);
810 _writeSint32(os, x);
811 break;
812 }
813
814 case CIMTYPE_UINT64:
815 {
816 Uint64 x;
817 cv.get(x);
818 _writeUint64(os, x);
819 break;
820 }
821
822 case CIMTYPE_SINT64:
823 {
824 Sint64 x;
825 mike 1.1 cv.get(x);
826 _writeSint64(os, x);
827 break;
828 }
829
830 case CIMTYPE_REAL32:
831 {
832 Real32 x;
833 cv.get(x);
834 _writeReal32(os, x);
835 break;
836 }
837
838 case CIMTYPE_REAL64:
839 {
840 Real64 x;
841 cv.get(x);
842 _writeReal64(os, x);
843 break;
844 }
845
846 mike 1.1 case CIMTYPE_CHAR16:
847 {
848 Char16 x;
849 cv.get(x);
850 _writeChar16(os, x);
851 break;
852 }
853
854 case CIMTYPE_STRING:
855 {
856 String x;
857 cv.get(x);
858 _writeString(os, x);
859 break;
860 }
861
862 case CIMTYPE_DATETIME:
863 {
864 CIMDateTime x;
865 cv.get(x);
866 _writeDateTime(os, x);
867 mike 1.1 break;
868 }
869
870 default:
871 return -1;
872 }
873 }
874
875 if (quote)
876 fputc('"', os);
877
878 return 0;
879 }
880
881 //==============================================================================
882 //
883 // cimmofMRR
884 //
885 //==============================================================================
886
|
887 kumpf 1.4 cimmofMRR::cimmofMRR(bool discard) :
|
888 mike 1.1 _discard(discard), _os(0)
889 {
890 }
891
892 cimmofMRR::~cimmofMRR()
893 {
894 }
895
896 void cimmofMRR::addClass(
897 const CIMNamespaceName& nameSpace,
898 CIMClass& cimClass)
899 {
900 if (_findClass(cimClass.getClassName()) != PEG_NOT_FOUND)
901 {
|
902 kumpf 1.4 _throw(CIM_ERR_ALREADY_EXISTS, "class already defined: %s:%s",
|
903 mike 1.1 *Str(nameSpace), *Str(cimClass.getClassName()));
904 }
905
906 _classes.append(cimClass);
907 }
908
909 void cimmofMRR::addQualifier(
910 const CIMNamespaceName& nameSpace,
911 CIMQualifierDecl& cimQualifierDecl)
912 {
913 if (_findQualifier(cimQualifierDecl.getName()) != PEG_NOT_FOUND)
914 {
|
915 kumpf 1.4 _throw(CIM_ERR_ALREADY_EXISTS, "qualifier already defined: %s:%s",
|
916 mike 1.1 *Str(nameSpace), *Str(cimQualifierDecl.getName()));
917 }
918
919 _qualifiers.append(cimQualifierDecl);
920 }
921
922 void cimmofMRR::addInstance(
923 const CIMNamespaceName& nameSpace,
924 CIMInstance& instance)
925 {
926 const CIMObjectPath& cop = instance.getPath();
927
928 for (Uint32 i = 0; i < _instances.size(); i++)
929 {
930 if (_instances[i].getPath() == cop)
931 {
932 _throw(CIM_ERR_ALREADY_EXISTS,
933 "instances already exists: %s", *Str(cop));
934 }
935 }
936
937 mike 1.1 _instances.append(instance);
938 }
939
940 CIMQualifierDecl cimmofMRR::getQualifierDecl(
941 const CIMNamespaceName& nameSpace,
942 const CIMName& qualifierName)
943 {
944 Uint32 pos = _findQualifier(qualifierName);
945
946 if (pos == PEG_NOT_FOUND)
947 {
948 _throw(CIM_ERR_NOT_FOUND,
949 "undefined qualifier: %s:%s", *Str(nameSpace), *Str(qualifierName));
950 }
951
952 return _qualifiers[pos];
953 }
954
955 CIMClass cimmofMRR::getClass(
956 const CIMNamespaceName& nameSpace,
957 const CIMName& className)
958 mike 1.1 {
959 Uint32 pos = _findClass(className);
960
961 if (pos == PEG_NOT_FOUND)
962 {
|
963 kumpf 1.4 _throw(CIM_ERR_NOT_FOUND,
|
964 mike 1.1 "undefined class: %s:%s", *Str(nameSpace), *Str(className));
965 }
966
967 return _classes[pos];
968 }
969
970 void cimmofMRR::modifyClass(
971 const CIMNamespaceName& nameSpace,
972 CIMClass& cimClass)
973 {
974 Uint32 pos = _findClass(cimClass.getClassName());
975
976 if (pos == PEG_NOT_FOUND)
977 {
|
978 kumpf 1.4 _throw(CIM_ERR_NOT_FOUND, "undefined class: %s:%s",
|
979 mike 1.1 *Str(nameSpace), *Str(cimClass.getClassName()));
980 }
981
982 _classes[pos] = cimClass;
983 }
984
985 void cimmofMRR::createNameSpace(
986 const CIMNamespaceName& nameSpace)
987 {
988 if (_nameSpace == nameSpace)
989 {
|
990 kumpf 1.4 _throw(CIM_ERR_ALREADY_EXISTS, "namespace already exists: %s",
|
991 mike 1.1 *Str(nameSpace));
992 }
993
994 if (!_nameSpace.isNull())
995 {
996 _throw(CIM_ERR_FAILED, "cannot create more than one namespace");
997 }
998
999 _nameSpace = nameSpace;
1000 }
1001
1002 void cimmofMRR::start()
1003 {
1004 }
1005
1006 void cimmofMRR::_loadClassFile(
1007 Array<CIMName>& classes, const String& path)
1008 {
1009 classes.clear();
1010
1011 // Open class file:
1012 mike 1.1
1013 FILE* is = fopen(*Str(path), "r");
1014
1015 if (!is)
1016 return;
1017
1018 char buffer[1024];
1019
1020 for (int line = 1; fgets(buffer, sizeof(buffer), is) != NULL; line++)
1021 {
1022 if (buffer[0] == '#')
1023 continue;
1024
1025 char* start = buffer;
1026
1027 // Remove leading whitespace.
1028
1029 while (isspace(*start))
1030 start++;
1031
1032 // Remove trailing whitespace.
1033 mike 1.1
1034 char* p = start;
1035
1036 while (*p)
1037 p++;
1038
1039 while (p != start && isspace(p[-1]))
1040 *--p = '\0';
1041
1042 // Skip empty lines.
1043
1044 if (*start == '\0')
1045 continue;
1046
1047 // Skip comment lines:
1048
1049 if (*start == '#')
1050 continue;
1051
1052 /* Check whether legal class name. */
1053
1054 mike 1.1 if (_findClass(start) == PEG_NOT_FOUND)
1055 {
|
1056 kumpf 1.4 fprintf(stderr,
1057 "cimmofl: unknown class on line %d of %s: \"%s\"\n",
|
1058 mike 1.1 line, *Str(path), start);
1059 exit(1);
1060 }
1061
1062 /* Append class to list. */
1063
1064 bool found = false;
1065
1066 for (Uint32 i = 0; i < classes.size(); i++)
1067 {
1068 if (classes[i] == start)
1069 {
1070 found = true;
1071 break;
1072 }
1073 }
1074
1075 if (!found)
1076 classes.append(start);
1077 }
1078
1079 mike 1.1 fclose(is);
1080 }
1081
1082 void cimmofMRR::finish()
1083 {
1084 String ns = _makeIdent(_nameSpace.getString());
1085
1086 // Open classes file, if any.
1087
1088 Array<CIMName> classNames;
1089 String classFile = ns + "_namespace.classes";
1090 _loadClassFile(classNames, classFile);
1091
1092 // Find closure of select classes:
1093
1094 _closure.clear();
1095
1096 if (classNames.size())
1097 {
1098 printf("Using %s to reduce class list\n", *Str(classFile));
1099
1100 mike 1.1 // Find closure of classes from class file:
1101
1102 for (Uint32 i = 0; i < classNames.size(); i++)
1103 {
1104 const CIMName& cn = classNames[i];
1105
1106 if (Closure(cn, _classes, _closure) != 0)
1107 {
1108 printf("cimmofl: failed to calculate closure for class %s\n",
1109 *Str(cn));
1110 }
1111 }
1112
1113 // Find closure of classes referred to by instances:
1114
1115 for (Uint32 i = 0; i < _instances.size(); i++)
1116 {
1117 const CIMInstance& ci = _instances[i];
1118 const CIMName& cn = ci.getClassName();
1119
1120 if (Closure(cn, _classes, _closure) != 0)
1121 mike 1.1 {
1122 printf("cimmofl: failed to calculate closure for class %s\n",
1123 *Str(cn));
1124 }
1125 }
1126 }
1127
1128 // Write header file:
1129
1130 _writeHeaderFile(ns);
1131
1132 // Open source file:
1133
1134 String path = ns + "_namespace.cpp";
1135 _os = fopen(*Str(path), "wb");
1136
1137 if (!_os)
1138 {
|
1139 kumpf 1.4 fprintf(stderr, "cimmofl: failed to open \"%s\" for write\n",
|
1140 mike 1.1 *Str(path));
1141 exit(1);
1142 }
1143
1144 // Write prologue:
1145
1146 _writeMetaPrologue();
1147
1148 // Write namespace:
1149
1150 _writeNameSpace(_nameSpace);
1151
1152 // Write epilogue:
1153
1154 _writeMetaEpilogue();
1155
1156 // Close file:
1157
1158 fclose(_os);
1159
1160 // Write instances file (if any instances encountered).
1161 mike 1.1
1162 if (_instances.size())
1163 {
1164 // Serialize all instances into a buffer:
1165
1166 Buffer out;
1167
1168 for (Uint32 i = 0; i < _instances.size(); i++)
1169 {
1170 MRRSerializeNameSpace(out, _nameSpace);
1171 MRRSerializeInstance(out, _instances[i]);
1172 }
1173
1174 // Open instances output file:
1175
1176 String path = ns + "_namespace.mrr";
1177 FILE* os = fopen(*Str(path), "wb");
1178
1179 if (!os)
1180 {
|
1181 kumpf 1.4 fprintf(stderr, "cimmofl: failed to open \"%s\" for write\n",
|
1182 mike 1.1 *Str(path));
1183 exit(1);
1184 }
1185
1186 // Write instances to a file.
1187
1188 if (fwrite(out.getData(), 1, out.size(), os) != out.size())
1189 {
|
1190 kumpf 1.4 fprintf(stderr, "cimmofl: failed to write to \"%s\"\n",
|
1191 mike 1.1 *Str(path));
1192 exit(1);
1193 }
1194
1195 // Close output file:
1196
1197 fclose(os);
1198 }
1199
1200 // Write messages:
1201
1202 printf("Created %s_namespace.h\n", *Str(ns));
1203 printf("Created %s_namespace.cpp\n", *Str(ns));
1204
1205 if (_instances.size())
1206 printf("Created %s_namespace.mrr\n", *Str(ns));
1207
1208 printf("\n");
1209 }
1210
1211 Uint32 cimmofMRR::_findClass(const CIMName& className) const
1212 mike 1.1 {
1213 for (Uint32 i = 0; i < _classes.size(); i++)
1214 {
1215 if (_classes[i].getClassName() == className)
1216 return i;
1217 }
1218
1219 // Not found!
1220 return PEG_NOT_FOUND;
1221 }
1222
1223 Uint32 cimmofMRR::_findQualifier(const CIMName& qualifierName) const
1224 {
1225 for (Uint32 i = 0; i < _qualifiers.size(); i++)
1226 {
1227 if (_qualifiers[i].getName() == qualifierName)
1228 return i;
1229 }
1230
1231 // Not found!
1232 return PEG_NOT_FOUND;
1233 mike 1.1 }
1234
1235 void cimmofMRR::_writeMetaPrologue()
1236 {
1237 String ns = _makeIdent(_nameSpace.getString());
1238 String path = ns + "_namespace.h";
1239
1240 _box(_os, "CAUTION: THIS FILE WAS GENERATED BY CIMMOFL; "
1241 "PLEASE DO NOT EDIT IT.");
1242 _nl();
1243
1244 _outn("#include \"%s\"", *Str(path));
1245 _nl();
1246 _outn("/*NOCHKSRC*/");
1247 _nl();
1248 _outn("PEGASUS_NAMESPACE_BEGIN");
1249 _nl();
1250 }
1251
1252 void cimmofMRR::_writeMetaEpilogue()
1253 {
1254 mike 1.1 _outn("PEGASUS_NAMESPACE_END");
1255 }
1256
1257 void cimmofMRR::_writeQualifier(
1258 const Array<CIMQualifierDecl>& qualifierDecls,
1259 const CIMConstQualifier& cq)
1260 {
1261 CIMName qn = cq.getName();
1262 CIMType qt = cq.getType();
1263 CIMValue qv = cq.getValue();
1264
1265 Uint32 pos = _findQualifier(qn);
1266
1267 if (pos == PEG_NOT_FOUND)
1268 _throw(CIM_ERR_FAILED, "undefined qualifier: %s", *Str(qn));
1269
1270 // Write the qualifier string literal:
1271
1272 _outn(" /* %s */", *Str(qn));
1273 _out(" (char*)\"");
1274 _writeUint8(_os, pos);
1275 mike 1.1 _writeValue(_os, qv, false);
1276 _outn("\",");
1277 }
1278
1279 void cimmofMRR::_writeQualifierDecl(const CIMConstQualifierDecl& cq)
1280 {
1281 CIMName qn = cq.getName();
1282 CIMType qt = cq.getType();
1283 const CIMValue& cv = cq.getValue();
1284
1285 // Write value definition (if any).
1286
1287 String path = "_" + qn.getString() + "_qualifier_decl";
1288
1289 // Write MRRQualifierDecl header:
1290
1291 _outn("static MRRQualifierDecl");
1292 _outn("%s =", *Str(path));
1293 _outn("{");
1294
1295 // MRRQualifierDecl.name:
1296 mike 1.1
1297 _outn(" /* name */");
1298 _outn(" (char*)\"%s\",", *Str(qn));
1299
1300 // MRRQualifierDecl.type:
1301
1302 _outn(" /* type */");
1303 _outn(" %s,", _typeNames[qt]);
1304
1305 // MRRQualifierDecl.subscript:
1306
1307 _outn(" /* subscript */");
1308
1309 if (cq.isArray())
1310 {
1311 Uint32 n = cq.getArraySize();
1312 _outn(" %u,", n);
1313 }
1314 else
1315 {
1316 _outn(" -1,");
1317 mike 1.1 }
1318
1319 // MRRQualifierDecl.scope:
1320 {
1321 _outn(" /* scope */");
1322
1323 CIMScope scope = cq.getScope();
1324 Array<String> scopes;
1325
1326 if (scope.hasScope(CIMScope::ANY))
1327 scopes.append("MRR_SCOPE_ANY");
1328 else
1329 {
1330 if (scope.hasScope(CIMScope::CLASS))
1331 scopes.append("MRR_SCOPE_CLASS");
1332 if (scope.hasScope(CIMScope::ASSOCIATION))
1333 scopes.append("MRR_SCOPE_ASSOCIATION");
1334 if (scope.hasScope(CIMScope::INDICATION))
1335 scopes.append("MRR_SCOPE_INDICATION");
1336 if (scope.hasScope(CIMScope::PROPERTY))
1337 scopes.append("MRR_SCOPE_PROPERTY");
1338 mike 1.1 if (scope.hasScope(CIMScope::REFERENCE))
1339 scopes.append("MRR_SCOPE_REFERENCE");
1340 if (scope.hasScope(CIMScope::METHOD))
1341 scopes.append("MRR_SCOPE_METHOD");
1342 if (scope.hasScope(CIMScope::PARAMETER))
1343 scopes.append("MRR_SCOPE_PARAMETER");
1344 }
1345
1346 _out(" ");
1347
1348 for (Uint32 i = 0; i < scopes.size(); i++)
1349 {
1350 _out("%s", *Str(scopes[i]));
1351
1352 if (i + 1 != scopes.size())
1353 _out("|");
1354 }
1355
1356 _outn(",");
1357 }
1358
1359 mike 1.1 // MRRQualifierDecl.flavor:
1360 {
1361 _outn(" /* flavor */");
1362
1363 CIMFlavor flavor = cq.getFlavor();
1364 Array<String> flavors;
1365
1366 if (flavor.hasFlavor(CIMFlavor::OVERRIDABLE))
1367 flavors.append("MRR_FLAVOR_OVERRIDABLE");
1368 if (flavor.hasFlavor(CIMFlavor::TOSUBCLASS))
1369 flavors.append("MRR_FLAVOR_TOSUBCLASS");
|
1370 kumpf 1.5 //if (flavor.hasFlavor(CIMFlavor::TOINSTANCE))
1371 // flavors.append("MRR_FLAVOR_TOINSTANCE");
|
1372 mike 1.1 if (flavor.hasFlavor(CIMFlavor::TRANSLATABLE))
1373 flavors.append("MRR_FLAVOR_TRANSLATABLE");
1374 if (flavor.hasFlavor(CIMFlavor::DISABLEOVERRIDE))
1375 flavors.append("MRR_FLAVOR_DISABLEOVERRIDE");
1376 if (flavor.hasFlavor(CIMFlavor::RESTRICTED))
1377 flavors.append("MRR_FLAVOR_RESTRICTED");
1378
1379 _out(" ");
1380
1381 for (Uint32 i = 0; i < flavors.size(); i++)
1382 {
1383 _out("%s", *Str(flavors[i]));
1384
1385 if (i + 1 != flavors.size())
1386 _out("|");
1387 }
1388
1389 _outn(",");
1390 }
1391
1392 // MRRQualifierDecl.value:
1393 mike 1.1
1394 _outn(" /* value */");
1395 _out(" ");
1396 _writeValue(_os, cv, true);
1397 _outn(",");
1398
1399 _outn("};");
1400 _nl();
1401 }
1402
1403 template<class C>
1404 Array<CIMConstQualifier> _Qualifiers(const C& c)
1405 {
1406 Array<CIMConstQualifier> tmp;
1407
1408 for (Uint32 i = 0; i < c.getQualifierCount(); i++)
1409 tmp.append(c.getQualifier(i));
1410
1411 return tmp;
1412 }
1413
1414 mike 1.1 void cimmofMRR::_writeQualifierArray(
1415 const String& root,
1416 const Array<CIMConstQualifier>& qualifiers)
1417 {
1418 _outn("static const char*");
1419 _outn("%s_qualifiers[] =", *Str(root));
1420 _outn("{");
1421
1422 for (Uint32 i = 0; i < qualifiers.size(); i++)
1423 {
1424 CIMConstQualifier cq = qualifiers[i];
1425 CIMName qn = cq.getName();
1426 CIMType qt = cq.getType();
1427
1428 if (_discard && qn == "Description")
|
1429 karl 1.6 {
|
1430 mike 1.1 continue;
|
1431 karl 1.6 }
|
1432 mike 1.1
1433 #if 0
1434 if (qt == CIMTYPE_BOOLEAN && !cq.isArray())
|
1435 karl 1.6 {
|
1436 mike 1.1 continue;
|
1437 karl 1.6 }
|
1438 mike 1.1 #endif
1439
1440 _writeQualifier(_qualifiers, cq);
1441 }
1442
1443 // Write terminator:
1444 _outn(" 0,");
1445
1446 _outn("};");
1447 _nl();
1448 }
1449
1450 void cimmofMRR::_writeProperty(
1451 const CIMNamespaceName& nameSpace,
1452 const CIMName& cn,
1453 const CIMConstProperty& cp)
1454 {
1455 String ns = _makeIdent(nameSpace.getString());
1456 CIMName pn = cp.getName();
1457 CIMType ct = cp.getType();
1458 CIMValue cv = cp.getValue();
1459 mike 1.1
1460 String path = "_" + cn.getString() + "_" + pn.getString();
1461
1462 // Write qualifiers:
1463
1464 _writeQualifierArray(path, _Qualifiers(cp));
1465
1466 // Header:
1467
1468 if (ct == CIMTYPE_REFERENCE)
1469 _outn("static MRRReference");
1470 else
1471 _outn("static MRRProperty");
1472
1473 _outn("%s =", *Str(path));
1474 _outn("{");
1475
1476 // MRRProperty.flags:
1477
1478 _outn(" /* flags */");
1479
1480 mike 1.1 if (ct == CIMTYPE_REFERENCE)
1481 _out(" MRR_FLAG_REFERENCE");
1482 else
1483 _out(" MRR_FLAG_PROPERTY");
1484
1485 _writeFlags(_os, cp, true, false);
1486 fprintf(_os, ",\n");
1487
1488 // MRRProperty.name:
1489
1490 _outn(" /* name */");
1491 _outn(" (char*)\"%s\",", *Str(pn));
1492
1493 // MRRProperty.qualifiers:
1494
1495 _outn(" /* qualifiers */");
1496 _outn(" %s_qualifiers,", *Str(path));
1497
1498 // MRRProperty.type:
1499
1500 if (ct != CIMTYPE_REFERENCE)
1501 mike 1.1 {
1502 _outn(" /* type */");
1503 _outn(" %s,", _typeNames[ct]);
1504 }
1505
1506 // MRRProperty.subscript:
1507
1508 _outn(" /* subscript */");
1509
1510 if (cp.isArray())
1511 {
1512 Uint32 n = cp.getArraySize();
1513 _outn(" %u,", n);
1514 }
1515 else
1516 {
1517 _outn(" -1,");
1518 }
1519
1520 // MRRReference.ref:
1521
1522 mike 1.1 if (ct == CIMTYPE_REFERENCE)
1523 {
1524 const CIMName& rcn = cp.getReferenceClassName();
1525 _outn(" /* refId */");
1526 _outn(" &__%s_%s,", *Str(ns), *Str(rcn));
1527 }
1528
1529 // MRRQualifierDecl.value:
1530
1531 if (ct != CIMTYPE_REFERENCE)
1532 {
1533 _outn(" /* value */");
1534 _out(" ");
1535 _writeValue(_os, cv, true);
1536 _outn(",");
1537 }
1538
1539 _outn("};");
1540 _nl();
1541 }
1542
1543 mike 1.1 void cimmofMRR::_writeParameter(
1544 const CIMNamespaceName& nameSpace,
1545 const CIMName& cn,
1546 const CIMName& mn,
1547 const CIMConstParameter& cp)
1548 {
1549 String ns = _makeIdent(nameSpace.getString());
1550 CIMName pn = cp.getName();
1551 CIMType ct = cp.getType();
1552
|
1553 kumpf 1.4 String path =
|
1554 mike 1.1 "_" + cn.getString() + "_" + mn.getString() + "_" + pn.getString();
1555
1556 _writeQualifierArray(path, _Qualifiers(cp));
1557
1558 if (ct == CIMTYPE_REFERENCE)
1559 _outn("static MRRReference");
1560 else
1561 _outn("static MRRProperty");
1562
1563 _outn("%s =", *Str(path));
1564 _outn("{");
1565
1566 // MRRProperty.flags:
1567
1568 _outn(" /* flags */");
1569
1570 if (ct == CIMTYPE_REFERENCE)
1571 _out(" MRR_FLAG_REFERENCE");
1572 else
1573 _out(" MRR_FLAG_PROPERTY");
1574
1575 mike 1.1 _writeFlags(_os, cp, false, true);
1576 fprintf(_os, ",\n");
1577
1578 // MRRProperty.name:
1579
1580 _outn(" /* name */");
1581 _outn(" (char*)\"%s\",", *Str(pn));
1582
1583 // MRRProperty.qualifiers:
1584
1585 _outn(" /* qualifiers */");
1586 _outn(" %s_qualifiers,", *Str(path));
1587
1588 // MRRProperty.type:
1589
1590 if (ct != CIMTYPE_REFERENCE)
1591 {
1592 _outn(" /* type */");
1593 _outn(" %s,", _typeNames[ct]);
1594 }
1595
1596 mike 1.1 // MRRProperty.subscript:
1597
1598 _outn(" /* subscript */");
1599
1600 if (cp.isArray())
1601 {
1602 Uint32 n = cp.getArraySize();
1603 _outn(" %u,", n);
1604 }
1605 else
1606 {
1607 _outn(" -1,");
1608 }
1609
1610 // MRRProperty.ref:
1611
1612 if (ct == CIMTYPE_REFERENCE)
1613 {
1614 const CIMName& rcn = cp.getReferenceClassName();
1615 _outn(" /* ref */");
1616 _outn(" &__%s_%s,", *Str(ns), *Str(rcn));
1617 mike 1.1 }
1618
1619 // MRRQualifierDecl.value:
1620
1621 if (ct != CIMTYPE_REFERENCE)
1622 {
1623 _outn(" /* value */");
1624 _outn(" 0,");
1625 }
1626
1627 _outn("};");
1628 _nl();
1629 }
1630
1631 void cimmofMRR::_writeMethod(
1632 const CIMNamespaceName& nameSpace,
1633 const CIMName& cn,
1634 const CIMConstMethod& cm)
1635 {
1636 CIMName mn = cm.getName();
1637
1638 mike 1.1 // Write parameter definitions:
1639
1640 Array<CIMName> parameterNames;
1641
1642 for (Uint32 i = 0; i < cm.getParameterCount(); i++)
1643 {
1644 CIMConstParameter cp = cm.getParameter(i);
1645 _writeParameter(nameSpace, cn, mn, cp);
1646 parameterNames.append(cp.getName());
1647 }
1648
1649 // Write parameters array:
1650
1651 _outn("static MRRFeature*");
1652 _outn("_%s_%s_parameters[] =", *Str(cn), *Str(mn));
1653 _outn("{");
1654
1655 for (Uint32 i = 0; i < parameterNames.size(); i++)
1656 {
1657 const CIMName& pn = parameterNames[i];
1658 _outn(" (MRRFeature*)&_%s_%s_%s,", *Str(cn), *Str(mn), *Str(pn));
1659 mike 1.1 }
1660
1661 _outn(" 0,");
1662 _outn("};");
1663 _nl();
1664
1665 // Method header:
1666
1667 String path = "_" + cn.getString() + "_" + mn.getString();
1668
1669 _writeQualifierArray(path, _Qualifiers(cm));
1670
1671 _outn("static MRRMethod");
1672 _outn("%s =", *Str(path));
1673 _outn("{");
1674
1675 // MRRMethod.flags:
1676
1677 _outn(" /* flags */");
1678 _out(" MRR_FLAG_METHOD");
1679 _writeFlags(_os, cm, false, false);
1680 mike 1.1 fprintf(_os, ",\n");
1681
1682 // MRRMethod.name:
1683
1684 _outn(" /* name */");
1685 _outn(" (char*)\"%s\",", *Str(mn));
1686
1687 // MRRMethod.qualifiers:
1688
1689 _outn(" /* qualifiers */");
1690 _outn(" %s_qualifiers,", *Str(path));
1691
1692 // MRRProperty.type:
1693
1694 _outn(" /* type */");
1695 _outn(" %s,", _typeNames[cm.getType()]);
1696
1697 // MRRMethod.parameters:
1698
1699 _outn(" /* parameters */");
1700 _outn(" _%s_%s_parameters,", *Str(cn), *Str(mn));
1701 mike 1.1
1702 // Method footer:
1703
1704 _outn("};");
1705 _nl();
1706 }
1707
1708 void cimmofMRR::_writeClass(
1709 const CIMNamespaceName& nameSpace,
1710 const CIMClass& cc)
1711 {
1712 String ns = _makeIdent(nameSpace.getString());
1713 CIMName cn = cc.getClassName();
1714
1715 // Write comment:
1716
1717 _box(_os, "Class: %s", *Str(cn));
1718 _nl();
1719
1720 // Write property definitions:
1721
1722 mike 1.1 Array<CIMName> featureNames;
1723
1724 for (Uint32 i = 0; i < cc.getPropertyCount(); i++)
1725 {
1726 CIMConstProperty cp = cc.getProperty(i);
1727 _writeProperty(nameSpace, cc.getClassName(), cp);
1728 featureNames.append(cp.getName());
1729 }
1730
1731 // Write method definitions:
1732
1733 for (Uint32 i = 0; i < cc.getMethodCount(); i++)
1734 {
1735 CIMConstMethod cm = cc.getMethod(i);
1736 _writeMethod(nameSpace, cc.getClassName(), cm);
1737 featureNames.append(cm.getName());
1738 }
1739
1740 // Write feature array:
1741
1742 _outn("static MRRFeature*");
1743 mike 1.1 _outn("_%s_features[] =", *Str(cn));
1744 _outn("{");
1745
1746 for (Uint32 i = 0; i < featureNames.size(); i++)
1747 {
1748 const CIMName& fn = featureNames[i];
1749 _outn(" (MRRFeature*)&_%s_%s,", *Str(cn), *Str(fn));
1750 }
1751
1752 _outn(" 0,");
1753 _outn("};");
1754 _nl();
1755
1756 // Class header:
1757
1758 String path = "__" + ns + "_" + cn.getString();
1759
1760 _writeQualifierArray(path, _Qualifiers(cc));
1761
1762 _outn("MRRClass");
1763 _outn("%s =", *Str(path));
1764 mike 1.1 _outn("{");
1765
1766 // MRRClass.flags:
1767
1768 _outn(" /* flags */");
1769
1770 if (_testBooleanQualifier(cc, "Association"))
1771 _out(" MRR_FLAG_ASSOCIATION");
1772 else if (_testBooleanQualifier(cc, "Indication"))
1773 _out(" MRR_FLAG_INDICATION");
1774 else
1775 _out(" MRR_FLAG_CLASS");
1776
1777 _writeFlags(_os, cc, false, false);
1778 fprintf(_os, ",\n");
1779
1780 // MRRClass.name:
1781
1782 _outn(" /* name */");
1783 _outn(" (char*)\"%s\",", *Str(cn));
1784
1785 mike 1.1 // MRRClass.qualifiers:
1786
1787 _outn(" /* qualifiers */");
1788 _outn(" %s_qualifiers,", *Str(path));
1789
1790 // MRRClass.super:
1791
1792 const CIMName& scn = cc.getSuperClassName();
1793 _outn(" /* super */");
1794
1795 if (scn.isNull())
1796 _outn(" 0,");
1797 else
1798 _outn(" &__%s_%s,", *Str(ns), *Str(scn));
1799
1800 // MRRClass.features:
1801
1802 _outn(" /* features */");
1803 _outn(" _%s_features,", *Str(cn));
1804
1805 // Class footer:
1806 mike 1.1
1807 _outn("};");
1808 _nl();
1809 }
1810
1811 void cimmofMRR::_writeNameSpace(const CIMNamespaceName& nameSpace)
1812 {
1813 String ns = _makeIdent(nameSpace.getString());
1814
1815 // Write qualifiers:
1816
1817 _box(_os, "Qualifiers");
1818 _nl();
1819
1820 for (Uint32 i = 0; i < _qualifiers.size(); i++)
1821 {
1822 _writeQualifierDecl(_qualifiers[i]);
1823 }
1824
1825 // Forward declare all classes:
1826
1827 mike 1.1 _box(_os, "Forward class declarations");
1828
1829 _nl();
1830
1831 for (Uint32 i = 0; i < _classes.size(); i++)
1832 {
1833 CIMName cn = _classes[i].getClassName();
1834
1835 if (_includeClass(cn))
1836 _outn("extern MRRClass __%s_%s;", *Str(ns), *Str(cn));
1837 }
1838
1839 _nl();
1840
1841 // Write classes:
1842
1843 for (Uint32 i = 0; i < _classes.size(); i++)
1844 {
1845 CIMName cn = _classes[i].getClassName();
1846
1847 if (_includeClass(cn))
1848 mike 1.1 _writeClass(nameSpace, _classes[i]);
1849 }
1850
1851 // Write qualifiers list:
1852
1853 _box(_os, "Qualifier array");
1854 _nl();
1855
1856 _outn("static MRRQualifierDecl*");
1857 _outn("_qualifiers[] =");
1858 _outn("{");
1859 _indent++;
1860
1861 for (Uint32 i = 0; i < _qualifiers.size(); i++)
1862 {
1863 _outn("&_%s_qualifier_decl,", *Str(_qualifiers[i].getName()));
1864 }
1865
1866 _outn("0,");
1867
1868 _indent--;
1869 mike 1.1 _outn("};");
1870 _nl();
1871
1872 // Write classes list:
1873
1874 _box(_os, "Class array");
1875 _nl();
1876
1877 _outn("static MRRClass*");
1878 _outn("_classes[] =");
1879 _outn("{");
1880 _indent++;
1881
1882 for (Uint32 i = 0; i < _classes.size(); i++)
1883 {
1884 CIMName cn = _classes[i].getClassName();
1885
1886 if (_includeClass(cn))
1887 _outn("&__%s_%s,", *Str(ns), *Str(cn));
1888 }
1889
1890 mike 1.1 _outn("0,");
1891
1892 _indent--;
1893 _outn("};");
1894 _nl();
1895
1896 // Write MRRNameSpace structure:
1897
1898 _outn("const MRRNameSpace %s_namespace =", *Str(ns));
1899 _outn("{");
1900 _outn(" (char*)\"%s\",", *Str(nameSpace));
1901 _outn(" _qualifiers,");
1902 _outn(" _classes,");
1903 _outn("};");
1904 _nl();
1905 }
1906
1907 PEGASUS_FORMAT(2, 3)
1908 void cimmofMRR::_out(const char* format, ...)
1909 {
1910 va_list ap;
1911 mike 1.1 va_start(ap, format);
1912 _vout(_os, format, ap);
1913 va_end(ap);
1914 }
1915
1916 PEGASUS_FORMAT(2, 3)
1917 void cimmofMRR::_outn(const char* format, ...)
1918 {
1919 va_list ap;
1920 va_start(ap, format);
1921 _vout(_os, format, ap);
1922 va_end(ap);
1923 fputc('\n', _os);
1924 }
1925
1926 void cimmofMRR::_nl()
1927 {
1928 _out("\n");
1929 }
1930
1931 bool cimmofMRR::_includeClass(const CIMName& cn)
1932 mike 1.1 {
1933 if (_closure.size() == 0)
1934 return true;
1935
1936 for (Uint32 i = 0; i < _closure.size(); i++)
1937 {
1938 if (_closure[i] == cn)
1939 return true;
1940 }
1941
1942 return false;
1943 }
1944
1945 PEGASUS_NAMESPACE_END
|