📄 cimprovidercommand.cpp
字号:
// Empty function } /** Parses the command line, validates the options, and sets instance variables based on the option arguments. This implementation of setCommand includes the parameters for output and error stream. @param ostream The stream to which command output is written. @param ostream The stream to which command errors are written. @param args The string array containing the command line arguments @param argc The int containing the arguments count @throws CommandFormatException if an error is encountered in parsing the command line */ void setCommand ( ostream& outPrintWriter, ostream& errPrintWriter, Uint32 argc, char* argv []); /** Executes the command and writes the results to the output streams. @param ostream The stream to which command output is written. @param ostream The stream to which command errors are written. @return 0 if the command is successful 1 if an error occurs in executing the command */ Uint32 execute ( ostream& outPrintWriter, ostream& errPrintWriter);private: // // Delete a provider or module // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // // @exception CIMException if failed to delete provider module // void _deleteProvider ( ostream& outPrintWriter, ostream& errPrintWriter ); // // Start a provider or module // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // // @exception CIMException if failed to start provider module // void _StartProvider ( ostream& outPrintWriter, ostream& errPrintWriter ); // // Stop a provider or module // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // // @exception CIMException if failed to stop provider // void _StopProvider ( ostream& outPrintWriter, ostream& errPrintWriter ); // // List all the registered providers or modules. // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // void _ListProviders ( ostream& outPrintWriter, ostream& errPrintWriter ); // // Get module status // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // // @exception CIMException if failed to get module status // void _GetStatus ( ostream& outPrintWriter, ostream& errPrintWriter ); // Get namedInstance for the provider module CIMInstance _getModuleInstance(); // Get namedInstance for the provider CIMInstance _getProviderInstance(); // Print out registered modules and status void _printList(Array<String>& moduleNames, Array<CIMInstance>& instances, ostream& outPrintWriter, ostream& errPrintWriter); // // The CIM Client reference // AutoPtr<CIMClient> _client;//PEP101 // // The host name. // String _hostName; // // The name of the provider module. // String _moduleName; // // The name of the provider. // String _providerName; // // The type of operation specified on the command line. // Uint32 _operationType; // // The flag to indicate whether the provider module is set or not // Boolean _moduleSet; // // The flag to indicate whether the provider is set or not // Boolean _providerSet; // // The flag to indicate whether the status is set or not // Boolean _statusSet; String usage;#ifdef PEGASUS_OS_OS400 // // The flag to indicate whether standard output and standard error are suppressed // Boolean _defaultQuietSet;#endif};/** Constructs a CIMProviderCommand and initializes instance variables.*/CIMProviderCommand::CIMProviderCommand (){ /** Initialize the instance variables. */ _operationType = OPERATION_TYPE_UNINITIALIZED; _hostName = String::EMPTY; _moduleName = String::EMPTY; _providerName = String::EMPTY; _moduleSet = false; _providerSet = false; _statusSet = false;#ifdef PEGASUS_OS_OS400 _defaultQuietSet = false;#endif /** Build the usage string for the config command. */ usage.reserveCapacity(200); usage.append(USAGE); usage.append(COMMAND_NAME);#ifdef PEGASUS_OS_OS400 usage.append(" -").append(OPTION_DISABLE); usage.append(" -").append(OPTION_MODULE).append(" module "); usage.append("[ -").append(OPTION_QUIET_VALUE).append(" ]\n"); usage.append(" -").append(OPTION_ENABLE); usage.append(" -").append(OPTION_MODULE).append(" module "); usage.append("[ -").append(OPTION_QUIET_VALUE).append(" ]\n"); usage.append(" -").append(OPTION_REMOVE); usage.append(" -").append(OPTION_MODULE).append(" module"); usage.append(" [ -").append(OPTION_PROVIDER).append(" provider ] "); usage.append("[ -").append(OPTION_QUIET_VALUE).append(" ]\n"); usage.append(" -").append(OPTION_LIST); usage.append(" [ -").append(OPTION_STATUS); usage.append(" | -").append(OPTION_MODULE).append(" module ] \n");#else usage.append(" -").append(OPTION_DISABLE); usage.append(" -").append(OPTION_MODULE).append(" module \n"); usage.append(" -").append(OPTION_ENABLE); usage.append(" -").append(OPTION_MODULE).append(" module \n"); usage.append(" -").append(OPTION_REMOVE); usage.append(" -").append(OPTION_MODULE).append(" module"); usage.append(" [ -").append(OPTION_PROVIDER).append(" provider ] \n"); usage.append(" -").append(OPTION_LIST); usage.append(" [ -").append(OPTION_STATUS); usage.append(" | -").append(OPTION_MODULE).append(" module ] \n");#endif //PEP167 changes - common for all platforms usage.append(" -").append(OPTION_HELP).append("\n"); usage.append(" --").append(LONG_HELP).append("\n"); usage.append(" --").append(LONG_VERSION).append("\n"); usage.append("Options : \n"); usage.append(" -d - Disable the specified CIM provider module\n"); usage.append(" -e - Enable the specified CIM provider module\n"); usage.append(" -h, --help - Display this help message\n"); usage.append(" -l - Display all the registered provider modules\n"); usage.append(" -m - Specify the provider module for the operation\n"); usage.append(" -p - Specify the provider for the operation\n");#ifdef PEGASUS_OS_OS400 usage.append(" -q - Specify quiet mode, avoiding output to stdout or stderr\n");#endif usage.append(" -r - Remove specified provider module and its contained providers\n"); usage.append(" -s - Display the status of registered provider modules\n"); usage.append(" --version - Display CIM Server version number\n");//l10n localize usage#ifdef PEGASUS_HAS_ICU# ifdef PEGASUS_OS_OS400 MessageLoaderParms menuparms("Clients.cimprovider.CIMProviderCommand.MENU.PEGASUS_OS_OS400",usage); menuparms.msg_src_path = MSG_PATH; usage = MessageLoader::getMessage(menuparms);# else MessageLoaderParms menuparms("Clients.cimprovider.CIMProviderCommand.MENU.STANDARD",usage); menuparms.msg_src_path = MSG_PATH; usage = MessageLoader::getMessage(menuparms);# endif#endif setUsage (usage);}/** Parses the command line, validates the options, and sets instance variables based on the option arguments.*/void CIMProviderCommand::setCommand ( ostream& outPrintWriter, ostream& errPrintWriter, Uint32 argc, char* argv []){ Uint32 i = 0; Uint32 c = 0; String badOptionString = String (); String optString = String (); // // Construct optString //#ifdef PEGASUS_OS_OS400 optString.append(OPTION_DISABLE); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_QUIET_VALUE); optString.append(OPTION_ENABLE); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_QUIET_VALUE); optString.append(OPTION_REMOVE); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_PROVIDER); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_QUIET_VALUE); optString.append(OPTION_LIST); optString.append(OPTION_STATUS); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);#else optString.append(OPTION_DISABLE); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_ENABLE); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_REMOVE); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_PROVIDER); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_LIST); optString.append(OPTION_STATUS); optString.append(OPTION_MODULE); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);#endif //PEP167 changes - common for all platforms optString.append(OPTION_LIST); optString.append(OPTION_HELP); // // Initialize and parse options // getoopt options (""); options.addFlagspec(optString); //PEP#167 - adding long flag for options : 'help' and 'version' options.addLongFlagspec(LONG_HELP,getoopt::NOARG); options.addLongFlagspec(LONG_VERSION,getoopt::NOARG); options.parse (argc, argv); if (options.hasErrors ()) { throw CommandFormatException(options.getErrorStrings()[0]); } _operationType = OPERATION_TYPE_UNINITIALIZED; // // Get options and arguments from the command line // for (i = options.first (); i < options.last (); i++) { if (options[i].getType () == Optarg::LONGFLAG) { if (options[i].getopt () == LONG_HELP) { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { String param = String (LONG_HELP); // // More than one operation option was found // throw UnexpectedOptionException(param); } _operationType = OPERATION_TYPE_HELP; } else if (options[i].getopt () == LONG_VERSION) { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { String param = String (LONG_VERSION); // // More than one operation option was found // throw UnexpectedOptionException(param); } _operationType = OPERATION_TYPE_VERSION; } } else if (options [i].getType () == Optarg::REGULAR) { // // The cimprovider command has no non-option argument options // throw UnexpectedArgumentException(options[i].Value()); } else /* if (options [i].getType () == Optarg::FLAG) */ { c = options [i].getopt () [0]; switch (c) { case OPTION_DISABLE: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { // // More than one operation option was found // throw UnexpectedOptionException(OPTION_DISABLE); } if (options.isSet (OPTION_DISABLE) > 1) { // // More than one disable provider option was found // throw DuplicateOptionException(OPTION_DISABLE); } _operationType = OPERATION_TYPE_DISABLE; break; } case OPTION_REMOVE: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -