29 mike 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "MRR.h"
33 #include <cstdarg>
34 #include <Pegasus/Common/Resolver.h>
35 #include <Pegasus/Common/Once.h>
36 #include <Pegasus/Common/System.h>
37 #include <Pegasus/Common/Tracer.h>
38 #include <Pegasus/Common/Pair.h>
39 #include "CIMRepository.h"
40 #include "RepositoryDeclContext.h"
41 #include "MRRSerialization.h"
42 #include "MRRTypes.h"
43
44 PEGASUS_NAMESPACE_BEGIN
45
46 typedef Pair<CIMNamespaceName, CIMInstance> NamespaceInstancePair;
47
48 #define PEGASUS_ARRAY_T NamespaceInstancePair
49 # include <Pegasus/Common/ArrayInter.h>
50 mike 1.1 #undef PEGASUS_ARRAY_T
51
52 class CIMRepositoryRep
53 {
54 public:
55
56 Uint32 _findInstance(
57 const CIMNamespaceName& nameSpace,
58 const CIMObjectPath& instanceName);
59
60 void _processSaveCallback();
61
62 void _processLoadCallback();
63
64 Array<NamespaceInstancePair> _rep;
65 };
66
67 typedef const MRRClass* ConstMRRClassPtr;
68 #define PEGASUS_ARRAY_T ConstMRRClassPtr
69 # include <Pegasus/Common/ArrayInter.h>
70 # include <Pegasus/Common/ArrayImpl.h>
71 mike 1.1 #undef PEGASUS_ARRAY_T
72
73 #define PEGASUS_ARRAY_T NamespaceInstancePair
74 # include <Pegasus/Common/ArrayImpl.h>
75 #undef PEGASUS_ARRAY_T
76
77 //==============================================================================
78 //
79 // Local definitions:
80 //
81 //==============================================================================
82
83 static size_t const _MAX_NAMESPACE_TABLE_SIZE = 64;
84 static const MRRNameSpace* _nameSpaceTable[_MAX_NAMESPACE_TABLE_SIZE];
85 static size_t _nameSpaceTableSize = 0;
86
87 class ThrowContext
88 {
89 public:
90
91 PEGASUS_FORMAT(3, 4)
92 mike 1.1 ThrowContext(CIMStatusCode code_, const char* format, ...) : code(code_)
93 {
94 char buffer[1024];
95 va_list ap;
96 va_start(ap, format);
97 vsprintf(buffer, format, ap);
98 va_end(ap);
99 msg = buffer;
100 }
101 CIMStatusCode code;
102 String msg;
103 };
104
105 #define Throw(ARGS) \
106 do \
107 { \
108 ThrowContext c ARGS; \
109 throw CIMException(c.code, c.msg); \
110 } \
111 while (0)
112
113 mike 1.1 class Str
114 {
115 public:
116 Str(const String& s) : _cstr(s.getCString()) { }
117 Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
118 Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
119 Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
120 Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
121 Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
122 const char* operator*() const { return (const char*)_cstr; }
123 operator const char*() const { return (const char*)_cstr; }
124 private:
125 CString _cstr;
126 };
127
128 /** Check to see if the specified property is in the property list
129 @param property the specified property
130 @param propertyList the property list
131 @return true if the property is in the list otherwise false.
132 */
133 static Boolean _containsProperty(
134 mike 1.1 CIMProperty& property,
135 const CIMPropertyList& propertyList)
136 {
137 // For each property in the propertly list
138 for (Uint32 p=0; p<propertyList.size(); p++)
139 {
140 if (propertyList[p].equal(property.getName()))
141 return true;
142 }
143 return false;
144 }
145
146 /* removes all Qualifiers from a CIMClass. This function removes all
147 of the qualifiers from the class, from all of the properties,
148 from the methods, and from the parameters attached to the methods.
149 @param cimClass reference to the class from which qualifiers are to
150 be removed.
151 NOTE: This would be logical to be moved to CIMClass since it may be
152 more general than this usage.
153 */
154 static void _removeAllQualifiers(CIMClass& cimClass)
155 mike 1.1 {
156 // remove qualifiers of the class
157 Uint32 count = 0;
158 while ((count = cimClass.getQualifierCount()) > 0)
159 cimClass.removeQualifier(count - 1);
160
161 // remove qualifiers from the properties
162 for (Uint32 i = 0; i < cimClass.getPropertyCount(); i++)
163 {
164 CIMProperty p = cimClass.getProperty(i);
165 count = 0;
166 while ((count = p.getQualifierCount()) > 0)
167 p.removeQualifier(count - 1);
168 }
169
170 // remove qualifiers from the methods
171 for (Uint32 i = 0; i < cimClass.getMethodCount(); i++)
172 {
173 CIMMethod m = cimClass.getMethod(i);
174 for (Uint32 j = 0 ; j < m.getParameterCount(); j++)
175 {
176 mike 1.1 CIMParameter p = m.getParameter(j);
177 count = 0;
178 while ((count = p.getQualifierCount()) > 0)
179 p.removeQualifier(count - 1);
180 }
181 count = 0;
182 while ((count = m.getQualifierCount()) > 0)
183 m.removeQualifier(count - 1);
184 }
185 }
186
187 /////////////////////////////////////////////////////////////////////////
188 //
189 // _removePropagatedQualifiers - Removes all qualifiers from the class
190 // that are marked propagated
191 //
192 /////////////////////////////////////////////////////////////////////////
193
194 /* removes propagatedQualifiers from the defined CIMClass.
195 This function removes the qualifiers from the class,
196 from each of the properties, from the methods and
197 mike 1.1 the parameters if the qualifiers are marked propagated.
198 NOTE: This could be logical to be moved to CIMClass since it may be
199 more general than the usage here.
200 */
201 static void _removePropagatedQualifiers(CIMClass& cimClass)
202 {
203 Uint32 count = cimClass.getQualifierCount();
204 // Remove nonlocal qualifiers from Class
205 for (Sint32 i = (count - 1); i >= 0; i--)
206 {
207 CIMQualifier q = cimClass.getQualifier(i);
208 if (q.getPropagated())
209 {
210 cimClass.removeQualifier(i);
211 }
212 }
213
214 // remove non localOnly qualifiers from the properties
215 for (Uint32 i = 0; i < cimClass.getPropertyCount(); i++)
216 {
217 CIMProperty p = cimClass.getProperty(i);
218 mike 1.1 // loop to search qualifiers for nonlocal parameters
219 count = p.getQualifierCount();
220 for (Sint32 j = (count - 1); j >= 0; j--)
221 {
222 CIMQualifier q = p.getQualifier(j);
223 if (q.getPropagated())
224 {
225 p.removeQualifier(j);
226 }
227 }
228 }
229
230 // remove non LocalOnly qualifiers from the methods and parameters
231 for (Uint32 i = 0; i < cimClass.getMethodCount(); i++)
232 {
233 CIMMethod m = cimClass.getMethod(i);
234 // Remove nonlocal qualifiers from all parameters
235 for (Uint32 j = 0 ; j < m.getParameterCount(); j++)
236 {
237 CIMParameter p = m.getParameter(j);
238 count = p.getQualifierCount();
239 mike 1.1 for (Sint32 k = (count - 1); k >= 0; k--)
240 {
241 CIMQualifier q = p.getQualifier(k);
242 if (q.getPropagated())
243 {
244 p.removeQualifier(k);
245 }
246 }
247 }
248
249 // remove nonlocal qualifiers from the method
250 count = m.getQualifierCount();
251 for (Sint32 j = (count - 1); j >= 0; j--)
252 {
253 CIMQualifier q = m.getQualifier(j);
254 if (q.getPropagated())
255 {
256 m.removeQualifier(j);
257 }
258 }
259 }
260 mike 1.1 }
261
262 /* remove the properties from an instance based on attributes.
263 @param Instance from which properties will be removed.
264 @param propertyList PropertyList is used in the removal algorithm
265 @param localOnly - Boolean used in the removal.
266 NOTE: This could be logical to move to CIMInstance since the
267 usage is more general than just in the repository
268 */
269 static void _removeProperties(
270 CIMInstance& cimInstance,
271 const CIMPropertyList& propertyList,
272 Boolean localOnly)
273 {
274 Boolean propertyListNull = propertyList.isNull();
275 if ((!propertyListNull) || localOnly)
276 {
277 // Loop through properties to remove those that do not filter through
278 // local only attribute and are not in the property list.
279 Uint32 count = cimInstance.getPropertyCount();
280 // Work backwards because removal may be cheaper. Sint32 covers count=0
281 mike 1.1 for (Sint32 i = (count - 1); i >= 0; i--)
282 {
283 CIMProperty p = cimInstance.getProperty(i);
284
285 // if localOnly == true, ignore properties defined in super class
286 if (localOnly && (p.getPropagated()))
287 {
288 cimInstance.removeProperty(i);
289 continue;
290 }
291
292 // propertyList NULL means deliver properties. PropertyList
293 // empty, none.
294 // Test for removal if propertyList not NULL. The empty list option
295 // is covered by fact that property is not in the list.
296 if (!propertyListNull)
297 if (!_containsProperty(p, propertyList))
298 cimInstance.removeProperty(i);
299 }
300 }
301 }
302 mike 1.1
303 /* remove all Qualifiers from a single CIMInstance. Removes
304 all of the qualifiers from the instance and from properties
305 within the instance.
306 @param instance from which parameters are removed.
307 NOTE: This could be logical to be moved to CIMInstance since
308 the usage may be more general than just in the repository.
309 */
310 static void _removeAllQualifiers(CIMInstance& cimInstance)
311 {
312 // remove qualifiers from the instance
313 Uint32 count = 0;
314 while ((count = cimInstance.getQualifierCount()) > 0)
315 cimInstance.removeQualifier(count - 1);
316
317 // remove qualifiers from the properties
318 for (Uint32 i = 0; i < cimInstance.getPropertyCount(); i++)
319 {
320 CIMProperty p = cimInstance.getProperty(i);
321 count = 0;
322 while ((count = p.getQualifierCount()) > 0)
323 mike 1.1 p.removeQualifier(count - 1);
324 }
325 }
326
327 /* removes all ClassOrigin attributes from a single CIMInstance. Removes
328 the classOrigin attribute from each property in the Instance.
329 @param Instance from which the ClassOrigin Properties will be removed.
330 NOTE: Logical to be moved to CIMInstance since it may be more general
331 than just the repositoryl
332 */
333 void _removeClassOrigins(CIMInstance& cimInstance)
334 {
335 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4, "Remove Class Origins");
336
337 Uint32 propertyCount = cimInstance.getPropertyCount();
338 for (Uint32 i = 0; i < propertyCount ; i++)
339 cimInstance.getProperty(i).setClassOrigin(CIMName());
340 }
341
342 /* Filters the properties, qualifiers, and classorigin out of a single instance.
343 Based on the parameters provided for localOnly, includeQualifiers,
344 mike 1.1 and includeClassOrigin, this function simply filters the properties
345 qualifiers, and classOrigins out of a single instance. This function
346 was created to have a single piece of code that processes getinstance
347 and enumerateInstances returns.
348 @param cimInstance reference to instance to be processed.
349 @param localOnly defines if request is for localOnly parameters.
350 @param includeQualifiers Boolean defining if qualifiers to be returned.
351 @param includeClassOrigin Boolean defining if ClassOrigin attribute to
352 be removed from properties.
353 */
354 static void _filterInstance(
355 CIMInstance& cimInstance,
356 Boolean localOnly,
357 Boolean includeQualifiers,
358 Boolean includeClassOrigin,
359 const CIMPropertyList& propertyList)
360 {
361 // Remove properties based on propertyList and localOnly flag
362 _removeProperties(cimInstance, propertyList, localOnly);
363
364 // If includequalifiers false, remove all qualifiers from
365 mike 1.1 // properties.
366
367 if (!includeQualifiers)
368 {
369 _removeAllQualifiers(cimInstance);
370 }
371
372 // if ClassOrigin Flag false, remove classOrigin info from Instance object
373 // by setting the classOrigin to Null.
374
375 if (!includeClassOrigin)
376 {
377 _removeClassOrigins(cimInstance);
378 }
379 }
380
381 static void _filterClass(
382 CIMClass& cimClass,
383 Boolean localOnly,
384 Boolean includeQualifiers,
385 Boolean includeClassOrigin,
386 mike 1.1 const CIMPropertyList& propertyList)
387 {
388 // Remove properties based on propertylist and localOnly flag (Bug 565)
389 Boolean propertyListNull = propertyList.isNull();
390
391 // if localOnly OR there is a property list, process properties
392 if ((!propertyListNull) || localOnly)
393 {
394 // Loop through properties to remove those that do not filter through
395 // local only attribute and are not in the property list.
396 Uint32 count = cimClass.getPropertyCount();
397 // Work backwards because removal may be cheaper. Sint32 covers count=0
398 for (Sint32 i = (count - 1); i >= 0; i--)
399 {
400 CIMProperty p = cimClass.getProperty(i);
401 // if localOnly==true, ignore properties defined in super class
402 if (localOnly && (p.getPropagated()))
403 {
404 cimClass.removeProperty(i);
405 continue;
406 }
407 mike 1.1
408 // propertyList NULL means all properties. PropertyList
409 // empty, none.
410 // Test for removal if propertyList not NULL. The empty list option
411 // is covered by fact that property is not in the list.
412 if (!propertyListNull)
413 if (!_containsProperty(p, propertyList))
414 cimClass.removeProperty(i);
415 }
416 }
417
418 // remove methods based on localOnly flag
419 if (localOnly)
420 {
421 Uint32 count = cimClass.getMethodCount();
422 // Work backwards because removal may be cheaper.
423 for (Sint32 i = (count - 1); i >= 0; i--)
424 {
425 CIMMethod m = cimClass.getMethod(i);
426
427 // if localOnly==true, ignore properties defined in super class
428 mike 1.1 if (localOnly && (m.getPropagated()))
429 cimClass.removeMethod(i);
430 }
431
432 }
433 // If includequalifiers false, remove all qualifiers from
434 // properties, methods and parameters.
435 if (!includeQualifiers)
436 {
437 _removeAllQualifiers(cimClass);
438 }
439 else
440 {
441 // if includequalifiers and localOnly, remove nonLocal qualifiers
442 if (localOnly)
443 {
444 _removePropagatedQualifiers(cimClass);
445 }
446
447 }
448
449 mike 1.1
450 // if ClassOrigin Flag false, remove classOrigin info from class object
451 // by setting the property to Null.
452 if (!includeClassOrigin)
453 {
454 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
455 "Remove Class Origins");
456
457 Uint32 propertyCount = cimClass.getPropertyCount();
458 for (Uint32 i = 0; i < propertyCount ; i++)
459 cimClass.getProperty(i).setClassOrigin(CIMName());
460
461 Uint32 methodCount = cimClass.getMethodCount();
462 for (Uint32 i=0; i < methodCount ; i++)
463 cimClass.getMethod(i).setClassOrigin(CIMName());
464 }
465 }
466
467
468 static bool _contains(const CIMPropertyList& propertyList, const CIMName& name)
469 {
470 mike 1.1 for (Uint32 i = 0; i < propertyList.size(); i++)
471 {
472 if (propertyList[i] == name)
473 return true;
474 }
475
476 return false;
477 }
478
479 static void _applyModifiedInstance(
480 const MRRClass* sc,
481 const CIMInstance& modifiedInstance_,
482 const CIMPropertyList& propertyList,
483 CIMInstance& resultInstance)
484 {
485 CIMInstance& modifiedInstance = *((CIMInstance*)&modifiedInstance_);
486
487 for (Uint32 i = 0; i < modifiedInstance.getPropertyCount(); i++)
488 {
489 CIMProperty cp = modifiedInstance.getProperty(i);
490 Uint32 pos = resultInstance.findProperty(cp.getName());
491 mike 1.1
492 if (propertyList.isNull() || _contains(propertyList, cp.getName()))
493 {
494 // Reject attempts to add properties not in class:
495
496 const MRRFeature* sf = FindFeature(sc,
497 *Str(cp.getName()), MRR_FLAG_PROPERTY|MRR_FLAG_REFERENCE);
498
499 if (!sf)
500 {
501 Throw((CIM_ERR_NOT_FOUND,
502 "modifyInstance() failed: unknown property: %s",
503 *Str(cp.getName())));
504 }
505
506 // Reject attempts to modify key properties:
507
508 if (sf->flags & MRR_FLAG_KEY)
509 {
510 Throw((CIM_ERR_FAILED,
511 "modifyInstance() failed to modify key property: %s",
512 mike 1.1 *Str(cp.getName())));
513 }
514
515 // Add or replace property in result instance:
516
517 if (pos != PEG_NOT_FOUND)
518 resultInstance.removeProperty(pos);
519
520 resultInstance.addProperty(cp);
521 }
522 }
523 }
524
525 static void _print(const CIMInstance& ci)
526 {
527 CIMObject co(ci);
528
529 std::cout << co.toString() << std::endl;
530 }
531
532 static Once _once = PEGASUS_ONCE_INITIALIZER;
533 mike 1.1 static const char* _hostName = 0;
534
535 static void _initHostName()
536 {
537 String hn = System::getHostName();
538 _hostName = strdup(*Str(hn));
539 }
540
541 static inline const char* _getHostName()
542 {
543 once(&_once, _initHostName);
544 return _hostName;
545 }
546
547 static bool _eqi(const char* s1, const char* s2)
548 {
549 return System::strcasecmp(s1, s2) == 0;
550 }
551
552 static const MRRNameSpace* _findNameSpace(const char* name)
553 {
554 mike 1.1 for (size_t i = 0; i < _nameSpaceTableSize; i++)
555 {
556 const MRRNameSpace* ns = _nameSpaceTable[i];
557
558 if (_eqi(ns->name, name))
559 return ns;
560 }
561
562 // Not found!
563 return 0;
564 }
565
566 static bool _isSubClass(const MRRClass* super, const MRRClass* sub)
567 {
568 if (!super)
569 return true;
570
571 for (MRRClass* p = sub->super; p; p = p->super)
572 {
573 if (p == super)
574 return true;
575 mike 1.1 }
576
577 return false;
578 }
579
580 static inline bool _isDirectSubClass(
581 const MRRClass* super,
582 const MRRClass* sub)
583 {
584 return sub->super == super;
585 }
586
587 static char** _makePropertyList(const CIMPropertyList& propertyList)
588 {
589 if (propertyList.isNull())
590 return 0;
591
592 size_t size = propertyList.size();
593 char** pl = (char**)malloc(sizeof(char*) * (size + 1));
594
595 for (size_t i = 0; i < size; i++)
596 mike 1.1 pl[i] = strdup(*Str(propertyList[i]));
597
598 pl[size] = 0;
599
600 return pl;
601 }
602
603 static void _freePropertyList(char** pl)
604 {
605 if (!pl)
606 return;
607
608 for (size_t i = 0; pl[i]; i++)
609 {
610 free(pl[i]);
611 }
612
613 free(pl);
614 }
615
616 static void _printPropertyList(const char* const* pl)
617 mike 1.1 {
618 if (!pl)
619 return;
620
621 for (size_t i = 0; pl[i]; i++)
622 printf("pl[%s]\n", pl[i]);
623 }
624
625 static bool _contains(const Array<const MRRClass*>& x, const MRRClass* sc)
626 {
627 Uint32 n = x.size();
628 const MRRClass* const* p = x.getData();
629
630 while (n--)
631 {
632 if (*p++ == sc)
633 return true;
634 }
635
636 return false;
637 }
638 mike 1.1
639 static void _associators(
640 const MRRNameSpace* ns,
641 const CIMName& className,
642 const CIMName& assocClass,
643 const CIMName& resultClass,
644 const String& role,
645 const String& resultRole,
646 Array<const MRRClass*>& result)
647 {
648 // Lookup source class:
649
650 const MRRClass* sc = FindClass(ns, *Str(className));
651
652 if (!sc)
653 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)));
654
655
656 // Lookup result class (if any).
657
658 const MRRClass* rmc = 0;
659 mike 1.1
660 if (!resultClass.isNull())
661 {
662 rmc = FindClass(ns, *Str(resultClass));
663
664 if (!rmc)
665 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(resultClass)));
666 }
667
668 // Convert these to UTF8 now to avoid doing so in loop below.
669
670 Str ac(assocClass);
671 Str r(role);
672 Str rr(resultRole);
673
674 // Process association classes:
675
676 for (size_t i = 0; ns->classes[i]; i++)
677 {
678 MRRClass* amc = ns->classes[i];
679
680 mike 1.1 // Skip non-association classes:
681
682 if (!(amc->flags & MRR_FLAG_ASSOCIATION))
683 continue;
684
685 // Filter by assocClass parameter:
686
687 if (!assocClass.isNull() && !_eqi(ac, amc->name))
688 continue;
689
690 // Process reference properties:
691
692 MRRFeatureInfo features[MRR_MAX_FEATURES];
693 size_t size = 0;
694 MergeFeatures(amc, false, MRR_FLAG_REFERENCE, features, size);
695
696 for (size_t j = 0; j < size; j++)
697 {
698 const MRRFeature* sf = features[j].sf;
699
700 // Skip non references:
701 mike 1.1
702 if (!(sf->flags & MRR_FLAG_REFERENCE))
703 continue;
704
705 const MRRReference* sr = (const MRRReference*)sf;
706
707 // Filter by role parameter.
708
709 if (role.size() && !_eqi(r, sf->name))
710 continue;
711
712 // Filter by source class:
713
714 if (!IsA(sr->ref, sc))
715 continue;
716
717 // Process result reference:
718
719 for (size_t k = 0; k < size; k++)
720 {
721 const MRRFeature* rmf = features[k].sf;
722 mike 1.1
723 // Skip the feature under consideration:
724
725 if (rmf == sf)
726 continue;
727
728 // Skip non references:
729
730 if (!(rmf->flags & MRR_FLAG_REFERENCE))
731 continue;
732
733 const MRRReference* rmr = (const MRRReference*)rmf;
734
735 // Filter by resultRole parameter.
736
737 if (resultRole.size() && !_eqi(rr, rmf->name))
738 continue;
739
740 // Skip references not of the result class kind:
741
742 if (rmc && !IsA(rmr->ref, rmc))
743 mike 1.1 continue;
744
745 // ATTN: should we include entire class hierarchy under
746 // result class?
747
748 // If reached, then save this one.
749
750 if (!_contains(result, rmr->ref))
751 result.append(rmr->ref);
752 }
753 }
754 }
755 }
756
757 static void _references(
758 const MRRNameSpace* ns,
759 const CIMName& className,
760 const CIMName& resultClass,
761 const String& role,
762 Array<const MRRClass*>& result)
763 {
764 mike 1.1 // Lookup source class:
765
766 const MRRClass* sc = FindClass(ns, *Str(className));
767
768 if (!sc)
769 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)));
770
771 // Lookup result class (if any).
772
773 const MRRClass* rmc = 0;
774
775 if (!resultClass.isNull())
776 {
777 rmc = FindClass(ns, *Str(resultClass));
778
779 if (!rmc)
780 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(resultClass)));
781 }
782
783 // Convert these to UTF8 now to avoid doing so in loop below.
784
785 mike 1.1 Str r(role);
786
787 // Process association classes:
788
789 for (size_t i = 0; ns->classes[i]; i++)
790 {
791 MRRClass* amc = ns->classes[i];
792
793 // Skip non-association classes:
794
795 if (!(amc->flags & MRR_FLAG_ASSOCIATION))
796 continue;
797
798 // Filter by result class:
799
800 if (rmc && !IsA(rmc, amc))
801 continue;
802
803 // Process reference properties:
804
805 MRRFeatureInfo features[MRR_MAX_FEATURES];
806 mike 1.1 size_t size = 0;
807 MergeFeatures(amc, false, MRR_FLAG_REFERENCE, features, size);
808
809 for (size_t j = 0; j < size; j++)
810 {
811 const MRRFeature* sf = features[j].sf;
812
813 // Skip non references:
814
815 if (!(sf->flags & MRR_FLAG_REFERENCE))
816 continue;
817
818 const MRRReference* sr = (const MRRReference*)sf;
819
820 // Filter by role parameter.
821
822 if (role.size() && !_eqi(r, sf->name))
823 continue;
824
825 // Filter by source class:
826
827 mike 1.1 if (!IsA(sr->ref, sc))
828 continue;
829
830 // Add this one to the output:
831
832 if (!_contains(result, amc))
833 result.append((MRRClass*)amc);
834 }
835 }
836 }
837
838 static const MRRClass* _findMRRClass(
839 const char* nameSpace,
840 const char* className)
841 {
842 // Lookup namespace:
843
844 const MRRNameSpace* ns = _findNameSpace(nameSpace);
845
846 if (!ns)
847 return 0;
848 mike 1.1
849 return FindClass(ns, className);
850 }
851
852 static Array<CIMName> _enumerateClassNames(
853 const CIMNamespaceName& nameSpace,
854 const CIMName& className,
855 Boolean deepInheritance)
856 {
857 // Lookup namespace:
858
859 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
860
861 if (!ns)
862 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
863
864 // Lookup class:
865
866 const MRRClass* super = 0;
867
868 if (!className.isNull())
869 mike 1.1 {
870 super = FindClass(ns, *Str(className));
871
872 if (!super)
873 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)));
874 }
875
876 // Iterate all classes looking for matches:
877
878 Array<CIMName> result;
879
880 for (size_t i = 0; ns->classes[i]; i++)
881 {
882 MRRClass* sc = ns->classes[i];
883
884 if (deepInheritance)
885 {
886 if (_isSubClass(super, sc))
887 result.append(sc->name);
888 }
889 else
890 mike 1.1 {
891 if (_isDirectSubClass(super, sc))
892 result.append(sc->name);
893 }
894 }
895
896 return result;
897 }
898
899 static void _getSubClassNames(
900 const CIMNamespaceName& nameSpace,
901 const CIMName& className,
902 Boolean deepInheritance,
903 Array<CIMName>& subClassNames)
904 {
905 subClassNames = _enumerateClassNames(
906 nameSpace, className, deepInheritance);
907 }
908
909 static Array<CIMObject> _associatorClasses(
910 const CIMNamespaceName& nameSpace,
911 mike 1.1 const CIMName& className,
912 const CIMName& assocClass,
913 const CIMName& resultClass,
914 const String& role,
915 const String& resultRole,
916 Boolean includeQualifiers,
917 Boolean includeClassOrigin,
918 const CIMPropertyList& propertyList)
919 {
920 // Lookup namespace:
921
922 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
923
924 if (!ns)
925 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
926
927 // Get associator schema-classes:
928
929 Array<const MRRClass*> mcs;
930 _associators(ns, className, assocClass, resultClass, role, resultRole, mcs);
931
932 mike 1.1 // Convert schema-classes to classes.
933
934 Array<CIMObject> result;
935
936 char** pl = _makePropertyList(propertyList);
937
938 for (Uint32 i = 0; i < mcs.size(); i++)
939 {
940 const MRRClass* sc = mcs[i];
941 CIMClass cc;
942
943 if (MakeClass(_getHostName(), ns, sc, false, includeQualifiers,
944 includeClassOrigin, pl, cc) != 0)
945 {
946 _freePropertyList(pl);
947 Throw((CIM_ERR_FAILED, "conversion failed: %s", sc->name));
948 }
949
950 result.append(cc);
951 }
952
953 mike 1.1 _freePropertyList(pl);
954 return result;
955 }
956
957 static Array<CIMObjectPath> _associatorClassPaths(
958 const CIMNamespaceName& nameSpace,
959 const CIMName& className,
960 const CIMName& assocClass,
961 const CIMName& resultClass,
962 const String& role,
963 const String& resultRole)
964 {
965 // Lookup namespace:
966
967 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
968
969 if (!ns)
970 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
971
972 // Get associator schema-classes:
973
974 mike 1.1 Array<const MRRClass*> mcs;
975 _associators(ns, className, assocClass, resultClass, role, resultRole, mcs);
976
977 // Convert schema-classes to object names:
978
979 Array<CIMObjectPath> result;
980
981 for (Uint32 i = 0; i < mcs.size(); i++)
982 result.append(CIMObjectPath(_getHostName(), nameSpace, mcs[i]->name));
983
984 return result;
985 }
986
987 static Array<CIMObject> _referenceClasses(
988 const CIMNamespaceName& nameSpace,
989 const CIMName& className,
990 const CIMName& resultClass,
991 const String& role,
992 Boolean includeQualifiers,
993 Boolean includeClassOrigin,
994 const CIMPropertyList& propertyList)
995 mike 1.1 {
996 // Lookup namespace:
997
998 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
999
1000 if (!ns)
1001 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
1002
1003 // Get reference schema-classes:
1004
1005 Array<const MRRClass*> mcs;
1006 _references(ns, className, resultClass, role, mcs);
1007
1008 // Convert schema-classes to classes.
1009
1010 Array<CIMObject> result;
1011
1012 char** pl = _makePropertyList(propertyList);
1013
1014 for (Uint32 i = 0; i < mcs.size(); i++)
1015 {
1016 mike 1.1 const MRRClass* sc = mcs[i];
1017 CIMClass cc;
1018
1019 if (MakeClass(_getHostName(), ns, sc, false, includeQualifiers,
1020 includeClassOrigin, pl, cc) != 0)
1021 {
1022 _freePropertyList(pl);
1023 Throw((CIM_ERR_FAILED, "conversion failed: %s", sc->name));
1024 }
1025
1026 result.append(cc);
1027 }
1028
1029 _freePropertyList(pl);
1030 return result;
1031 }
1032
1033 static Array<CIMObjectPath> _referenceClassPaths(
1034 const CIMNamespaceName& nameSpace,
1035 const CIMName& className,
1036 const CIMName& resultClass,
1037 mike 1.1 const String& role)
1038 {
1039 // Lookup namespace:
1040
1041 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
1042
1043 if (!ns)
1044 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
1045
1046 // Get reference schema-classes:
1047
1048 Array<const MRRClass*> mcs;
1049 _references(ns, className, resultClass, role, mcs);
1050
1051 // Convert schema-classes to object paths.
1052
1053 Array<CIMObjectPath> result;
1054
1055 for (Uint32 i = 0; i < mcs.size(); i++)
1056 result.append(CIMObjectPath(_getHostName(), nameSpace, mcs[i]->name));
1057
1058 mike 1.1 return result;
1059 }
1060
1061 static CIMQualifierDecl _getQualifier(
1062 const CIMNamespaceName& nameSpace,
1063 const CIMName& qualifierName)
1064 {
1065 // Lookup namespace:
1066
1067 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
1068
1069 if (!ns)
1070 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
1071
1072 // Lookup qualifier:
1073
1074 const MRRQualifierDecl* mqd = FindQualifierDecl(ns, *Str(qualifierName));
1075
1076 if (!mqd)
1077 Throw((CIM_ERR_NOT_FOUND,
1078 "unknown qualifier: %s", *Str(qualifierName)));
1079 mike 1.1
1080 // Make the qualifier declaration:
1081
1082 CIMQualifierDecl cqd;
1083
1084 if (MakeQualifierDecl(ns, mqd, cqd) != 0)
1085 {
1086 Throw((CIM_ERR_FAILED, "conversion failed: %s", mqd->name));
1087 }
1088
1089 return cqd;
1090 }
1091
1092 static Array<CIMQualifierDecl> _enumerateQualifiers(
1093 const CIMNamespaceName& nameSpace)
1094 {
1095 // Lookup namespace:
1096
1097 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
1098
1099 if (!ns)
1100 mike 1.1 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
1101
1102 // Build the array of qualifier declarations:
1103
1104 Array<CIMQualifierDecl> result;
1105
1106 for (size_t i = 0; ns->qualifiers[i]; i++)
1107 {
1108 const MRRQualifierDecl* mqd = ns->qualifiers[i];
1109 CIMQualifierDecl cqd;
1110
1111 if (MakeQualifierDecl(ns, mqd, cqd) != 0)
1112 {
1113 Throw((CIM_ERR_FAILED, "conversion failed: %s", mqd->name));
1114 }
1115
1116 result.append(cqd);
1117 }
1118
1119 return result;
1120
1121 mike 1.1 }
1122
1123 static Array<CIMNamespaceName> _enumerateNameSpaces()
1124 {
1125 Array<CIMNamespaceName> result;
1126
1127 for (size_t i = 0; i < _nameSpaceTableSize; i++)
1128 {
1129 const MRRNameSpace* ns = _nameSpaceTable[i];
1130 result.append(ns->name);
1131 }
1132
1133 return result;
1134 }
1135
1136 static void _getSuperClassNames(
1137 const CIMNamespaceName& nameSpace,
1138 const CIMName& className,
1139 Array<CIMName>& superClassNames)
1140 {
1141 superClassNames.clear();
1142 mike 1.1
1143 // Lookup namespace:
1144
1145 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
1146
1147 if (!ns)
1148 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
1149
1150 // Lookup class:
1151
1152 const MRRClass* sc = FindClass(ns, *Str(className));
1153
1154 if (!sc)
1155 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)));
1156
1157 // Append superclass names:
1158
1159 for (const MRRClass* p = sc->super; p; p = p->super)
1160 superClassNames.append(p->name);
1161 }
1162
1163 mike 1.1 //==============================================================================
1164 //
1165 // class CIMRepository:
1166 //
1167 //==============================================================================
1168
1169 static void (*_saveCallback)(const Buffer& buffer, void* data);
1170 static void* _saveData;
1171
1172 static void (*_loadCallback)(Buffer& buffer, void* data);
1173 static void* _loadData;
1174
1175 static void (*_initializeCallback)(CIMRepository* rep, void* data);
1176 static void* _initializeData;
1177
1178 CIMRepository::CIMRepository(
1179 const String& repositoryRoot,
1180 Uint32 mode,
1181 RepositoryDeclContext* declContext)
1182 {
1183 /* ATTN: declContext is not used here! */
1184 mike 1.1
1185 _rep = new CIMRepositoryRep;
1186
1187 // Load users data if any:
1188 _rep->_processLoadCallback();
1189
1190 // Call initialize callback if any.
1191
1192 if (_initializeCallback)
1193 (*_initializeCallback)(this, _initializeData);
1194 }
1195
1196 CIMRepository::~CIMRepository()
1197 {
1198 delete _rep;
1199 }
1200
1201 CIMClass CIMRepository::getClass(
1202 const CIMNamespaceName& nameSpace,
1203 const CIMName& className,
1204 Boolean localOnly,
1205 mike 1.1 Boolean includeQualifiers,
1206 Boolean includeClassOrigin,
1207 const CIMPropertyList& propertyList)
1208 {
1209 // Lookup namespace:
1210
1211 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
1212
1213 if (!ns)
1214 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
1215
1216 // Lookup class:
1217
1218 const MRRClass* sc = FindClass(ns, *Str(className));
1219
1220 if (!sc)
1221 {
1222 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)));
1223 }
1224
1225 // Build property list:
1226 mike 1.1
1227 char** pl = _makePropertyList(propertyList);
1228
1229 // Make class:
1230
1231 CIMClass cc;
1232
1233 if (MakeClass(_getHostName(), ns, sc, localOnly, includeQualifiers,
1234 includeClassOrigin, pl, cc) != 0)
1235 {
1236 _freePropertyList(pl);
1237 Throw((CIM_ERR_FAILED, "conversion failed: %s", sc->name));
1238 }
1239
1240 _freePropertyList(pl);
1241 return cc;
1242 }
1243
1244 CIMInstance CIMRepository::getInstance(
1245 const CIMNamespaceName& nameSpace,
1246 const CIMObjectPath& instanceName,
1247 mike 1.1 Boolean localOnly,
1248 Boolean includeQualifiers,
1249 Boolean includeClassOrigin,
1250 const CIMPropertyList& propertyList)
1251 {
1252 Uint32 pos = _rep->_findInstance(nameSpace, instanceName);
1253
1254 if (pos == PEG_NOT_FOUND)
1255 Throw((CIM_ERR_NOT_FOUND, "%s", *Str(instanceName)));
1256
1257 CIMInstance cimInstance = _rep->_rep[pos].second.clone();
1258
1259 _filterInstance(
1260 cimInstance,
1261 localOnly,
1262 includeQualifiers,
1263 includeClassOrigin,
1264 propertyList);
1265
1266 return cimInstance;
1267 }
1268 mike 1.1
1269 void CIMRepository::deleteClass(
1270 const CIMNamespaceName& nameSpace,
1271 const CIMName& className)
1272 {
1273 Throw((CIM_ERR_NOT_SUPPORTED, "deleteClass()"));
1274 }
1275
1276 void CIMRepository::deleteInstance(
1277 const CIMNamespaceName& nameSpace,
1278 const CIMObjectPath& instanceName)
1279 {
1280 Uint32 pos = _rep->_findInstance(nameSpace, instanceName);
1281
1282 if (pos == PEG_NOT_FOUND)
1283 Throw((CIM_ERR_NOT_FOUND, "%s", *Str(instanceName)));
1284
1285 _rep->_rep.remove(pos);
1286 _rep->_processSaveCallback();
1287 }
1288
1289 mike 1.1 void CIMRepository::createClass(
1290 const CIMNamespaceName& nameSpace,
|
1336 mike 1.1 {
1337 const CIMObjectPath& cop = modifiedInstance.getPath();
1338 CIMName className = cop.getClassName();
1339
1340 // Get the schema-class for this instance.
1341
1342 const MRRClass* sc = _findMRRClass(*Str(nameSpace), *Str(className));
1343
1344 if (!sc)
1345 {
1346 Throw((CIM_ERR_FAILED,
1347 "modifyInstance() failed: unknown class: %s:%s",
1348 *Str(nameSpace), *Str(className)));
1349 }
1350
1351 // Get original instance to be modified:
1352
1353 Uint32 pos = _rep->_findInstance(nameSpace, cop);
1354
1355 if (pos == PEG_NOT_FOUND)
1356 {
1357 mike 1.1 Throw((CIM_ERR_NOT_FOUND,
1358 "modifyInstance() failed: unknown instance: %s",
1359 *Str(cop.toString())));
1360 }
1361
1362 CIMInstance resultInstance = _rep->_rep[pos].second.clone();
1363
1364 // Apply features of modifiedInstance to result instance.
1365
1366 _applyModifiedInstance(sc, modifiedInstance, propertyList, resultInstance);
1367
1368 // Resolve the instance.
1369
1370 CIMConstClass cc;
1371 RepositoryDeclContext context;
1372 context.setRepository(this);
1373 Resolver::resolveInstance(resultInstance, &context, nameSpace, cc, false);
1374
1375 // Replace original instance.
1376
1377 _rep->_rep[pos].second = resultInstance;
1378 mike 1.1 _rep->_processSaveCallback();
1379 }
1380
1381 Array<CIMClass> CIMRepository::enumerateClasses(
1382 const CIMNamespaceName& nameSpace,
1383 const CIMName& className,
1384 Boolean deepInheritance,
1385 Boolean localOnly,
1386 Boolean includeQualifiers,
1387 Boolean includeClassOrigin)
1388 {
1389 // Lookup namespace:
1390
1391 const MRRNameSpace* ns = _findNameSpace(*Str(nameSpace));
1392
1393 if (!ns)
1394 Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)));
1395
1396 // Lookup class:
1397
1398 const MRRClass* super = 0;
1399 mike 1.1
1400 if (!className.isNull())
1401 {
1402 super = FindClass(ns, *Str(className));
1403
1404 if (!super)
1405 Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)));
1406 }
1407
1408 // Iterate all classes looking for matches:
1409
1410 Array<CIMClass> result;
1411
1412 for (size_t i = 0; ns->classes[i]; i++)
1413 {
1414 MRRClass* sc = ns->classes[i];
1415
1416 bool flag = false;
1417
1418 if (deepInheritance)
1419 {
1420 mike 1.1 if (_isSubClass(super, sc))
1421 flag = true;
1422 }
1423 else
1424 {
1425 if (_isDirectSubClass(super, sc))
1426 flag = true;
1427 }
1428
1429 if (flag)
1430 {
1431 CIMClass cc;
1432
1433 if (MakeClass(_getHostName(), ns, sc, localOnly, includeQualifiers,
1434 includeClassOrigin, 0, cc) != 0)
1435 {
1436 Throw((CIM_ERR_FAILED, "conversion failed: %s", sc->name));
1437 }
1438
1439 result.append(cc);
1440 }
1441 mike 1.1 }
1442
1443 return result;
1444 }
1445
1446 Array<CIMName> CIMRepository::enumerateClassNames(
1447 const CIMNamespaceName& nameSpace,
1448 const CIMName& className,
1449 Boolean deepInheritance)
1450 {
1451 return _enumerateClassNames(nameSpace, className, deepInheritance);
1452 }
1453
1454 Array<CIMInstance> CIMRepository::enumerateInstancesForSubtree(
1455 const CIMNamespaceName& nameSpace,
1456 const CIMName& className,
1457 Boolean deepInheritance,
1458 Boolean localOnly,
1459 Boolean includeQualifiers,
1460 Boolean includeClassOrigin,
1461 const CIMPropertyList& propertyList)
1462 mike 1.1 {
1463 // Form array of classnames for this class and descendent classes:
1464
1465 Array<CIMName> classNames;
1466 classNames.append(className);
1467 _getSubClassNames(nameSpace, className, true, classNames);
1468
1469 // Get all instances for this class and all descendent classes
1470
1471 Array<CIMInstance> result;
1472
1473 for (Uint32 i = 0; i < classNames.size(); i++)
1474 {
1475 Array<CIMInstance> instances = enumerateInstancesForClass(
1476 nameSpace, classNames[i], false, includeQualifiers,
1477 includeClassOrigin, propertyList);
1478
1479 for (Uint32 i = 0 ; i < instances.size(); i++)
1480 {
1481 _filterInstance(
1482 instances[i],
1483 mike 1.1 localOnly,
1484 includeQualifiers,
1485 includeClassOrigin,
1486 propertyList);
1487 }
1488
1489 result.appendArray(instances);
1490 }
1491
1492 return result;
1493 }
1494
1495 Array<CIMInstance> CIMRepository::enumerateInstancesForClass(
1496 const CIMNamespaceName& nameSpace,
1497 const CIMName& className,
1498 Boolean localOnly,
1499 Boolean includeQualifiers,
1500 Boolean includeClassOrigin,
1501 const CIMPropertyList& propertyList)
1502 {
1503 Array<CIMInstance> result;
1504 mike 1.1
1505 for (Uint32 i = 0; i < _rep->_rep.size(); i++)
1506 {
1507 if (_rep->_rep[i].first != nameSpace)
1508 continue;
1509
1510 CIMInstance& ci = _rep->_rep[i].second;
1511
1512 if (ci.getPath().getClassName() == className)
1513 {
1514 CIMInstance tmp = ci.clone();
1515
1516 _filterInstance(
1517 tmp,
1518 localOnly,
1519 includeQualifiers,
1520 includeClassOrigin,
1521 propertyList);
1522
1523 result.append(tmp);
1524 }
1525 mike 1.1 }
1526
1527 return result;
1528 }
1529
1530 Array<CIMObjectPath> CIMRepository::enumerateInstanceNamesForSubtree(
1531 const CIMNamespaceName& nameSpace,
1532 const CIMName& className)
1533 {
1534 // Form array of classnames for this class and descendent classes:
1535
1536 Array<CIMName> classNames;
1537 classNames.append(className);
1538 _getSubClassNames(nameSpace, className, true, classNames);
1539
1540 // Get all instances for this class and all descendent classes
1541
1542 Array<CIMObjectPath> result;
1543
1544 for (Uint32 i = 0; i < classNames.size(); i++)
1545 {
1546 mike 1.1 Array<CIMObjectPath> paths = enumerateInstanceNamesForClass(
1547 nameSpace, classNames[i]);
1548
1549 result.appendArray(paths);
1550 }
1551
1552 return result;
1553 }
1554
1555 Array<CIMObjectPath> CIMRepository::enumerateInstanceNamesForClass(
1556 const CIMNamespaceName& nameSpace,
1557 const CIMName& className)
1558 {
1559 Array<CIMObjectPath> result;
1560
1561 for (Uint32 i = 0; i < _rep->_rep.size(); i++)
1562 {
1563 if (_rep->_rep[i].first != nameSpace)
1564 continue;
1565
1566 CIMInstance& ci = _rep->_rep[i].second;
1567 mike 1.1
1568 if (ci.getPath().getClassName() == className)
1569 result.append(ci.getPath());
1570 }
1571
1572 return result;
1573 }
1574
1575 Array<CIMObject> CIMRepository::associators(
1576 const CIMNamespaceName& nameSpace,
1577 const CIMObjectPath& objectName,
1578 const CIMName& assocClass,
1579 const CIMName& resultClass,
1580 const String& role,
1581 const String& resultRole,
1582 Boolean includeQualifiers,
1583 Boolean includeClassOrigin,
1584 const CIMPropertyList& propertyList)
1585 {
1586 if (objectName.getKeyBindings().size() == 0)
1587 {
1588 mike 1.1 return _associatorClasses(
1589 nameSpace,
1590 objectName.getClassName(),
1591 assocClass,
1592 resultClass,
1593 role,
1594 resultRole,
1595 includeQualifiers,
1596 includeClassOrigin,
1597 propertyList);
1598 }
1599 else
1600 {
1601 Throw((CIM_ERR_NOT_SUPPORTED, "associators()"));
1602 return Array<CIMObject>();
1603 }
1604 }
1605
1606 Array<CIMObjectPath> CIMRepository::associatorNames(
1607 const CIMNamespaceName& nameSpace,
1608 const CIMObjectPath& objectName,
1609 mike 1.1 const CIMName& assocClass,
1610 const CIMName& resultClass,
1611 const String& role,
1612 const String& resultRole)
1613 {
1614 if (objectName.getKeyBindings().size() == 0)
1615 {
1616 return _associatorClassPaths(
1617 nameSpace,
1618 objectName.getClassName(),
1619 assocClass,
1620 resultClass,
1621 role,
1622 resultRole);
1623 }
1624 else
1625 {
1626 Throw((CIM_ERR_NOT_SUPPORTED, "associatorNames()"));
1627 return Array<CIMObjectPath>();
1628 }
1629 }
1630 mike 1.1
1631 Array<CIMObject> CIMRepository::references(
1632 const CIMNamespaceName& nameSpace,
1633 const CIMObjectPath& objectName,
1634 const CIMName& resultClass,
1635 const String& role,
1636 Boolean includeQualifiers,
1637 Boolean includeClassOrigin,
1638 const CIMPropertyList& propertyList)
1639 {
1640 if (objectName.getKeyBindings().size() == 0)
1641 {
1642 return _referenceClasses(
1643 nameSpace,
1644 objectName.getClassName(),
1645 resultClass,
1646 role,
1647 includeQualifiers,
1648 includeClassOrigin,
1649 propertyList);
1650 }
1651 mike 1.1 else
1652 {
1653 Throw((CIM_ERR_NOT_SUPPORTED, "references()"));
1654 return Array<CIMObject>();
1655 }
1656 }
1657
1658 Array<CIMObjectPath> CIMRepository::referenceNames(
1659 const CIMNamespaceName& nameSpace,
1660 const CIMObjectPath& objectName,
1661 const CIMName& resultClass,
1662 const String& role)
1663 {
1664 if (objectName.getKeyBindings().size() == 0)
1665 {
1666 return _referenceClassPaths(
1667 nameSpace,
1668 objectName.getClassName(),
1669 resultClass,
1670 role);
1671 }
1672 mike 1.1 else
1673 {
1674 Throw((CIM_ERR_NOT_SUPPORTED, "referenceNames()"));
1675 return Array<CIMObjectPath>();
1676 }
1677 }
1678
1679 CIMValue CIMRepository::getProperty(
1680 const CIMNamespaceName& nameSpace,
1681 const CIMObjectPath& instanceName,
1682 const CIMName& propertyName)
1683 {
1684 CIMInstance ci = getInstance(
1685 nameSpace, instanceName, false, true, true, CIMPropertyList());
1686
1687 Uint32 pos = ci.findProperty(propertyName);
1688
1689 if (pos == PEG_NOT_FOUND)
1690 {
1691 Throw((CIM_ERR_NO_SUCH_PROPERTY, "%s", *Str(propertyName)));
1692 }
1693 mike 1.1
1694 return ci.getProperty(pos).getValue();
1695 }
1696
1697 void CIMRepository::setProperty(
1698 const CIMNamespaceName& nameSpace,
1699 const CIMObjectPath& instanceName,
1700 const CIMName& propertyName,
|
1724 mike 1.1 {
1725 Throw((CIM_ERR_NOT_SUPPORTED, "setQualifier()"));
1726 }
1727
1728 void CIMRepository::deleteQualifier(
1729 const CIMNamespaceName& nameSpace,
1730 const CIMName& qualifierName)
1731 {
1732 Throw((CIM_ERR_NOT_SUPPORTED, "deleteQualifier()"));
1733 }
1734
1735 Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
1736 const CIMNamespaceName& nameSpace)
1737 {
1738 return _enumerateQualifiers(nameSpace);
1739 }
1740
1741 void CIMRepository::createNameSpace(
1742 const CIMNamespaceName& nameSpace,
1743 const NameSpaceAttributes& attributes)
1744 {
1745 mike 1.1 Throw((CIM_ERR_NOT_SUPPORTED, "createNameSpace()"));
1746 }
1747
1748 void CIMRepository::modifyNameSpace(
1749 const CIMNamespaceName& nameSpace,
1750 const NameSpaceAttributes& attributes)
1751 {
1752 Throw((CIM_ERR_NOT_SUPPORTED, "modifyNameSpace()"));
1753 }
1754
1755 Array<CIMNamespaceName> CIMRepository::enumerateNameSpaces() const
1756 {
1757 return _enumerateNameSpaces();
1758 }
1759
1760 void CIMRepository::deleteNameSpace(
1761 const CIMNamespaceName& nameSpace)
1762 {
1763 Throw((CIM_ERR_NOT_SUPPORTED, "deleteNameSpace()"));
1764 }
1765
1766 mike 1.1 Boolean CIMRepository::getNameSpaceAttributes(
1767 const CIMNamespaceName& nameSpace,
1768 NameSpaceAttributes& attributes)
1769 {
1770 attributes.clear();
1771 return false;
1772 }
1773
1774 Boolean CIMRepository::isDefaultInstanceProvider()
1775 {
1776 return true;
1777 }
1778
1779 void CIMRepository::getSubClassNames(
1780 const CIMNamespaceName& nameSpace,
1781 const CIMName& className,
1782 Boolean deepInheritance,
1783 Array<CIMName>& subClassNames) const
1784 {
1785 _getSubClassNames(nameSpace, className, deepInheritance, subClassNames);
1786 }
1787 mike 1.1
1788 void CIMRepository::getSuperClassNames(
1789 const CIMNamespaceName& nameSpace,
1790 const CIMName& className,
1791 Array<CIMName>& superClassNames) const
1792 {
1793 _getSuperClassNames(nameSpace, className, superClassNames);
1794 }
1795
1796 Boolean CIMRepository::isRemoteNameSpace(
1797 const CIMNamespaceName& nameSpace,
1798 String& remoteInfo)
1799 {
1800 return false;
1801 }
1802
1803 #ifdef PEGASUS_DEBUG
1804 void CIMRepository::DisplayCacheStatistics()
1805 {
1806 }
1807 #endif
1808 mike 1.1
1809 Uint32 CIMRepositoryRep::_findInstance(
1810 const CIMNamespaceName& nameSpace,
1811 const CIMObjectPath& instanceName)
1812 {
1813 for (Uint32 i = 0; i < _rep.size(); i++)
1814 {
1815 if (_rep[i].first == nameSpace &&
1816 _rep[i].second.getPath() == instanceName)
1817 {
1818 return i;
1819 }
1820 }
1821
1822 return PEG_NOT_FOUND;
1823 }
1824
1825 void MRRInstallSaveCallback(
1826 void (*callback)(const Buffer& buffer, void* data),
1827 void * data)
1828 {
1829 mike 1.1 _saveCallback = callback;
1830 _saveData = data;
1831 }
1832
1833 void MRRInstallLoadCallback(
1834 void (*callback)(Buffer& buffer, void* data),
1835 void * data)
1836 {
1837 _loadCallback = callback;
1838 _loadData = data;
1839 }
1840
1841 void CIMRepositoryRep::_processSaveCallback()
1842 {
1843 if (!_saveCallback)
1844 return;
1845
1846 Buffer out;
1847
1848 for (Uint32 i = 0; i < _rep.size(); i++)
1849 {
1850 mike 1.1 MRRSerializeNameSpace(out, _rep[i].first);
1851 MRRSerializeInstance(out, _rep[i].second);
1852 }
1853
1854 (*_saveCallback)(out, _saveData);
1855 }
1856
1857 void CIMRepositoryRep::_processLoadCallback()
1858 {
1859 if (!_loadCallback)
1860 return;
1861
1862 Buffer in;
1863 (*_loadCallback)(in, _loadData);
1864 size_t pos = 0;
1865
1866 while (pos != in.size())
1867 {
1868 CIMNamespaceName nameSpace;
1869
1870 if (MRRDeserializeNameSpace(in, pos, nameSpace) != 0)
1871 mike 1.1 return;
1872
1873 CIMInstance cimInstance;
1874
1875 if (MRRDeserializeInstance(in, pos, cimInstance) != 0)
1876 return;
1877
1878 _rep.append(NamespaceInstancePair(nameSpace, cimInstance));
1879 }
1880 }
1881
1882 Boolean MRRAddNameSpace(const MRRNameSpace* nameSpace)
1883 {
1884 if (!nameSpace)
1885 return false;
1886
1887 if (_nameSpaceTableSize == _MAX_NAMESPACE_TABLE_SIZE)
1888 return false;
1889
1890 if (_findNameSpace(nameSpace->name))
1891 return false;
1892 mike 1.1
1893 _nameSpaceTable[_nameSpaceTableSize++] = nameSpace;
1894
1895 return true;
1896 }
1897
1898 void MRRInstallInitializeCallback(
1899 void (*callback)(CIMRepository* repository, void * data),
1900 void *data)
1901 {
1902 _initializeCallback = callback;
1903 _initializeData = data;
1904 }
1905
1906 //==============================================================================
1907 //
1908 // Non-locking forms of repository methods.
1909 //
1910 //==============================================================================
1911
1912 CIMClass CIMRepository::_getClass(
1913 mike 1.1 const CIMNamespaceName& nameSpace,
1914 const CIMName& className,
1915 Boolean localOnly,
1916 Boolean includeQualifiers,
1917 Boolean includeClassOrigin,
1918 const CIMPropertyList& propertyList)
1919 {
1920 return getClass(nameSpace, className, localOnly, includeQualifiers,
1921 includeClassOrigin, propertyList);
1922 }
1923
1924 CIMInstance CIMRepository::_getInstance(
1925 const CIMNamespaceName& nameSpace,
1926 const CIMObjectPath& instanceName,
1927 Boolean localOnly,
1928 Boolean includeQualifiers,
1929 Boolean includeClassOrigin,
|