00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #include "OWBI1_config.h"
00036 #include "OWBI1_SimpleInstanceProviderIFC.hpp"
00037 #include "OWBI1_CIMObjectPath.hpp"
00038 #include "OWBI1_CIMInstance.hpp"
00039 #include "OWBI1_CIMException.hpp"
00040 #include "OWBI1_ResultHandlerIFC.hpp"
00041
00042 namespace OWBI1
00043 {
00044
00045 using namespace WBEMFlags;
00046 namespace {
00047 OWBI1_DECLARE_EXCEPTION(FoundTheInst);
00048 OWBI1_DEFINE_EXCEPTION(FoundTheInst);
00050 class GetInstanceHandler : public CIMInstanceResultHandlerIFC
00051 {
00052 public:
00053 GetInstanceHandler(const CIMObjectPath& instanceName, CIMInstance& theInst)
00054 : m_instanceName(instanceName)
00055 , m_theInst(theInst)
00056 {
00057 }
00058 void doHandle(const CIMInstance& inst)
00059 {
00060 if (CIMObjectPath(m_instanceName.getNameSpace(), inst) == m_instanceName)
00061 {
00062 m_theInst = inst;
00063 OWBI1_THROW(FoundTheInstException, "");
00064 }
00065 }
00066 private:
00067 CIMObjectPath m_instanceName;
00068 CIMInstance& m_theInst;
00069 };
00070 }
00072 CIMInstance
00073 BI1SimpleInstanceProviderIFC::getInstance(
00074 const ProviderEnvironmentIFCRef &env,
00075 const String &ns,
00076 const CIMObjectPath &instanceName,
00077 const CIMPropertyList& propertyList,
00078 const CIMClass &cimClass)
00079 {
00080 CIMInstance theInst(CIMNULL);
00081 GetInstanceHandler handler(instanceName, theInst);
00082
00083
00084
00085 try
00086 {
00087 this->doSimpleEnumInstances(env,ns,cimClass,handler, E_ALL_PROPERTIES);
00088 }
00089 catch (const FoundTheInstException&)
00090 {
00091 return theInst.clone(propertyList);
00092 }
00093 OWBI1_THROWCIMMSG(CIMException::NOT_FOUND, instanceName.toString().c_str());
00094 }
00095 namespace {
00097 class EnumInstanceNamesHandler : public CIMInstanceResultHandlerIFC
00098 {
00099 public:
00100 EnumInstanceNamesHandler(CIMObjectPathResultHandlerIFC &result,
00101 const String& ns)
00102 : m_result(result)
00103 , m_ns(ns)
00104 {
00105 }
00106 void doHandle(const CIMInstance& inst)
00107 {
00108 m_result.handle(CIMObjectPath(m_ns, inst));
00109 }
00110 private:
00111 CIMObjectPathResultHandlerIFC& m_result;
00112 String m_ns;
00113 };
00114 }
00116 void
00117 BI1SimpleInstanceProviderIFC::enumInstanceNames(
00118 const ProviderEnvironmentIFCRef &env,
00119 const String &ns,
00120 const CIMName& className,
00121 CIMObjectPathResultHandlerIFC &result,
00122 const CIMClass &cimClass)
00123 {
00124 EnumInstanceNamesHandler handler(result, ns);
00125 this->doSimpleEnumInstances(env,ns,cimClass,handler, E_KEY_PROPERTIES_ONLY);
00126 }
00127 namespace {
00129 class EnumInstancesHandler : public CIMInstanceResultHandlerIFC
00130 {
00131 public:
00132 EnumInstancesHandler(CIMInstanceResultHandlerIFC &result,
00133 const CIMPropertyList& propertyList_)
00134 : m_result(result)
00135 , propertyList(propertyList_)
00136 {
00137 }
00138 void doHandle(const CIMInstance& inst)
00139 {
00140 m_result.handle(inst.clone(propertyList));
00141 }
00142 private:
00143 CIMInstanceResultHandlerIFC& m_result;
00144 const CIMPropertyList& propertyList;
00145 };
00146 }
00148 void
00149 BI1SimpleInstanceProviderIFC::enumInstances(
00150 const ProviderEnvironmentIFCRef &env,
00151 const String &ns,
00152 const CIMName& className,
00153 CIMInstanceResultHandlerIFC &result,
00154 const CIMPropertyList& propertyList,
00155 const CIMClass &requestedClass,
00156 const CIMClass &cimClass)
00157 {
00158 EnumInstancesHandler handler(result, propertyList);
00159 this->doSimpleEnumInstances(env,ns,cimClass,handler, E_ALL_PROPERTIES);
00160 }
00161
00162 }
00163