OW_provinstCIM_IndicationFilter.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Copyright (C) 2002-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_CppInstanceProviderIFC.hpp"
00037 #include "OW_ConfigOpts.hpp"
00038 #include "OW_CIMObjectPath.hpp"
00039 #include "OW_CIMException.hpp"
00040 #include "OW_CIMInstance.hpp"
00041 #include "OW_CIMOMEnvironment.hpp"
00042 #include "OW_IndicationServer.hpp"
00043 #include "OW_CIMClass.hpp"
00044 #include "OW_CIMValue.hpp"
00045 #include "OW_CIMOMHandleIFC.hpp"
00046 #include "OW_RepositoryIFC.hpp"
00047 
00048 namespace OW_NAMESPACE
00049 {
00050 
00051 using namespace WBEMFlags;
00052 namespace
00053 {
00054 // This is a pass through provider.  The instances are really stored in the repository.  All CIM_IndicationFilter modifications are intercepted and passed to the indication
00055 // server so it can keep track of subscriptions.
00056 class provinstCIM_IndicationFilter : public CppInstanceProviderIFC
00057 {
00058 public:
00059    virtual void initialize(const ProviderEnvironmentIFCRef& env)
00060    {
00061       indicationsEnabled = !(env->getConfigItem(ConfigOpts::DISABLE_INDICATIONS_opt, OW_DEFAULT_DISABLE_INDICATIONS).equalsIgnoreCase("true"));
00062       // get the indication server and save it.
00063       if (indicationsEnabled)
00064       {
00065          if (!CIMOMEnvironment::instance()->getIndicationServer())
00066          {
00067             indicationsEnabled = false;
00068          }
00069       }
00070    }
00071    virtual void getInstanceProviderInfo(InstanceProviderInfo& info)
00072    {
00073       info.addInstrumentedClass("CIM_IndicationFilter");
00074    }
00075 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00076    virtual void deleteInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMObjectPath &cop)
00077    {
00078       // delete it from the repository
00079       CIMOMHandleIFCRef rephdl = env->getRepositoryCIMOMHandle();
00080       rephdl->deleteInstance(ns, cop);
00081    }
00082    virtual CIMObjectPath createInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMInstance &cimInstance)
00083    {
00084       if (!indicationsEnabled)
00085       {
00086          OW_THROWCIMMSG(CIMException::FAILED, "Indications are disabled.  Filter creation is not allowed.");
00087       }
00088 
00089       // TODO: Remove this or do something better.
00090       // wbemservices tries to create an instance without any keys.
00091       CIMInstance newInstance(cimInstance);
00092       if (!newInstance.propertyHasValue("SystemCreationClassName"))
00093          newInstance.setProperty("SystemCreationClassName", CIMValue("foo"));
00094       if (!newInstance.propertyHasValue("SystemName"))
00095          newInstance.setProperty("SystemName", CIMValue("foo"));
00096       if (!newInstance.propertyHasValue("CreationClassName"))
00097          newInstance.setProperty("CreationClassName", CIMValue("foo"));
00098       if (!newInstance.propertyHasValue("Name"))
00099          newInstance.setProperty("Name", CIMValue("foo"));
00100 
00101       return env->getRepositoryCIMOMHandle()->createInstance(ns, newInstance);
00102    }
00103    virtual void modifyInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMInstance &modifiedInstance, const CIMInstance &previousInstance,
00104          EIncludeQualifiersFlag includeQualifiers, const StringArray *propertyList, const CIMClass &theClass)
00105    {
00106       if (!indicationsEnabled)
00107       {
00108          OW_THROWCIMMSG(CIMException::FAILED, "Indications are disabled.  Filter creation is not allowed.");
00109       }
00110       CIMOMHandleIFCRef rephdl = env->getRepositoryCIMOMHandle();
00111       rephdl->modifyInstance(ns, modifiedInstance, includeQualifiers, propertyList);
00112       // Tell the indication server about the modified subscription.
00113       CIMOMEnvironment::instance()->getIndicationServer()->modifyFilter(
00114          ns,
00115          modifiedInstance.createModifiedInstance(previousInstance,includeQualifiers,propertyList,theClass),
00116          env->getUserName());
00117    }
00118 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00119    virtual CIMInstance getInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMObjectPath &instanceName, ELocalOnlyFlag localOnly, EIncludeQualifiersFlag includeQualifiers,
00120          EIncludeClassOriginFlag includeClassOrigin, const StringArray *propertyList, const CIMClass &cimClass)
00121    {
00122       return env->getRepositoryCIMOMHandle()->getInstance(ns, instanceName, localOnly, includeQualifiers, includeClassOrigin, propertyList);
00123    }
00124    virtual void enumInstances(const ProviderEnvironmentIFCRef &env, const String &ns, const String &className, CIMInstanceResultHandlerIFC &result, ELocalOnlyFlag localOnly,
00125          EDeepFlag deep, EIncludeQualifiersFlag includeQualifiers, EIncludeClassOriginFlag includeClassOrigin, const StringArray *propertyList, const CIMClass &requestedClass, const CIMClass &cimClass)
00126    {
00127       RepositoryIFCRef rephdl = env->getRepository();
00128       rephdl->enumInstances(ns,className,result,deep,localOnly,includeQualifiers,includeClassOrigin,propertyList, E_DONT_ENUM_SUBCLASSES, env->getOperationContext());
00129    }
00130    virtual void enumInstanceNames(const ProviderEnvironmentIFCRef &env, const String &ns, const String &className, CIMObjectPathResultHandlerIFC &result,
00131          const CIMClass &cimClass)
00132    {
00133       RepositoryIFCRef rephdl = env->getRepository();
00134       rephdl->enumInstanceNames(ns,className,result, E_SHALLOW, env->getOperationContext());
00135    }
00136 private:
00137    bool indicationsEnabled;
00138 };
00139 } // end anonymous namespace
00140 } // end namespace OW_NAMESPACE
00141 
00142 OW_PROVIDERFACTORY(OpenWBEM::provinstCIM_IndicationFilter, owprovinstCIM_IndicationFilter);
00143 

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