Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 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 __VOM_INSPECT_H__ |
| 17 | #define __VOM_INSPECT_H__ |
| 18 | |
| 19 | #include <deque> |
| 20 | #include <map> |
| 21 | #include <ostream> |
| 22 | #include <string> |
| 23 | |
| 24 | namespace VOM { |
| 25 | /** |
| 26 | * A means to inspect the state VPP has built, in total, and per-client |
| 27 | */ |
| 28 | class inspect |
| 29 | { |
| 30 | public: |
| 31 | /** |
| 32 | * Constructor |
| 33 | */ |
| 34 | inspect() = default; |
| 35 | |
| 36 | /** |
| 37 | * Destructor to tidyup socket resources |
| 38 | */ |
| 39 | ~inspect() = default; |
| 40 | |
| 41 | /** |
| 42 | * handle input from the requester |
| 43 | * |
| 44 | * @param input command |
| 45 | * @param output output |
| 46 | */ |
| 47 | void handle_input(const std::string& input, std::ostream& output); |
| 48 | |
| 49 | /** |
| 50 | * inspect command handler Handler |
| 51 | */ |
| 52 | class command_handler |
| 53 | { |
| 54 | public: |
| 55 | command_handler() = default; |
| 56 | virtual ~command_handler() = default; |
| 57 | |
| 58 | /** |
| 59 | * Show each object |
| 60 | */ |
| 61 | virtual void show(std::ostream& os) = 0; |
| 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * Register a command handler for inspection |
| 66 | */ |
| 67 | static void register_handler(const std::vector<std::string>& cmds, |
| 68 | const std::string& help, |
| 69 | command_handler* ch); |
| 70 | |
| 71 | private: |
| 72 | /** |
| 73 | * command handler list |
| 74 | */ |
| 75 | static std::unique_ptr<std::map<std::string, command_handler*>> |
| 76 | m_cmd_handlers; |
| 77 | /** |
| 78 | * help handler list |
| 79 | */ |
| 80 | static std::unique_ptr< |
| 81 | std::deque<std::pair<std::vector<std::string>, std::string>>> |
| 82 | m_help_handlers; |
| 83 | }; |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * fd.io coding-style-patch-verification: ON |
| 88 | * |
| 89 | * Local Variables: |
| 90 | * eval: (c-set-style "mozilla") |
| 91 | * End: |
| 92 | */ |
| 93 | |
| 94 | #endif |