]> git.sesse.net Git - casparcg/blob - protocol/amcp/AMCPCommand.h
d9028b2680d45c13820019adb05edacb8fe89c00
[casparcg] / protocol / amcp / AMCPCommand.h
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\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
10 *\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
15 *\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
18 *\r
19 * Author: Nicklas P Andersson\r
20 */\r
21 \r
22 #pragma once\r
23 \r
24 #include "../util/clientinfo.h"\r
25 \r
26 #include <core/consumer/frame_consumer.h>\r
27 #include <core/video_channel.h>\r
28 \r
29 #include <boost/algorithm/string.hpp>\r
30 \r
31 namespace caspar { namespace protocol {\r
32 namespace amcp {\r
33         \r
34         class AMCPCommand\r
35         {\r
36                 AMCPCommand(const AMCPCommand&);\r
37                 AMCPCommand& operator=(const AMCPCommand&);\r
38         public:\r
39                 AMCPCommand();\r
40                 virtual ~AMCPCommand() {}\r
41                 virtual bool Execute() = 0;\r
42 \r
43                 virtual bool NeedChannel() = 0;\r
44                 virtual int GetMinimumParameters() = 0;\r
45 \r
46                 void SendReply();\r
47 \r
48                 void AddParameter(const std::wstring& param){_parameters.push_back(param);}\r
49 \r
50                 void SetClientInfo(IO::ClientInfoPtr& s){pClientInfo_ = s;}\r
51                 IO::ClientInfoPtr GetClientInfo(){return pClientInfo_;}\r
52 \r
53                 void SetChannel(const std::shared_ptr<core::video_channel>& pChannel){pChannel_ = pChannel;}\r
54                 std::shared_ptr<core::video_channel> GetChannel(){return pChannel_;}\r
55 \r
56                 void SetChannels(const std::vector<spl::shared_ptr<core::video_channel>>& channels){channels_ = channels;}\r
57                 const std::vector<spl::shared_ptr<core::video_channel>>& GetChannels() { return channels_; }\r
58 \r
59                 void SetChannelIndex(unsigned int channelIndex){channelIndex_ = channelIndex;}\r
60                 unsigned int GetChannelIndex(){return channelIndex_;}\r
61 \r
62                 void SetLayerIntex(int layerIndex){layerIndex_ = layerIndex;}\r
63                 int GetLayerIndex(int defaultValue = 0) const{return layerIndex_ != -1 ? layerIndex_ : defaultValue;}\r
64 \r
65                 virtual void Clear();\r
66 \r
67                 virtual std::wstring print() const = 0;\r
68 \r
69                 void SetReplyString(const std::wstring& str){replyString_ = str;}\r
70 \r
71         protected:\r
72                 std::vector<std::wstring> _parameters;\r
73                 std::vector<std::wstring> _parameters2;\r
74 \r
75         private:\r
76                 unsigned int channelIndex_;\r
77                 int layerIndex_;\r
78                 IO::ClientInfoPtr pClientInfo_;\r
79                 std::shared_ptr<core::video_channel> pChannel_;\r
80                 std::vector<spl::shared_ptr<core::video_channel>> channels_;\r
81                 std::wstring replyString_;\r
82         };\r
83 \r
84         typedef std::tr1::shared_ptr<AMCPCommand> AMCPCommandPtr;\r
85 \r
86         template<bool TNeedChannel,int TMinParameters>\r
87         class AMCPCommandBase : public AMCPCommand\r
88         {\r
89         public:\r
90                 virtual bool Execute()\r
91                 {\r
92                         _parameters2 = _parameters;\r
93                         for(size_t n = 0; n < _parameters.size(); ++n)\r
94                                 _parameters[n] = boost::to_upper_copy(_parameters[n]);\r
95                         return (TNeedChannel && !GetChannel()) || _parameters.size() < TMinParameters ? false : DoExecute();\r
96                 }\r
97 \r
98                 virtual bool NeedChannel(){return TNeedChannel;}                \r
99                 virtual int GetMinimumParameters(){return TMinParameters;}\r
100         protected:\r
101                 ~AMCPCommandBase(){}\r
102         private:\r
103                 virtual bool DoExecute() = 0;\r
104         };      \r
105 \r
106 }}}\r