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