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 * SCMO_TYPE_MISSMATCH : Given type does not
335 * match to key binding type
336 * SCMO_NOT_FOUND : Given property name not found.
337 */
338 SCMO_RC setKeyBinding(
339 const char* name,
340 CIMKeyBinding::Type type,
341 const char* pvalue);
342 thilo.boehm 1.1.2.1
343 /**
344 * Gets the key binding count.
345 * @return the number of key bindings set.
346 */
347 Uint32 getKeyBindingCount();
348
349 /**
350 * Get the indexed key binding.
351 * @parm idx The key bining index
352 * @parm pname Returns the name.
353 * Has to be copied by caller.
354 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
355 * @param type Returns the type as CIMKeyBinding::Type.
356 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
357 * @parma pvalue Returns the value as string.
358 * Has to be copied by caller.
359 * It is only valid if rc == SCMO_OK.
360 * @return SCMO_OK
361 * SCMO_NULL_VALUE : The key binding is not set.
362 * SCMO_INDEX_OUT_OF_BOUND : Given index not found
363 thilo.boehm 1.1.2.1 *
364 */
365 SCMO_RC getKeyBindingAt(
366 Uint32 idx,
367 const char** pname,
368 CIMKeyBinding::Type& type,
369 const char** pvalue) const;
370
371 /**
372 * Get the named key binding.
373 * @parm name The name of the key binding.
374 * @param type Returns the type as CIMKeyBinding::Type.
375 * It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
376 * @parma value Returns the value as string.
377 * Has to be copied by caller.
378 * It is only valid if rc == SCMO_OK.
379 * @return SCMO_OK
380 * SCMO_NULL_VALUE : The key binding is not set.
381 * SCMO_NOT_FOUND : Given property name not found.
382 */
383 SCMO_RC getKeyBinding(
384 thilo.boehm 1.1.2.1 const char* name,
385 CIMKeyBinding::Type& ptype,
386 const char** pvalue) const;
387
388 /**
389 * Determines whether the object has been initialized.
390 * @return True if the object has not been initialized, false otherwise.
391 */
392 Boolean isUninitialized( ) const {return (inst.base == NULL); };
393
394 /**
395 * Determies if two objects are referencing to the same instance
396 * @return True if the objects are referencing to the some instance.
397 */
398 Boolean isSame(SCMOInstance& theInstance) const;
399
400 /**
401 * Get the host name of the instance. The caller has to make a copy !
402 * @return The host name as UTF8.
403 */
404 const char* getHostName() const;
405 thilo.boehm 1.1.2.1
406 /**
407 * Sets the provided host name at the instance.
408 * @param hostName The host name as UTF8.
409 */
410 void setHostName(const char* hostName);
411
412 /**
413 * Get the class name of the instance. The cabler has to make a copy !
414 * @return The class name as UTF8.
415 */
416 const char* getClassName() const;
417
418 /**
419 * Get the name space of the instance. The caller has to make a copy !
420 * @return The name space as UTF8.
421 */
422 const char* getNameSpace() const;
423
424 /**
425 * To indicate the export processing ( eg. XMLWriter )
426 thilo.boehm 1.1.2.1 * to include qualifiers for this instance.
427 */
428 void includeQualifiers()
429 {
430 inst.hdr->flags.includeQualifiers = true;
431 };
432
433 /**
434 * To indicate the export processing ( eg. XMLWriter )
435 * to NOT to include (exclude) qualifiers for this instance.
436 */
437 void excludeQualifiers()
438 {
439 inst.hdr->flags.includeQualifiers = false;
440 }
441
442 /**
443 * To indicate the export processing ( eg. XMLWriter )
444 * to include class origins for this instance.
445 */
446 void includeClassOrigins()
447 thilo.boehm 1.1.2.1 {
448 inst.hdr->flags.includeClassOrigin = true;
449 };
450
451 /**
452 * To indicate the export processing ( eg. XMLWriter )
453 * to NOT to include (exclude) class origins for this instance.
454 */
455 void excludeClassOrigins()
456 {
457 inst.hdr->flags.includeClassOrigin = false;
458 }
459
460 private:
461
462 void Ref()
463 {
464 inst.hdr->refCount++;
465 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
466 };
467
468 thilo.boehm 1.1.2.1 void Unref()
469 {
470 if (inst.hdr->refCount.decAndTestIfZero())
471 {
472 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
473 // The class has also be dereferenced.
474 delete inst.hdr->theClass;
475 free(inst.base);
476 inst.base=NULL;
477 }
478 else
479 {
480 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
481 }
482
483 };
484 /**
485 * A SCMOInstance can only be created by a SCMOClass
486 */
487 SCMOInstance();
488
489 thilo.boehm 1.1.2.1 void _initSCMOInstance(
490 SCMOClass* pClass,
491 Boolean inclQual,
492 Boolean inclOrigin);
493
494
495 SCMO_RC _getPropertyAtNodeIndex(
496 Uint32 pos,
497 const char** pname,
498 CIMType& type,
499 const void** pvalue,
500 Boolean& isArray,
501 Uint32& size ) const;
502
503 void _setPropertyAtNodeIndex(
504 Uint32 pos,
505 CIMType type,
506 void* value,
507 Boolean isArray,
508 Uint32 size);
509
|
510 thilo.boehm 1.1.2.4 void _setCIMValueAtNodeIndex(Uint32 node, CIMValueRep* valRep);
511
|
512 thilo.boehm 1.1.2.6 void _getCIMValueFromSCMBValue(
513 CIMValue& cimV,
514 const SCMBValue& scmbV,
515 const char * base) const;
516
517 CIMProperty _getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const;
518
|
519 thilo.boehm 1.1.2.4 void _setCIMObjectPath(const CIMObjectPath& cimObj);
520
|
521 thilo.boehm 1.1.2.6 void _getCIMObjectPath(CIMObjectPath& cimObj) const;
522
|
523 thilo.boehm 1.1.2.1 void* _getSCMBUnion(
524 CIMType type,
525 Boolean isArray,
526 Uint32 size,
527 Uint64 start,
528 char* base) const;
529
530 void _setSCMBUnion(
531 void* value,
532 CIMType type,
533 Boolean isArray,
534 Uint32 size,
535 Uint64 start);
536
|
537 thilo.boehm 1.1.2.4 static void _setUnionValue(
538 Uint64 start,
539 SCMBMgmt_Header** pmem,
540 CIMType type,
541 Union& u);
542
543 static void _setArrayValue(
544 Uint64 start,
545 SCMBMgmt_Header** pmem,
546 CIMType type,
547 Uint32& n,
548 Union& u);
549
|
550 thilo.boehm 1.1.2.1 SCMO_RC _getKeyBindingAtNodeIndex(
551 Uint32 pos,
552 const char** pname,
553 CIMKeyBinding::Type& ptype,
554 const char** pvalue) const;
555
|
556 thilo.boehm 1.1.2.5 void _copyKeyBindings(SCMOInstance& targetInst) const;
557
|
558 thilo.boehm 1.1.2.1 Uint32 _initPropFilterWithKeys();
559
560 void _setPropertyInPropertyFilter(Uint32 i);
561
562 Boolean _isPropertyInFilter(Uint32 i) const;
563
564 void _clearPropertyFilter();
565
|
566 thilo.boehm 1.1.2.3 void _setKeyBindingFromSCMBUnion(
|
567 thilo.boehm 1.1.2.4 CIMType type,
|
568 thilo.boehm 1.1.2.3 SCMBUnion& u,
569 SCMBDataPtr& keyNode);
|
570 thilo.boehm 1.1.2.2
|
571 thilo.boehm 1.1.2.1 union{
572 // To access the instance main structure
573 SCMBInstance_Main *hdr;
574 // To access the memory management header
575 SCMBMgmt_Header *mem;
576 // Generic access pointer
577 char *base;
578 }inst;
579
580 friend class SCMOClass;
581 friend class SCMODump;
582 };
583
584
585 PEGASUS_NAMESPACE_END
586
587
588 #endif
|