(file) Return to CMPISCMOUtilities.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI

  1 r.kieninger 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 r.kieninger 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                     #include "CMPI_Version.h"
 33                     
 34                     #include "CMPI_String.h"
 35                     #include "CMPI_Value.h"
 36                     #include "CMPISCMOUtilities.h"
 37                     
 38 r.kieninger 1.1.2.6 #include <Pegasus/Common/Tracer.h>
 39                     
 40 r.kieninger 1.1.2.1 PEGASUS_USING_STD;
 41                     PEGASUS_NAMESPACE_BEGIN
 42                     
 43                     CIMDateTimeRep* CMPISCMOUtilities::scmoDateTimeFromCMPI(CMPIDateTime* cmpidt)
 44                     {
 45                         CIMDateTimeRep* cimdt = 0;
 46                     
 47                         if (cmpidt && cmpidt->hdl)
 48                         {
 49                             cimdt = ((CIMDateTime*)cmpidt->hdl)->_rep;
 50                         }
 51                         return cimdt;
 52                     }
 53                     
 54 r.kieninger 1.1.2.6 
 55                     // Function to copy all key bindings from one SCMOInstance to another
 56                     CMPIrc CMPISCMOUtilities::copySCMOKeyProperties( const SCMOInstance* sourcePath,
 57                                                                      SCMOInstance* targetPath )
 58                     {
 59                         PEG_METHOD_ENTER(
 60                             TRC_CMPIPROVIDERINTERFACE,
 61                             "CMPISCMOUtilities::copySCMOKeyProperties()");
 62                     
 63                         if ((0!=sourcePath) && (0!=targetPath)) 
 64                         {
 65                             SCMO_RC rc;
 66                             const char* keyName = 0;
 67                             const SCMBUnion* keyValue = 0;
 68                             CIMType keyType;
 69                     
 70                             Uint32 numKeys = sourcePath->getKeyBindingCount();
 71                             for (Uint32 x=0; x < numKeys; x++)
 72                             {
 73                                 rc = sourcePath->getKeyBindingAt(
 74                                     x, &keyName, keyType, &keyValue);
 75 r.kieninger 1.1.2.6             if ((rc != SCMO_OK) || (0==keyValue))
 76                                 {
 77                                     PEG_TRACE_CSTRING(
 78                                         TRC_CMPIPROVIDERINTERFACE,
 79                                         Tracer::LEVEL1,
 80                                         "Failed to retrieve keybinding");
 81                                     PEG_METHOD_EXIT();
 82                                     return CMPI_RC_ERR_FAILED;
 83                                 }
 84                                 rc = targetPath->setKeyBinding(
 85                                     keyName, keyType, keyValue);
 86                                 if (rc != SCMO_OK)
 87                                 {
 88                                     PEG_TRACE_CSTRING(
 89                                         TRC_CMPIPROVIDERINTERFACE,
 90                                         Tracer::LEVEL1,
 91                                         "Failed to set keybinding");
 92                                     PEG_METHOD_EXIT();
 93                                     return CMPI_RC_ERR_FAILED;
 94                                 }
 95                             }
 96 r.kieninger 1.1.2.6     }
 97                         else
 98                         {
 99                             PEG_TRACE_CSTRING(
100                                 TRC_CMPIPROVIDERINTERFACE,
101                                 Tracer::LEVEL1,
102                                 "Called with Nullpointer for source or target");
103                             PEG_METHOD_EXIT();
104                             return CMPI_RC_ERR_FAILED;
105                         }
106                     
107                         return CMPI_RC_OK;
108                     }
109                     
110 r.kieninger 1.1.2.4 // Function to convert a CIMInstance into an SCMOInstance
111                     // CAUTION: This function requires access to the CMPIClassCache, and
112                     //          therefore can only be called from within a CMPI provider !!!
113                     SCMOInstance* CMPISCMOUtilities::getSCMOFromCIMInstance(
114 r.kieninger 1.1.2.5     const CIMInstance& cimInst,
115                         const char* ns,
116                         const char* cls)
117 r.kieninger 1.1.2.4 {
118 r.kieninger 1.1.2.7     Boolean isDirty=false;
119 r.kieninger 1.1.2.4     const CIMObjectPath& cimPath = cimInst.getPath();
120 r.kieninger 1.1.2.5 
121                         const CString nameSpace = cimPath.getNameSpace().getString().getCString();
122                         const CString className = cimPath.getClassName().getString().getCString();
123 r.kieninger 1.1.2.7 
124                         if (!ns) 
125                         {
126                             ns = (const char*)nameSpace;
127                         }
128                         if (!cls) 
129                         {
130                             cls = (const char*)className;
131                         }
132                     
133                         SCMOClass* scmoClass = mbGetSCMOClass(0,ns,cls);
134                     
135                         if (0 == scmoClass)
136                         {
137                             isDirty=true;
138                             scmoClass = new SCMOClass(cls,ns);
139                         }
140 r.kieninger 1.1.2.4 
141                         SCMOInstance* scmoInst = new SCMOInstance(*scmoClass, cimInst);
142                     
143 r.kieninger 1.1.2.7     if (isDirty) 
144                         {
145                             scmoInst->markAsCompromised();
146                         }
147                     
148 r.kieninger 1.1.2.4     return scmoInst;
149                     }
150                     
151                     // Function to convert a CIMObjectPath into an SCMOInstance
152                     // CAUTION: This function requires access to the CMPIClassCache, and
153                     //          therefore can only be called from within a CMPI provider !!!
154                     SCMOInstance* CMPISCMOUtilities::getSCMOFromCIMObjectPath(
155 r.kieninger 1.1.2.5     const CIMObjectPath& cimPath,
156                         const char* ns,
157                         const char* cls)
158 r.kieninger 1.1.2.4 {
159 r.kieninger 1.1.2.7     Boolean isDirty=false;
160 r.kieninger 1.1.2.4     CString nameSpace = cimPath.getNameSpace().getString().getCString();
161                         CString className = cimPath.getClassName().getString().getCString();
162 r.kieninger 1.1.2.7 
163                         if (!ns) 
164                         {
165                             ns = (const char*)nameSpace;
166                         }
167                         if (!cls) 
168                         {
169                             cls = (const char*)className;
170                         }
171                     
172                     
173                         SCMOClass* scmoClass = mbGetSCMOClass(0,ns,cls);
174                     
175                         if (0 == scmoClass)
176                         {
177                             isDirty=true;
178                             scmoClass = new SCMOClass(cls,ns);
179                         }
180 r.kieninger 1.1.2.4 
181                         SCMOInstance* scmoRef = new SCMOInstance(*scmoClass, cimPath);
182 r.kieninger 1.1.2.7     if (isDirty) 
183                         {
184                             scmoRef->markAsCompromised();
185                         }
186 r.kieninger 1.1.2.4 
187                         return scmoRef;
188                     }
189                     
190 r.kieninger 1.1.2.1 // Function to convert a SCMO Value into a CMPIData structure
191                     CMPIrc CMPISCMOUtilities::scmoValue2CMPIData(
192 r.kieninger 1.1.2.3     const SCMBUnion* scmoValue, 
193                         CMPIType type, 
194                         CMPIData *data, 
195                         Uint32 arraySize)
196 r.kieninger 1.1.2.1 {
197                         //Initialize CMPIData object
198                         data->type = type;
199                         data->value.uint64 = 0;
200 r.kieninger 1.1.2.3     data->state = CMPI_goodValue;
201 r.kieninger 1.1.2.1 
202                         //Check for NULL CIMValue
203                         if( scmoValue == 0 )
204                         {
205 r.kieninger 1.1.2.3         data->state = CMPI_nullValue;
206 r.kieninger 1.1.2.1         return CMPI_RC_OK;
207                         }
208                     
209                         if (type & CMPI_ARRAY)
210                         {
211 r.kieninger 1.1.2.3         // Get the type of the element of the CMPIArray
212                             CMPIType aType = type&~CMPI_ARRAY;
213                     
214                             //Allocate CMPIData array to hold the values
215                             CMPIData *arrayRoot = new CMPIData[arraySize+1];
216                     
217                             // Advance array pointer to first array element
218                             CMPIData *aData = arrayRoot;
219                             aData++;
220                     
221                             // Set the type, state and value of array elements
222                             for( Uint32 i=0; i<arraySize; i++ )
223                             {
224                                 CMPIrc rc = scmoValue2CMPIData(&(scmoValue[i]),aType,&(aData[i]));
225                                 if (rc != CMPI_RC_OK)
226                                 {
227                                     return rc;
228                                 }
229                             }
230                     
231                             // Create array encapsulation object
232 r.kieninger 1.1.2.3         arrayRoot->type = aType;
233                             arrayRoot->value.sint32 = arraySize;
234                             CMPI_Array *arr = new CMPI_Array(arrayRoot);
235                     
236                             // Set the encapsulated array as data
237                             data->value.array = 
238                                 reinterpret_cast<CMPIArray*>(new CMPI_Object(arr));
239 r.kieninger 1.1.2.1     }
240                         else
241                         {
242 r.kieninger 1.1.2.3         // Check for encpsulated type, which need special handling
243                             if (type&CMPI_ENC)
244 r.kieninger 1.1.2.1         {
245 r.kieninger 1.1.2.3             switch (type)
246 r.kieninger 1.1.2.1             {
247 r.kieninger 1.1.2.3             case CMPI_chars:
248                                 case CMPI_string:
249 r.kieninger 1.1.2.2                 {
250 r.kieninger 1.1.2.3                     if (scmoValue->extString.pchar)
251                                         {
252                                             data->value.string = reinterpret_cast<CMPIString*>(
253                                                 new CMPI_Object(scmoValue->extString.pchar));
254                                             data->type = CMPI_string;
255                                         }
256                                         else
257                                         {
258                                             data->state=CMPI_nullValue;
259                                         }
260                                         break;
261 r.kieninger 1.1.2.2                 }
262 r.kieninger 1.1.2.3 
263                                 case CMPI_dateTime:
264 r.kieninger 1.1.2.2                 {
265 r.kieninger 1.1.2.3                     CIMDateTime* cimdt = 
266                                             new CIMDateTime(&scmoValue->dateTimeValue);
267                                         data->value.dateTime = reinterpret_cast<CMPIDateTime*>
268                                             (new CMPI_Object(cimdt));
269                                         break;
270 r.kieninger 1.1.2.2                 }
271 r.kieninger 1.1.2.1 
272 r.kieninger 1.1.2.3             case CMPI_ref:
273                                     {
274 r.kieninger 1.1.2.4                     SCMOInstance* ref = 
275                                             new SCMOInstance(*(scmoValue->extRefPtr));
276 r.kieninger 1.1.2.3                     data->value.ref = reinterpret_cast<CMPIObjectPath*>
277 r.kieninger 1.1.2.8                         (new CMPI_Object(
278                                                 ref,
279                                                 CMPI_Object::ObjectTypeObjectPath));
280 r.kieninger 1.1.2.3                 }
281 r.kieninger 1.1.2.1                 break;
282                     
283 r.kieninger 1.1.2.3             case CMPI_instance:
284                                     {
285 r.kieninger 1.1.2.4                     SCMOInstance* inst = 
286                                             new SCMOInstance(*(scmoValue->extRefPtr));
287 r.kieninger 1.1.2.3                     data->value.inst = reinterpret_cast<CMPIInstance*>
288 r.kieninger 1.1.2.8                         (new CMPI_Object(
289                                                 inst, 
290                                                 CMPI_Object::ObjectTypeInstance));
291 r.kieninger 1.1.2.3                 }
292                                     break;
293                                 default:
294                                     {
295                                         // Not supported for this CMPItype
296                                         return CMPI_RC_ERR_NOT_SUPPORTED;
297                                         break;
298                                     }
299 r.kieninger 1.1.2.1             }
300 r.kieninger 1.1.2.3         }
301                             else
302                             {
303                                 // For non-encapsulated type simply copy the first 64bit
304                                 // of the SCMBUnion to CMPIValue
305                                 if (scmoValue->simple.hasValue)
306 r.kieninger 1.1.2.1             {
307 r.kieninger 1.1.2.3                 data->value.uint64 = scmoValue->simple.val.u64;
308 r.kieninger 1.1.2.1             }
309 r.kieninger 1.1.2.3             else
310 r.kieninger 1.1.2.1             {
311 r.kieninger 1.1.2.3                 data->value.uint64 = 0;
312                                     data->state = CMPI_nullValue;
313 r.kieninger 1.1.2.1             }
314                             }
315                         }
316                         return CMPI_RC_OK;
317                     }
318                     
319                     PEGASUS_NAMESPACE_END
320                     

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2