@@ -26,6 +26,30 @@ limitations under the License.
2626#include " shared/rpc/RPCClient.h"
2727#include " CtrlPrinters.h"
2828
29+ // / @brief Class that provides access to the RPC side of things.
30+ struct RPCAccessor {
31+ protected:
32+ // / @brief Invoke the remote server. This is the very basic function which does not play or interact with any codec. Request
33+ // / and message should be already en|de coded.
34+ // / @param request A string representation of the json/yaml request.
35+ // / @return a string with the json/yaml response.
36+ // / @note This function does print the raw string if requested by the "--format". No printer involved, standard output.
37+ std::string invoke_rpc (std::string const &request);
38+
39+ // / @brief Function that calls the rpc server. This function takes a json objects and uses the defined coded to convert them to a
40+ // / string. This function will call invoke_rpc(string) overload.
41+ // / @param A Client request.
42+ // / @return A server response.
43+ shared::rpc::JSONRPCResponse invoke_rpc (shared::rpc::ClientRequest const &request);
44+
45+ // / @brief Function that calls the rpc server. The response will not be decoded, it will be a raw string.
46+ void invoke_rpc (shared::rpc::ClientRequest const &request, std::string &bw);
47+
48+ std::unique_ptr<BasePrinter> _printer; // !< Specific output formatter. This should be created by the derived class.
49+ private:
50+ shared::rpc::RPCClient _rpcClient; // !< RPC socket client implementation.
51+ };
52+
2953// ----------------------------------------------------------------------------------------------------------------------------------
3054// /
3155// / @brief Base Control Command class.
@@ -49,24 +73,6 @@ class CtrlCommand
4973 virtual void execute ();
5074
5175protected:
52- // / @brief Invoke the remote server. This is the very basic function which does not play or interact with any codec. Request
53- // / and message should be already en|de coded.
54- // / @param request A string representation of the json/yaml request.
55- // / @return a string with the json/yaml response.
56- // / @note This function does print the raw string if requested by the "--format". No printer involved, standard output.
57- std::string invoke_rpc (std::string const &request);
58-
59- // / @brief Function that calls the rpc server. This function takes a json objects and uses the defined coded to convert them to a
60- // / string. This function will call invoke_rpc(string) overload.
61- // / @param A Client request.
62- // / @return A server response.
63- shared::rpc::JSONRPCResponse invoke_rpc (shared::rpc::ClientRequest const &request);
64-
65- // / @brief Function that calls the rpc server. The response will not be decoded, it will be a raw string.
66- void invoke_rpc (shared::rpc::ClientRequest const &request, std::string &bw);
67-
68- std::unique_ptr<BasePrinter> _printer; // !< Specific output formatter. This should be created by the derived class.
69-
7076 // / @brief The whole design is that the command will execute the @c _invoked_func once invoked. This function ptr should be
7177 // / set by the appropriated derived class base on the passed parameters. The derived class have the option to override
7278 // / the execute() function and do something else. Check @c RecordCommand as an example.
@@ -81,15 +87,14 @@ class CtrlCommand
8187
8288private:
8389 ts::Arguments *_arguments = nullptr ; // !< parsed traffic_ctl arguments.
84- shared::rpc::RPCClient _rpcClient; // !< RPC socket client implementation.
8590};
8691
8792// -----------------------------------------------------------------------------------------------------------------------------------
8893// /
8994// / @brief Record Command Implementation
9095// / Used as base class for any command that needs to access to a TS record.
9196// / If deriving from this class, make sure you implement @c execute_subcommand() and call the _invoked_func yourself.
92- class RecordCommand : public CtrlCommand
97+ class RecordCommand : public CtrlCommand , public RPCAccessor
9398{
9499public:
95100 using CtrlCommand::CtrlCommand;
@@ -114,6 +119,8 @@ class ConfigCommand : public RecordCommand
114119 static inline const std::string DIFF_STR{" diff" };
115120 static inline const std::string DEFAULTS_STR{" defaults" };
116121 static inline const std::string SET_STR{" set" };
122+ static inline const std::string COLD_STR{" cold" };
123+ static inline const std::string APPEND_STR{" append" };
117124 static inline const std::string STATUS_STR{" status" };
118125 static inline const std::string RELOAD_STR{" reload" };
119126 static inline const std::string REGISTRY_STR{" registry" };
@@ -125,6 +132,7 @@ class ConfigCommand : public RecordCommand
125132 void config_diff ();
126133 void config_status ();
127134 void config_set ();
135+ void file_config_set ();
128136 void config_reload ();
129137 void config_show_file_registry ();
130138
@@ -147,7 +155,7 @@ class MetricCommand : public RecordCommand
147155 MetricCommand (ts::Arguments *args);
148156};
149157// -----------------------------------------------------------------------------------------------------------------------------------
150- class HostCommand : public CtrlCommand
158+ class HostCommand : public CtrlCommand , public RPCAccessor
151159{
152160public:
153161 HostCommand (ts::Arguments *args);
@@ -163,7 +171,7 @@ class HostCommand : public CtrlCommand
163171 void status_up ();
164172};
165173// -----------------------------------------------------------------------------------------------------------------------------------
166- class PluginCommand : public CtrlCommand
174+ class PluginCommand : public CtrlCommand , public RPCAccessor
167175{
168176public:
169177 PluginCommand (ts::Arguments *args);
@@ -173,7 +181,7 @@ class PluginCommand : public CtrlCommand
173181 void plugin_msg ();
174182};
175183// -----------------------------------------------------------------------------------------------------------------------------------
176- class DirectRPCCommand : public CtrlCommand
184+ class DirectRPCCommand : public CtrlCommand , public RPCAccessor
177185{
178186public:
179187 DirectRPCCommand (ts::Arguments *args);
@@ -194,7 +202,7 @@ class DirectRPCCommand : public CtrlCommand
194202 bool validate_input (std::string const &in) const ;
195203};
196204// -----------------------------------------------------------------------------------------------------------------------------------
197- class ServerCommand : public CtrlCommand
205+ class ServerCommand : public CtrlCommand , public RPCAccessor
198206{
199207public:
200208 ServerCommand (ts::Arguments *args);
@@ -208,7 +216,7 @@ class ServerCommand : public CtrlCommand
208216};
209217//
210218// -----------------------------------------------------------------------------------------------------------------------------------
211- struct StorageCommand : public CtrlCommand {
219+ struct StorageCommand : public CtrlCommand , public RPCAccessor {
212220 StorageCommand (ts::Arguments *args);
213221
214222private:
@@ -219,3 +227,6 @@ struct StorageCommand : public CtrlCommand {
219227 void set_storage_offline ();
220228};
221229// -----------------------------------------------------------------------------------------------------------------------------------
230+
231+ BasePrinter::Options::OutputFormat parse_format (ts::Arguments *args);
232+ BasePrinter::Options parse_print_opts (ts::Arguments *args);
0 commit comments