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