(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.3      * 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 thilo.boehm 1.1.2.3      * @exception NoSuchProperty
243 thilo.boehm 1.1.2.1      */
244 thilo.boehm 1.1.2.2     void buildKeyBindingsFromProperties();
245 thilo.boehm 1.1.2.1 
246                         /**
247                          * Set/replace a property filter on an instance.
248                          * The filter is a white list of property names.
249                          * A property part of the list can be accessed by name or index and
250                          * is eligible to be returned to requester.
251                          * Key properties can not be filtered. They are always a part of the
252                          * instance. If a key property is not part of the property list,
253                          * it will not be filtered out.
254                          * @param propertyList Is an NULL terminated array of char* to
255                          * property names
256                          */
257                         void setPropertyFilter(const char **propertyList);
258                     
259                         /**
260                          * Gets the hash index for the named property. Filtering is ignored.
261                          * @param theName The property name
262                          * @param pos Returns the hash index.
263                          * @return     SCMO_OK
264                          *             SCMO_INVALID_PARAMETER: name was a NULL pointer.
265                          *             SCMO_NOT_FOUND : Given property name not found.
266 thilo.boehm 1.1.2.1      */
267                         SCMO_RC getPropertyNodeIndex(const char* name, Uint32& pos) const;
268                     
269                         /**
270                          * Set/replace a property in the instance at node index.
271                          * Note: If node is filtered, the property is not set but the return value 
272                          * is still SCMO_OK.
273                          * @param index The node index.
274                          * @param type The CIMType of the property
275                          * @param value A pointer to property  value.
276                          *         The value is copied into the instance
277                          *         If the value is an array, the
278                          *         value array must be stored in continuous memory.
279                          *         e.g. If the CIMType is CIMTYPE_UINT32:
280                          *         value = (void*)Uint32[0 to size-1]
281                          * @param isArray Indicate that the value is an array. Default false.
282                          * @param size The size of the array. If not an array this
283                          *         this parameter is ignorer. Default 0.
284                          * @return     SCMO_OK
285                          *             SCMO_INDEX_OUT_OF_BOUND : Given index not found
286                          *             SCMO_WRONG_TYPE : The property at given node index
287 thilo.boehm 1.1.2.1      *                               has the wrong type.
288                          *             SCMO_NOT_AN_ARRAY : The property at given node index
289                          *                                 is not an array.
290                          *             SCMO_IS_AN_ARRAY  : The property at given node index
291                          *                                 is an array.
292                          */
293                         SCMO_RC setPropertyWithNodeIndex(
294                             Uint32 node,
295                             CIMType type,
296                             void* value,
297                             Boolean isArray=false,
298                             Uint32 size = 0);
299                     
300                         /**
301                          * Set/replace the named key binding
302                          * @param name The key binding name.
303                          * @param type The type as CIMKeyBinding::Type.
304                          * @parma value The value as string.
305                          * @return     SCMO_OK
306                          *             SCMO_TYPE_MISSMATCH : Given type does not
307                          *                                   match to key binding type
308 thilo.boehm 1.1.2.1      *             SCMO_NOT_FOUND : Given property name not found.
309                          */
310                         SCMO_RC setKeyBinding(
311                             const char* name,
312                             CIMKeyBinding::Type type,
313                             const char* pvalue);
314                     
315                         /**
316                          * Gets the key binding count.
317                          * @return the number of key bindings set.
318                          */
319                         Uint32 getKeyBindingCount();
320                     
321                         /**
322                          * Get the indexed key binding.
323                          * @parm idx The key bining index
324                          * @parm pname Returns the name.
325                          *             Has to be copied by caller.
326                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
327                          * @param type Returns the type as CIMKeyBinding::Type.
328                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
329 thilo.boehm 1.1.2.1      * @parma pvalue Returns the value as string.
330                          *             Has to be copied by caller.
331                          *             It is only valid if rc == SCMO_OK.
332                          * @return     SCMO_OK
333                          *             SCMO_NULL_VALUE : The key binding is not set.
334                          *             SCMO_INDEX_OUT_OF_BOUND : Given index not found
335                          *
336                          */
337                         SCMO_RC getKeyBindingAt(
338                             Uint32 idx,
339                             const char** pname,
340                             CIMKeyBinding::Type& type,
341                             const char** pvalue) const;
342                     
343                         /**
344                          * Get the named key binding.
345                          * @parm name The name of the key binding.
346                          * @param type Returns the type as CIMKeyBinding::Type.
347                          *             It is invalid if rc == SCMO_INDEX_OUT_OF_BOUND.
348                          * @parma value Returns the value as string.
349                          *             Has to be copied by caller.
350 thilo.boehm 1.1.2.1      *             It is only valid if rc == SCMO_OK.
351                          * @return     SCMO_OK
352                          *             SCMO_NULL_VALUE : The key binding is not set.
353                          *             SCMO_NOT_FOUND : Given property name not found.
354                          */
355                         SCMO_RC getKeyBinding(
356                             const char* name,
357                             CIMKeyBinding::Type& ptype,
358                             const char** pvalue) const;
359                     
360                         /**
361                          * Determines whether the object has been initialized.
362                          * @return True if the object has not been initialized, false otherwise.
363                          */
364                         Boolean isUninitialized( ) const {return (inst.base == NULL); };
365                     
366                         /**
367                          * Determies if two objects are referencing to the same instance
368                          * @return True if the objects are referencing to the some instance.
369                          */
370                         Boolean isSame(SCMOInstance& theInstance) const;
371 thilo.boehm 1.1.2.1 
372                         /**
373                          * Get the host name of the instance. The caller has to make a copy !
374                          * @return The host name as UTF8.
375                          */
376                         const char* getHostName() const;
377                     
378                         /**
379                          * Sets the provided host name at the instance.
380                          * @param hostName The host name as UTF8.
381                          */
382                         void setHostName(const char* hostName);
383                     
384                         /**
385                          * Get the class name of the instance. The cabler has to make a copy !
386                          * @return The class name as UTF8.
387                          */
388                         const char* getClassName() const;
389                     
390                         /**
391                          * Get the name space of the instance. The caller has to make a copy !
392 thilo.boehm 1.1.2.1      * @return The name space as UTF8.
393                          */
394                         const char* getNameSpace() const;
395                     
396                         /**
397                          *  To indicate the export processing ( eg. XMLWriter )
398                          *  to include qualifiers for this instance.
399                          */
400                         void includeQualifiers()
401                         {
402                             inst.hdr->flags.includeQualifiers = true;
403                         };
404                     
405                         /**
406                          *  To indicate the export processing ( eg. XMLWriter )
407                          *  to NOT to include (exclude) qualifiers for this instance.
408                          */
409                         void excludeQualifiers()
410                         {
411                             inst.hdr->flags.includeQualifiers = false;
412                         }
413 thilo.boehm 1.1.2.1 
414                         /**
415                          *  To indicate the export processing ( eg. XMLWriter )
416                          *  to include class origins for this instance.
417                          */
418                         void includeClassOrigins()
419                         {
420                             inst.hdr->flags.includeClassOrigin = true;
421                         };
422                     
423                         /**
424                          *  To indicate the export processing ( eg. XMLWriter )
425                          *  to NOT to include (exclude) class origins for this instance.
426                          */
427                         void excludeClassOrigins()
428                         {
429                             inst.hdr->flags.includeClassOrigin = false;
430                         }
431                     
432                     private:
433                     
434 thilo.boehm 1.1.2.1     void Ref()
435                         {
436                             inst.hdr->refCount++;
437                             // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
438                         };
439                     
440                         void Unref()
441                         {
442                             if (inst.hdr->refCount.decAndTestIfZero())
443                             {
444                                 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
445                                 // The class has also be dereferenced.
446                                 delete inst.hdr->theClass;
447                                 free(inst.base);
448                                 inst.base=NULL;
449                             }
450                             else
451                             {
452                                 // printf("\ninst.hdr->refCount=%u\n",inst.hdr->refCount.get());
453                             }
454                     
455 thilo.boehm 1.1.2.1     };
456                         /**
457                          * A SCMOInstance can only be created by a SCMOClass
458                          */
459                         SCMOInstance();
460                     
461                         void _initSCMOInstance(
462                             SCMOClass* pClass,
463                             Boolean inclQual,
464                             Boolean inclOrigin);
465                     
466                     
467                         SCMO_RC _getPropertyAtNodeIndex(
468                                 Uint32 pos,
469                                 const char** pname,
470                                 CIMType& type,
471                                 const void** pvalue,
472                                 Boolean& isArray,
473                                 Uint32& size ) const;
474                     
475                         void _setPropertyAtNodeIndex(
476 thilo.boehm 1.1.2.1         Uint32 pos,
477                             CIMType type,
478                             void* value,
479                             Boolean isArray,
480                             Uint32 size);
481                     
482                         void* _getSCMBUnion(
483                             CIMType type,
484                             Boolean isArray,
485                             Uint32 size,
486                             Uint64 start,
487                             char* base) const;
488                     
489                         void _setSCMBUnion(
490                             void* value,
491                             CIMType type,
492                             Boolean isArray,
493                             Uint32 size,
494                             Uint64 start);
495                     
496                         SCMO_RC _getKeyBindingAtNodeIndex(
497 thilo.boehm 1.1.2.1         Uint32 pos,
498                             const char** pname,
499                             CIMKeyBinding::Type& ptype,
500                             const char** pvalue) const;
501                     
502                         Uint32 _initPropFilterWithKeys();
503                     
504                         void _setPropertyInPropertyFilter(Uint32 i);
505                     
506                         Boolean _isPropertyInFilter(Uint32 i) const;
507                     
508                         void _clearPropertyFilter();
509                     
510 thilo.boehm 1.1.2.3     void _setKeyBindingFromSCMBUnion(
511                             CIMType type, 
512                             SCMBUnion& u,
513                             SCMBDataPtr& keyNode);
514 thilo.boehm 1.1.2.2 
515 thilo.boehm 1.1.2.1     union{
516                             // To access the instance main structure
517                             SCMBInstance_Main *hdr;
518                             // To access the memory management header
519                             SCMBMgmt_Header     *mem;
520                             // Generic access pointer
521                             char *base;
522                         }inst;
523                     
524                         friend class SCMOClass;
525                         friend class SCMODump;
526                     };
527                     
528                     
529                     PEGASUS_NAMESPACE_END
530                     
531                     
532                     #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2