OW_CppSimpleInstanceProviderIFC.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00035 #include "OW_config.h"
00036 #include "OW_CppSimpleInstanceProviderIFC.hpp"
00037 #include "OW_CIMObjectPath.hpp"
00038 #include "OW_CIMInstance.hpp"
00039 #include "OW_CIMException.hpp"
00040 #include "OW_ResultHandlerIFC.hpp"
00041 
00042 namespace OW_NAMESPACE
00043 {
00044 
00045 using namespace WBEMFlags;
00046 namespace {
00047 OW_DECLARE_EXCEPTION(FoundTheInst);
00048 OW_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          OW_THROW(FoundTheInstException, "");
00064       }
00065    }
00066 private:
00067    CIMObjectPath m_instanceName;
00068    CIMInstance& m_theInst;
00069 };
00070 } // end anonymous namespace
00072 CIMInstance
00073 CppSimpleInstanceProviderIFC::getInstance(
00074    const ProviderEnvironmentIFCRef &env,
00075    const String &ns,
00076    const CIMObjectPath &instanceName,
00077    ELocalOnlyFlag localOnly,
00078    EIncludeQualifiersFlag includeQualifiers,
00079    EIncludeClassOriginFlag includeClassOrigin,
00080    const StringArray *propertyList,
00081    const CIMClass &cimClass)
00082 {
00083    CIMInstance theInst(CIMNULL);
00084    GetInstanceHandler handler(instanceName, theInst);
00085    // this usage of exceptions is slightly abnormal, we use it to terminate
00086    // enumInstances once we've found the instance we want. The exception
00087    // is thrown in GetInstanceHandler::doHandle()
00088    try
00089    {
00090       this->doSimpleEnumInstances(env,ns,cimClass,handler, E_ALL_PROPERTIES);
00091    }
00092    catch (const FoundTheInstException&)
00093    {
00094       return theInst.clone(localOnly, includeQualifiers, includeClassOrigin, propertyList);
00095    }
00096    OW_THROWCIMMSG(CIMException::NOT_FOUND, instanceName.toString().c_str());
00097 }
00098 namespace {
00100 class EnumInstanceNamesHandler : public CIMInstanceResultHandlerIFC
00101 {
00102 public:
00103    EnumInstanceNamesHandler(CIMObjectPathResultHandlerIFC &result,
00104       const String& ns)
00105       : m_result(result)
00106       , m_ns(ns)
00107    {
00108    }
00109    void doHandle(const CIMInstance& inst)
00110    {
00111       m_result.handle(CIMObjectPath(m_ns, inst));
00112    }
00113 private:
00114    CIMObjectPathResultHandlerIFC& m_result;
00115    String m_ns;
00116 };
00117 } // end anonymous namespace
00119 void
00120 CppSimpleInstanceProviderIFC::enumInstanceNames(
00121    const ProviderEnvironmentIFCRef &env,
00122    const String &ns,
00123    const String &className,
00124    CIMObjectPathResultHandlerIFC &result,
00125    const CIMClass &cimClass)
00126 {
00127    EnumInstanceNamesHandler handler(result, ns);
00128    this->doSimpleEnumInstances(env,ns,cimClass,handler, E_KEY_PROPERTIES_ONLY);
00129 }
00130 namespace {
00132 class EnumInstancesHandler : public CIMInstanceResultHandlerIFC
00133 {
00134 public:
00135    EnumInstancesHandler(CIMInstanceResultHandlerIFC &result,
00136       ELocalOnlyFlag localOnly_,
00137       EDeepFlag deep_,
00138       EIncludeQualifiersFlag includeQualifiers_,
00139       EIncludeClassOriginFlag includeClassOrigin_,
00140       const StringArray *propertyList_,
00141       const CIMClass &requestedClass_,
00142       const CIMClass &cimClass_)
00143       : m_result(result)
00144       , localOnly(localOnly_)
00145       , deep(deep_)
00146       , includeQualifiers(includeQualifiers_)
00147       , includeClassOrigin(includeClassOrigin_)
00148       , propertyList(propertyList_)
00149       , requestedClass(requestedClass_)
00150       , cimClass(cimClass_)
00151    {
00152    }
00153    void doHandle(const CIMInstance& inst)
00154    {
00155       m_result.handle(inst.clone(localOnly, deep, includeQualifiers,
00156          includeClassOrigin, propertyList, requestedClass,
00157          cimClass));
00158    }
00159 private:
00160    CIMInstanceResultHandlerIFC& m_result;
00161    ELocalOnlyFlag localOnly;
00162    EDeepFlag deep;
00163    EIncludeQualifiersFlag includeQualifiers;
00164    EIncludeClassOriginFlag includeClassOrigin;
00165    const StringArray *propertyList;
00166    const CIMClass &requestedClass;
00167    const CIMClass &cimClass;
00168 };
00169 } // end anonymous namespace
00171 void
00172 CppSimpleInstanceProviderIFC::enumInstances(
00173    const ProviderEnvironmentIFCRef &env,
00174    const String &ns,
00175    const String &className,
00176    CIMInstanceResultHandlerIFC &result,
00177    ELocalOnlyFlag localOnly,
00178    EDeepFlag deep,
00179    EIncludeQualifiersFlag includeQualifiers,
00180    EIncludeClassOriginFlag includeClassOrigin,
00181    const StringArray *propertyList,
00182    const CIMClass &requestedClass,
00183    const CIMClass &cimClass)
00184 {
00185    EnumInstancesHandler handler(result, localOnly, deep, includeQualifiers,
00186       includeClassOrigin, propertyList, requestedClass, cimClass);
00187    this->doSimpleEnumInstances(env,ns,cimClass,handler, E_ALL_PROPERTIES);
00188 }
00189 
00190 } // end namespace OW_NAMESPACE
00191 

Generated on Thu Feb 9 08:47:58 2006 for openwbem by  doxygen 1.4.6