196279301Sopenharmony_ci/*
296279301Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
396279301Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
496279301Sopenharmony_ci * you may not use this file except in compliance with the License.
596279301Sopenharmony_ci * You may obtain a copy of the License at
696279301Sopenharmony_ci *
796279301Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
896279301Sopenharmony_ci *
996279301Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1096279301Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1196279301Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1296279301Sopenharmony_ci * See the License for the specific language governing permissions and
1396279301Sopenharmony_ci * limitations under the License.
1496279301Sopenharmony_ci */
1596279301Sopenharmony_ci
1696279301Sopenharmony_ci#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_TOOLS_DUMP_INCLUDE_SHELL_COMMAND_H
1796279301Sopenharmony_ci#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_TOOLS_DUMP_INCLUDE_SHELL_COMMAND_H
1896279301Sopenharmony_ci
1996279301Sopenharmony_ci#include <functional>
2096279301Sopenharmony_ci#include <map>
2196279301Sopenharmony_ci#include <string>
2296279301Sopenharmony_ci#include <vector>
2396279301Sopenharmony_ci
2496279301Sopenharmony_ci#include "errors.h"
2596279301Sopenharmony_ci
2696279301Sopenharmony_cinamespace OHOS {
2796279301Sopenharmony_cinamespace Notification {
2896279301Sopenharmony_ciclass ShellCommand {
2996279301Sopenharmony_cipublic:
3096279301Sopenharmony_ci    /**
3196279301Sopenharmony_ci     * @brief Constructor.
3296279301Sopenharmony_ci     *
3396279301Sopenharmony_ci     * @param argc Indicates the count of arguments.
3496279301Sopenharmony_ci     * @param argv Indicates the arguments.
3596279301Sopenharmony_ci     * @param name Indicates the tool name.
3696279301Sopenharmony_ci     */
3796279301Sopenharmony_ci    ShellCommand(int argc, char *argv[], std::string name);
3896279301Sopenharmony_ci
3996279301Sopenharmony_ci    /**
4096279301Sopenharmony_ci     * @brief Destructor.
4196279301Sopenharmony_ci     */
4296279301Sopenharmony_ci    virtual ~ShellCommand();
4396279301Sopenharmony_ci
4496279301Sopenharmony_ci    /**
4596279301Sopenharmony_ci     * @brief Process the command.
4696279301Sopenharmony_ci     *
4796279301Sopenharmony_ci     * @return Indicates the command result code.
4896279301Sopenharmony_ci     */
4996279301Sopenharmony_ci    ErrCode OnCommand();
5096279301Sopenharmony_ci
5196279301Sopenharmony_ci    /**
5296279301Sopenharmony_ci     * @brief Execute the command.
5396279301Sopenharmony_ci     *
5496279301Sopenharmony_ci     * @return Indicates the output text.
5596279301Sopenharmony_ci     */
5696279301Sopenharmony_ci    std::string ExecCommand();
5796279301Sopenharmony_ci
5896279301Sopenharmony_ci    /**
5996279301Sopenharmony_ci     * @brief Get the error message of the command.
6096279301Sopenharmony_ci     *
6196279301Sopenharmony_ci     * @return Indicates the error message.
6296279301Sopenharmony_ci     */
6396279301Sopenharmony_ci    std::string GetCommandErrorMsg() const;
6496279301Sopenharmony_ci
6596279301Sopenharmony_ci    /**
6696279301Sopenharmony_ci     * @brief Get the error message of the unknown option.
6796279301Sopenharmony_ci     *
6896279301Sopenharmony_ci     * @param unknownOption Indicates the unknown option.
6996279301Sopenharmony_ci     * @return Indicates the error message.
7096279301Sopenharmony_ci     */
7196279301Sopenharmony_ci    std::string GetUnknownOptionMsg(std::string &unknownOption) const;
7296279301Sopenharmony_ci
7396279301Sopenharmony_ci    /**
7496279301Sopenharmony_ci     * @brief Get the message from the code.
7596279301Sopenharmony_ci     *
7696279301Sopenharmony_ci     * @param code Indicates the code.
7796279301Sopenharmony_ci     * @return Indicates the message.
7896279301Sopenharmony_ci     */
7996279301Sopenharmony_ci    std::string GetMessageFromCode(int32_t code) const;
8096279301Sopenharmony_ci
8196279301Sopenharmony_ci    /**
8296279301Sopenharmony_ci     * @brief Create the command map.
8396279301Sopenharmony_ci     *
8496279301Sopenharmony_ci     * @return Indicates the result code.
8596279301Sopenharmony_ci     */
8696279301Sopenharmony_ci    virtual ErrCode CreateCommandMap() = 0;
8796279301Sopenharmony_ci
8896279301Sopenharmony_ci    /**
8996279301Sopenharmony_ci     * @brief The initialize function.
9096279301Sopenharmony_ci     *
9196279301Sopenharmony_ci     * @return Indicates the result code.
9296279301Sopenharmony_ci     */
9396279301Sopenharmony_ci    virtual ErrCode Init() = 0;
9496279301Sopenharmony_ci
9596279301Sopenharmony_ciprotected:
9696279301Sopenharmony_ci    static constexpr int32_t MIN_ARGUMENT_NUMBER = 2;
9796279301Sopenharmony_ci    static constexpr int32_t MAX_ARGUMENT_NUMBER = 256;
9896279301Sopenharmony_ci
9996279301Sopenharmony_ci    int argc_;
10096279301Sopenharmony_ci    char **argv_;
10196279301Sopenharmony_ci
10296279301Sopenharmony_ci    std::string cmd_;
10396279301Sopenharmony_ci    std::vector<std::string> argList_;
10496279301Sopenharmony_ci    std::string name_;
10596279301Sopenharmony_ci    std::map<std::string, std::function<int()>> commandMap_;
10696279301Sopenharmony_ci    std::map<int32_t, std::string> messageMap_;
10796279301Sopenharmony_ci    std::string resultReceiver_;
10896279301Sopenharmony_ci};
10996279301Sopenharmony_ci}  // namespace Notification
11096279301Sopenharmony_ci}  // namespace OHOS
11196279301Sopenharmony_ci
11296279301Sopenharmony_ci#endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_TOOLS_DUMP_INCLUDE_SHELL_COMMAND_H