]> git.sesse.net Git - casparcg/blob - protocol/cii/CIIProtocolStrategy.h
set svn:eol-style native on .h and .cpp files
[casparcg] / protocol / cii / CIIProtocolStrategy.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 #pragma once
24
25 #include <core/video_channel.h>
26
27 #include "../util/ProtocolStrategy.h"
28 #include "CIICommand.h"
29
30 #include <core/producer/stage.h>
31
32 #include <common/executor.h>
33
34 #include <string>
35
36 namespace caspar { namespace protocol { namespace cii {
37
38 class CIIProtocolStrategy : public IO::IProtocolStrategy
39 {
40 public:
41         CIIProtocolStrategy(const std::vector<spl::shared_ptr<core::video_channel>>& channels);
42
43         void Parse(const TCHAR* pData, int charCount, IO::ClientInfoPtr pClientInfo);
44         std::string GetCodepage() {return "ISO-8859-1";}        //ISO 8859-1
45
46         void SetProfile(const std::wstring& profile) {currentProfile_ = profile;}
47
48         spl::shared_ptr<core::video_channel> GetChannel() const{return this->pChannel_;}
49
50         void DisplayMediaFile(const std::wstring& filename);
51         void DisplayTemplate(const std::wstring& titleName);
52         void WriteTemplateData(const std::wstring& templateName, const std::wstring& titleName, const std::wstring& xmlData);
53
54 public:
55         struct TitleHolder
56         {
57                 TitleHolder() : titleName(TEXT("")), pframe_producer(core::frame_producer::empty())     {}
58                 TitleHolder(const std::wstring& name, spl::shared_ptr<core::frame_producer> pFP) : titleName(name), pframe_producer(pFP) {}
59                 TitleHolder(const TitleHolder& th) : titleName(th.titleName), pframe_producer(th.pframe_producer) {}
60                 const TitleHolder& operator=(const TitleHolder& th) 
61                 {
62                         titleName = th.titleName;
63                         pframe_producer = th.pframe_producer;
64                 }
65                 bool operator==(const TitleHolder& rhs) 
66                 {
67                         return pframe_producer == rhs.pframe_producer;
68                 }
69
70                 std::wstring titleName;
71                 spl::shared_ptr<core::frame_producer> pframe_producer;
72                 friend CIIProtocolStrategy;
73         };
74 private:
75
76         typedef std::list<TitleHolder> TitleList;
77         TitleList titles_;
78         spl::shared_ptr<core::frame_producer> GetPreparedTemplate(const std::wstring& name);
79         void PutPreparedTemplate(const std::wstring& name, spl::shared_ptr<core::frame_producer>& pframe_producer);
80
81         static const TCHAR TokenDelimiter;
82         static const std::wstring MessageDelimiter;
83
84         void ProcessMessage(const std::wstring& message, IO::ClientInfoPtr pClientInfo);
85         int TokenizeMessage(const std::wstring& message, std::vector<std::wstring>* pTokenVector);
86         CIICommandPtr Create(const std::wstring& name);
87
88         executor executor_;
89         std::wstring currentMessage_;
90
91         std::wstring currentProfile_;
92         spl::shared_ptr<core::video_channel> pChannel_;
93 };
94
95 }}}