]> git.sesse.net Git - casparcg/blob - server/amcp/AMCPProtocolStrategy.h
e13c3447db1b5db7d00a79cf737bf49b7f95a388
[casparcg] / server / amcp / AMCPProtocolStrategy.h
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 #ifndef _AMCPMESSAGEHANDLER_H__\r
22 #define _AMCPMESSAGEHANDLER_H__\r
23 #pragma once\r
24 \r
25 #include <string>\r
26 #include <vector>\r
27 \r
28 #include "..\io\protocolstrategy.h"\r
29 #include "AMCPCommand.h"\r
30 #include "AMCPCommandQueue.h"\r
31 \r
32 namespace caspar {\r
33 namespace amcp {\r
34 \r
35 \r
36 class AMCPProtocolStrategy : public caspar::IO::IProtocolStrategy\r
37 {\r
38         enum MessageParserState {\r
39                 New = 0,\r
40                 GetSwitch,\r
41                 GetCommand,\r
42                 GetParameters,\r
43                 GetChannel,\r
44                 Done\r
45         };\r
46 \r
47         AMCPProtocolStrategy(const AMCPProtocolStrategy&);\r
48         AMCPProtocolStrategy& operator=(const AMCPProtocolStrategy&);\r
49 \r
50 public:\r
51         AMCPProtocolStrategy();\r
52         virtual ~AMCPProtocolStrategy();\r
53 \r
54         virtual void Parse(const TCHAR* pData, int charCount, caspar::IO::ClientInfoPtr pClientInfo);\r
55         virtual UINT GetCodepage() {\r
56                 return CP_UTF8;\r
57         }\r
58 \r
59         static AMCPCommandPtr InterpretCommandString(const tstring& str, MessageParserState* pOutState=0);\r
60 \r
61 private:\r
62         friend class AMCPCommand;\r
63 \r
64         void ProcessMessage(const tstring& message, caspar::IO::ClientInfoPtr& pClientInfo);\r
65         static std::size_t TokenizeMessage(const tstring& message, std::vector<tstring>* pTokenVector);\r
66         static AMCPCommandPtr CommandFactory(const tstring& str);\r
67 \r
68         bool QueueCommand(AMCPCommandPtr);\r
69 \r
70         std::vector<AMCPCommandQueuePtr> commandQueues_;\r
71         static const tstring MessageDelimiter;\r
72 };\r
73 \r
74 }       //namespace amcp\r
75 }       //namespace caspar\r
76 \r
77 #endif  //_AMCPMESSAGEHANDLER_H__