00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <iostream>
00025 #include "cmpisrv.h"
00026 #include "OW_Char16.hpp"
00027 #include "OW_CIMValue.hpp"
00028 #include "OW_CIMDateTime.hpp"
00029
00030 #define CopyToArray(pt,ct) { pt##Array ar(aSize); \
00031 for (int i=0; i<aSize; i++) ar[i]=pt(aData[i].value.ct); \
00032 v.set(OpenWBEM::CIMValue(ar)); }
00033
00034 #define CopyToStringArray(pt,ct) { OpenWBEM::Array<pt> ar(aSize); \
00035 for (int i=0; i<aSize; i++) ar[i]=OpenWBEM::String(((char*)aData[i].value)->ct); \
00036 v.set(OpenWBEM::CIMValue(ar)); }
00037
00038 #define CopyToEncArray(pt,ct) { OpenWBEM::Array<pt> ar(aSize); \
00039 for (int i=0; i<aSize; i++) ar[i]=*((pt*)aData[i].value.ct->hdl); \
00040 v.set(OpenWBEM::CIMValue(ar)); }
00041
00042
00043 OpenWBEM::CIMValue value2CIMValue(const CMPIValue* data, const CMPIType type, CMPIrc *rc)
00044 {
00045 OpenWBEM::CIMValue v(OpenWBEM::CIMNULL);
00046 if(rc)
00047 {
00048 *rc = CMPI_RC_OK;
00049 }
00050
00051 if (data == NULL)
00052 {
00053 return v;
00054 }
00055
00056 if(type & CMPI_ARRAY)
00057 {
00058 CMPIArray *ar=data->array;
00059 CMPIData *aData=(CMPIData*)ar->hdl;
00060 CMPIType aType=aData->type;
00061
00062 if(aType & CMPI_ARRAY)
00063 {
00064 aType ^= CMPI_ARRAY;
00065 }
00066
00067 int aSize=aData->value.sint32;
00068 aData++;
00069
00070 if((aType & (CMPI_UINT|CMPI_SINT)) == CMPI_SINT)
00071 {
00072 switch(aType)
00073 {
00074 case CMPI_sint32: CopyToArray(OpenWBEM::Int32,sint32); break;
00075 case CMPI_sint16: CopyToArray(OpenWBEM::Int16,sint16); break;
00076 case CMPI_sint8: CopyToArray(OpenWBEM::Int8,sint8); break;
00077 case CMPI_sint64: CopyToArray(OpenWBEM::Int64,sint64); break;
00078 default: ;
00079 }
00080 }
00081
00082
00083
00084 else if(aType == CMPI_charsA || aType == CMPI_chars)
00085 {
00086 OpenWBEM::Array<OpenWBEM::String> helper(aSize);
00087 for(int i = 0; i < aSize; i++)
00088 {
00089 helper[i] = OpenWBEM::String( (char *)(aData[i].value.chars));
00090 }
00091 v.set(OpenWBEM::CIMValue(helper));
00092 }
00093
00094 else if(aType == CMPI_string)
00095 {
00096 OpenWBEM::Array<OpenWBEM::String> helper(aSize);
00097 for(int i = 0; i < aSize; i++)
00098 {
00099 helper[i]=OpenWBEM::String((char *)(aData[i].value.string->hdl));
00100 }
00101
00102 v.set(OpenWBEM::CIMValue(helper));
00103 }
00104
00105 else if((aType & (CMPI_UINT|CMPI_SINT)) == CMPI_UINT)
00106 {
00107 switch(aType)
00108 {
00109 case CMPI_uint32: CopyToArray(OpenWBEM::UInt32,uint32); break;
00110 case CMPI_uint16: CopyToArray(OpenWBEM::UInt16,uint16); break;
00111 case CMPI_uint8: CopyToArray(OpenWBEM::UInt8,uint8); break;
00112 case CMPI_uint64: CopyToArray(OpenWBEM::UInt64,uint64); break;
00113 default: ;
00114 }
00115 }
00116
00117 else switch(aType)
00118 {
00119 case CMPI_ref: CopyToEncArray(OpenWBEM::CIMObjectPath,ref); break;
00120 case CMPI_dateTime: CopyToEncArray(OpenWBEM::CIMDateTime,dateTime); break;
00121 case CMPI_boolean: CopyToArray(OpenWBEM::Bool,boolean); break;
00122 case CMPI_char16: CopyToArray(OpenWBEM::Char16,char16); break;
00123 case CMPI_real32: CopyToArray(OpenWBEM::Real32,real32); break;
00124 case CMPI_real64: CopyToArray(OpenWBEM::Real64,real64); break;
00125 default:
00126 if(rc)
00127 {
00128 *rc=CMPI_RC_ERR_NOT_SUPPORTED;
00129 }
00130 }
00131 return OpenWBEM::CIMValue(v);
00132 }
00133 else if((type & (CMPI_UINT|CMPI_SINT)) == CMPI_SINT)
00134 {
00135 switch(type)
00136 {
00137
00138
00139
00140
00141 case CMPI_sint32: v.set(OpenWBEM::CIMValue((OpenWBEM::Int32)data->sint32)); break;
00142 case CMPI_sint16: v.set(OpenWBEM::CIMValue((OpenWBEM::Int16)data->sint16)); break;
00143 case CMPI_sint8: v.set(OpenWBEM::CIMValue((OpenWBEM::Int8)data->sint8)); break;
00144 case CMPI_sint64: v.set(OpenWBEM::CIMValue((OpenWBEM::Int64)data->sint64)); break;
00145 default: ;
00146 }
00147 }
00148
00149
00150 else if(type == CMPI_string)
00151 {
00152 v.set(OpenWBEM::CIMValue(OpenWBEM::String((char*)data->string->hdl)));
00153 }
00154 else if(type == CMPI_chars)
00155 {
00156
00157
00158
00159
00160
00161
00162
00163 v.set(OpenWBEM::CIMValue(OpenWBEM::String((const char*)data)));
00164 }
00165 else if(((type & (CMPI_UINT|CMPI_SINT)) == CMPI_UINT) && type != CMPI_boolean)
00166 {
00167 switch(type)
00168 {
00169 case CMPI_uint32:
00170 v.set(OpenWBEM::CIMValue((OpenWBEM::UInt32)data->sint32));
00171 break;
00172 case CMPI_uint16:
00173 v.set(OpenWBEM::CIMValue((OpenWBEM::UInt16)data->sint16));
00174 break;
00175 case CMPI_uint8:
00176 v.set(OpenWBEM::CIMValue((OpenWBEM::UInt8)data->sint8));
00177 break;
00178 case CMPI_uint64:
00179 v.set(OpenWBEM::CIMValue((OpenWBEM::UInt64)data->sint64));
00180 break;
00181 default: ;
00182 }
00183 }
00184 else
00185 {
00186 switch(type)
00187 {
00188 case CMPI_ref:
00189 v.set(OpenWBEM::CIMValue(*((OpenWBEM::CIMObjectPath*)data->ref->hdl)));
00190 break;
00191 case CMPI_dateTime:
00192 v.set(OpenWBEM::CIMValue(*((OpenWBEM::CIMDateTime*)data->dateTime->hdl)));
00193 break;
00194 case CMPI_boolean:
00195 v.set(OpenWBEM::CIMValue((OpenWBEM::Bool)data->boolean));
00196 break;
00197 case CMPI_char16:
00198 v.set(OpenWBEM::CIMValue((OpenWBEM::Char16)data->char16));
00199 break;
00200 case CMPI_real32:
00201 v.set(OpenWBEM::CIMValue((OpenWBEM::Real32)data->real32));
00202 break;
00203 case CMPI_real64:
00204 v.set(OpenWBEM::CIMValue((OpenWBEM::Real64)data->real64));
00205 break;
00206 default:
00207 if(rc)
00208 {
00209 *rc = CMPI_RC_ERR_NOT_SUPPORTED;
00210 }
00211 }
00212 }
00213
00214
00215 return v;
00216 }
00217
00218
00219
00220 #define CopyFromArray(pt,ct) { OpenWBEM::Array<pt> ar; \
00221 v.get(ar); \
00222 for (int i=0; i<aSize; i++) aData[i].value.ct=ar[i]; }
00223
00224 #define CopyFromStringArray(pt,ct) { OpenWBEM::Array<pt> ar; \
00225 v.get(ar); \
00226 for (int i=0; i<aSize; i++) { \
00227 aData[i].value.ct=(CMPIString*)new CMPI_Object(ar[i]); } }
00228
00229 #define CopyFromEncArray(pt,ct,cn) { OpenWBEM::Array<pt> ar; \
00230 v.get(ar); \
00231 for (int i=0; i<aSize; i++) { \
00232 aData[i].value.cn=(ct*)new CMPI_Object(new pt(ar[i])); } }
00233
00234
00235 CMPIrc value2CMPIData(const OpenWBEM::CIMValue& v, CMPIType t, CMPIData *data)
00236 {
00237 data->type=t;
00238 data->state=0;
00239
00240 if(t & CMPI_ARRAY)
00241 {
00242 int aSize = v.getArraySize();
00243 CMPIType aType = t & (~CMPI_ARRAY);
00244 CMPIData *aData = new CMPIData[aSize+1];
00245 aData->type = aType;
00246 aData->value.sint32 = aSize;
00247 aData++;
00248
00249 if((aType & (CMPI_UINT | CMPI_SINT)) == CMPI_SINT)
00250 {
00251 switch(aType)
00252 {
00253 case CMPI_sint32: CopyFromArray(OpenWBEM::Int32,sint32); break;
00254 case CMPI_sint16: CopyFromArray(OpenWBEM::Int16,sint16); break;
00255 case CMPI_sint8: CopyFromArray(OpenWBEM::Int8,sint8); break;
00256 case CMPI_sint64: CopyFromArray(OpenWBEM::Int64,sint64); break;
00257 default: ;
00258 }
00259 }
00260 else if(aType == CMPI_string)
00261 {
00262 CopyFromStringArray(OpenWBEM::String,string)
00263 }
00264 else if((aType & (CMPI_UINT | CMPI_SINT)) == CMPI_UINT)
00265 {
00266 switch(aType)
00267 {
00268 case CMPI_uint32: CopyFromArray(OpenWBEM::UInt32,uint32); break;
00269 case CMPI_uint16: CopyFromArray(OpenWBEM::UInt16,uint16); break;
00270 case CMPI_uint8: CopyFromArray(OpenWBEM::UInt8,uint8); break;
00271 case CMPI_uint64: CopyFromArray(OpenWBEM::UInt64,uint64); break;
00272 default: ;
00273 }
00274 }
00275 else
00276 {
00277 switch(aType)
00278 {
00279 case CMPI_ref: CopyFromEncArray(OpenWBEM::CIMObjectPath,CMPIObjectPath,ref); break;
00280 case CMPI_dateTime: CopyFromEncArray(OpenWBEM::CIMDateTime,CMPIDateTime,dateTime); break;
00281 case CMPI_boolean: CopyFromArray(OpenWBEM::Bool,boolean); break;
00282 case CMPI_char16: CopyFromArray(OpenWBEM::Char16,char16); break;
00283 case CMPI_real32: CopyFromArray(OpenWBEM::Real32,real32); break;
00284 case CMPI_real64: CopyFromArray(OpenWBEM::Real64,real64); break;
00285 default:
00286 return CMPI_RC_ERR_NOT_SUPPORTED;
00287 }
00288 }
00289
00290 data->value.array=(CMPIArray*)new CMPI_Object(aData-1);
00291 }
00292
00293 else if((t & (CMPI_UINT | CMPI_SINT)) == CMPI_SINT)
00294 {
00295 switch(t)
00296 {
00297 case CMPI_sint32: v.get((OpenWBEM::Int32&)data->value.sint32); break;
00298 case CMPI_sint16: v.get((OpenWBEM::Int16&)data->value.sint16); break;
00299 case CMPI_sint8: v.get((OpenWBEM::Int8&)data->value.sint8); break;
00300 case CMPI_sint64: v.get((OpenWBEM::Int64&)data->value.sint64); break;
00301 default: ;
00302 }
00303 }
00304
00305 else if((t & (CMPI_UINT | CMPI_SINT)) == CMPI_UINT)
00306 {
00307 switch(t)
00308 {
00309 case CMPI_uint32: v.get((OpenWBEM::UInt32&)data->value.uint32); break;
00310 case CMPI_uint16: v.get((OpenWBEM::UInt16&)data->value.uint16); break;
00311 case CMPI_uint8: v.get((OpenWBEM::UInt8&)data->value.uint8); break;
00312 case CMPI_uint64: v.get((OpenWBEM::UInt64&)data->value.uint64); break;
00313 default: ;
00314 }
00315 }
00316
00317 else if(t == CMPI_string)
00318 {
00319 OpenWBEM::String str;
00320 v.get(str);
00321
00322 data->value.string=string2CMPIString(str);
00323 }
00324
00325
00326 else
00327 {
00328 switch(t)
00329 {
00330 case CMPI_ref:
00331 {
00332 OpenWBEM::CIMObjectPath ref;
00333 v.get(ref);
00334 data->value.ref =(CMPIObjectPath*)new CMPI_Object(
00335 new OpenWBEM::CIMObjectPath(ref));
00336 }
00337 break;
00338
00339 case CMPI_dateTime:
00340 {
00341 OpenWBEM::CIMDateTime dt;
00342 v.get(dt);
00343 data->value.dateTime=(CMPIDateTime*)new CMPI_Object(
00344 new OpenWBEM::CIMDateTime(dt));
00345 }
00346 break;
00347
00348 case CMPI_boolean: v.get((OpenWBEM::Bool&)data->value.boolean); break;
00349 case CMPI_char16: v.get((OpenWBEM::Char16&)data->value.char16); break;
00350 case CMPI_real32: v.get((OpenWBEM::Real32&)data->value.real32); break;
00351 case CMPI_real64: v.get((OpenWBEM::Real64&)data->value.real64); break;
00352 default:
00353 return CMPI_RC_ERR_NOT_SUPPORTED;
00354 }
00355 }
00356 return CMPI_RC_OK;
00357 }
00358
00359 CMPIType type2CMPIType(OpenWBEM::CIMDataType pt, int array)
00360 {
00361 static CMPIType types[] = {
00362 CMPI_uint8,
00363 CMPI_uint8,
00364 CMPI_sint8,
00365 CMPI_uint16,
00366 CMPI_sint16,
00367 CMPI_uint32,
00368 CMPI_sint32,
00369 CMPI_uint64,
00370 CMPI_sint64,
00371 CMPI_string,
00372 CMPI_boolean,
00373 CMPI_real32,
00374 CMPI_real64,
00375 CMPI_dateTime,
00376 CMPI_char16,
00377 CMPI_ref,
00378 };
00379
00380 int t = types[pt.getType()];
00381
00382 if(array)
00383 {
00384 t |= CMPI_ARRAY;
00385 }
00386
00387 return (CMPIType)t;
00388 }
00389
00390 CMPIrc key2CMPIData(const OpenWBEM::String& v, OpenWBEM::CIMDataType t, CMPIData *data)
00391 {
00392 data->state = CMPI_keyValue;
00393
00394
00395 if(t.isNumericType())
00396 {
00397 const char *vp = v.c_str();
00398 data->value.sint64 = OpenWBEM::String(vp).toInt64();
00399 data->type = CMPI_sint64;
00400
00401 }
00402
00403 else if(t.getType() == OpenWBEM::CIMDataType::STRING)
00404 {
00405 data->value.string = string2CMPIString(v);
00406 data->type = CMPI_string;
00407 }
00408
00409 else if(t.getType() == OpenWBEM::CIMDataType::BOOLEAN)
00410 {
00411 data->value.boolean = (v.compareToIgnoreCase("true"));
00412 data->type=CMPI_boolean;
00413 }
00414
00415 else if(t.getType() == OpenWBEM::CIMDataType::BOOLEAN)
00416 {
00417 data->value.ref = (CMPIObjectPath*)new CMPI_Object(new OpenWBEM::CIMObjectPath(v));
00418 data->type = CMPI_ref;
00419 }
00420 else
00421 {
00422 return CMPI_RC_ERR_NOT_SUPPORTED;
00423 }
00424
00425 return CMPI_RC_OK;
00426 }