]> git.sesse.net Git - casparcg/blob - protocol/clk/clk_command_processor.h
Merged CLK changes from trunk, and separated delimiter message splitting and codepage...
[casparcg] / protocol / clk / clk_command_processor.h
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Helge Norberg, helge.norberg@svt.se\r
20 */\r
21 \r
22 #pragma once\r
23 \r
24 #include <vector>\r
25 #include <string>\r
26 #include <map>\r
27 \r
28 #include <common/memory.h>\r
29 \r
30 #include <boost/function.hpp>\r
31 \r
32 namespace caspar { namespace protocol { namespace CLK {\r
33 \r
34 typedef boost::function<void (const std::vector<std::wstring>&)> clk_command_handler;\r
35 \r
36 /**\r
37  * CLK command processor composed by multiple command handlers.\r
38  *\r
39  * Not thread-safe.\r
40  */\r
41 class clk_command_processor\r
42 {\r
43         std::map<std::wstring, clk_command_handler> handlers_;\r
44 public:\r
45         /**\r
46          * Register a handler for a specific command.\r
47          *\r
48          * @param command_name The command name to use this handler for.\r
49          * @param handler      The handler that will handle all commands with the\r
50          *                     specified name.\r
51          *\r
52          * @return this command processor for method chaining.\r
53          */\r
54         clk_command_processor& add_handler(\r
55                 const std::wstring& command_name, const clk_command_handler& handler);\r
56 \r
57         /**\r
58          * Handle an incoming command.\r
59          *\r
60          * @param command_name The command name.\r
61          * @param parameters   The raw parameters supplied with the command.\r
62          *\r
63          * @return true if the command was handled, false if no handler was\r
64          *         registered to handle the command.\r
65          */\r
66         bool handle(\r
67                 const std::wstring& command_name, \r
68                 const std::vector<std::wstring>& parameters);\r
69 };\r
70 \r
71 }}}\r