OWBI1_SimpleInstanceProviderIFC.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 "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 } // end anonymous namespace
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    // this usage of exceptions is slightly abnormal, we use it to terminate
00083    // enumInstances once we've found the instance we want. The exception
00084    // is thrown in GetInstanceHandler::doHandle()
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 } // end anonymous namespace
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 } // end anonymous namespace
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 } // end namespace OWBI1
00163 

Generated on Thu Feb 9 08:48:28 2006 for openwbem by  doxygen 1.4.6