2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Nicklas P Andersson
24 #include "../util/ClientInfo.h"
25 #include "amcp_shared.h"
26 #include <core/consumer/frame_consumer.h>
27 #include <core/producer/frame_producer.h>
28 #include <accelerator/ogl/util/device.h>
30 #include <boost/algorithm/string.hpp>
32 namespace caspar { namespace protocol {
35 struct command_context
37 IO::ClientInfoPtr client;
38 channel_context channel;
41 std::vector<channel_context> channels;
42 spl::shared_ptr<core::help_repository> help_repo;
43 spl::shared_ptr<core::media_info_repository> media_info_repo;
44 spl::shared_ptr<core::cg_producer_registry> cg_registry;
45 spl::shared_ptr<core::system_info_provider_repository> system_info_repo;
46 std::shared_ptr<core::thumbnail_generator> thumb_gen;
47 spl::shared_ptr<const core::frame_producer_registry> producer_registry;
48 spl::shared_ptr<const core::frame_consumer_registry> consumer_registry;
49 std::shared_ptr<accelerator::ogl::device> ogl_device;
50 std::promise<bool>& shutdown_server_now;
51 std::vector<std::wstring> parameters;
53 int layer_index(int default_ = 0) const { return layer_id == -1 ? default_: layer_id; }
56 IO::ClientInfoPtr client,
57 channel_context channel,
60 std::vector<channel_context> channels,
61 spl::shared_ptr<core::help_repository> help_repo,
62 spl::shared_ptr<core::media_info_repository> media_info_repo,
63 spl::shared_ptr<core::cg_producer_registry> cg_registry,
64 spl::shared_ptr<core::system_info_provider_repository> system_info_repo,
65 std::shared_ptr<core::thumbnail_generator> thumb_gen,
66 spl::shared_ptr<const core::frame_producer_registry> producer_registry,
67 spl::shared_ptr<const core::frame_consumer_registry> consumer_registry,
68 std::shared_ptr<accelerator::ogl::device> ogl_device,
69 std::promise<bool>& shutdown_server_now)
70 : client(std::move(client))
72 , channel_index(channel_index)
74 , channels(std::move(channels))
75 , help_repo(std::move(help_repo))
76 , media_info_repo(std::move(media_info_repo))
77 , cg_registry(std::move(cg_registry))
78 , system_info_repo(std::move(system_info_repo))
79 , thumb_gen(std::move(thumb_gen))
80 , producer_registry(std::move(producer_registry))
81 , consumer_registry(std::move(consumer_registry))
82 , ogl_device(std::move(ogl_device))
83 , shutdown_server_now(shutdown_server_now)
88 typedef std::function<std::wstring(command_context& args)> amcp_command_func;
94 amcp_command_func command_;
97 std::wstring replyString_;
99 AMCPCommand(const command_context& ctx, const amcp_command_func& command, int min_num_params, const std::wstring& name)
102 , min_num_params_(min_num_params)
107 typedef std::shared_ptr<AMCPCommand> ptr_type;
111 SetReplyString(command_(ctx_));
115 int minimum_parameters() const
117 return min_num_params_;
122 if (replyString_.empty())
125 ctx_.client->send(std::move(replyString_));
128 std::vector<std::wstring>& parameters() { return ctx_.parameters; }
130 IO::ClientInfoPtr client() { return ctx_.client; }
132 std::wstring print() const
137 void SetReplyString(const std::wstring& str)