]> git.sesse.net Git - casparcg/blob - protocol/amcp/AMCPCommandsImpl.h
Manually merged 44adc50 from master
[casparcg] / protocol / amcp / AMCPCommandsImpl.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Nicklas P Andersson
20 */
21
22  
23 #ifndef __AMCPCOMMANDSIMPL_H__
24 #define __AMCPCOMMANDSIMPL_H__
25
26 #include "AMCPCommand.h"
27
28 #include <boost/thread/future.hpp>
29 #include <core/thumbnail_generator.h>
30
31 namespace caspar { namespace protocol {
32         
33 std::wstring ListMedia();
34 std::wstring ListTemplates();
35
36 namespace amcp {
37         
38 class ChannelGridCommand : public AMCPCommandBase<0>
39 {
40 public:
41         explicit ChannelGridCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
42         std::wstring print() const { return L"ChannelGridCommand";}
43         bool DoExecute();
44 };
45
46 class DiagnosticsCommand : public AMCPCommandBase<0>
47 {
48 public:
49         explicit DiagnosticsCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
50         std::wstring print() const { return L"DiagnosticsCommand";}
51         bool DoExecute();
52 };
53
54 class CallCommand : public AMCPChannelCommandBase<1>
55 {
56 public:
57         CallCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
58         {}
59
60 private:
61         std::wstring print() const { return L"CallCommand";}
62         bool DoExecute();
63 };
64
65 class MixerCommand : public AMCPChannelCommandBase<1>
66 {
67 public:
68         MixerCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
69         {}
70
71 private:
72         std::wstring print() const { return L"MixerCommand";}
73         bool DoExecute();
74 };
75         
76 class AddCommand : public AMCPChannelCommandBase<1>
77 {
78 public:
79         AddCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
80         {}
81
82 private:
83         std::wstring print() const { return L"AddCommand";}
84         bool DoExecute();
85 };
86
87 class RemoveCommand : public AMCPChannelCommandBase<0>
88 {
89 public:
90         RemoveCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
91         {}
92
93 private:
94         std::wstring print() const { return L"RemoveCommand";}
95         bool DoExecute();
96 };
97
98 class SwapCommand : public AMCPChannelCommandBase<1>, AMCPChannelsAwareCommand
99 {
100 public:
101         SwapCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index, const std::vector<channel_context>& channels) : AMCPChannelCommandBase(client, channel, channel_index, layer_index), AMCPChannelsAwareCommand(channels)
102         {}
103
104 private:
105         std::wstring print() const { return L"SwapCommand";}
106         bool DoExecute();
107 };
108
109 class LoadCommand : public AMCPChannelCommandBase<1>
110 {
111 public:
112         LoadCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
113         {}
114
115 private:
116         std::wstring print() const { return L"LoadCommand";}
117         bool DoExecute();
118 };
119
120
121 class PlayCommand: public AMCPChannelCommandBase<0>, public AMCPChannelsAwareCommand
122 {
123 public:
124         PlayCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index, const std::vector<channel_context>& channels) : AMCPChannelCommandBase(client, channel, channel_index, layer_index), AMCPChannelsAwareCommand(channels)
125         {}
126
127 private:
128         std::wstring print() const { return L"PlayCommand";}
129         bool DoExecute();
130 };
131
132 class LoadbgCommand : public AMCPChannelCommandBase<1>, public AMCPChannelsAwareCommand
133 {
134 public:
135         LoadbgCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index, const std::vector<channel_context>& channels) : AMCPChannelCommandBase(client, channel, channel_index, layer_index), AMCPChannelsAwareCommand(channels)
136         {}
137         LoadbgCommand(const PlayCommand& rhs) : AMCPChannelCommandBase<1>(rhs), AMCPChannelsAwareCommand(rhs) {}
138
139 private:
140         std::wstring print() const { return L"LoadbgCommand";}
141         bool DoExecute();
142 };
143
144 class PauseCommand: public AMCPChannelCommandBase<0>
145 {
146 public:
147         PauseCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
148         {}
149
150 private:
151         std::wstring print() const { return L"PauseCommand";}
152         bool DoExecute();
153 };
154
155 class StopCommand : public AMCPChannelCommandBase<0>
156 {
157 public:
158         StopCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
159         {}
160
161 private:
162         std::wstring print() const { return L"StopCommand";}
163         bool DoExecute();
164 };
165
166 class ClearCommand : public AMCPChannelCommandBase<0>
167 {
168 public:
169         ClearCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
170         {}
171
172 private:
173         std::wstring print() const { return L"ClearCommand";}
174         bool DoExecute();
175 };
176
177 class PrintCommand : public AMCPChannelCommandBase<0>
178 {
179 public:
180         PrintCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
181         {}
182
183 private:
184         std::wstring print() const { return L"PrintCommand";}
185         bool DoExecute();
186 };
187
188 class LogCommand : public AMCPCommandBase<2>
189 {
190 public:
191         explicit LogCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
192         std::wstring print() const { return L"LogCommand";}
193         bool DoExecute();
194 };
195
196 class CGCommand : public AMCPChannelCommandBase<1>
197 {
198 public:
199         CGCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
200         {}
201
202 private:
203         std::wstring print() const { return L"CGCommand";}
204         bool DoExecute();
205         bool ValidateLayer(const std::wstring& layerstring);
206
207         bool DoExecuteAdd();
208         bool DoExecutePlay();
209         bool DoExecuteStop();
210         bool DoExecuteNext();
211         bool DoExecuteRemove();
212         bool DoExecuteClear();
213         bool DoExecuteUpdate();
214         bool DoExecuteInvoke();
215         bool DoExecuteInfo();
216 };
217
218 class DataCommand : public AMCPCommandBase<1>
219 {
220 public:
221         explicit DataCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
222
223         std::wstring print() const { return L"DataCommand";}
224         bool DoExecute();
225         bool DoExecuteStore();
226         bool DoExecuteRetrieve();
227         bool DoExecuteRemove();
228         bool DoExecuteList();
229 };
230
231 class ClsCommand : public AMCPCommandBase<0>
232 {
233 public:
234         explicit ClsCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
235         std::wstring print() const { return L"ClsCommand";}
236         bool DoExecute();
237 };
238
239 class TlsCommand : public AMCPCommandBase<0>
240 {
241 public:
242         explicit TlsCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
243         std::wstring print() const { return L"TlsCommand";}
244         bool DoExecute();
245 };
246
247 class CinfCommand : public AMCPCommandBase<1>
248 {
249 public:
250         explicit CinfCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
251         std::wstring print() const { return L"CinfCommand";}
252         bool DoExecute();
253 };
254
255 class InfoCommand : public AMCPCommandBase<0>, AMCPChannelsAwareCommand
256 {
257 public:
258         InfoCommand(IO::ClientInfoPtr client, const std::vector<channel_context>& channels) : AMCPChannelsAwareCommand(channels), AMCPCommandBase(client) {}
259         std::wstring print() const { return L"InfoCommand";}
260         bool DoExecute();
261 };
262
263 class VersionCommand : public AMCPCommandBase<0>
264 {
265 public:
266         explicit VersionCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
267         std::wstring print() const { return L"VersionCommand";}
268         bool DoExecute();
269 };
270
271 class ByeCommand : public AMCPCommandBase<0>
272 {
273 public:
274         explicit ByeCommand(IO::ClientInfoPtr client) : AMCPCommandBase(client) {}
275         std::wstring print() const { return L"ByeCommand";}
276         bool DoExecute();
277 };
278
279 class SetCommand : public AMCPChannelCommandBase<2>
280 {
281 public:
282         SetCommand(IO::ClientInfoPtr client, const channel_context& channel, unsigned int channel_index, int layer_index) : AMCPChannelCommandBase(client, channel, channel_index, layer_index)
283         {}
284
285         std::wstring print() const { return L"SetCommand";}
286         bool DoExecute();
287 };
288
289 class LockCommand : public AMCPCommandBase<1>, AMCPChannelsAwareCommand
290 {
291 public:
292         LockCommand(IO::ClientInfoPtr client, const std::vector<channel_context>& channels) : AMCPChannelsAwareCommand(channels), AMCPCommandBase(client) {}
293         std::wstring print() const { return L"LockCommand";}
294         bool DoExecute();
295 };
296
297 class ThumbnailCommand : public AMCPCommandBase<1>
298 {
299 public:
300         ThumbnailCommand::ThumbnailCommand(IO::ClientInfoPtr client, std::shared_ptr<core::thumbnail_generator> thumb_gen) : AMCPCommandBase(client), thumb_gen_(thumb_gen) 
301         {}
302         std::wstring print() const { return L"ThumbnailCommand";}
303         bool DoExecute();
304
305 private:
306         bool DoExecuteRetrieve();
307         bool DoExecuteList();
308         bool DoExecuteGenerate();
309         bool DoExecuteGenerateAll();
310
311         std::shared_ptr<core::thumbnail_generator> thumb_gen_;
312 };
313
314 class KillCommand : public AMCPCommandBase<0> 
315 {
316 public:
317         KillCommand(IO::ClientInfoPtr client, boost::promise<bool>& shutdown_server_now) : AMCPCommandBase(client), shutdown_server_now_(&shutdown_server_now) {}
318         std::wstring print() const { return L"KillCommand";}
319         bool DoExecute();
320
321 private:
322         boost::promise<bool>* shutdown_server_now_;
323 };
324
325 //class KillCommand : public AMCPCommand
326 //{
327 //public:
328 //      KillCommand() {}
329 //      virtual bool DoExecute();
330 //      virtual AMCPCommandCondition CheckConditions();
331 //
332 //      virtual bool NeedChannel() {
333 //              return false;
334 //      }
335 //      virtual AMCPCommandScheduling GetDefaultScheduling() {
336 //              return AddToQueue;
337 //      }
338 //      virtual int GetMinimumParameters() {
339 //              return 0;
340 //      }
341 //};
342
343 }       //namespace amcp
344 }}      //namespace caspar
345
346 #endif  //__AMCPCOMMANDSIMPL_H__