OSDN Git Service

am 9a6b9137: Merge "Implement simpleperf list subcommand."
[android-x86/system-extras.git] / simpleperf / command.h
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef SIMPLE_PERF_COMMAND_H_
18 #define SIMPLE_PERF_COMMAND_H_
19
20 #include <string>
21 #include <vector>
22
23 #include <base/macros.h>
24
25 class Command {
26  public:
27   Command(const std::string& name, const std::string& short_help_string,
28           const std::string& long_help_string)
29       : name_(name), short_help_string_(short_help_string), long_help_string_(long_help_string) {
30     RegisterCommand(this);
31   }
32
33   virtual ~Command() {
34   }
35
36   const std::string& Name() const {
37     return name_;
38   }
39
40   const std::string& ShortHelpString() const {
41     return short_help_string_;
42   }
43
44   const std::string LongHelpString() const {
45     return long_help_string_;
46   }
47
48   virtual bool Run(const std::vector<std::string>& args) = 0;
49
50   static Command* FindCommandByName(const std::string& cmd_name);
51   static const std::vector<Command*>& GetAllCommands();
52
53  private:
54   const std::string name_;
55   const std::string short_help_string_;
56   const std::string long_help_string_;
57
58   static void RegisterCommand(Command* cmd);
59
60   DISALLOW_COPY_AND_ASSIGN(Command);
61 };
62
63 #endif  // SIMPLE_PERF_COMMAND_H_