📄 providerregistrationprovider.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Yi Zhou (yi_zhou@hp.com)//// Modified By: Chip Vincent (cvincent@us.ibm.com)// Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)// Carol Ann Krug Graves, Hewlett-Packard Company// (carolann_graves@hp.com)// Seema Gupta (gseema@in.ibm.com) for PEP135////%/////////////////////////////////////////////////////////////////////////////#include "ProviderRegistrationProvider.h"#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/CIMMessage.h>#include <Pegasus/Common/OperationContextInternal.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/MessageLoader.h> //l10n#include <Pegasus/Common/Constants.h>PEGASUS_NAMESPACE_BEGIN/** The name of the CapabilityID property for provider capabilities class*/static const CIMName _PROPERTY_CAPABILITYID = CIMName ("CapabilityID");/** stopping provider method*/static const CIMName _STOP_PROVIDER = CIMName ("Stop");/** starting provider method*/static const CIMName _START_PROVIDER = CIMName ("Start");ProviderRegistrationProvider::ProviderRegistrationProvider( ProviderRegistrationManager * providerRegistrationManager) { _providerRegistrationManager = providerRegistrationManager; _controller = ModuleController::getModuleController();}ProviderRegistrationProvider::~ProviderRegistrationProvider(void) {}// get registered providervoid ProviderRegistrationProvider::getInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList & propertyList, InstanceResponseHandler & handler){ if(!instanceReference.getNameSpace().equal (PEGASUS_NAMESPACENAME_INTEROP)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, instanceReference.getNameSpace().getString()); } // ensure the class existing in the specified namespace CIMName className = instanceReference.getClassName(); if(!className.equal (PEGASUS_CLASSNAME_PROVIDER) && !className.equal (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_CONSUMERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_PROVIDERMODULE)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, className.getString()); } // begin processing the request handler.processing(); CIMInstance instance; try { instance = _providerRegistrationManager->getInstance(instanceReference, includeQualifiers, includeClassOrigin, propertyList); } catch(const CIMException&) { throw; } handler.deliver(instance); // complete processing the request handler.complete();}// get all registered providersvoid ProviderRegistrationProvider::enumerateInstances( const OperationContext & context, const CIMObjectPath & classReference, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList & propertyList, InstanceResponseHandler & handler){ if(!classReference.getNameSpace().equal (PEGASUS_NAMESPACENAME_INTEROP)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, classReference.getNameSpace().getString()); } // ensure the class existing in the specified namespace CIMName className = classReference.getClassName(); if(!className.equal (PEGASUS_CLASSNAME_PROVIDER) && !className.equal (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_CONSUMERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_PROVIDERMODULE)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, className.getString()); } // begin processing the request handler.processing(); Array<CIMInstance> enumInstances; try { enumInstances = _providerRegistrationManager->enumerateInstancesForClass( classReference, includeQualifiers, includeClassOrigin, propertyList); } catch(const CIMException&) { throw; } handler.deliver(enumInstances); // complete processing the request handler.complete();}// get all registered provider namesvoid ProviderRegistrationProvider::enumerateInstanceNames( const OperationContext & context, const CIMObjectPath & classReference, ObjectPathResponseHandler & handler){ if(!classReference.getNameSpace().equal (PEGASUS_NAMESPACENAME_INTEROP)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, classReference.getNameSpace().getString()); } // ensure the class existing in the specified namespace CIMName className = classReference.getClassName(); if(!className.equal (PEGASUS_CLASSNAME_PROVIDER) && !className.equal (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_CONSUMERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_PROVIDERMODULE)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, className.getString()); } // begin processing the request handler.processing(); Array<CIMObjectPath> enumInstanceNames; // get all instance names from repository try { enumInstanceNames = _providerRegistrationManager->enumerateInstanceNamesForClass( classReference); } catch(const CIMException&) { throw; } handler.deliver(enumInstanceNames); // complete processing the request handler.complete();}// change properties for the registered provider// only support to change property of Namespaces, property of// SupportedProperties, and property of SupportedMethodsvoid ProviderRegistrationProvider::modifyInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, const Boolean includeQualifiers, const CIMPropertyList & propertyList, ResponseHandler & handler){ // get userName and only privileged user can execute this operation String userName; try { IdentityContainer container = context.get(IdentityContainer::NAME); userName = container.getUserName(); } catch (...) { userName = String::EMPTY; } if ((userName != String::EMPTY) && !System::isPrivilegedUser(userName)) { //l10n //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, //"You must have superuser privilege to modify the registration."); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED,MessageLoaderParms( "ControlProviders.ProviderRegistrationProvider.ProviderRegistrationProvider.SUPERUSER_PRIVILEGE_REQUIRED_MODIFY_REGISTRATION", "You must have superuser privilege to modify the registration.")); } if(!instanceReference.getNameSpace().equal (PEGASUS_NAMESPACENAME_INTEROP)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, instanceReference.getNameSpace().getString()); } // // only support to modify the instance of PG_ProviderCapabilities // if (!instanceReference.getClassName().equal (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, instanceReference.getClassName().getString()); } // // only can modify the property of Namespaces, property of // SupportedProperties, and property of SupportedMethods // if (propertyList.isNull()) { //l10n //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, //"Only can modify Namespaces, SupportedProperties, and SupportedMethods."); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, MessageLoaderParms( "ControlProviders.ProviderRegistrationProvider.ProviderRegistrationProvider.CAN_ONLY_MODIFY_ERR", "Only can modify Namespaces, SupportedProperties, and SupportedMethods.")); } Array<CIMName> propertyArray = propertyList.getPropertyNameArray(); for (Uint32 i=0; i<propertyArray.size(); i++) { if (!propertyArray[i].equal (_PROPERTY_NAMESPACES) && !propertyArray[i].equal (_PROPERTY_SUPPORTEDPROPERTIES) && !propertyArray[i].equal (_PROPERTY_SUPPORTEDMETHODS)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, propertyArray[i].getString()); } } // begin processing the request handler.processing(); try { _providerRegistrationManager->modifyInstance(instanceReference, instanceObject, includeQualifiers, propertyArray); } catch(const CIMException&) { throw; } // complete processing the request handler.complete();}// register a providervoid ProviderRegistrationProvider::createInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, ObjectPathResponseHandler & handler){ // get userName and only privileged user can execute this operation String userName; try { IdentityContainer container = context.get(IdentityContainer::NAME); userName = container.getUserName(); } catch (...) { userName = String::EMPTY; } if ((userName != String::EMPTY) && !System::isPrivilegedUser(userName)) { //l10n //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, //"You must have superuser privilege to register providers."); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms( "ControlProviders.ProviderRegistrationProvider.ProviderRegistrationProvider.SUPERUSER_PRIVILEGE_REQUIRED_REGISTER_PROVIDERS", "You must have superuser privilege to register providers.")); } CIMName className = instanceReference.getClassName(); CIMNamespaceName nameSpace = instanceReference.getNameSpace(); CIMObjectPath returnReference; CIMInstance instance = instanceObject; if(!nameSpace.equal (PEGASUS_NAMESPACENAME_INTEROP)) { throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, nameSpace.getString()); } // ensure the class existing in the specified namespace if(!className.equal (PEGASUS_CLASSNAME_PROVIDER) && !className.equal (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_CONSUMERCAPABILITIES) && !className.equal (PEGASUS_CLASSNAME_PROVIDERMODULE))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -