]> git.sesse.net Git - casparcg/blob - protocol/amcp/AMCPCommand.h
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/trunk@1951...
[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         enum AMCPCommandScheduling\r
35         {\r
36                 Default = 0,\r
37                 AddToQueue,\r
38                 ImmediatelyAndClear\r
39         };\r
40 \r
41         class AMCPCommand\r
42         {\r
43                 AMCPCommand(const AMCPCommand&);\r
44                 AMCPCommand& operator=(const AMCPCommand&);\r
45         public:\r
46                 AMCPCommand();\r
47                 virtual ~AMCPCommand() {}\r
48                 virtual bool Execute() = 0;\r
49 \r
50                 virtual bool NeedChannel() = 0;\r
51                 virtual AMCPCommandScheduling GetDefaultScheduling() = 0;\r
52                 virtual int GetMinimumParameters() = 0;\r
53 \r
54                 void SendReply();\r
55 \r
56                 void AddParameter(const std::wstring& param){_parameters.push_back(param);}\r
57 \r
58                 void SetClientInfo(IO::ClientInfoPtr& s){pClientInfo_ = s;}\r
59                 IO::ClientInfoPtr GetClientInfo(){return pClientInfo_;}\r
60 \r
61                 void SetChannel(const std::shared_ptr<core::video_channel>& pChannel){pChannel_ = pChannel;}\r
62                 std::shared_ptr<core::video_channel> GetChannel(){return pChannel_;}\r
63 \r
64                 void SetChannels(const std::vector<safe_ptr<core::video_channel>>& channels){channels_ = channels;}\r
65                 const std::vector<safe_ptr<core::video_channel>>& GetChannels() { return channels_; }\r
66 \r
67                 void SetChannelIndex(unsigned int channelIndex){channelIndex_ = channelIndex;}\r
68                 unsigned int GetChannelIndex(){return channelIndex_;}\r
69 \r
70                 void SetLayerIntex(int layerIndex){layerIndex_ = layerIndex;}\r
71                 int GetLayerIndex(int defaultValue = 0) const{return layerIndex_ != -1 ? layerIndex_ : defaultValue;}\r
72 \r
73                 virtual void Clear();\r
74 \r
75                 AMCPCommandScheduling GetScheduling()\r
76                 {\r
77                         return scheduling_ == Default ? GetDefaultScheduling() : scheduling_;\r
78                 }\r
79 \r
80                 virtual std::wstring print() const = 0;\r
81 \r
82                 void SetScheduling(AMCPCommandScheduling s){scheduling_ = s;}\r
83                 void SetReplyString(const std::wstring& str){replyString_ = str;}\r
84 \r
85         protected:\r
86                 std::vector<std::wstring> _parameters;\r
87                 std::vector<std::wstring> _parameters2;\r
88 \r
89         private:\r
90                 unsigned int channelIndex_;\r
91                 int layerIndex_;\r
92                 IO::ClientInfoPtr pClientInfo_;\r
93                 std::shared_ptr<core::video_channel> pChannel_;\r
94                 std::vector<safe_ptr<core::video_channel>> channels_;\r
95                 AMCPCommandScheduling scheduling_;\r
96                 std::wstring replyString_;\r
97         };\r
98 \r
99         typedef std::tr1::shared_ptr<AMCPCommand> AMCPCommandPtr;\r
100 \r
101         template<bool TNeedChannel, AMCPCommandScheduling TScheduling, int TMinParameters>\r
102         class AMCPCommandBase : public AMCPCommand\r
103         {\r
104         public:\r
105                 virtual bool Execute()\r
106                 {\r
107                         _parameters2 = _parameters;\r
108                         for(size_t n = 0; n < _parameters.size(); ++n)\r
109                                 _parameters[n] = boost::to_upper_copy(_parameters[n]);\r
110                         return (TNeedChannel && !GetChannel()) || _parameters.size() < TMinParameters ? false : DoExecute();\r
111                 }\r
112 \r
113                 virtual bool NeedChannel(){return TNeedChannel;}                \r
114                 virtual AMCPCommandScheduling GetDefaultScheduling(){return TScheduling;}\r
115                 virtual int GetMinimumParameters(){return TMinParameters;}\r
116         protected:\r
117                 ~AMCPCommandBase(){}\r
118         private:\r
119                 virtual bool DoExecute() = 0;\r
120         };      \r
121 \r
122 }}}\r