2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\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
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
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
19 * Author: Helge Norberg, helge.norberg@svt.se
\r
26 #include <common/memory.h>
\r
28 namespace caspar { namespace IO {
\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
34 template<class CharT>
\r
35 class protocol_strategy
\r
38 typedef spl::shared_ptr<protocol_strategy<CharT>> ptr;
\r
40 virtual ~protocol_strategy() { }
\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
49 * @param data The data received.
\r
51 virtual void parse(const std::basic_string<CharT>& data) = 0;
\r
55 * A handle for a protocol_strategy to use when interacting with the client.
\r
57 template<class CharT>
\r
58 class client_connection
\r
61 typedef spl::shared_ptr<client_connection<CharT>> ptr;
\r
63 virtual ~client_connection() { }
\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
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
74 * Creates unique instances of protocol_strategy implementations.
\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
79 * Any shared state between client interactions could be held in the factory.
\r
81 template<class CharT>
\r
82 class protocol_strategy_factory
\r
85 typedef spl::shared_ptr<protocol_strategy_factory<CharT>> ptr;
\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