📄 subscription.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: Carol Ann Krug Graves, Hewlett-Packard Company// (carolann_graves@hp.com)////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/CIMType.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/CIMInstance.h>#include <Pegasus/Common/CIMProperty.h>#include <Pegasus/Common/CIMValue.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/InternalException.h>#include <Pegasus/Client/CIMClient.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;// Interop namespace defined in PEGASUS_NAMESPACENAME_INTEROP (constants.h)const CIMNamespaceName NAMESPACE1 = CIMNamespaceName ("root/cimv2");const CIMNamespaceName NAMESPACE2 = CIMNamespaceName ("test/TestProvider");const CIMNamespaceName NAMESPACE3 = CIMNamespaceName ("root/SampleProvider");const CIMNamespaceName SOURCENAMESPACE = CIMNamespaceName ("root/SampleProvider");Boolean verbose;void _createModuleInstance (CIMClient & client, const String & name, const String & location){ CIMInstance moduleInstance (PEGASUS_CLASSNAME_PROVIDERMODULE); moduleInstance.addProperty (CIMProperty (CIMName ("Name"), name)); moduleInstance.addProperty (CIMProperty (CIMName ("Vendor"), String ("Hewlett-Packard Company"))); moduleInstance.addProperty (CIMProperty (CIMName ("Version"), String ("2.0"))); moduleInstance.addProperty (CIMProperty (CIMName ("InterfaceType"), String ("C++Default"))); moduleInstance.addProperty (CIMProperty (CIMName ("InterfaceVersion"), String ("2.2.0"))); moduleInstance.addProperty (CIMProperty (CIMName ("Location"), location)); CIMObjectPath path = client.createInstance (PEGASUS_NAMESPACENAME_INTEROP, moduleInstance);}void _createProviderInstance (CIMClient & client, const String & name, const String & providerModuleName){ CIMInstance providerInstance (PEGASUS_CLASSNAME_PROVIDER); providerInstance.addProperty (CIMProperty (CIMName ("Name"), name)); providerInstance.addProperty (CIMProperty (CIMName ("ProviderModuleName"), providerModuleName)); CIMObjectPath path = client.createInstance (PEGASUS_NAMESPACENAME_INTEROP, providerInstance);}void _createCapabilityInstance (CIMClient & client, const String & providerModuleName, const String & providerName, const String & capabilityID, const String & className, const Array <String> & namespaces, const Array <Uint16> & providerTypes, const CIMPropertyList & supportedProperties){ CIMInstance capabilityInstance (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES); capabilityInstance.addProperty (CIMProperty (CIMName ("ProviderModuleName"), providerModuleName)); capabilityInstance.addProperty (CIMProperty (CIMName ("ProviderName"), providerName)); capabilityInstance.addProperty (CIMProperty (CIMName ("CapabilityID"), capabilityID)); capabilityInstance.addProperty (CIMProperty (CIMName ("ClassName"), className)); capabilityInstance.addProperty (CIMProperty (CIMName ("Namespaces"), namespaces)); capabilityInstance.addProperty (CIMProperty (CIMName ("ProviderType"), providerTypes)); if (!supportedProperties.isNull ()) { Array <String> propertyNameStrings; for (Uint32 i = 0; i < supportedProperties.size (); i++) { propertyNameStrings.append (supportedProperties [i].getString ()); } capabilityInstance.addProperty (CIMProperty (CIMName ("supportedProperties"), propertyNameStrings)); } CIMObjectPath path = client.createInstance (PEGASUS_NAMESPACENAME_INTEROP, capabilityInstance);}void _modifyCapabilityInstance (CIMClient & client, const String & providerModuleName, const String & providerName, const String & capabilityID, const CIMPropertyList & supportedProperties){ CIMInstance capabilityInstance (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES); if (!supportedProperties.isNull ()) { Array <String> propertyNameStrings; for (Uint32 i = 0; i < supportedProperties.size (); i++) { propertyNameStrings.append (supportedProperties [i].getString ()); } capabilityInstance.addProperty (CIMProperty (CIMName ("SupportedProperties"), propertyNameStrings)); } CIMObjectPath path; Array <CIMKeyBinding> keyBindings; keyBindings.append (CIMKeyBinding ("ProviderModuleName", providerModuleName, CIMKeyBinding::STRING)); keyBindings.append (CIMKeyBinding ("ProviderName", providerName, CIMKeyBinding::STRING)); keyBindings.append (CIMKeyBinding ("CapabilityID", capabilityID, CIMKeyBinding::STRING)); path.setClassName (PEGASUS_CLASSNAME_PROVIDERCAPABILITIES); path.setKeyBindings (keyBindings); capabilityInstance.setPath (path); Array <CIMName> propertyNames; propertyNames.append (CIMName ("SupportedProperties")); CIMPropertyList properties (propertyNames); client.modifyInstance (PEGASUS_NAMESPACENAME_INTEROP, capabilityInstance, false, properties);}void _addStringProperty (CIMInstance & instance, const String & name, const String & value, Boolean null = false, Boolean isArray = false){ if (null) { instance.addProperty (CIMProperty (CIMName (name), CIMValue (CIMTYPE_STRING, false))); } else { if (isArray) { Array <String> values; values.append (value); instance.addProperty (CIMProperty (CIMName (name), values)); } else { instance.addProperty (CIMProperty (CIMName (name), value)); } }}void _addUint16Property (CIMInstance & instance, const String & name, Uint16 value, Boolean null = false, Boolean isArray = false){ if (null) { instance.addProperty (CIMProperty (CIMName (name), CIMValue (CIMTYPE_UINT16, false))); } else { if (isArray) { Array <Uint16> values; values.append (value); instance.addProperty (CIMProperty (CIMName (name), values)); } else { instance.addProperty (CIMProperty (CIMName (name), value)); } }}void _addUint32Property (CIMInstance & instance, const String & name, Uint32 value, Boolean null = false, Boolean isArray = false){ if (null) { instance.addProperty (CIMProperty (CIMName (name), CIMValue (CIMTYPE_UINT32, false))); } else { if (isArray) { Array <Uint32> values; values.append (value); instance.addProperty (CIMProperty (CIMName (name), values)); } else { instance.addProperty (CIMProperty (CIMName (name), value)); } }}void _addUint64Property (CIMInstance & instance, const String & name, Uint64 value, Boolean null = false, Boolean isArray = false){ if (null) { instance.addProperty (CIMProperty (CIMName (name), CIMValue (CIMTYPE_UINT64, false))); } else { if (isArray) { Array <Uint64> values; values.append (value); instance.addProperty (CIMProperty (CIMName (name), values)); } else { instance.addProperty (CIMProperty (CIMName (name), value)); } }}CIMObjectPath _buildFilterOrHandlerPath (const CIMName & className, const String & name, const String & host, const CIMNamespaceName & namespaceName = CIMNamespaceName ()){ CIMObjectPath path; Array <CIMKeyBinding> keyBindings; keyBindings.append (CIMKeyBinding ("SystemCreationClassName", System::getSystemCreationClassName (), CIMKeyBinding::STRING)); keyBindings.append (CIMKeyBinding ("SystemName", System::getFullyQualifiedHostName (), CIMKeyBinding::STRING)); keyBindings.append (CIMKeyBinding ("CreationClassName", className.getString(), CIMKeyBinding::STRING)); keyBindings.append (CIMKeyBinding ("Name", name, CIMKeyBinding::STRING)); path.setClassName (className); path.setKeyBindings (keyBindings); path.setNameSpace (namespaceName); path.setHost (host); return path;}CIMObjectPath _buildFilterOrHandlerPath (const CIMName & className, const String & name){ return _buildFilterOrHandlerPath (className, name, String::EMPTY, CIMNamespaceName ());}CIMObjectPath _buildSubscriptionPath (const String & filterName, const CIMName & handlerClass, const String & handlerName, const String & filterHost, const String & handlerHost, const CIMNamespaceName & filterNS, const CIMNamespaceName & handlerNS){ CIMObjectPath filterPath = _buildFilterOrHandlerPath (PEGASUS_CLASSNAME_INDFILTER, filterName, filterHost, filterNS); CIMObjectPath handlerPath = _buildFilterOrHandlerPath (handlerClass, handlerName, handlerHost, handlerNS); Array<CIMKeyBinding> subscriptionKeyBindings;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -