⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimsubcommand.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//%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.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <iostream>#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/System.h>#include <Pegasus/Client/CIMClient.h>#include <Pegasus/Common/Exception.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/AutoPtr.h>#include <Pegasus/getoopt/getoopt.h>#include <Clients/cliutils/CommandException.h>#include "CIMSubCommand.h"PEGASUS_NAMESPACE_BEGIN/** * The CLI message resource name */static const char MSG_PATH [] = "pegasus/pegasusCLI";/**    The command name. */const char COMMAND_NAME[] = "cimsub";/**   The default subscription namespace */static const CIMNamespaceName _DEFAULT_SUBSCRIPTION_NAMESPACE  =    PEGASUS_NAMESPACENAME_INTEROP;/**    The usage string for this command.  This string is displayed    when an error occurs in parsing or validating the command line. */static const char USAGE[] = "Usage: ";/**    This constant represents the getoopt argument designator */static const char GETOPT_ARGUMENT_DESIGNATOR = ':';/*    These constants represent the operation modes supported by the CLI.    Any new operation should be added here. *//**    This constant signifies that an operation option has not been recorded */const Uint32 CIMSubCommand::OPERATION_TYPE_UNINITIALIZED = 0;/**    This constant represents a disable subscription operation */const Uint32 CIMSubCommand::OPERATION_TYPE_DISABLE = 1;/**    This constant represents a enable subscription operation */const Uint32 CIMSubCommand::OPERATION_TYPE_ENABLE = 2;/**    This constant represents a list operation */const Uint32 CIMSubCommand::OPERATION_TYPE_LIST = 3;/**    This constant represents a remove operation */const Uint32 CIMSubCommand::OPERATION_TYPE_REMOVE = 4;/**    This constant represents a help operation */const Uint32 CIMSubCommand::OPERATION_TYPE_HELP = 5;/**    This constant represents a verbose list operation */const Uint32 CIMSubCommand::OPERATION_TYPE_VERBOSE = 6;/**    This constant represents a version display operation */const Uint32 CIMSubCommand::OPERATION_TYPE_VERSION = 7;/**    The constants representing the messages. */static const char CIMOM_NOT_RUNNING[] =    "The CIM server may not be running.";static const char CIMOM_NOT_RUNNING_KEY[] =    "Clients.cimsub.CIMSubCommand.CIMOM_NOT_RUNNING";static const char ENABLE_SUBSCRIPTION_FAILURE[] =    "Failed to enable subscription.";static const char ENABLE_SUBSCRIPTION_FAILURE_KEY[] =    "Clients.cimsub.CIMSubCommand.ENABLE_SUBSCRIPTION_FAILURE";static const char DISABLE_SUBSCRIPTION_FAILURE[] =    "Failed to disable subscription.";static const char DISABLE_SUBSCRIPTION_FAILURE_KEY[] =    "Clients.cimsub.CIMSubCommand.DISABLE_SUBSCRIPTION_FAILURE";static const char SUBSCRIPTION_NOT_FOUND_FAILURE[] =    "The requested subscription could not be found.";static const char SUBSCRIPTION_NOT_FOUND_KEY[] =    "Clients.cimsub.CIMSubCommand."        "SUBSCRIPTION_NOT_FOUND_FAILURE_KEY";static const char HANDLER_NOT_FOUND_FAILURE[] =    "The requested handler could not be found.";static const char HANDLER_NOT_FOUND_KEY[] =    "Clients.cimsub.CIMSubCommand."        "HANDLER_NOT_FOUND_FAILURE_KEY";static const char FILTER_NOT_FOUND_FAILURE[] =    "The requested filter could not be found.";static const char FILTER_NOT_FOUND_KEY[] =    "Clients.cimsub.CIMSubCommand."        "FILTER_NOT_FOUND_FAILURE_KEY";static const char SUBSCRIPTION_ALREADY_DISABLED[] =    "The subscription is already disabled.";static const char SUBSCRIPTION_ALREADY_DISABLED_KEY[] =    "Clients.cimsub.CIMSubCommand.SUBSCRIPTION_ALREADY_DISABLED";static const char SUBSCRIPTION_ALREADY_ENABLED[] =    "The subscription is already enabled.";static const char SUBSCRIPTION_ALREADY_ENABLED_KEY[] =    "Clients.cimsub.CIMSubCommand.SUBSCRIPTION_ALREADY_ENABLED";static const char ERR_OPTION_NOT_SUPPORTED[] =    "Invalid option. Use '--help' to obtain command syntax.";static const char ERR_OPTION_NOT_SUPPORTED_KEY[] =    "Clients.cimsub.CIMSubCommand.ERR_OPTION_NOT_SUPPORTED";static const char REQUIRED_OPTION_MISSING[] =    "Required option missing.";static const char REQUIRED_OPTION_MISSING_KEY[] =    "Clients.cimsub.CIMSubCommand.REQUIRED_OPTION_MISSING";static const char INVALID_ARGS[] =    "Invalid arguments.";static const char INVALID_ARGS_KEY[] =    "Clients.cimsub.CIMSubCommand.INVALID_ARGS";static const char UNEXPECTED_OPTION[] = "Unexpected Option.";static const char UNEXPECTED_OPTION_KEY[] =    "Clients.cimsub.CIMSubCommand.UNEXPECTED_OPTION";static const char ERR_USAGE_KEY[] =    "Clients.cimsub.CIMSubCommand.ERR_USAGE";static const char ERR_USAGE[] =    "Incorrect usage. Use '--help' to obtain command syntax.";static const char LONG_HELP[] = "help";static const char LONG_VERSION[] = "version";/**    The option character used to specify disable a specified subscription */static const char OPTION_DISABLE = 'd';/**    The option character used to specify remove a specified subscription */static const char OPTION_REMOVE = 'r';/**    The option character used to specify the Filter Name of a subscription */static const char OPTION_FILTER = 'F';/**    The option character used to specify enable a specified subscription. */static const char OPTION_ENABLE = 'e';/**    The option character used to specify the Handler Name of a subscription */static const char OPTION_HANDLER = 'H';/**    The option character used to specify listing */static const char OPTION_LIST = 'l';/**    The option argument character used to specify subscriptions */static String ARG_SUBSCRIPTIONS = "s";/**    The option argument character used to specify filters */static String ARG_FILTERS = "f";/**    The option argument character used to specify handlers */static String ARG_HANDLERS = "h";/**    The option argument character used to specify handlers, filters,    and subscriptions */static String ARG_ALL = "a";/**    The option character used to specify namespace of subscription */static const char OPTION_NAMESPACE = 'n';/**    The option character used to display verbose info. */static const char OPTION_VERBOSE = 'v';static const char DELIMITER_NAMESPACE = ':';static const char DELIMITER_HANDLER_CLASS = '.';/**    List output header values */const Uint32 TITLE_SEPERATOR_LEN = 2;static const Uint32 RC_CONNECTION_FAILED = 2;static const Uint32 RC_CONNECTION_TIMEOUT = 3;static const Uint32 RC_ACCESS_DENIED = 4;static const Uint32 RC_NAMESPACE_NONEXISTENT = 5;static const Uint32 RC_OBJECT_NOT_FOUND = 6;static const Uint32 RC_OPERATION_NOT_SUPPORTED = 7;//// List column header constants//const Uint32 _HANDLER_LIST_NAME_COLUMN = 0;const Uint32 _HANDLER_LIST_DESTINATION_COLUMN = 1;const Uint32 _FILTER_LIST_NAME_COLUMN = 0;const Uint32 _FILTER_LIST_QUERY_COLUMN = 1;const Uint32 _FILTER_LIST_QUERYLANGUAGE_COLUMN = 2;const Uint32 _SUBSCRIPTION_LIST_NS_COLUMN = 0;const Uint32 _SUBSCRIPTION_LIST_FILTER_COLUMN = 1;const Uint32 _SUBSCRIPTION_LIST_HANDLER_COLUMN = 2;const Uint32 _SUBSCRIPTION_LIST_STATE_COLUMN = 3;//// Handler persistence display values//const String _PERSISTENTENCE_OTHER_STRING = "Other";const String _PERSISTENTENCE_PERMANENT_STRING = "Permanent";const String _PERSISTENTENCE_TRANSIENT_STRING = "Transient";const String _PERSISTENTENCE_UNKNOWN_STRING = "Unknown";//// Subscription state display values//const String _SUBSCRIPTION_STATE_UNKNOWN_STRING = "Unknown";const String _SUBSCRIPTION_STATE_OTHER_STRING = "Other";const String _SUBSCRIPTION_STATE_ENABLED_STRING = "Enabled";const String _SUBSCRIPTION_STATE_ENABLED_DEGRADED_STRING = "Enabled Degraded";const String _SUBSCRIPTION_STATE_DISABLED_STRING = "Disabled";const String _SUBSCRIPTION_STATE_NOT_SUPPORTED_STRING = "Not Supported";//// SNMP version display values//const String _SNMP_VERSION_SNMPV1_TRAP_STRING = "SNMPv1 Trap";const String _SNMP_VERSION_SNMPV2C_TRAP_STRING = "SNMPv2C Trap";const String _SNMP_VERSION_PEGASUS_RESERVED_STRING = "Pegasus Reserved";/**    Constructs a CIMSubCommand and initializes instance variables. */CIMSubCommand::CIMSubCommand(){    /**        Initialize the instance variables.    */    _operationType = OPERATION_TYPE_UNINITIALIZED;    _verbose = false;    /**        Build the usage string for the config command.    */    usage.reserveCapacity(200);    usage.append(USAGE);    usage.append(COMMAND_NAME);    usage.append(" -").append(OPTION_LIST);    usage.append(" ").append(ARG_SUBSCRIPTIONS).append("|");    usage.append(ARG_FILTERS).append("|");    usage.append(ARG_HANDLERS);    usage.append(" [-").append(OPTION_VERBOSE).append("]");    usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");    usage.append(" [-").append(OPTION_FILTER).append        (" [fnamespace:]filtername] \n");    usage.append("                  [-").append(OPTION_HANDLER).append        (" [hnamespace:][hclassname.]handlername] \n");    usage.append("              -").append(OPTION_ENABLE);    usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");    usage.append(" -").append(OPTION_FILTER).append        (" [fnamespace:]filtername \n");    usage.append("                  -").append(OPTION_HANDLER).append        (" [hnamespace:][hclassname.]handlername \n");    usage.append("              -").append(OPTION_DISABLE);    usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");    usage.append(" -").append(OPTION_FILTER).append        (" [fnamespace:]filtername\n");    usage.append("                  -").append(OPTION_HANDLER).append        (" [hnamespace:][hclassname.]handlername \n");    usage.append("              -").append(OPTION_REMOVE);    usage.append(" ").append (ARG_SUBSCRIPTIONS).append("|");    usage.append(ARG_FILTERS).append("|");    usage.append(ARG_HANDLERS).append("|");    usage.append(ARG_ALL);    usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");    usage.append(" [-").append(OPTION_FILTER).append        ("[fnamespace:]filtername] \n");    usage.append("                  [-").append(OPTION_HANDLER).append        (" [hnamespace:][hclassname.]handlername]\n");    usage.append("              --").append(LONG_HELP).append("\n");    usage.append("              --").append(LONG_VERSION).append("\n");    usage.append("Options : \n");    usage.append("    -l         - List and display information\n");    usage.append("    -e         - Enable specified subscription\n");    usage.append("                   (set SubscriptionState to Enabled) \n");    usage.append("    -d         - Disable specified subscription \n");    usage.append("                   (set SubscriptionState to Disabled) \n");    usage.append("    -r         - Remove specified subscription, handler, filter \n");    usage.append("    -v         - Include verbose information \n");    usage.append("    -F         - Specify Filter Name of subscription for the operation\n");    usage.append("    -H         - Specify Handler Name of subscription for the operation\n");    usage.append("    -n         - Specify namespace of subscription\n");    usage.append("                   (root/PG_InterOp, if not specified) \n");    usage.append("    --help     - Display this help message\n");    usage.append("    --version  - Display CIM Server version\n");#ifdef PEGASUS_HAS_ICU    MessageLoaderParms menuparms("Clients.cimsub.CIMSubCommand.MENU.STANDARD",usage);    menuparms.msg_src_path = MSG_PATH;    usage = MessageLoader::getMessage(menuparms);#endif    setUsage(usage);}/**    Parses the command line, validates the options, and sets instance    variables based on the option arguments.*/void CIMSubCommand::setCommand(    ostream& outPrintWriter,    ostream& errPrintWriter,    Uint32 argc,    char* argv[]){    Uint32 i = 0;    Uint32 c = 0;    String badOptionString;    String optString;    String filterNameString;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -