2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\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
22 #include "../util/clientinfo.h"
\r
24 #include <core/consumer/frame_consumer.h>
\r
25 #include <core/channel.h>
\r
27 #include <boost/algorithm/string.hpp>
\r
29 namespace caspar { namespace protocol {
\r
32 enum AMCPCommandScheduling
\r
41 AMCPCommand(const AMCPCommand&);
\r
42 AMCPCommand& operator=(const AMCPCommand&);
\r
45 virtual ~AMCPCommand() {}
\r
46 virtual bool Execute() = 0;
\r
48 virtual bool NeedChannel() = 0;
\r
49 virtual AMCPCommandScheduling GetDefaultScheduling() = 0;
\r
50 virtual int GetMinimumParameters() = 0;
\r
54 void AddParameter(const std::wstring& param){_parameters.push_back(param);}
\r
56 void SetClientInfo(IO::ClientInfoPtr& s){pClientInfo_ = s;}
\r
57 IO::ClientInfoPtr GetClientInfo(){return pClientInfo_;}
\r
59 void SetChannel(const std::shared_ptr<core::channel>& pChannel){pChannel_ = pChannel;}
\r
60 std::shared_ptr<core::channel> GetChannel(){return pChannel_;}
\r
62 void SetChannels(const std::vector<safe_ptr<core::channel>>& channels){channels_ = channels;}
\r
63 const std::vector<safe_ptr<core::channel>>& GetChannels() { return channels_; }
\r
65 void SetChannelIndex(unsigned int channelIndex){channelIndex_ = channelIndex;}
\r
66 unsigned int GetChannelIndex(){return channelIndex_;}
\r
68 void SetLayerIntex(int layerIndex){layerIndex_ = layerIndex;}
\r
69 int GetLayerIndex(int defaultValue = 0) const{return layerIndex_ != -1 ? layerIndex_ : defaultValue;}
\r
71 virtual void Clear();
\r
73 AMCPCommandScheduling GetScheduling()
\r
75 return scheduling_ == Default ? GetDefaultScheduling() : scheduling_;
\r
78 virtual std::wstring print() const = 0;
\r
80 void SetScheduling(AMCPCommandScheduling s){scheduling_ = s;}
\r
83 void SetReplyString(const std::wstring& str){replyString_ = str;}
\r
84 std::vector<std::wstring> _parameters;
\r
87 unsigned int channelIndex_;
\r
89 IO::ClientInfoPtr pClientInfo_;
\r
90 std::shared_ptr<core::channel> pChannel_;
\r
91 std::vector<safe_ptr<core::channel>> channels_;
\r
92 AMCPCommandScheduling scheduling_;
\r
93 std::wstring replyString_;
\r
96 typedef std::tr1::shared_ptr<AMCPCommand> AMCPCommandPtr;
\r
98 template<bool TNeedChannel, AMCPCommandScheduling TScheduling, int TMinParameters>
\r
99 class AMCPCommandBase : public AMCPCommand
\r
102 virtual bool Execute()
\r
104 for(size_t n = 0; n < _parameters.size(); ++n)
\r
105 _parameters[n] = boost::to_upper_copy(_parameters[n]);
\r
106 return (TNeedChannel && !GetChannel()) || _parameters.size() < TMinParameters ? false : DoExecute();
\r
109 virtual bool NeedChannel(){return TNeedChannel;}
\r
110 virtual AMCPCommandScheduling GetDefaultScheduling(){return TScheduling;}
\r
111 virtual int GetMinimumParameters(){return TMinParameters;}
\r
113 ~AMCPCommandBase(){}
\r
115 virtual bool DoExecute() = 0;
\r