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"
26 #include <core/consumer/frame_consumer.h>
27 #include <core/video_channel.h>
29 #include <boost/algorithm/string.hpp>
31 namespace caspar { namespace protocol {
36 AMCPCommand(const AMCPCommand&);
37 AMCPCommand& operator=(const AMCPCommand&);
40 virtual ~AMCPCommand() {}
41 virtual bool Execute() = 0;
43 virtual bool NeedChannel() = 0;
44 virtual int GetMinimumParameters() = 0;
48 void AddParameter(const std::wstring& param){_parameters.push_back(param);}
50 void SetClientInfo(IO::ClientInfoPtr& s){pClientInfo_ = s;}
51 IO::ClientInfoPtr GetClientInfo(){return pClientInfo_;}
53 void SetChannel(const std::shared_ptr<core::video_channel>& pChannel){pChannel_ = pChannel;}
54 std::shared_ptr<core::video_channel> GetChannel(){return pChannel_;}
56 void SetChannels(const std::vector<spl::shared_ptr<core::video_channel>>& channels){channels_ = channels;}
57 const std::vector<spl::shared_ptr<core::video_channel>>& GetChannels() { return channels_; }
59 void SetChannelIndex(unsigned int channelIndex){channelIndex_ = channelIndex;}
60 unsigned int GetChannelIndex(){return channelIndex_;}
62 void SetLayerIntex(int layerIndex){layerIndex_ = layerIndex;}
63 int GetLayerIndex(int defaultValue = 0) const{return layerIndex_ != -1 ? layerIndex_ : defaultValue;}
67 virtual std::wstring print() const = 0;
69 void SetReplyString(const std::wstring& str){replyString_ = str;}
72 std::vector<std::wstring> _parameters;
73 std::vector<std::wstring> _parameters2;
76 unsigned int channelIndex_;
78 IO::ClientInfoPtr pClientInfo_;
79 std::shared_ptr<core::video_channel> pChannel_;
80 std::vector<spl::shared_ptr<core::video_channel>> channels_;
81 std::wstring replyString_;
84 typedef std::tr1::shared_ptr<AMCPCommand> AMCPCommandPtr;
86 template<bool TNeedChannel,int TMinParameters>
87 class AMCPCommandBase : public AMCPCommand
90 virtual bool Execute()
92 _parameters2 = _parameters;
93 for(size_t n = 0; n < _parameters.size(); ++n)
94 _parameters[n] = boost::to_upper_copy(_parameters[n]);
95 return (TNeedChannel && !GetChannel()) || _parameters.size() < TMinParameters ? false : DoExecute();
98 virtual bool NeedChannel(){return TNeedChannel;}
99 virtual int GetMinimumParameters(){return TMinParameters;}
103 virtual bool DoExecute() = 0;