]> git.sesse.net Git - casparcg/blob - protocol/util/protocol_strategy.h
[ffmpeg] Use last video frame with audio instead of empty frame when audio is longer...
[casparcg] / protocol / util / protocol_strategy.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 <string>\r
25 \r
26 #include <common/memory.h>\r
27 \r
28 namespace caspar { namespace IO {\r
29 \r
30 /**\r
31  * A protocol strategy handles a single client connection. A client_connection\r
32  * instance is needed in order to send data to the client.\r
33  */\r
34 template<class CharT>\r
35 class protocol_strategy\r
36 {\r
37 public:\r
38         typedef spl::shared_ptr<protocol_strategy<CharT>> ptr;\r
39 \r
40         virtual ~protocol_strategy() { }\r
41 \r
42         /**\r
43          * Parse some data received. If used directly by the async event server,\r
44          * then the data will be what was received from the TCP/IP stack, but if\r
45          * a delimiter based protocol is used, delimiter_based_chunking_strategy\r
46          * can be used to ensure that the strategy implementation is only\r
47          * provided complete messages.\r
48          *\r
49          * @param data The data received.\r
50          */\r
51         virtual void parse(const std::basic_string<CharT>& data) = 0;\r
52 };\r
53 \r
54 /**\r
55  * A handle for a protocol_strategy to use when interacting with the client.\r
56  */\r
57 template<class CharT>\r
58 class client_connection\r
59 {\r
60 public:\r
61         typedef spl::shared_ptr<client_connection<CharT>> ptr;\r
62 \r
63         virtual ~client_connection() { }\r
64 \r
65         virtual void send(std::basic_string<CharT>&& data) = 0;\r
66         virtual void disconnect() = 0;\r
67         virtual std::wstring address() const = 0;\r
68 \r
69         virtual void add_lifecycle_bound_object(const std::wstring& key, const std::shared_ptr<void>& lifecycle_bound) = 0;\r
70         virtual std::shared_ptr<void> remove_lifecycle_bound_object(const std::wstring& key) = 0;\r
71 };\r
72 \r
73 /**\r
74  * Creates unique instances of protocol_strategy implementations.\r
75  *\r
76  * Each async event server will have one instance of this factory, but create\r
77  * unique protocol_strategy<char> instances for each connected client.\r
78  *\r
79  * Any shared state between client interactions could be held in the factory.\r
80  */\r
81 template<class CharT>\r
82 class protocol_strategy_factory\r
83 {\r
84 public:\r
85         typedef spl::shared_ptr<protocol_strategy_factory<CharT>> ptr;\r
86 \r
87         virtual ~protocol_strategy_factory() { }\r
88         virtual typename protocol_strategy<CharT>::ptr create(\r
89                 const typename client_connection<CharT>::ptr& client_connection) = 0;\r
90 };\r
91 \r
92 }}\r