]> git.sesse.net Git - casparcg/blob - protocol/amcp/AMCPCommand.h
- Increased consumer timeout to 10 seconds.
[casparcg] / protocol / amcp / AMCPCommand.h
1 /*\r
2 * Copyright 2013 Sveriges Television AB http://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/parameters/parameters.h>\r
28 #include <core/video_channel.h>\r
29 #include <core/mixer/gpu/ogl_device.h>\r
30 #include <core/thumbnail_generator.h>\r
31 \r
32 #include <boost/algorithm/string.hpp>\r
33 \r
34 namespace caspar { namespace protocol { namespace amcp {\r
35 \r
36         enum AMCPCommandScheduling\r
37         {\r
38                 Default = 0,\r
39                 AddToQueue\r
40         };\r
41 \r
42         class AMCPCommand\r
43         {\r
44                 AMCPCommand(const AMCPCommand&);\r
45                 AMCPCommand& operator=(const AMCPCommand&);\r
46         public:\r
47                 AMCPCommand();\r
48                 virtual ~AMCPCommand() {}\r
49                 virtual bool Execute() = 0;\r
50 \r
51                 virtual bool NeedChannel() = 0;\r
52                 virtual AMCPCommandScheduling GetDefaultScheduling() = 0;\r
53                 virtual int GetMinimumParameters() = 0;\r
54 \r
55                 void SendReply();\r
56 \r
57                 void AddParameter(const std::wstring& param){_parameters.push_back(param);}\r
58 \r
59                 void SetParameters(const core::parameters& p) {\r
60                         _parameters = p;\r
61                 }\r
62 \r
63                 void SetClientInfo(IO::ClientInfoPtr& s){pClientInfo_ = s;}\r
64                 IO::ClientInfoPtr GetClientInfo(){return pClientInfo_;}\r
65 \r
66                 void SetChannel(const std::shared_ptr<core::video_channel>& pChannel){pChannel_ = pChannel;}\r
67                 std::shared_ptr<core::video_channel> GetChannel(){return pChannel_;}\r
68 \r
69                 void SetChannels(const std::vector<safe_ptr<core::video_channel>>& channels){channels_ = channels;}\r
70                 const std::vector<safe_ptr<core::video_channel>>& GetChannels() { return channels_; }\r
71 \r
72                 void SetThumbGenerator(const std::shared_ptr<core::thumbnail_generator>& thumb_gen) {thumb_gen_ = thumb_gen;}\r
73                 std::shared_ptr<core::thumbnail_generator> GetThumbGenerator() { return thumb_gen_; }\r
74 \r
75                 void SetMediaInfoRepo(const safe_ptr<core::media_info_repository>& media_info_repo) {media_info_repo_ = media_info_repo;}\r
76                 std::shared_ptr<core::media_info_repository> GetMediaInfoRepo() { return media_info_repo_; }\r
77 \r
78                 void SetShutdownServerNow(boost::promise<bool>& shutdown_server_now) {shutdown_server_now_ = &shutdown_server_now;}\r
79                 boost::promise<bool>& GetShutdownServerNow() { return *shutdown_server_now_; }\r
80 \r
81                 void SetChannelIndex(unsigned int channelIndex){channelIndex_ = channelIndex;}\r
82                 unsigned int GetChannelIndex(){return channelIndex_;}\r
83 \r
84                 void SetLayerIntex(int layerIndex){layerIndex_ = layerIndex;}\r
85                 int GetLayerIndex(int defaultValue = 0) const{return layerIndex_ != -1 ? layerIndex_ : defaultValue;}\r
86 \r
87                 void SetOglDevice(const safe_ptr<core::ogl_device>& device){ogl_ = device;}\r
88                 std::shared_ptr<core::ogl_device> GetOglDevice() const { return ogl_; }\r
89 \r
90                 virtual void Clear();\r
91 \r
92                 AMCPCommandScheduling GetScheduling()\r
93                 {\r
94                         return scheduling_ == Default ? GetDefaultScheduling() : scheduling_;\r
95                 }\r
96 \r
97                 virtual std::wstring print() const = 0;\r
98 \r
99                 void SetScheduling(AMCPCommandScheduling s){scheduling_ = s;}\r
100                 void SetReplyString(const std::wstring& str){replyString_ = str;}\r
101 \r
102         protected:\r
103                 core::parameters _parameters;\r
104 \r
105         private:\r
106                 unsigned int channelIndex_;\r
107                 int layerIndex_;\r
108                 IO::ClientInfoPtr pClientInfo_;\r
109                 std::shared_ptr<core::ogl_device> ogl_;\r
110                 std::shared_ptr<core::video_channel> pChannel_;\r
111                 std::vector<safe_ptr<core::video_channel>> channels_;\r
112                 std::shared_ptr<core::thumbnail_generator> thumb_gen_;\r
113                 std::shared_ptr<core::media_info_repository> media_info_repo_;\r
114                 boost::promise<bool>* shutdown_server_now_;\r
115                 AMCPCommandScheduling scheduling_;\r
116                 std::wstring replyString_;\r
117         };\r
118 \r
119         typedef std::tr1::shared_ptr<AMCPCommand> AMCPCommandPtr;\r
120 \r
121         template<bool TNeedChannel, AMCPCommandScheduling TScheduling, int TMinParameters>\r
122         class AMCPCommandBase : public AMCPCommand\r
123         {\r
124         public:\r
125                 virtual bool Execute()\r
126                 {\r
127                         _parameters.to_upper();\r
128                         return (TNeedChannel && !GetChannel()) || _parameters.size() < TMinParameters ? false : DoExecute();\r
129                 }\r
130 \r
131                 virtual bool NeedChannel(){return TNeedChannel;}                \r
132                 virtual AMCPCommandScheduling GetDefaultScheduling(){return TScheduling;}\r
133                 virtual int GetMinimumParameters(){return TMinParameters;}\r
134         protected:\r
135                 ~AMCPCommandBase(){}\r
136 \r
137         private:\r
138                 virtual bool DoExecute() = 0;\r
139         };      \r
140 \r
141 }}}\r