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