00001 #include <cstdio>
00002 #include "OW_config.h"
00003 #include "NPIExternal.hpp"
00004 #include "OW_CIMParamValue.hpp"
00005 #include "OW_Format.hpp"
00006 #include "OW_FTABLERef.hpp"
00007 #include "OW_NPIProviderIFCUtils.hpp"
00008 #include "OW_CIMObjectPathEnumeration.hpp"
00009 #include "OW_CIMInstanceEnumeration.hpp"
00010 #include "OW_WQLSelectStatement.hpp"
00011 #include "OW_Logger.hpp"
00012
00013 namespace OW_NAMESPACE
00014 {
00015
00016 namespace
00017 {
00018 const String COMPONENT_NAME("ow.provider.npi.ifc");
00019 }
00020
00021 using namespace WBEMFlags;
00022
00023 void _NPIGarbageCan(NPIHandle * nh, void * object, NPIGarbageType type)
00024 {
00025 ((NPIContext *)(nh->context))->garbage.append(object);
00026 ((NPIContext *)(nh->context))->garbageType.append(type);
00027 }
00028 void _NPIGarbageRetrieve(NPIHandle * nh, void * object)
00029 {
00030 for (int i = ((NPIContext *)(nh->context))->garbage.size()-1;i >=0;i--)
00031 {
00032 if ( ((NPIContext *)(nh->context))->garbage[i] == object)
00033 ((NPIContext *)(nh->context))->garbageType[i] = NOTHING;
00034 }
00035 }
00036
00038 extern "C" CIMClass
00039 NPI_getmyClass(NPIHandle* npiHandle, const String& nameSpace,
00040 const String& className)
00041 {
00042 ProviderEnvironmentIFCRef * provenv =
00043 static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
00044 CIMClass cc(CIMNULL);
00045 try
00046 {
00047 cc = (*provenv)->getCIMOMHandle()->getClass(
00048 nameSpace, className,
00049 E_NOT_LOCAL_ONLY,
00050 E_INCLUDE_QUALIFIERS,
00051 E_INCLUDE_CLASS_ORIGIN, NULL);
00052 }
00053 catch (...)
00054 {
00055
00056
00057 raiseError(npiHandle,"Class or Namespace does not exist");
00058 }
00059 return cc;
00060 }
00062 extern "C" CIMObjectPathEnumeration
00063 NPI_enumeratemyInstanceNames(NPIHandle* npiHandle,
00064 const String& nameSpace, const String& className)
00065 {
00066 ProviderEnvironmentIFCRef * provenv =
00067 static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
00068 CIMObjectPathEnumeration crefs;
00069 try
00070 {
00071 crefs =
00072 (*provenv)->getCIMOMHandle()->enumInstanceNamesE(nameSpace, className);
00073 }
00074 catch (...)
00075 {
00076
00077
00078 npiHandle->errorOccurred = 1;
00079 raiseError(npiHandle,"Class or Namespace does not exist");
00080 }
00081 return crefs;
00082 }
00084 extern "C" CIMInstanceEnumeration
00085 NPI_enumeratemyInstances(NPIHandle* npiHandle, const String& nameSpace,
00086 const String& className)
00087 {
00088 ProviderEnvironmentIFCRef * provenv =
00089 static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
00090 CIMInstanceEnumeration cinsts;
00091 try
00092 {
00093 cinsts = (*provenv)->getCIMOMHandle()->enumInstancesE(
00094 nameSpace, className,
00095 E_DEEP,
00096 E_NOT_LOCAL_ONLY,
00097 E_EXCLUDE_QUALIFIERS,
00098 E_EXCLUDE_CLASS_ORIGIN, NULL);
00099 }
00100 catch (...)
00101 {
00102
00103
00104 raiseError(npiHandle,"Class or Namespace does not exist");
00105 }
00106 return cinsts;
00107 }
00109 extern "C" CIMInstance
00110 NPI_getmyInstance(NPIHandle* npiHandle, const CIMObjectPath& owcop,
00111 const int localOnly)
00112 {
00113 ProviderEnvironmentIFCRef * provenv =
00114 static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
00115 CIMInstance ci(CIMNULL);
00116 try
00117 {
00118 ci = (*provenv)->getCIMOMHandle()->getInstance(owcop.getNameSpace(),
00119 owcop, localOnly ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY);
00120 }
00121 catch (...)
00122 {
00123
00124
00125 raiseError(npiHandle,"Class or Namespace does not exist");
00126 }
00127 return ci;
00128 }
00129
00130 }
00131
00132 using namespace OpenWBEM;
00133
00134
00136 extern "C" Vector
00137 VectorNew(NPIHandle* npiHandle)
00138 {
00139 Vector v;
00140 v.ptr = (void*) new charVect;
00141 _NPIGarbageCan(npiHandle, v.ptr, VECTOR);
00142 return v;
00143 }
00145 extern "C" void
00146 _VectorAddTo(NPIHandle* npiHandle, Vector v, void* obj)
00147 {
00148 ((charVect*)v.ptr)->append((char*)obj);
00149 }
00151 extern "C" int
00152 VectorSize(NPIHandle* npiHandle, Vector v)
00153 {
00154 return((charVect*)v.ptr)->size();
00155 }
00157 extern "C" void*
00158 _VectorGet(NPIHandle* npiHandle, Vector v, int pos)
00159 {
00160 void* result = NULL;
00161 result = (void*) ((*((charVect*)v.ptr))[pos]);
00162 return result;
00163 }
00164
00166 extern "C" CIMType
00167 CIMValueGetType(NPIHandle*, ::CIMValue cv)
00168 {
00169 OpenWBEM::CIMValue* pcv = (OpenWBEM::CIMValue*)cv.ptr;
00170 int pct = pcv->getType();
00171 switch (pct)
00172 {
00173 case CIMDataType::BOOLEAN :
00174 case CIMDataType::UINT8:
00175 case CIMDataType::SINT8:
00176 case CIMDataType::UINT16:
00177 case CIMDataType::SINT16:
00178 case CIMDataType::UINT32:
00179 case CIMDataType::SINT32:
00180 case CIMDataType::UINT64:
00181 case CIMDataType::SINT64:
00182 case CIMDataType::REAL32:
00183 case CIMDataType::REAL64:
00184 case CIMDataType::DATETIME:
00185 return CIM_INTEGER;
00186 case CIMDataType::CHAR16:
00187 case CIMDataType::STRING:
00188 return CIM_STRING;
00189 case CIMDataType::REFERENCE:
00190 return CIM_REF;
00191 }
00192 return CIM_INTEGER;
00193 }
00195 extern "C" ::CIMValue
00196 CIMValueNewString(NPIHandle* npiHandle, const char* val)
00197 {
00198 OpenWBEM::CIMValue* pcv = new OpenWBEM::CIMValue(String(val));
00199 ::CIMValue cv = { (void*) pcv};
00200 _NPIGarbageCan(npiHandle, (void *) pcv, CIM_VALUE);
00201 return cv;
00202 }
00204 extern "C" ::CIMValue
00205 CIMValueNewInteger(NPIHandle* npiHandle, int val)
00206 {
00207 OpenWBEM::CIMValue* pcv = new OpenWBEM::CIMValue(val);
00208 ::CIMValue cv = { (void*) pcv};
00209 _NPIGarbageCan(npiHandle, (void *) pcv, CIM_VALUE);
00210 return cv;
00211 }
00213 extern "C" ::CIMValue
00214 CIMValueNewRef(NPIHandle* npiHandle, ::CIMObjectPath cop)
00215 {
00216 OpenWBEM::CIMValue* pcv = new OpenWBEM::CIMValue(*((OpenWBEM::CIMObjectPath*)cop.ptr));
00217 ::CIMValue cv = { (void*) pcv};
00218 _NPIGarbageCan(npiHandle, (void *) pcv, CIM_VALUE);
00219 return cv;
00220 }
00222 extern "C" char*
00223 CIMValueGetString(NPIHandle* npiHandle, ::CIMValue cv)
00224 {
00225 try {
00226 OpenWBEM::CIMValue* pcv = (OpenWBEM::CIMValue*)cv.ptr;
00227 String mystring = pcv->toString();
00228 return mystring.allocateCString();
00229 } catch (...) {
00230 raiseError(npiHandle, "Error getting string value");
00231 return NULL;
00232 }
00233 }
00235 extern "C" int
00236 CIMValueGetInteger(NPIHandle* npiHandle, ::CIMValue cv)
00237 {
00238 int retval;
00239 try {
00240 OpenWBEM::CIMValue* pcv = (OpenWBEM::CIMValue*)cv.ptr;
00241 pcv->get(retval);
00242 } catch (...) {
00243 raiseError(npiHandle, "Error getting int value");
00244 }
00245 return retval;
00246 }
00248 extern "C" ::CIMObjectPath
00249 CIMValueGetRef(NPIHandle* npiHandle, ::CIMValue cv)
00250 {
00251 ::CIMObjectPath cop = { NULL};
00252 try {
00253 OpenWBEM::CIMValue* pcv = (OpenWBEM::CIMValue*) cv.ptr;
00254 OpenWBEM::CIMObjectPath cref(CIMNULL);
00255 pcv->get(cref);
00256 OpenWBEM::CIMObjectPath* ncop = new OpenWBEM::CIMObjectPath(cref);
00257 ::CIMObjectPath cop = {(void*) ncop};
00258 _NPIGarbageCan(npiHandle, (void *) ncop, CIM_OBJECTPATH);
00259 } catch (...) {
00260 raiseError(npiHandle, "Error getting ref value");
00261 }
00262 return cop;
00263 }
00264
00266 extern "C" ::CIMType
00267 CIMParameterGetType(NPIHandle* npiHandle, ::CIMParameter cp)
00268 {
00269 int dt;
00270 try {
00271 OpenWBEM::CIMParamValue* pcp = (OpenWBEM::CIMParamValue*)cp.ptr;
00272 dt = pcp->getValue().getType();
00273 } catch (...) {
00274 raiseError(npiHandle, "Error getting parameter type");
00275 }
00276
00277
00278 switch (dt)
00279 {
00280 case CIMDataType::BOOLEAN :
00281 case CIMDataType::UINT8 :
00282 case CIMDataType::SINT8 :
00283 case CIMDataType::UINT16 :
00284 case CIMDataType::SINT16 :
00285 case CIMDataType::UINT32 :
00286 case CIMDataType::SINT32 :
00287 case CIMDataType::UINT64 :
00288 case CIMDataType::SINT64 :
00289 case CIMDataType::REAL32 :
00290 case CIMDataType::REAL64 :
00291 case CIMDataType::DATETIME :
00292 return CIM_INTEGER;
00293 case CIMDataType::CHAR16 :
00294 case CIMDataType::STRING :
00295 return CIM_STRING;
00296 case CIMDataType::REFERENCE :
00297 return CIM_REF;
00298 }
00299 return CIM_INTEGER;
00300 }
00302 extern "C" char*
00303 CIMParameterGetName(NPIHandle* npiHandle, ::CIMParameter cp)
00304 {
00305 try {
00306 CIMParamValue* pcp = (CIMParamValue*)cp.ptr;
00307 return pcp->getName().allocateCString();
00308 } catch (...) {
00309 raiseError(npiHandle, "Error getting parameter name");
00310
00311 return NULL;
00312 }
00313 }
00315 extern "C" ::CIMParameter
00316 CIMParameterNewString(NPIHandle* npiHandle, const char* name, const char* value)
00317 {
00318 ::CIMParameter mycp = { NULL};
00319
00320 if (name == NULL)
00321 return mycp;
00322 if (strlen(name) == 0)
00323 return mycp;
00324 CIMParamValue* pcp = new CIMParamValue(String(name),
00325 OpenWBEM::CIMValue(String(value)));
00326 mycp.ptr = pcp;
00327 _NPIGarbageCan(npiHandle, (void *) mycp.ptr, CIM_PARAMVALUE);
00328 return mycp;
00329 }
00331 extern "C" ::CIMParameter
00332 CIMParameterNewInteger(NPIHandle* npiHandle, const char* name, int value)
00333 {
00334 ::CIMParameter mycp = { NULL};
00335
00336 if (name == NULL)
00337 return mycp;
00338 if (strlen(name) == 0)
00339 return mycp;
00340 CIMParamValue * pcp = new CIMParamValue(String(name),
00341 OpenWBEM::CIMValue(Int32(value)));
00342 mycp.ptr = pcp;
00343 _NPIGarbageCan(npiHandle, (void *) mycp.ptr, CIM_PARAMVALUE);
00344 return mycp;
00345 }
00347 extern "C" ::CIMParameter
00348 CIMParameterNewRef(NPIHandle* npiHandle, const char* name, ::CIMObjectPath value)
00349 {
00350 ::CIMParameter mycp = { NULL};
00351
00352 if (name == NULL)
00353 return mycp;
00354 if (strlen(name) == 0)
00355 return mycp;
00356 OpenWBEM::CIMValue val(*((OpenWBEM::CIMObjectPath*)value.ptr));
00357 mycp.ptr = new CIMParamValue(String(name), val);
00358 _NPIGarbageCan(npiHandle, (void *) mycp.ptr, CIM_PARAMVALUE);
00359 return mycp;
00360 }
00362 extern "C" char*
00363 CIMParameterGetString(NPIHandle* npiHandle, ::CIMParameter cp)
00364 {
00365 try {
00366 CIMParamValue* pcpv = static_cast<CIMParamValue *> (cp.ptr);
00367 String value = pcpv->getValue().toString();
00368 return value.allocateCString();
00369 } catch (...) {
00370 raiseError(npiHandle, "Retrieving string parameter failed. Possible attemt to retrieve non-string parameter");
00371
00372 return NULL;
00373 }
00374 }
00376 extern "C" int
00377 CIMParameterGetIntegerValue(NPIHandle* npiHandle, ::CIMParameter cp)
00378 {
00379 int value;
00380 try {
00381 CIMParamValue* pcpv = (CIMParamValue*)cp.ptr;
00382 pcpv->getValue().get(value);
00383 } catch (...) {
00384 raiseError(npiHandle, "Retrieving integer parameter failed. Possible attemt to retrieve non-integer parameter");
00385
00386 }
00387 return value;
00388 }
00390 extern "C" ::CIMObjectPath
00391 CIMParameterGetRefValue(NPIHandle* npiHandle, ::CIMParameter cp)
00392 {
00393 ::CIMObjectPath cop = { NULL};
00394 try {
00395 CIMParamValue* pcpv = (CIMParamValue*)cp.ptr;
00396 OpenWBEM::CIMObjectPath op(CIMNULL);
00397 OpenWBEM::CIMValue val = pcpv->getValue();
00398 val.get(op);
00399 OpenWBEM::CIMObjectPath * pop = new OpenWBEM::CIMObjectPath(op);
00400 ::CIMObjectPath cop = { (void*) pop};
00401 _NPIGarbageCan(npiHandle, (void *) pop, CIM_OBJECTPATH);
00402 } catch (...) {
00403 raiseError(npiHandle, "Retrieving ref parameter failed. Possible attemt to retrieve non-ref parameter");
00404
00405 }
00406 return cop;
00407 }
00408
00410 extern "C" ::CIMInstance
00411 CIMClassNewInstance(NPIHandle* npiHandle, ::CIMClass cc)
00412 {
00413 ::CIMInstance ci ={ NULL};
00414 try {
00415 OpenWBEM::CIMClass * owcc = static_cast<OpenWBEM::CIMClass *>(cc.ptr);
00416 OpenWBEM::CIMInstance * owci = new OpenWBEM::CIMInstance(owcc->newInstance());
00417 ci.ptr = static_cast<void *>(owci);
00418 _NPIGarbageCan(npiHandle, (void *) owci, CIM_INSTANCE);
00419 } catch (...) {
00420 raiseError(npiHandle,"Error creating instance");
00421
00422 }
00423 return ci;
00424 }
00426 extern "C" void
00427 CIMInstanceSetStringProperty(NPIHandle* npiHandle, ::CIMInstance ci,
00428 const char* name, const char* value )
00429 {
00430
00431 if (name == NULL) return;
00432
00433 try {
00434 if (strlen(name) == 0) return;
00435 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00436 String Key(name);
00437 String Val;
00438 if (value)
00439 {
00440 if (strlen(value)>0)
00441 {
00442 Val = String(value);
00443 }
00444 else
00445 {
00446 Val = String("-empty-");
00447 }
00448 }
00449 else
00450 {
00451 Val = String("-empty-");
00452 }
00453 OpenWBEM::CIMValue Value(Val);
00454 owci->setProperty(Key,Value);
00455 } catch (...) {
00456 raiseError(npiHandle,"Error setting string property");
00457
00458 return;
00459 }
00460 }
00462 extern "C" void
00463 CIMInstanceSetIntegerProperty(NPIHandle* npiHandle, ::CIMInstance ci,
00464 const char* name, const int value)
00465 {
00466
00467 if (name == NULL) return;
00468
00469 try {
00470 if (strlen(name) == 0) return;
00471 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00472 owci->setProperty(String(name),OpenWBEM::CIMValue(value));
00473 } catch (...) {
00474 raiseError(npiHandle,"Error setting integer property");
00475
00476 return;
00477 }
00478 }
00480 extern "C" void
00481 CIMInstanceSetLongProperty(NPIHandle* npiHandle, ::CIMInstance ci,
00482 const char* name, const long long value)
00483 {
00484
00485 if (name == NULL) return;
00486 try {
00487 if (strlen(name) == 0) return;
00488 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00489 String Key(name);
00490 OpenWBEM::CIMValue Value(static_cast<UInt64>(value));
00491 owci->setProperty(Key,Value);
00492 } catch (...) {
00493 raiseError(npiHandle,"Error creating instance");
00494 return;
00495 }
00496 }
00498 extern "C" void
00499 CIMInstanceSetBooleanProperty(NPIHandle* npiHandle, ::CIMInstance ci,
00500 const char* name, const unsigned char value)
00501 {
00502
00503 if (name == NULL) return;
00504 try {
00505 if (strlen(name) == 0) return;
00506 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00507 String Key(name);
00508 OpenWBEM::CIMValue Value(Bool((int)value));
00509 owci->setProperty(Key,Value);
00510 } catch (...) {
00511 raiseError(npiHandle,"Error setting boolean property");
00512 return;
00513 }
00514 }
00516 extern "C" void
00517 CIMInstanceSetRefProperty(NPIHandle* npiHandle, ::CIMInstance ci,
00518 const char* name, ::CIMObjectPath value)
00519 {
00520
00521 if (name == NULL) return;
00522 try {
00523 if (strlen(name) == 0) return;
00524 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00525 OpenWBEM::CIMObjectPath * owcop = static_cast<OpenWBEM::CIMObjectPath *> (value.ptr);
00526 String Key(name);
00527 OpenWBEM::CIMValue Value(*owcop);
00528 owci->setProperty(Key,Value);
00529 } catch (...) {
00530 raiseError(npiHandle,"Error setting ref property");
00531
00532 return;
00533 }
00534 }
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554 extern "C" void
00555 CIMInstanceAddStringArrayPropertyValue(NPIHandle* npiHandle, ::CIMInstance ci,
00556 const char* name, const char* value)
00557 {
00558
00559 if (name == NULL) return;
00560 try {
00561 if (strlen(name) == 0) return;
00562 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00563 String Key(name);
00564 String Value(value);
00565
00566 OpenWBEM::CIMProperty cp = owci->getProperty(Key);
00567 OpenWBEM::CIMValue cv = cp.getValue();
00568 OpenWBEM::StringArray sa;
00569 if (!cv) {
00570
00571 } else {
00572
00573 sa = cv.toStringArray();
00574 }
00575 sa.append(Value);
00576 OpenWBEM::CIMValue newcv(sa);
00577 owci->setProperty(Key,newcv);
00578 } catch (...) {
00579 raiseError(npiHandle,"Error adding string array property");
00580 return;
00581 }
00582 }
00583
00585
00586
00587 extern "C" char*
00588 CIMInstanceGetStringArrayPropertyValue(NPIHandle* npiHandle, ::CIMInstance ci,
00589 const char* name, const int pos)
00590 {
00591 char * result = NULL;
00592
00593 if (name == NULL) return result;
00594 try {
00595 if (strlen(name) == 0) return result;
00596 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00597 String Key(name);
00598
00599 OpenWBEM::CIMProperty cp = owci->getProperty(Key);
00600 OpenWBEM::CIMValue cv = cp.getValue();
00601 OpenWBEM::StringArray sa;
00602 sa = cv.toStringArray();
00603 return sa[pos].toString().allocateCString();
00604 } catch (...) {
00605 raiseError(npiHandle, "Error retrieving array property element. Possible attempt to retrive element of non-array property");
00606 return NULL;
00607 }
00608 }
00609
00611
00612 extern "C" int
00613 CIMInstanceGetStringArrayPropertySize(NPIHandle* npiHandle, ::CIMInstance ci,
00614 const char* name)
00615 {
00616
00617 if (name == NULL) return -1;
00618 if (strlen(name) == 0) return -1;
00619 try {
00620 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00621 String Key(name);
00622
00623 OpenWBEM::CIMProperty cp = owci->getProperty(Key);
00624 OpenWBEM::CIMValue cv = cp.getValue();
00625 OpenWBEM::StringArray sa;
00626 if (!cv) {
00627 return -1;
00628 }
00629 sa = cv.toStringArray();
00630 return sa.size();
00631 } catch (...) {
00632 raiseError(npiHandle, "Error retrieving array property size. Possible attempt to retrive size of non-array property");
00633 return -1;
00634 }
00635 }
00636
00638 extern "C" char*
00639 CIMInstanceGetStringValue(NPIHandle* npiHandle, ::CIMInstance ci,
00640 const char* name)
00641 {
00642
00643 if (name == NULL) return NULL;
00644 try {
00645 if (strlen(name) == 0) return NULL;
00646 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00647 String Key(name);
00648 CIMProperty prop = owci->getProperty(Key);
00649 if (!prop) return NULL;
00650 OpenWBEM::CIMValue cv = prop.getValue();
00651 if (!cv) return NULL;
00652 if (cv.getType() != CIMDataType::STRING) return NULL;
00653 cv.get(Key);
00654 return Key.allocateCString();
00655 } catch (...) {
00656 raiseError(npiHandle, "Error getting string property");
00657 return NULL;
00658 }
00659 }
00661 extern "C" int
00662 CIMInstanceGetIntegerValue(NPIHandle* npiHandle, ::CIMInstance ci,
00663 const char* name)
00664 {
00665
00666 if (name == NULL) return 0;
00667 if (strlen(name) == 0) return 0;
00668 try {
00669 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00670 String Key(name);
00671 CIMProperty prop = owci->getProperty(Key);
00672 if (!prop) return 0;
00673 OpenWBEM::CIMValue cv = prop.getValue();
00674 if (!cv) return 0;
00675 switch (cv.getType())
00676 {
00677 case CIMDataType::UINT8: {UInt8 i; cv.get(i); return i; break;}
00678 case CIMDataType::SINT8: {Int8 i; cv.get(i); return i; break;}
00679 case CIMDataType::UINT16: {UInt16 i; cv.get(i); return i; break;}
00680 case CIMDataType::SINT16: {Int16 i; cv.get(i); return i; break;}
00681 case CIMDataType::UINT32: {UInt32 i; cv.get(i); return i; break;}
00682 case CIMDataType::SINT32: {Int32 i; cv.get(i); return i; break;}
00683 case CIMDataType::UINT64: {UInt64 i; cv.get(i); return i; break;}
00684 case CIMDataType::SINT64: {Int64 i; cv.get(i); return i; break;}
00685 case CIMDataType::BOOLEAN: {Bool i; cv.get(i); return (i?-1:0); break;}
00686 default: return 0;
00687 }
00688 } catch (...) {
00689 raiseError(npiHandle, "Error getting integer property");
00690 }
00691 return 0;
00692 }
00694 extern "C" ::CIMObjectPath
00695 CIMInstanceGetRefValue(NPIHandle* npiHandle, ::CIMInstance ci, const char* name)
00696 {
00697 ::CIMObjectPath cop = {NULL};
00698
00699 if (name == NULL) return cop;
00700 if (strlen(name) == 0) return cop;
00701 try {
00702 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00703 String Key(name);
00704 CIMProperty prop = owci->getProperty(Key);
00705 OpenWBEM::CIMValue cv = prop.getValue();
00706 if (cv.getType() != CIMDataType::REFERENCE) return cop;
00707 OpenWBEM::CIMObjectPath owcop(CIMNULL);
00708 cv.get(owcop);
00709 cop.ptr = static_cast<void *>(&owcop);
00710 } catch (...) {
00711 raiseError(npiHandle, "Error getting ref property");
00712 }
00713 return cop;
00714 }
00715
00717
00718 extern "C" ::CIMObjectPath
00719 CIMObjectPathNew(NPIHandle* npiHandle, const char* classname)
00720 {
00721 ::CIMObjectPath cop = {NULL};
00722 try {
00723 String className(classname);
00724 OpenWBEM::CIMObjectPath * ref = new OpenWBEM::CIMObjectPath(className);
00725 cop.ptr = static_cast<void *>(ref);
00726 _NPIGarbageCan(npiHandle, (void *) ref, CIM_OBJECTPATH);
00727 } catch (...) {
00728 raiseError(npiHandle, "Error creating object path");
00729 }
00730 return cop;
00731 }
00733
00734
00735
00736 extern "C" ::CIMObjectPath
00737 CIMObjectPathFromCIMInstance(NPIHandle* npiHandle, ::CIMInstance ci)
00738 {
00739 ::CIMObjectPath cop = {NULL};
00740 try {
00741 OpenWBEM::CIMInstance * owci = static_cast<OpenWBEM::CIMInstance *>(ci.ptr);
00742 String host;
00743 OpenWBEM::CIMObjectPath * ref = new OpenWBEM::CIMObjectPath("", *owci);
00744 cop.ptr = static_cast<void *>(ref);
00745 _NPIGarbageCan(npiHandle, (void *) ref, CIM_OBJECTPATH);
00746 } catch (...) {
00747 raiseError(npiHandle, "Error creating object path from instance");
00748 }
00749 return cop;
00750 }
00752 extern "C" char*
00753 CIMObjectPathGetClassName(NPIHandle* npiHandle, ::CIMObjectPath cop)
00754 {
00755 try {
00756 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *> (cop.ptr);
00757 return ref->getClassName().allocateCString();
00758 } catch (...) {
00759 raiseError(npiHandle, "Error getting class name");
00760 return NULL;
00761 }
00762 }
00764 extern "C" char*
00765 CIMObjectPathGetNameSpace(NPIHandle* npiHandle, ::CIMObjectPath cop)
00766 {
00767 try {
00768 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00769 return ref->getNameSpace().allocateCString();
00770 } catch (...) {
00771 raiseError(npiHandle, "Error getting namespace");
00772 return NULL;
00773 }
00774 }
00776 extern "C" void
00777 CIMObjectPathSetNameSpace(NPIHandle* npiHandle, ::CIMObjectPath cop,
00778 const char* str)
00779 {
00780 try {
00781 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00782 ref->setNameSpace(String(str));
00783 } catch (...) {
00784 raiseError(npiHandle, "Error getting string property");
00785 return;
00786 }
00787
00788 }
00790 extern "C" void CIMObjectPathSetNameSpaceFromCIMObjectPath(
00791 NPIHandle* npiHandle, ::CIMObjectPath cop, ::CIMObjectPath src)
00792 {
00793 try {
00794 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00795 OpenWBEM::CIMObjectPath * rsrc = static_cast<OpenWBEM::CIMObjectPath *>(src.ptr);
00796 ref->setNameSpace(rsrc->getNameSpace());
00797 } catch (...) {
00798 raiseError(npiHandle, "Error seting namespace from COP");
00799 return;
00800 }
00801
00802 }
00804 extern "C" char*
00805 CIMObjectPathGetStringKeyValue(NPIHandle* npiHandle,
00806 ::CIMObjectPath cop, const char* key)
00807 {
00808
00809 if (key == NULL) return NULL;
00810 if (strlen(key) == 0) return NULL;
00811 try {
00812 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00813 CIMPropertyArray props = ref->getKeys();
00814 String Key(key);
00815 for (int i = props.size()-1; i >= 0; i--)
00816 {
00817 CIMProperty cp = props[i];
00818 if (cp.getName().equalsIgnoreCase(Key))
00819 {
00820 OpenWBEM::CIMValue cv = cp.getValue();
00821 if (!cv) return NULL;
00822 if (cv.getType() != CIMDataType::STRING)
00823 return NULL;
00824 cv.get(Key);
00825 return Key.allocateCString();
00826 }
00827 }
00828 return NULL;
00829 } catch (...) {
00830 raiseError(npiHandle, "Error getting string property");
00831 return NULL;
00832 }
00833
00834 }
00835
00836 static void _CIMObjectPathAddKey(OpenWBEM::CIMObjectPath * ref,
00837 const String& Key, const OpenWBEM::CIMValue & Value)
00838 {
00839 if (ref->getKey(Key))
00840 {
00841 bool b = false;
00842 CIMPropertyArray cprops = ref->getKeys();
00843 for (Int32 i=cprops.size()-1; i >= 0; i--)
00844 {
00845 if (cprops[i].getName().equalsIgnoreCase(Key))
00846 {
00847 cprops[i].setValue(Value);
00848 b = true;
00849 }
00850 }
00851 if (b)
00852 {
00853 ref->setKeys(cprops);
00854 return;
00855 }
00856 }
00857 ref->setKeyValue(Key,Value);
00858 }
00860 extern "C" void
00861 CIMObjectPathAddStringKeyValue(NPIHandle* npiHandle, ::CIMObjectPath cop,
00862 const char* key, const char* value)
00863 {
00864
00865 if (key == NULL) return;
00866 if (strlen(key) == 0) return;
00867 try {
00868 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00869 String Key(key);
00870 String Val(value);
00871 OpenWBEM::CIMValue Value(Val);
00872 _CIMObjectPathAddKey(ref, Key, Value);
00873 } catch (...) {
00874 raiseError(npiHandle, "Error adding string key");
00875 return;
00876 }
00877
00878 }
00880 extern "C" int
00881 CIMObjectPathGetIntegerKeyValue(NPIHandle* npiHandle,
00882 ::CIMObjectPath cop, const char* key)
00883 {
00884
00885 if (key == NULL) return -1;
00886 if (strlen(key) == 0) return -1;
00887 try {
00888 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00889 CIMPropertyArray props = ref->getKeys();
00890 String Key(key);
00891
00892 for (int i = props.size()-1; i >= 0; i--)
00893 {
00894 CIMProperty cp = props[i];
00895 if (cp.getName().equalsIgnoreCase(Key))
00896 {
00897 OpenWBEM::CIMValue cv = cp.getValue();
00898 if (!cv) return 0;
00899 switch (cv.getType())
00900 {
00901 case CIMDataType::UINT8:
00902 {UInt8 i; cv.get(i); return i; break;}
00903 case CIMDataType::SINT8:
00904 {Int8 i; cv.get(i); return i; break;}
00905 case CIMDataType::UINT16:
00906 {UInt16 i; cv.get(i); return i; break;}
00907 case CIMDataType::SINT16:
00908 {Int16 i; cv.get(i); return i; break;}
00909 case CIMDataType::UINT32:
00910 {UInt32 i; cv.get(i); return i; break;}
00911 case CIMDataType::SINT32:
00912 {Int32 i; cv.get(i); return i; break;}
00913 case CIMDataType::UINT64:
00914 {UInt64 i; cv.get(i); return i; break;}
00915 case CIMDataType::SINT64:
00916 {Int64 i; cv.get(i); return i; break;}
00917 default: return 0;
00918 }
00919 }
00920 }
00921 } catch (...) {
00922 raiseError(npiHandle, "Error getting integer key");
00923 }
00924 return 0;
00925 }
00927 extern "C" void
00928 CIMObjectPathAddIntegerKeyValue(NPIHandle* npiHandle, ::CIMObjectPath cop,
00929 const char* key, const int value)
00930 {
00931
00932 if (key == NULL) return;
00933 if (strlen(key) == 0) return;
00934 try {
00935 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00936 String Key(key);
00937 OpenWBEM::CIMValue Value(value);
00938 _CIMObjectPathAddKey(ref, Key, Value);
00939 } catch (...) {
00940 raiseError(npiHandle, "Error adding int key");
00941 return;
00942 }
00943
00944 }
00946 extern "C" ::CIMObjectPath
00947 CIMObjectPathGetRefKeyValue(NPIHandle* npiHandle, ::CIMObjectPath cop,
00948 const char* key)
00949 {
00950
00951 ::CIMObjectPath cop2 = {NULL};
00952 if (key == NULL) return cop2;
00953 if (strlen(key) == 0) return cop2;
00954 try {
00955 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00956 CIMPropertyArray props = ref->getKeys();
00957 String Key(key);
00958
00959 for (int i = props.size()-1; i >= 0; i--)
00960 {
00961 CIMProperty cp = props[i];
00962 if (cp.getName().equalsIgnoreCase(Key))
00963 {
00964 OpenWBEM::CIMValue cv = cp.getValue();
00965 if (!cv) return cop2;
00966 if (cv.getType() != CIMDataType::REFERENCE) return cop2;
00967 OpenWBEM::CIMObjectPath * ref2 = new OpenWBEM::CIMObjectPath(CIMNULL);
00968 cv.get(*ref2);
00969 cop2.ptr = (void *) ref;
00970 _NPIGarbageCan(npiHandle,(void *)ref2,CIM_OBJECTPATH);
00971 return cop2;
00972 }
00973 }
00974 } catch (...) {
00975 raiseError(npiHandle, "Error getting ref key");
00976 }
00977 return cop2;
00978 }
00980 extern "C" void
00981 CIMObjectPathAddRefKeyValue(NPIHandle* npiHandle, ::CIMObjectPath cop,
00982 const char* key, ::CIMObjectPath cop2)
00983 {
00984
00985 if (key == NULL) return;
00986 if (strlen(key) == 0) return;
00987 try {
00988 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
00989 OpenWBEM::CIMObjectPath * ref2 = static_cast<OpenWBEM::CIMObjectPath *>(cop2.ptr);
00990 String Key(key);
00991 OpenWBEM::CIMValue Value(*ref2);
00992 _CIMObjectPathAddKey(ref, Key, Value);
00993 } catch (...) {
00994 raiseError(npiHandle, "Error adding ref key");
00995 return;
00996 }
00997 }
00998
01000 extern "C" char *
01001 SelectExpGetSelectString(NPIHandle* npiHandle, ::SelectExp sxp)
01002 {
01003 try {
01004 WQLSelectStatement * wf =
01005 static_cast<WQLSelectStatement *>(sxp.ptr);
01006 char * query = wf->toString().allocateCString();
01007 return query;
01008 } catch (...) {
01009 raiseError(npiHandle, "Error getting select string from select exp");
01010 return NULL;
01011 }
01012 }
01013
01015 extern "C" ::CIMClass
01016 CIMOMGetClass(NPIHandle* npiHandle, ::CIMObjectPath cop, int localOnly)
01017 {
01018 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
01019 String nameSpace = ref->getNameSpace();
01020 String className = ref->getClassName();
01021 OpenWBEM::CIMClass cc = NPI_getmyClass(npiHandle, nameSpace, className);
01022 OpenWBEM::CIMClass * my_cc = new OpenWBEM::CIMClass(cc);
01023 ::CIMClass localcc = { static_cast<void *> (my_cc)};
01024 _NPIGarbageCan(npiHandle, (void *) my_cc, CIM_CLASS);
01025 return localcc;
01026 }
01028 extern "C" ::Vector
01029 CIMOMEnumInstanceNames(NPIHandle* npiHandle, ::CIMObjectPath cop, int i)
01030 {
01031 Vector v = VectorNew(npiHandle);
01032 try {
01033 OpenWBEM::CIMObjectPath * ref = (OpenWBEM::CIMObjectPath *) cop.ptr;
01034 String nameSpace = ref->getNameSpace();
01035 String className = ref->getClassName();
01036 CIMObjectPathEnumeration instNames =
01037 NPI_enumeratemyInstanceNames(npiHandle,nameSpace,className);
01038
01039 while (instNames.hasMoreElements())
01040 {
01041 OpenWBEM::CIMObjectPath * cowp = new
01042 OpenWBEM::CIMObjectPath(instNames.nextElement());
01043 _NPIGarbageCan(npiHandle, (void *) cowp, CIM_OBJECTPATH);
01044 _VectorAddTo(npiHandle, v, (void *) cowp);
01045 }
01046 } catch (...) {
01047 raiseError(npiHandle, "Error enumerating instance names");
01048 }
01049 return v;
01050 }
01052 extern "C" ::Vector
01053 CIMOMEnumInstances(NPIHandle* npiHandle, ::CIMObjectPath cop, int i, int j)
01054 {
01055 Vector v = VectorNew(npiHandle);
01056 try {
01057 OpenWBEM::CIMObjectPath * ref = (OpenWBEM::CIMObjectPath *) cop.ptr;
01058 String nameSpace = ref->getNameSpace();
01059 String className = ref->getClassName();
01060 CIMInstanceEnumeration insts =
01061 NPI_enumeratemyInstances(npiHandle,nameSpace,className);
01062
01063 while (insts.hasMoreElements())
01064 {
01065 OpenWBEM::CIMInstance * ci = new OpenWBEM::CIMInstance(insts.nextElement());
01066 _NPIGarbageCan(npiHandle, (void *) ci, CIM_INSTANCE);
01067 _VectorAddTo(npiHandle, v, (void *) ci);
01068 }
01069 } catch (...) {
01070 raiseError(npiHandle, "Error enumerating instances");
01071 }
01072 return v;
01073 }
01075 extern "C" ::CIMInstance
01076 CIMOMGetInstance(NPIHandle* npiHandle, ::CIMObjectPath cop, int i)
01077 {
01078 ::CIMInstance localci = { NULL};
01079 try {
01080 OpenWBEM::CIMObjectPath * ref = static_cast<OpenWBEM::CIMObjectPath *>(cop.ptr);
01081 OpenWBEM::CIMInstance ci = NPI_getmyInstance(npiHandle, *ref, i);
01082 OpenWBEM::CIMInstance * my_ci = new OpenWBEM::CIMInstance(ci);
01083 _NPIGarbageCan(npiHandle, (void *) my_ci, CIM_INSTANCE);
01084 localci.ptr = static_cast<void *> (my_ci);
01085 } catch (...) {
01086 raiseError(npiHandle, "Error getting instance");
01087 }
01088 return localci;
01089 }
01091 extern "C" void
01092 CIMOMDeliverProcessEvent(NPIHandle* npiHandle, char * ns,
01093 ::CIMInstance indication)
01094 {
01095 ProviderEnvironmentIFCRef * provenv =
01096 static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
01097 OpenWBEM::CIMInstance * ow_indication =
01098 static_cast<OpenWBEM::CIMInstance *>(indication.ptr);
01099 try
01100 {
01101 (*provenv)->getCIMOMHandle()->exportIndication(
01102 * ow_indication, String("root/cimv2"));
01103 }
01104 catch (...)
01105 {
01106
01107
01108 npiHandle->errorOccurred = 1;
01109 }
01110 }
01112 extern "C" void
01113 CIMOMDeliverInstanceEvent(NPIHandle* npiHandle, char * ns,
01114 ::CIMInstance indication,
01115 ::CIMInstance source, ::CIMInstance previous)
01116 {
01117 ProviderEnvironmentIFCRef * provenv =
01118 static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
01119 OpenWBEM::CIMInstance * ow_indication =
01120 static_cast<OpenWBEM::CIMInstance *>(indication.ptr);
01121 OpenWBEM::CIMInstance * ow_source = static_cast<OpenWBEM::CIMInstance *>(source.ptr);
01122 OpenWBEM::CIMInstance * ow_previous =
01123 static_cast<OpenWBEM::CIMInstance *>(previous.ptr);
01124 OpenWBEM::CIMValue src_val(* ow_source);
01125 OpenWBEM::CIMValue prev_val(* ow_previous);
01126 ow_indication->setProperty(String("SourceInstance"), src_val);
01127
01128 ow_indication->setProperty(String("PreviousInstance"), prev_val);
01129 try
01130 {
01131 (*provenv)->getCIMOMHandle()->exportIndication(
01132 * ow_indication, String("root/cimv2"));
01133 }
01134 catch (...)
01135 {
01136
01137
01138 npiHandle->errorOccurred = 1;
01139 }
01140 OW_LOG_DEBUG((*provenv)->getLogger(COMPONENT_NAME), Format("NPIExternal: Deliver %1", npiHandle->errorOccurred));
01141 }
01143 extern "C" NPIHandle *
01144 CIMOMPrepareAttach(NPIHandle* npiHandle)
01145 {
01146 ::NPIHandle * nh = new ::NPIHandle(*npiHandle);
01147
01148 ProviderEnvironmentIFCRef * provenv =
01149 static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
01150 nh->thisObject = new ProviderEnvironmentIFCRef(*provenv);
01151
01152 nh->context = new ::NPIContext;
01153 ((NPIContext *)(nh->context))->scriptName =
01154 ((NPIContext *)(npiHandle->context))->scriptName;
01155
01156 ((NPIContext *)(nh->context))->my_perl =
01157 ((NPIContext *)(npiHandle->context))->my_perl;
01158
01159 return nh;
01160 }
01162 extern "C" void
01163 CIMOMCancelAttach(NPIHandle* npiHandle)
01164 {
01165 delete static_cast<ProviderEnvironmentIFCRef *>(npiHandle->thisObject);
01166 if (npiHandle->providerError != NULL)
01167 free((void *)(npiHandle->providerError));
01168
01169 free(npiHandle);
01170 }
01172 extern "C" void
01173 CIMOMAttachThread(NPIHandle* npiHandle)
01174 {
01175 if (npiHandle == NULL) return;
01176 npiHandle->errorOccurred = 0;
01177
01178
01179 }
01181 extern "C" void
01182 CIMOMDetachThread(NPIHandle* npiHandle)
01183 {
01184 if (npiHandle == NULL) return;
01185 npiHandle->errorOccurred = 0;
01186
01187 NPIHandleFreer nf(* npiHandle);
01188 }
01191 extern "C" char*
01192 _ObjectToString(NPIHandle* npiHandle, void* co)
01193 {
01194 return 0;
01195
01196 }
01197
01199 extern "C" int
01200 errorCheck(NPIHandle* npiHandle )
01201 {
01202 return npiHandle->errorOccurred;
01203 }
01205 extern "C" void
01206 errorReset(NPIHandle* npiHandle )
01207 {
01208 npiHandle->errorOccurred = 0;
01209 }
01211 extern "C" void
01212 raiseError(NPIHandle* npiHandle, const char* msg)
01213 {
01214 if (npiHandle->providerError != NULL)
01215 free ( (void*) npiHandle->providerError );
01216 npiHandle->errorOccurred = 1;
01217 npiHandle->providerError = strdup ( msg );
01218 }
01219
01220
01221 extern "C" {
01222
01223 void* NPIOnCMPI_Create_InstanceMI(void *, void *, const char *) {
01224 return 0;
01225 }
01226 void* NPIOnCMPI_Create_AssociationMI(void *, void *, const char *)
01227 {
01228 return 0;
01229 }
01230 void* NPIOnCMPI_Create_MethodMI(void *, void *, const char *)
01231 {
01232 return 0;
01233 }
01234 void* NPIOnCMPI_Create_IndicationMI(void *, void *, const char *)
01235 {
01236 return 0;
01237 }
01238 }
01239
01240