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>
28 #include <boost/algorithm/string.hpp>
30 namespace caspar { namespace protocol {
35 AMCPCommand& operator=(const AMCPCommand&);
37 AMCPCommand(const AMCPCommand& rhs) : client_(rhs.client_), parameters_(rhs.parameters_)
41 typedef std::shared_ptr<AMCPCommand> ptr_type;
43 explicit AMCPCommand(IO::ClientInfoPtr client) : client_(client) {}
44 virtual ~AMCPCommand() {}
46 virtual bool Execute() = 0;
47 virtual int minimum_parameters() = 0;
51 std::vector<std::wstring>& parameters() { return parameters_; }
53 IO::ClientInfoPtr client() { return client_; }
55 virtual std::wstring print() const = 0;
57 void SetReplyString(const std::wstring& str){replyString_ = str;}
60 std::vector<std::wstring> parameters_;
61 IO::ClientInfoPtr client_;
62 std::wstring replyString_;
65 template<int TMinParameters>
66 class AMCPCommandBase : public AMCPCommand
69 explicit AMCPCommandBase(IO::ClientInfoPtr client) : AMCPCommand(client) {}
70 AMCPCommandBase(const AMCPCommandBase& rhs) : AMCPCommand(rhs) {}
72 AMCPCommandBase(const AMCPCommandBase<T>& rhs) : AMCPCommand(rhs) {}
76 virtual bool Execute()
78 return (parameters().size() < TMinParameters) ? false : DoExecute();
80 virtual int minimum_parameters(){return TMinParameters;}
82 virtual bool DoExecute() = 0;
85 class AMCPChannelCommand
88 AMCPChannelCommand(const channel_context& ctx, unsigned int channel_index, int layer_index) : ctx_(ctx), channel_index_(channel_index), layer_index_(layer_index)
90 AMCPChannelCommand(const AMCPChannelCommand& rhs) : ctx_(rhs.ctx_), channel_index_(rhs.channel_index_), layer_index_(rhs.layer_index_)
93 spl::shared_ptr<core::video_channel>& channel() { return ctx_.channel; }
94 spl::shared_ptr<IO::lock_container>& lock_container() { return ctx_.lock; }
96 unsigned int channel_index(){return channel_index_;}
97 int layer_index(int default = 0) const{return layer_index_ != -1 ? layer_index_ : default; }
100 unsigned int channel_index_;
102 channel_context ctx_;
105 class AMCPChannelsAwareCommand
108 AMCPChannelsAwareCommand(const std::vector<channel_context>& c) : channels_(c) {}
109 AMCPChannelsAwareCommand(const AMCPChannelsAwareCommand& rhs) : channels_(rhs.channels_) {}
111 const std::vector<channel_context>& channels() { return channels_; }
114 const std::vector<channel_context>& channels_;
117 template<int TMinParameters>
118 class AMCPChannelCommandBase : public AMCPChannelCommand, public AMCPCommandBase<TMinParameters>
121 AMCPChannelCommandBase(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommand(channel, channel_index, layer_index), AMCPCommandBase(client)
124 AMCPChannelCommandBase(const AMCPChannelCommandBase& rhs) : AMCPChannelCommand(rhs), AMCPCommandBase(rhs)
127 AMCPChannelCommandBase(const AMCPChannelCommandBase<T>& rhs) : AMCPChannelCommand(rhs), AMCPCommandBase(rhs)