1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BASE_NOTIFICATION_CES_STANDARD_CESFWK_TOOLS_CEM_INCLUDE_COMMON_EVENT_COMMAND_H 17 #define BASE_NOTIFICATION_CES_STANDARD_CESFWK_TOOLS_CEM_INCLUDE_COMMON_EVENT_COMMAND_H 18 19 #include "shell_command.h" 20 #include "common_event.h" 21 22 namespace OHOS { 23 namespace EventFwk { 24 namespace { 25 const std::string TOOL_NAME = "cem"; 26 27 const std::string HELP_MSG = "usage: cem <command> [<options>]\n" 28 "These are common cem commands list:\n" 29 " help list available commands\n" 30 " publish publish a common event with options\n" 31 " dump dump the info of events\n"; 32 33 const std::string HELP_MSG_PUBLISH = 34 "usage: cem publish [<options>]\n" 35 "options list:\n" 36 " -h, --help list available commands\n" 37 " -e, --event <name> [-s, --sticky] [-o, --ordered] [-c, --code <code>] [-d, --data <data>]\n" 38 " publish a common event\n"; 39 40 const std::string HELP_MSG_DUMP = "usage: cem dump [<options>]\n" 41 "options list:\n" 42 " -h, --help list available commands\n" 43 " -a, --all dump the info of all events\n" 44 " -e, --event <name> dump the info of a specified event\n"; 45 46 const std::string HELP_MSG_NO_EVENT_OPTION = "error: you must specify an event name with '-e' or '--event'."; 47 48 const std::string STRING_PUBLISH_COMMON_EVENT_OK = "publish the common event successfully."; 49 const std::string STRING_PUBLISH_COMMON_EVENT_NG = "error: failed to publish the common event."; 50 51 const std::string STRING_DUMP_COMMON_EVENT_NG = "error: failed to dump the common event(s)."; 52 } // namespace 53 54 class CommonEventCommand : public OHOS::EventFwk::ShellCommand { 55 public: 56 CommonEventCommand(int argc, char *argv[]); ~CommonEventCommand()57 ~CommonEventCommand() override 58 {} 59 60 private: 61 ErrCode CreateCommandMap() override; 62 ErrCode CreateMessageMap() override; 63 ErrCode init() override; 64 65 ErrCode RunAsHelpCommand(); 66 ErrCode RunAsPublishCommand(); 67 ErrCode RunAsDumpCommand(); 68 69 std::shared_ptr<CommonEvent> commonEventPtr_; 70 }; 71 } // namespace EventFwk 72 } // namespace OHOS 73 74 #endif // BASE_NOTIFICATION_CES_STANDARD_CESFWK_TOOLS_CEM_INCLUDE_COMMON_EVENT_COMMAND_H 75