OW_provCIM_IndicationSubscription.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_IndicationSubscription actions are intercepted and passed to the indication
00055 // server so it can keep track of subscriptions and also deny the creation of any subscriptions for which no providers exist.
00056 class provCIM_IndicationSubscription : 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          CIMOMEnvironment::instance()->getIndicationServer();
00066          if (!CIMOMEnvironment::instance()->getIndicationServer())
00067          {
00068             indicationsEnabled = false;
00069          }
00070       }
00071    }
00072    virtual void getInstanceProviderInfo(InstanceProviderInfo& info)
00073    {
00074       info.addInstrumentedClass("CIM_IndicationSubscription");
00075    }
00076 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00077    virtual void deleteInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMObjectPath &cop)
00078    {
00079       // delete it from the repository
00080       CIMOMHandleIFCRef rephdl = env->getRepositoryCIMOMHandle();
00081       rephdl->deleteInstance(ns, cop);
00082       // tell the indication server it's being deleted.
00083       CIMOMEnvironment::instance()->getIndicationServer()->startDeleteSubscription(ns, cop);
00084    }
00085    virtual CIMObjectPath createInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMInstance &cimInstance_)
00086    {
00087       // make a copy so we can add the __Subscription_UserName property to it.
00088       CIMInstance cimInstance(cimInstance_);
00089       // we add this property so that if the cimom restarts, we can recover the username of whoever created the subscription.
00090       String username = env->getUserName();
00091       cimInstance.setProperty("__Subscription_UserName", CIMValue(username));
00092       if (!indicationsEnabled)
00093       {
00094          OW_THROWCIMMSG(CIMException::FAILED, "Indication are disabled.  Subscription creation is not allowed.");
00095       }
00096       CIMObjectPath rv = env->getRepositoryCIMOMHandle()->createInstance(ns, cimInstance);
00097       // Tell the indication server about the new subscription.
00098       CIMOMEnvironment::instance()->getIndicationServer()->startCreateSubscription(ns, cimInstance, username);
00099       return rv;
00100    }
00101    virtual void modifyInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMInstance &modifiedInstance, const CIMInstance &previousInstance,
00102       EIncludeQualifiersFlag includeQualifiers, const StringArray *propertyList, const CIMClass &theClass)
00103    {
00104       if (!indicationsEnabled)
00105       {
00106          OW_THROWCIMMSG(CIMException::FAILED, "Indication are disabled.  Subscription creation is not allowed.");
00107       }
00108       
00109       CIMOMHandleIFCRef rephdl = env->getRepositoryCIMOMHandle();
00110       rephdl->modifyInstance(ns, modifiedInstance, includeQualifiers, propertyList);
00111       // Tell the indication server about the modified subscription.
00112       CIMOMEnvironment::instance()->getIndicationServer()->startModifySubscription(ns, modifiedInstance.createModifiedInstance(previousInstance,includeQualifiers,propertyList,theClass));
00113    }
00114 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00115    virtual CIMInstance getInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMObjectPath &instanceName, ELocalOnlyFlag localOnly, EIncludeQualifiersFlag includeQualifiers,
00116       EIncludeClassOriginFlag includeClassOrigin, const StringArray *propertyList, const CIMClass &cimClass)
00117    {
00118       return env->getRepositoryCIMOMHandle()->getInstance(ns, instanceName, localOnly, includeQualifiers, includeClassOrigin, propertyList);
00119    }
00120    
00121    virtual void enumInstances(const ProviderEnvironmentIFCRef &env, const String &ns, const String &className, CIMInstanceResultHandlerIFC &result, ELocalOnlyFlag localOnly,
00122       EDeepFlag deep, EIncludeQualifiersFlag includeQualifiers, EIncludeClassOriginFlag includeClassOrigin, const StringArray *propertyList, const CIMClass &requestedClass, const CIMClass &cimClass)
00123    {
00124       RepositoryIFCRef rephdl = env->getRepository();
00125       rephdl->enumInstances(ns,className,result,deep,localOnly,includeQualifiers,includeClassOrigin,propertyList, E_DONT_ENUM_SUBCLASSES, env->getOperationContext());
00126    }
00127    
00128    virtual void enumInstanceNames(const ProviderEnvironmentIFCRef &env, const String &ns, const String &className, CIMObjectPathResultHandlerIFC &result,
00129       const CIMClass &cimClass)
00130    {
00131       RepositoryIFCRef rephdl = env->getRepository();
00132       rephdl->enumInstanceNames(ns,className,result, E_SHALLOW, env->getOperationContext());
00133    }
00134 private:
00135    bool indicationsEnabled;
00136 };
00137 } // end anonymous namespace
00138 } // end namespace OW_NAMESPACE
00139 
00140 OW_PROVIDERFACTORY(OpenWBEM::provCIM_IndicationSubscription, owprovCIM_IndicationSubscription);
00141 

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