]> git.sesse.net Git - casparcg/blob - protocol/amcp/AMCPCommandQueue.cpp
set svn:eol-style native on .h and .cpp files
[casparcg] / protocol / amcp / AMCPCommandQueue.cpp
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 #include "..\stdafx.h"
23
24 #include "AMCPCommandQueue.h"
25
26 #include <boost/timer.hpp>
27
28 namespace caspar { namespace protocol { namespace amcp {
29         
30 AMCPCommandQueue::AMCPCommandQueue() 
31         : executor_(L"AMCPCommandQueue")
32 {
33 }
34
35 AMCPCommandQueue::~AMCPCommandQueue() 
36 {
37 }
38
39 void AMCPCommandQueue::AddCommand(AMCPCommandPtr pCurrentCommand)
40 {
41         if(!pCurrentCommand)
42                 return;
43         
44         if(executor_.size() > 128)
45         {
46                 try
47                 {
48                         CASPAR_LOG(error) << "AMCP Command Queue Overflow.";
49                         CASPAR_LOG(error) << "Failed to execute command:" << pCurrentCommand->print();
50                         pCurrentCommand->SetReplyString(L"500 FAILED\r\n");
51                         pCurrentCommand->SendReply();
52                 }
53                 catch(...)
54                 {
55                         CASPAR_LOG_CURRENT_EXCEPTION();
56                 }
57         }
58         
59         executor_.begin_invoke([=]
60         {
61                 try
62                 {
63                         try
64                         {
65                                 boost::timer timer;
66                                 if(pCurrentCommand->Execute()) 
67                                         CASPAR_LOG(debug) << "Executed command: " << pCurrentCommand->print() << " " << timer.elapsed();
68                                 else 
69                                         CASPAR_LOG(warning) << "Failed to execute command: " << pCurrentCommand->print() << " " << timer.elapsed();
70                         }
71                         catch(...)
72                         {
73                                 CASPAR_LOG_CURRENT_EXCEPTION();
74                                 CASPAR_LOG(error) << "Failed to execute command:" << pCurrentCommand->print();
75                                 pCurrentCommand->SetReplyString(L"500 FAILED\r\n");
76                         }
77                                 
78                         pCurrentCommand->SendReply();
79                         
80                         CASPAR_LOG(trace) << "Ready for a new command";
81                 }
82                 catch(...)
83                 {
84                         CASPAR_LOG_CURRENT_EXCEPTION();
85                 }
86         });
87 }
88
89 }}}