YODAU 1.0
YEAR OF THE DEPEND ADULT UNDERGARMENT
Loading...
Searching...
No Matches
cli_client.hpp
Go to the documentation of this file.
1#ifndef YODAU_BACKEND_CLI_CLIENT_HPP
2#define YODAU_BACKEND_CLI_CLIENT_HPP
3
4#include <cxxopts.hpp>
5
7
8#include <string>
9#include <vector>
10
11namespace yodau::backend {
12
13/**
14 * @brief Simple interactive CLI (REPL) for controlling a @ref stream_manager.
15 *
16 * The cli_client provides a text-based command loop that allows the user to:
17 * - list/add/start/stop streams,
18 * - list/add lines,
19 * - connect lines to streams,
20 * using cxxopts-style option parsing.
21 *
22 * The client does not own the manager; it holds a reference and issues
23 * synchronous calls to it.
24 *
25 * @note When compiled with YODAU_OPENCV, the constructor installs OpenCV-based
26 * daemon start and motion frame processor hooks (see implementation).
27 */
29public:
30 /**
31 * @brief Construct a CLI client operating on an existing manager.
32 *
33 * The manager reference must remain valid for the lifetime of this client.
34 *
35 * @param mgr Stream manager to control.
36 */
37 explicit cli_client(backend::stream_manager& mgr);
38
39 /**
40 * @brief Run the interactive command loop.
41 *
42 * This function reads commands from stdin and prints results/errors to
43 * stdout/stderr until the user enters one of the quit commands:
44 * "quit", "q", or "exit".
45 *
46 * @return 0 on normal termination, non-zero if stdin closes / EOF occurs.
47 */
48 int run() const;
49
50private:
51 /**
52 * @brief Split a line into whitespace-separated tokens.
53 *
54 * Used to parse the REPL input into:
55 * - command name (first token),
56 * - positional/flag arguments (remaining tokens).
57 *
58 * @param line Raw input line.
59 * @return Vector of tokens; empty if line contains no tokens.
60 */
61 static std::vector<std::string> tokenize(const std::string& line);
62
63 /**
64 * @brief Dispatch a command to its handler.
65 *
66 * Looks up @p cmd in the internal command map and invokes the corresponding
67 * cmd_* method. Unknown commands print an error to stderr.
68 *
69 * @param cmd Command name (e.g., "add-stream").
70 * @param args Tokenized arguments excluding the command name.
71 */
73 const std::string& cmd, const std::vector<std::string>& args
74 ) const;
75
76 /**
77 * @brief Parse command arguments using cxxopts.
78 *
79 * Builds a temporary argv-like array from @p cmd and @p args and calls
80 * @ref cxxopts::Options::parse.
81 *
82 * @param cmd Command name (used as argv[0]).
83 * @param args Command arguments.
84 * @param options Configured cxxopts options for this command.
85 * @return cxxopts parse result.
86 */
87 static cxxopts::ParseResult parse_with_cxxopts(
88 const std::string& cmd, const std::vector<std::string>& args,
89 cxxopts::Options& options
90 );
91
92 /**
93 * @brief Handler for `list-streams`.
94 *
95 * Supports optional `--connections` to show connected line names.
96 *
97 * @param args Tokenized arguments.
98 */
99 void cmd_list_streams(const std::vector<std::string>& args) const;
100
101 /**
102 * @brief Handler for `add-stream`.
103 *
104 * Positional arguments:
105 * - path (required)
106 * - name (optional)
107 * - type (optional: local/file/rtsp/http)
108 * - loop (optional: true/false)
109 *
110 * @param args Tokenized arguments.
111 */
112 void cmd_add_stream(const std::vector<std::string>& args) const;
113
114 /**
115 * @brief Handler for `start-stream`.
116 *
117 * Positional argument:
118 * - name (required)
119 *
120 * @param args Tokenized arguments.
121 */
122 void cmd_start_stream(const std::vector<std::string>& args) const;
123
124 /**
125 * @brief Handler for `stop-stream`.
126 *
127 * Positional argument:
128 * - name (required)
129 *
130 * @param args Tokenized arguments.
131 */
132 void cmd_stop_stream(const std::vector<std::string>& args) const;
133
134 /**
135 * @brief Handler for `list-lines`.
136 *
137 * Lists all stored lines in the manager.
138 *
139 * @param args Tokenized arguments.
140 */
141 void cmd_list_lines(const std::vector<std::string>& args) const;
142
143 /**
144 * @brief Handler for `add-line`.
145 *
146 * Positional arguments:
147 * - path (required; coordinates string like "0,0;100,100")
148 * - name (optional)
149 * - close (optional: true/false)
150 *
151 * Options:
152 * - --dir / -d to set tripwire direction.
153 *
154 * @param args Tokenized arguments.
155 */
156 void cmd_add_line(const std::vector<std::string>& args) const;
157
158 /**
159 * @brief Handler for `set-line`.
160 *
161 * Positional arguments:
162 * - stream (required; stream name)
163 * - line (required; line name)
164 *
165 * Connects an existing line to an existing stream.
166 *
167 * @param args Tokenized arguments.
168 */
169 void cmd_set_line(const std::vector<std::string>& args) const;
170
171 /**
172 * @brief Stream manager controlled by this CLI.
173 *
174 * Non-owning reference.
175 */
177};
178
179} // namespace yodau::backend
180
181#endif // YODAU_BACKEND_CLI_CLIENT_HPP
Simple interactive CLI (REPL) for controlling a stream_manager.
void cmd_start_stream(const std::vector< std::string > &args) const
Handler for start-stream.
void dispatch_command(const std::string &cmd, const std::vector< std::string > &args) const
Dispatch a command to its handler.
void cmd_set_line(const std::vector< std::string > &args) const
Handler for set-line.
int run() const
Run the interactive command loop.
void cmd_add_line(const std::vector< std::string > &args) const
Handler for add-line.
static cxxopts::ParseResult parse_with_cxxopts(const std::string &cmd, const std::vector< std::string > &args, cxxopts::Options &options)
Parse command arguments using cxxopts.
backend::stream_manager & stream_mgr
Stream manager controlled by this CLI.
void cmd_stop_stream(const std::vector< std::string > &args) const
Handler for stop-stream.
void cmd_list_streams(const std::vector< std::string > &args) const
Handler for list-streams.
void cmd_add_stream(const std::vector< std::string > &args) const
Handler for add-stream.
void cmd_list_lines(const std::vector< std::string > &args) const
Handler for list-lines.
cli_client(backend::stream_manager &mgr)
Construct a CLI client operating on an existing manager.
Definition cli_client.cpp:5
static std::vector< std::string > tokenize(const std::string &line)
Split a line into whitespace-separated tokens.
Central coordinator for streams, geometry, frame processing and events.
static yodau::backend::tripwire_dir parse_tripwire_dir(const std::string &s)
tripwire_dir
Allowed crossing direction for a tripwire.
Definition geometry.hpp:62