]> git.sesse.net Git - casparcg/blob - protocol/clk/CLKCommand.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / protocol / clk / CLKCommand.cpp
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\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 */\r
20  \r
21 #include "..\stdafx.h"\r
22 #include <algorithm>\r
23 #include <locale>\r
24 #include "CLKCommand.h"\r
25 \r
26 namespace caspar { namespace protocol { namespace CLK {\r
27 \r
28 CLKCommand::CLKCommand() : clockID_(0), command_(CLKInvalidCommand) {}\r
29 \r
30 CLKCommand::~CLKCommand() {}\r
31 \r
32 const std::wstring& CLKCommand::GetData() \r
33 {\r
34         std::wstringstream dataStream;\r
35 \r
36         dataStream << TEXT("<templateData>");   \r
37         dataStream << TEXT("<componentData id=\"command\">");\r
38         dataStream << TEXT("<command id=\"") << commandString_ << TEXT("\" time=\"") << time_ << TEXT("\" clockID=\"") << clockID_ << TEXT("\">");\r
39 \r
40         std::vector<std::wstring>::const_iterator it = parameters_.begin();\r
41         std::vector<std::wstring>::const_iterator end = parameters_.end();\r
42         for(; it != end; ++it) {\r
43                 dataStream << TEXT("<parameter>") << (*it) << TEXT("</parameter>"); \r
44         }\r
45 \r
46         dataStream << TEXT("</command>"); \r
47         dataStream << TEXT("</componentData>"); \r
48         dataStream << TEXT("</templateData>");\r
49 \r
50         dataCache_ = dataStream.str();\r
51         return dataCache_;\r
52 }\r
53 \r
54 bool CLKCommand::SetCommand() \r
55 {\r
56         bool bResult = true;\r
57         std::transform(commandString_.begin(), commandString_.end(), commandString_.begin(), toupper);\r
58 \r
59         if(commandString_ == TEXT("DUR"))\r
60                 command_ = CLKDuration;\r
61         else if(commandString_ == TEXT("NEWDUR"))\r
62                 command_ = CLKNewDuration;\r
63         else if(commandString_ == TEXT("NEXTEVENT"))\r
64                 command_ = CLKNextEvent;\r
65         else if(commandString_ == TEXT("STOP"))\r
66                 command_ = CLKStop;\r
67         else if(commandString_ == TEXT("UNTIL"))\r
68                 command_ = CLKUntil;\r
69         else if(commandString_ == TEXT("ADD"))\r
70                 command_ = CLKAdd;\r
71         else if(commandString_ == TEXT("SUB"))\r
72                 command_ = CLKSub;\r
73         else if(commandString_ == TEXT("RESET"))\r
74                 command_ = CLKReset;\r
75         else \r
76         {\r
77                 command_ = CLKInvalidCommand;\r
78                 bResult = false;\r
79         }\r
80 \r
81         return bResult;\r
82 }\r
83 \r
84 void CLKCommand::Clear() \r
85 {\r
86         dataCache_.clear();\r
87         commandString_.clear();\r
88         time_.clear();\r
89         command_ = CLKDuration;\r
90         clockID_ = 0;\r
91         parameters_.clear();\r
92 }\r
93 \r
94 }}}