1 thilo.boehm 1.1.2.1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // 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 //
10 // 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 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 thilo.boehm 1.1.2.1 // 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 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef _SCMOINSTANCE_H_
33 #define _SCMOINSTANCE_H_
34
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Linkage.h>
38 #include <Pegasus/Common/SCMO.h>
|
39 thilo.boehm 1.1.2.2 #include <Pegasus/Common/SCMOClass.h>
|
40 thilo.boehm 1.1.2.1
41 PEGASUS_NAMESPACE_BEGIN
42
43 #define PEGASUS_SCMB_INSTANCE_MAGIC 0xD00D1234
44
45 class SCMOClass;
46
47 class PEGASUS_COMMON_LINKAGE SCMOInstance
48 {
49 public:
50
51 /**
52 * Creating a SCMOInstance using a SCMOClass.
53 * @param baseClass A SCMOClass.
54 */
55 SCMOInstance(SCMOClass baseClass);
56
57 /**
58 * Copy constructor for the SCMO instance, used to implement refcounting.
59 * @param theSCMOClass The instance for which to create a copy
60 * @return
61 thilo.boehm 1.1.2.1 */
62 SCMOInstance(const SCMOInstance& theSCMOInstance )
63 {
64 inst.hdr = theSCMOInstance.inst.hdr;
65 Ref();
66 }
67
68 /**
69 * Destructor is decrementing the refcount. If refcount is zero, the
70 * singele chunk memory object is deallocated.
71 */
72 ~SCMOInstance()
73 {
74 Unref();
75 }
76
77 /**
78 * Builds a SCMOInstance based on this SCMOClass.
79 * The method arguments determine whether qualifiers are included,
80 * the class origin attributes are included,
81 * and which properties are included in the new instance.
82 thilo.boehm 1.1.2.1 * @param baseClass The SCMOClass of this instance.
83 * @param includeQualifiers A Boolean indicating whether qualifiers in
84 * the class definition (and its properties) are to be added to the
85 * instance. The TOINSTANCE flavor is ignored.
86 * @param includeClassOrigin A Boolean indicating whether ClassOrigin
87 * attributes are to be added to the instance.
88 * @param propertyList Is an NULL terminated array of char* to property
89 * names defining the properties that are included in the created instance.
90 * If the propertyList is NULL, all properties are included to the instance.
91 * If the propertyList is empty, no properties are added.
92 *
93 * Note that this function does NOT generate an error if a property name
94 * is supplied that is NOT in the class;
95 * it simply does not add that property to the instance.
96 *
97 */
98 SCMOInstance(
99 SCMOClass baseClass,
100 Boolean includeQualifiers,
101 Boolean includeClassOrigin,
102 const char** propertyList);
103 thilo.boehm 1.1.2.1
104 /**
105 * Builds a SCMOInstance from the given SCMOClass and copies all
106 * CIMInstance data into the new SCMOInstance.
107 * @param baseClass The SCMOClass of this instance.
108 * @param cimInstance A CIMInstace of the same class.
|
109 thilo.boehm 1.1.2.4 * @exception Exception if class name and name space does not match.
110 * @exception
111 * Exception if CIMInstance has more key bindings then the SCMOClass.
112 * @exception
113 * Exception if a key binding is not found as a key property
114 * of the SCMOClass.
115 * @exception Exception if a key binding does not match
116 * the class definition.
117 * @exception Exception if a property is not part of class definition.
118 * @exception Exception if a property does not match the class definition.
|
119 thilo.boehm 1.1.2.1 */
120 SCMOInstance(SCMOClass baseClass, const CIMInstance& cimInstance);
121
122 /**
|
123 thilo.boehm 1.1.2.4 * Builds a SCMOInstance from the given SCMOClass and copies all
124 * CIMObjectPath data into the new SCMOInstance.
125 * @param baseClass The SCMOClass of this instance.
126 * @param cimInstance A CIMObjectpath of the same class.
127 * @exception Exception if class name and name space does not match.
128 * @exception
129 * Exception if CIMInstance has more key bindings then the SCMOClass.
130 * @exception
131 * Exception if a key binding is not found as a key property
132 * of the SCMOClass.
133 * @exception Exception if a key binding does not match
134 * the class definition.
135 */
136 SCMOInstance(SCMOClass baseClass, const CIMObjectPath& cimObj);
137
138 /**
|
139 thilo.boehm 1.1.2.1 * Converts the SCMOInstance into a CIMInstance.
140 * It is a deep copy of the SCMOInstance into the CIMInstance.
141 * @param cimInstance An empty CIMInstance.
142 */
|
143 thilo.boehm 1.1.2.6 SCMO_RC getCIMInstance(CIMInstance& cimInstance) const;
|
144 thilo.boehm 1.1.2.1
145 /**
146 * Makes a deep copy of the instance.
147 * This creates a new copy of the instance.
|
148 thilo.boehm 1.1.2.5 * @param objectPathOnly If set to true, only the object path relevant parts
149 * host name and key bindings are part of the cloned instance.
|
150 thilo.boehm 1.1.2.1 * @return A new copy of the SCMOInstance object.
151 */
|
152 thilo.boehm 1.1.2.5 SCMOInstance clone(Boolean objectPathOnly = false) const;
|
153 thilo.boehm 1.1.2.1
154 /**
155 * Returns the number of properties of the instance.
156 * @param Number of properties
157 */
158 Uint32 getPropertyCount() const;
159
160 /**
161 * Gets the property name, type, and value addressed by a positional index.
162 * The property name and value has to be copied by the caller !
163 * @param pos The positional index of the property
164 * @param pname Returns the property name as '\0' terminated string.
165 * Has to be copied by caller.
166 * It is set to NULL if rc != SCMO_OK.
167 * @param pvalue Returns a pointer to the value of property.
168 * The value has to be copied by the caller !
169 * It returns NULL if rc != SCMO_OK.
170 * If the value is an array, the
171 * value array is stored in continuous memory.
172 * e.g. If the CIMType is CIMTYPE_UINT32:
173 * value = (void*)Uint32[0 to size-1]
174 thilo.boehm 1.1.2.1 * If it is an array of CIMTYPE_STRING, an array
175 * of char* to the string values is returned.
176 * This array has to be freed by the caller !
177 * @param type Returns the CIMType of the property
178 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
179 * @param isArray Returns if the value is an array.
180 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
181 * @param size Returns the size of the array.
182 * If it is not an array, 0 is returned.
183 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
184 *
185 * @return SCMO_OK
186 * SCMO_NULL_VALUE : The value is a null value.
187 * SCMO_INDEX_OUT_OF_BOUND : Given index not found
188 *
189 */
190 SCMO_RC getPropertyAt(
191 Uint32 pos,
192 const char** pname,
193 CIMType& type,
194 const void** pvalue,
195 thilo.boehm 1.1.2.1 Boolean& isArray,
196 Uint32& size ) const;
197
198 /**
199 * Gets the type and value of the named property.
200 * The value has to be copied by the caller !
201 * @param name The property name
202 * @param pvalue Returns a pointer to the value of property.
203 * The value has to be copied by the caller !
204 * It returns NULL if rc != SCMO_OK.
205 * If the value is an array, the
206 * value array is stored in continuous memory.
207 * e.g. If the CIMType is CIMTYPE_UINT32:
208 * value = (void*)Uint32[0 to size-1]
209 * If it is an array of CIMTYPE_STRING, an array
210 * of char* to the string values is returned.
211 * This array has to be freed by the caller !
212 * @param type Returns the CIMType of the property
213 * It is invalid if rc == SCMO_NOT_FOUND.
214 * @param isArray Returns if the value is an array.
215 * It is invalid if rc == SCMO_NOT_FOUND.
216 thilo.boehm 1.1.2.1 * @param size Returns the size of the array.
217 * If it is not an array, 0 is returned.
218 * It is invalid if rc == SCMO_NOT_FOUND.
219 *
220 * @return SCMO_OK
221 * SCMO_NULL_VALUE : The value is a null value.
222 * SCMO_NOT_FOUND : Given property name not found.
223 */
224 SCMO_RC getProperty(
225 const char* name,
226 CIMType& type,
227 const void** pvalue,
228 Boolean& isArray,
229 Uint32& size ) const;
230
231 /**
232 * Set/replace a property in the instance.
233 * If the class origin is specified, it is honored at identifying
234 * the property within the instance.
235 * Note: Only properties which are already part of the instance/class can
236 * be set/replaced.
237 thilo.boehm 1.1.2.1 * @param name The name of the property to be set.
238 * @param type The CIMType of the property
239 * @param value A pointer to property value.
240 * The value is copied into the instance
241 * If the value == NULL, a null value is assumed.
242 * If the value is an array, the
243 * value array must be stored in continuous memory.
244 * e.g. If the CIMType is CIMTYPE_UINT32:
245 * value = (void*)Uint32[0 to size-1]
246 * @param isArray Indicate that the value is an array. Default false.
247 * @param size Returns the size of the array. If not an array this
248 * this parameter is ignorer. Default 0.
249 * @param origin The class originality of the property.
250 * If NULL, then it is ignorred. Default NULL.
251 * @return SCMO_OK
252 * SCMO_NOT_SAME_ORIGIN : The property name was found, but
253 * the origin was not the same.
254 * SCMO_NOT_FOUND : Given property name not found.
255 * SCMO_WRONG_TYPE : Named property has the wrong type.
256 * SCMO_NOT_AN_ARRAY : Named property is not an array.
257 * SCMO_IS_AN_ARRAY : Named property is an array.
258 thilo.boehm 1.1.2.1 */
259 SCMO_RC setPropertyWithOrigin(
260 const char* name,
261 CIMType type,
262 void* value,
263 Boolean isArray=false,
264 Uint32 size = 0,
265 const char* origin = NULL);
266
267 /**
|
268 thilo.boehm 1.1.2.3 * Rebuild of the key bindings from the property values
|
269 thilo.boehm 1.1.2.1 * if no or incomplete key properties are set on the instance.
|
270 thilo.boehm 1.1.2.3 * @exception NoSuchProperty
|
271 thilo.boehm 1.1.2.1 */
|
272 thilo.boehm 1.1.2.2 void buildKeyBindingsFromProperties();
|
273 thilo.boehm 1.1.2.1
274 /**
275 * Set/replace a property filter on an instance.
276 * The filter is a white list of property names.
277 * A property part of the list can be accessed by name or index and
278 * is eligible to be returned to requester.
279 * Key properties can not be filtered. They are always a part of the
280 * instance. If a key property is not part of the property list,
281 * it will not be filtered out.
282 * @param propertyList Is an NULL terminated array of char* to
283 * property names
284 */
285 void setPropertyFilter(const char **propertyList);
286
287 /**
288 * Gets the hash index for the named property. Filtering is ignored.
289 * @param theName The property name
290 * @param pos Returns the hash index.
291 * @return SCMO_OK
292 * SCMO_INVALID_PARAMETER: name was a NULL pointer.
293 * SCMO_NOT_FOUND : Given property name not found.
294 thilo.boehm 1.1.2.1 */
295 SCMO_RC getPropertyNodeIndex(const char* name, Uint32& pos) const;
296
297 /**
298 * Set/replace a property in the instance at node index.
|
299 thilo.boehm 1.1.2.4 * Note: If node is filtered, the property is not set but the return value
|
300 thilo.boehm 1.1.2.1 * is still SCMO_OK.
301 * @param index The node index.
302 * @param type The CIMType of the property
303 * @param value A pointer to property value.
304 * The value is copied into the instance
305 * If the value is an array, the
306 * value array must be stored in continuous memory.
307 * e.g. If the CIMType is CIMTYPE_UINT32:
308 * value = (void*)Uint32[0 to size-1]
309 * @param isArray Indicate that the value is an array. Default false.
310 * @param size The size of the array. If not an array this
311 * this parameter is ignorer. Default 0.
312 * @return SCMO_OK
313 * SCMO_INDEX_OUT_OF_BOUND : Given index not found
314 * SCMO_WRONG_TYPE : The property at given node index
315 * has the wrong type.
316 * SCMO_NOT_AN_ARRAY : The property at given node index
317 * is not an array.
318 * SCMO_IS_AN_ARRAY : The property at given node index
319 * is an array.
320 */
321 thilo.boehm 1.1.2.1 SCMO_RC setPropertyWithNodeIndex(
322 Uint32 node,
323 CIMType type,
324 void* value,
325 Boolean isArray=false,
326 Uint32 size = 0);
327
328 /**
329 * Set/replace the named key binding
330 * @param name The key binding name.
331 * @param type The type as CIMKeyBinding::Type.
332 * @parma value The value as string.
333 * @return SCMO_OK
|
334 thilo.boehm 1.1.2.8 * SCMO_INVALID_PARAMETER : Given name or pvalue
335 * is a NULL pointer.
|
336 thilo.boehm 1.1.2.1 * SCMO_TYPE_MISSMATCH : Given type does not
337 * match to key binding type
338 * SCMO_NOT_FOUND : Given property name not found.
339 */
340 SCMO_RC setKeyBinding(
341 const char* name,
342 CIMKeyBinding::Type type,
343 const char* pvalue);
344
345 /**
|
346 thilo.boehm 1.1.2.7 * Set/replace the named key binding
347 * @param node The node index of the key.
348 * @param type The type as CIMKeyBinding::Type.
349 * @parma value The value as string.
350 * @return SCMO_OK
|
351 thilo.boehm 1.1.2.8 * SCMO_INVALID_PARAMETER : Given pvalue is a NULL pointer.
|
352 thilo.boehm 1.1.2.7 * SCMO_TYPE_MISSMATCH : Given type does not
353 * match to key binding type
354 * SCMO_INDEX_OUT_OF_BOUND : Given index is our of range.
355 */
356 SCMO_RC setKeyBindingAt(
357 Uint32 node,
358 CIMKeyBinding::Type type,
359 const char* pvalue);
360
361 /**
|
362 thilo.boehm 1.1.2.1 * Gets the key binding count.
363 * @return the number of key bindings set.
364 */
365 Uint32 getKeyBindingCount();
366
367 /**
368 * Get the indexed key binding.
369 * @parm idx The key bining index
370 * @parm pname Returns the name.
371 * Has to be copied by caller.
372 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
373 * @param type Returns the type as CIMKeyBinding::Type.
374 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
375 * @parma pvalue Returns the value as string.
376 * Has to be copied by caller.
377 * It is only valid if rc == SCMO_OK.
378 * @return SCMO_OK
379 * SCMO_NULL_VALUE : The key binding is not set.
380 * SCMO_INDEX_OUT_OF_BOUND : Given index not found
381 *
382 */
383 thilo.boehm 1.1.2.1 SCMO_RC getKeyBindingAt(
384 Uint32 idx,
385 const char** pname,
386 CIMKeyBinding::Type& type,
387 const char** pvalue) const;
388
389 /**
390 * Get the named key binding.
391 * @parm name The name of the key binding.
392 * @param type Returns the type as CIMKeyBinding::Type.
393 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
394 * @parma value Returns the value as string.
395 * Has to be copied by caller.
396 * It is only valid if rc == SCMO_OK.
397 * @return SCMO_OK
398 * SCMO_NULL_VALUE : The key binding is not set.
399 * SCMO_NOT_FOUND : Given property name not found.
400 */
401 SCMO_RC getKeyBinding(
402 const char* name,
403 CIMKeyBinding::Type& ptype,
404 thilo.boehm 1.1.2.1 const char** pvalue) const;
405
406 /**
407 * Determines whether the object has been initialized.
408 * @return True if the object has not been initialized, false otherwise.
409 */
410 Boolean isUninitialized( ) const {return (inst.base == NULL); };
411
412 /**
413 * Determies if two objects are referencing to the same instance
414 * @return True if the objects are referencing to the some instance.
415 */
416 Boolean isSame(SCMOInstance& theInstance) const;
417
418 /**
419 * Get the host name of the instance. The caller has to make a copy !
420 * @return The host name as UTF8.
421 */
422 const char* getHostName() const;
423
424 /**
425 thilo.boehm 1.1.2.1 * Sets the provided host name at the instance.
426 * @param hostName The host name as UTF8.
427 */
428 void setHostName(const char* hostName);
429
430 /**
431 * Get the class name of the instance. The cabler has to make a copy !
432 * @return The class name as UTF8.
433 */
434 const char* getClassName() const;
435
436 /**
437 * Get the name space of the instance. The caller has to make a copy !
438 * @return The name space as UTF8.
439 */
440 const char* getNameSpace() const;
441
442 /**
443 * To indicate the export processing ( eg. XMLWriter )
444 * to include qualifiers for this instance.
445 */
446 thilo.boehm 1.1.2.1 void includeQualifiers()
447 {
448 inst.hdr->flags.includeQualifiers = true;
449 };
450
451 /**
452 * To indicate the export processing ( eg. XMLWriter )
453 * to NOT to include (exclude) qualifiers for this instance.
454 */
455 void excludeQualifiers()
456 {
457 inst.hdr->flags.includeQualifiers = false;
458 }
459
460 /**
461 * To indicate the export processing ( eg. XMLWriter )
462 * to include class origins for this instance.
463 */
464 void includeClassOrigins()
465 {
466 inst.hdr->flags.includeClassOrigin = true;
467 thilo.boehm 1.1.2.1 };
468
469 /**
470 * To indicate the export processing ( eg. XMLWriter )
471 * to NOT to include (exclude) class origins for this instance.
472 */
473 void excludeClassOrigins()
474 {
475 inst.hdr->flags.includeClassOrigin = false;
476 }
477
478 private:
479
480 void Ref()
481 {
482 inst.hdr->refCount++;
483 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
484 };
485
486 void Unref()
487 {
488 thilo.boehm 1.1.2.1 if (inst.hdr->refCount.decAndTestIfZero())
489 {
490 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
491 // The class has also be dereferenced.
492 delete inst.hdr->theClass;
493 free(inst.base);
494 inst.base=NULL;
495 }
496 else
497 {
498 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
499 }
500
501 };
502 /**
503 * A SCMOInstance can only be created by a SCMOClass
504 */
505 SCMOInstance();
506
507 void _initSCMOInstance(
508 SCMOClass* pClass,
509 thilo.boehm 1.1.2.1 Boolean inclQual,
510 Boolean inclOrigin);
511
512
513 SCMO_RC _getPropertyAtNodeIndex(
514 Uint32 pos,
515 const char** pname,
516 CIMType& type,
517 const void** pvalue,
518 Boolean& isArray,
519 Uint32& size ) const;
520
521 void _setPropertyAtNodeIndex(
522 Uint32 pos,
523 CIMType type,
524 void* value,
525 Boolean isArray,
526 Uint32 size);
527
|
528 thilo.boehm 1.1.2.4 void _setCIMValueAtNodeIndex(Uint32 node, CIMValueRep* valRep);
529
|
530 thilo.boehm 1.1.2.6 void _getCIMValueFromSCMBValue(
531 CIMValue& cimV,
532 const SCMBValue& scmbV,
533 const char * base) const;
534
535 CIMProperty _getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const;
536
|
537 thilo.boehm 1.1.2.4 void _setCIMObjectPath(const CIMObjectPath& cimObj);
538
|
539 thilo.boehm 1.1.2.6 void _getCIMObjectPath(CIMObjectPath& cimObj) const;
540
|
541 thilo.boehm 1.1.2.1 void* _getSCMBUnion(
542 CIMType type,
543 Boolean isArray,
544 Uint32 size,
545 Uint64 start,
546 char* base) const;
547
548 void _setSCMBUnion(
549 void* value,
550 CIMType type,
551 Boolean isArray,
552 Uint32 size,
553 Uint64 start);
554
|
555 thilo.boehm 1.1.2.4 static void _setUnionValue(
556 Uint64 start,
557 SCMBMgmt_Header** pmem,
558 CIMType type,
559 Union& u);
560
561 static void _setArrayValue(
562 Uint64 start,
563 SCMBMgmt_Header** pmem,
564 CIMType type,
565 Uint32& n,
566 Union& u);
567
|
568 thilo.boehm 1.1.2.1 SCMO_RC _getKeyBindingAtNodeIndex(
569 Uint32 pos,
570 const char** pname,
571 CIMKeyBinding::Type& ptype,
572 const char** pvalue) const;
573
|
574 thilo.boehm 1.1.2.5 void _copyKeyBindings(SCMOInstance& targetInst) const;
575
|
576 thilo.boehm 1.1.2.1 Uint32 _initPropFilterWithKeys();
577
578 void _setPropertyInPropertyFilter(Uint32 i);
579
580 Boolean _isPropertyInFilter(Uint32 i) const;
581
582 void _clearPropertyFilter();
583
|
584 thilo.boehm 1.1.2.3 void _setKeyBindingFromSCMBUnion(
|
585 thilo.boehm 1.1.2.4 CIMType type,
|
586 thilo.boehm 1.1.2.3 SCMBUnion& u,
587 SCMBDataPtr& keyNode);
|
588 thilo.boehm 1.1.2.2
|
589 thilo.boehm 1.1.2.1 union{
590 // To access the instance main structure
591 SCMBInstance_Main *hdr;
592 // To access the memory management header
593 SCMBMgmt_Header *mem;
594 // Generic access pointer
595 char *base;
596 }inst;
597
598 friend class SCMOClass;
599 friend class SCMODump;
600 };
601
602
603 PEGASUS_NAMESPACE_END
604
605
606 #endif
|