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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2