(file) Return to SCMOInstance.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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                          */
110                         SCMOInstance(SCMOClass baseClass, const CIMInstance& cimInstance);
111                     
112                         /**
113                          * Converts the SCMOInstance into a CIMInstance.
114                          * It is a deep copy of the SCMOInstance into the CIMInstance.
115                          * @param cimInstance An empty CIMInstance.
116                          */
117                         void getCIMInstance(CIMInstance& cimInstance) const;
118                     
119                         /**
120                          * Makes a deep copy of the instance.
121                          * This creates a new copy of the instance.
122                          * @return A new copy of the SCMOInstance object.
123                          */
124 thilo.boehm 1.1.2.1     SCMOInstance clone() const;
125                     
126                         /**
127                          * Returns the number of properties of the instance.
128                          * @param Number of properties
129                          */
130                         Uint32 getPropertyCount() const;
131                     
132                         /**
133                          * Gets the property name, type, and value addressed by a positional index.
134                          * The property name and value has to be copied by the caller !
135                          * @param pos The positional index of the property
136                          * @param pname Returns the property name as '\0' terminated string.
137                          *              Has to be copied by caller.
138                          *              It is set to NULL if rc != SCMO_OK.
139                          * @param pvalue Returns a pointer to the value of property.
140                          *               The value has to be copied by the caller !
141                          *               It returns NULL if rc != SCMO_OK.
142                          *               If the value is an array, the
143                          *               value array is stored in continuous memory.
144                          *               e.g. If the CIMType is CIMTYPE_UINT32:
145 thilo.boehm 1.1.2.1      *               value = (void*)Uint32[0 to size-1]
146                          *               If it is an array of CIMTYPE_STRING, an array
147                          *               of char* to the string values is returned.
148                          *               This array has to be freed by the caller !
149                          * @param type Returns the CIMType of the property
150                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
151                          * @param isArray Returns if the value is an array.
152                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
153                          * @param size Returns the size of the array.
154                          *             If it is not an array, 0 is returned.
155                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
156                          *
157                          * @return     SCMO_OK
158                          *             SCMO_NULL_VALUE : The value is a null value.
159                          *             SCMO_INDEX_OUT_OF_BOUND : Given index not found
160                          *
161                          */
162                         SCMO_RC getPropertyAt(
163                             Uint32 pos,
164                             const char** pname,
165                             CIMType& type,
166 thilo.boehm 1.1.2.1         const void** pvalue,
167                             Boolean& isArray,
168                             Uint32& size ) const;
169                     
170                         /**
171                          * Gets the type and value of the named property.
172                          * The value has to be copied by the caller !
173                          * @param name The property name
174                          * @param pvalue Returns a pointer to the value of property.
175                          *               The value has to be copied by the caller !
176                          *               It returns NULL if rc != SCMO_OK.
177                          *               If the value is an array, the
178                          *               value array is stored in continuous memory.
179                          *               e.g. If the CIMType is CIMTYPE_UINT32:
180                          *               value = (void*)Uint32[0 to size-1]
181                          *               If it is an array of CIMTYPE_STRING, an array
182                          *               of char* to the string values is returned.
183                          *               This array has to be freed by the caller !
184                          * @param type Returns the CIMType of the property
185                          *             It is invalid if rc == SCMO_NOT_FOUND.
186                          * @param isArray Returns if the value is an array.
187 thilo.boehm 1.1.2.1      *             It is invalid if rc == SCMO_NOT_FOUND.
188                          * @param size Returns the size of the array.
189                          *             If it is not an array, 0 is returned.
190                          *             It is invalid if rc == SCMO_NOT_FOUND.
191                          *
192                          * @return     SCMO_OK
193                          *             SCMO_NULL_VALUE : The value is a null value.
194                          *             SCMO_NOT_FOUND : Given property name not found.
195                          */
196                         SCMO_RC getProperty(
197                             const char* name,
198                             CIMType& type,
199                             const void** pvalue,
200                             Boolean& isArray,
201                             Uint32& size ) const;
202                     
203                         /**
204                          * Set/replace a property in the instance.
205                          * If the class origin is specified, it is honored at identifying
206                          * the property within the instance.
207                          * Note: Only properties which are already part of the instance/class can
208 thilo.boehm 1.1.2.1      * be set/replaced.
209                          * @param name The name of the property to be set.
210                          * @param type The CIMType of the property
211                          * @param value A pointer to property  value.
212                          *         The value is copied into the instance
213                          *         If the value == NULL, a null value is assumed.
214                          *         If the value is an array, the
215                          *         value array must be stored in continuous memory.
216                          *         e.g. If the CIMType is CIMTYPE_UINT32:
217                          *         value = (void*)Uint32[0 to size-1]
218                          * @param isArray Indicate that the value is an array. Default false.
219                          * @param size Returns the size of the array. If not an array this
220                          *         this parameter is ignorer. Default 0.
221                          * @param origin The class originality of the property.
222                          *               If NULL, then it is ignorred. Default NULL.
223                          * @return     SCMO_OK
224                          *             SCMO_NOT_SAME_ORIGIN : The property name was found, but
225                          *                                    the origin was not the same.
226                          *             SCMO_NOT_FOUND : Given property name not found.
227                          *             SCMO_WRONG_TYPE : Named property has the wrong type.
228                          *             SCMO_NOT_AN_ARRAY : Named property is not an array.
229 thilo.boehm 1.1.2.1      *             SCMO_IS_AN_ARRAY  : Named property is an array.
230                          */
231                         SCMO_RC setPropertyWithOrigin(
232                             const char* name,
233                             CIMType type,
234                             void* value,
235                             Boolean isArray=false,
236                             Uint32 size = 0,
237                             const char* origin = NULL);
238                     
239                         /**
240 thilo.boehm 1.1.2.2      * Rebuild of the key bindings from the property values.
241 thilo.boehm 1.1.2.1      * if no or incomplete key properties are set on the instance.
242                          */
243 thilo.boehm 1.1.2.2     void buildKeyBindingsFromProperties();
244 thilo.boehm 1.1.2.1 
245                         /**
246                          * Set/replace a property filter on an instance.
247                          * The filter is a white list of property names.
248                          * A property part of the list can be accessed by name or index and
249                          * is eligible to be returned to requester.
250                          * Key properties can not be filtered. They are always a part of the
251                          * instance. If a key property is not part of the property list,
252                          * it will not be filtered out.
253                          * @param propertyList Is an NULL terminated array of char* to
254                          * property names
255                          */
256                         void setPropertyFilter(const char **propertyList);
257                     
258                         /**
259                          * Gets the hash index for the named property. Filtering is ignored.
260                          * @param theName The property name
261                          * @param pos Returns the hash index.
262                          * @return     SCMO_OK
263                          *             SCMO_INVALID_PARAMETER: name was a NULL pointer.
264                          *             SCMO_NOT_FOUND : Given property name not found.
265 thilo.boehm 1.1.2.1      */
266                         SCMO_RC getPropertyNodeIndex(const char* name, Uint32& pos) const;
267                     
268                         /**
269                          * Set/replace a property in the instance at node index.
270                          * Note: If node is filtered, the property is not set but the return value 
271                          * is still SCMO_OK.
272                          * @param index The node index.
273                          * @param type The CIMType of the property
274                          * @param value A pointer to property  value.
275                          *         The value is copied into the instance
276                          *         If the value is an array, the
277                          *         value array must be stored in continuous memory.
278                          *         e.g. If the CIMType is CIMTYPE_UINT32:
279                          *         value = (void*)Uint32[0 to size-1]
280                          * @param isArray Indicate that the value is an array. Default false.
281                          * @param size The size of the array. If not an array this
282                          *         this parameter is ignorer. Default 0.
283                          * @return     SCMO_OK
284                          *             SCMO_INDEX_OUT_OF_BOUND : Given index not found
285                          *             SCMO_WRONG_TYPE : The property at given node index
286 thilo.boehm 1.1.2.1      *                               has the wrong type.
287                          *             SCMO_NOT_AN_ARRAY : The property at given node index
288                          *                                 is not an array.
289                          *             SCMO_IS_AN_ARRAY  : The property at given node index
290                          *                                 is an array.
291                          */
292                         SCMO_RC setPropertyWithNodeIndex(
293                             Uint32 node,
294                             CIMType type,
295                             void* value,
296                             Boolean isArray=false,
297                             Uint32 size = 0);
298                     
299                         /**
300                          * Set/replace the named key binding
301                          * @param name The key binding name.
302                          * @param type The type as CIMKeyBinding::Type.
303                          * @parma value The value as string.
304                          * @return     SCMO_OK
305                          *             SCMO_TYPE_MISSMATCH : Given type does not
306                          *                                   match to key binding type
307 thilo.boehm 1.1.2.1      *             SCMO_NOT_FOUND : Given property name not found.
308                          */
309                         SCMO_RC setKeyBinding(
310                             const char* name,
311                             CIMKeyBinding::Type type,
312                             const char* pvalue);
313                     
314                         /**
315                          * Gets the key binding count.
316                          * @return the number of key bindings set.
317                          */
318                         Uint32 getKeyBindingCount();
319                     
320                         /**
321                          * Get the indexed key binding.
322                          * @parm idx The key bining index
323                          * @parm pname Returns the name.
324                          *             Has to be copied by caller.
325                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
326                          * @param type Returns the type as CIMKeyBinding::Type.
327                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
328 thilo.boehm 1.1.2.1      * @parma pvalue Returns the value as string.
329                          *             Has to be copied by caller.
330                          *             It is only valid if rc == SCMO_OK.
331                          * @return     SCMO_OK
332                          *             SCMO_NULL_VALUE : The key binding is not set.
333                          *             SCMO_INDEX_OUT_OF_BOUND : Given index not found
334                          *
335                          */
336                         SCMO_RC getKeyBindingAt(
337                             Uint32 idx,
338                             const char** pname,
339                             CIMKeyBinding::Type& type,
340                             const char** pvalue) const;
341                     
342                         /**
343                          * Get the named key binding.
344                          * @parm name The name of the key binding.
345                          * @param type Returns the type as CIMKeyBinding::Type.
346                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
347                          * @parma value Returns the value as string.
348                          *             Has to be copied by caller.
349 thilo.boehm 1.1.2.1      *             It is only valid if rc == SCMO_OK.
350                          * @return     SCMO_OK
351                          *             SCMO_NULL_VALUE : The key binding is not set.
352                          *             SCMO_NOT_FOUND : Given property name not found.
353                          */
354                         SCMO_RC getKeyBinding(
355                             const char* name,
356                             CIMKeyBinding::Type& ptype,
357                             const char** pvalue) const;
358                     
359                         /**
360                          * Determines whether the object has been initialized.
361                          * @return True if the object has not been initialized, false otherwise.
362                          */
363                         Boolean isUninitialized( ) const {return (inst.base == NULL); };
364                     
365                         /**
366                          * Determies if two objects are referencing to the same instance
367                          * @return True if the objects are referencing to the some instance.
368                          */
369                         Boolean isSame(SCMOInstance& theInstance) const;
370 thilo.boehm 1.1.2.1 
371                         /**
372                          * Get the host name of the instance. The caller has to make a copy !
373                          * @return The host name as UTF8.
374                          */
375                         const char* getHostName() const;
376                     
377                         /**
378                          * Sets the provided host name at the instance.
379                          * @param hostName The host name as UTF8.
380                          */
381                         void setHostName(const char* hostName);
382                     
383                         /**
384                          * Get the class name of the instance. The cabler has to make a copy !
385                          * @return The class name as UTF8.
386                          */
387                         const char* getClassName() const;
388                     
389                         /**
390                          * Get the name space of the instance. The caller has to make a copy !
391 thilo.boehm 1.1.2.1      * @return The name space as UTF8.
392                          */
393                         const char* getNameSpace() const;
394                     
395                         /**
396                          *  To indicate the export processing ( eg. XMLWriter )
397                          *  to include qualifiers for this instance.
398                          */
399                         void includeQualifiers()
400                         {
401                             inst.hdr->flags.includeQualifiers = true;
402                         };
403                     
404                         /**
405                          *  To indicate the export processing ( eg. XMLWriter )
406                          *  to NOT to include (exclude) qualifiers for this instance.
407                          */
408                         void excludeQualifiers()
409                         {
410                             inst.hdr->flags.includeQualifiers = false;
411                         }
412 thilo.boehm 1.1.2.1 
413                         /**
414                          *  To indicate the export processing ( eg. XMLWriter )
415                          *  to include class origins for this instance.
416                          */
417                         void includeClassOrigins()
418                         {
419                             inst.hdr->flags.includeClassOrigin = true;
420                         };
421                     
422                         /**
423                          *  To indicate the export processing ( eg. XMLWriter )
424                          *  to NOT to include (exclude) class origins for this instance.
425                          */
426                         void excludeClassOrigins()
427                         {
428                             inst.hdr->flags.includeClassOrigin = false;
429                         }
430                     
431                     private:
432                     
433 thilo.boehm 1.1.2.1     void Ref()
434                         {
435                             inst.hdr->refCount++;
436                             // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
437                         };
438                     
439                         void Unref()
440                         {
441                             if (inst.hdr->refCount.decAndTestIfZero())
442                             {
443                                 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
444                                 // The class has also be dereferenced.
445                                 delete inst.hdr->theClass;
446                                 free(inst.base);
447                                 inst.base=NULL;
448                             }
449                             else
450                             {
451                                 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
452                             }
453                     
454 thilo.boehm 1.1.2.1     };
455                         /**
456                          * A SCMOInstance can only be created by a SCMOClass
457                          */
458                         SCMOInstance();
459                     
460                         void _initSCMOInstance(
461                             SCMOClass* pClass,
462                             Boolean inclQual,
463                             Boolean inclOrigin);
464                     
465                     
466                         SCMO_RC _getPropertyAtNodeIndex(
467                                 Uint32 pos,
468                                 const char** pname,
469                                 CIMType& type,
470                                 const void** pvalue,
471                                 Boolean& isArray,
472                                 Uint32& size ) const;
473                     
474                         void _setPropertyAtNodeIndex(
475 thilo.boehm 1.1.2.1         Uint32 pos,
476                             CIMType type,
477                             void* value,
478                             Boolean isArray,
479                             Uint32 size);
480                     
481                         void* _getSCMBUnion(
482                             CIMType type,
483                             Boolean isArray,
484                             Uint32 size,
485                             Uint64 start,
486                             char* base) const;
487                     
488                         void _setSCMBUnion(
489                             void* value,
490                             CIMType type,
491                             Boolean isArray,
492                             Uint32 size,
493                             Uint64 start);
494                     
495                         SCMO_RC _getKeyBindingAtNodeIndex(
496 thilo.boehm 1.1.2.1         Uint32 pos,
497                             const char** pname,
498                             CIMKeyBinding::Type& ptype,
499                             const char** pvalue) const;
500                     
501                         Uint32 _initPropFilterWithKeys();
502                     
503                         void _setPropertyInPropertyFilter(Uint32 i);
504                     
505                         Boolean _isPropertyInFilter(Uint32 i) const;
506                     
507                         void _clearPropertyFilter();
508                     
509 thilo.boehm 1.1.2.2     static String _printArrayValue(
510                             CIMType type,
511                             Uint32 size,
512                             SCMBUnion u,
513                             char* base);
514                     
515                     
516                         static String _printUnionValue(CIMType type,SCMBUnion u,char* base);
517                     
518                     
519 thilo.boehm 1.1.2.1     union{
520                             // To access the instance main structure
521                             SCMBInstance_Main *hdr;
522                             // To access the memory management header
523                             SCMBMgmt_Header     *mem;
524                             // Generic access pointer
525                             char *base;
526                         }inst;
527                     
528                         friend class SCMOClass;
529                         friend class SCMODump;
530                     };
531                     
532                     
533                     PEGASUS_NAMESPACE_END
534                     
535                     
536                     #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2