All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CommandServerModule.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 
7 #include "Networking.h"
8 #include "Commands.h"
9 #include "ITcpListener.h"
10 #include "CommandBuffer.h"
11 #include "CommandRegistry.h"
12 #include "CommandProcessor.h"
13 #include "CommandParser.h"
14 #include "CommandServer.h"
15 
16 namespace Eegeo
17 {
18  namespace Debug
19  {
20  namespace DebugServer
21  {
23  {
24  public:
25  static const int DefaultPort = 12345;
26 
28  Commands::CommandRegistry* pRegistry,
29  Commands::CommandProcessor* pProcessor,
30  Commands::CommandParser* pParser,
31  Commands::CommandTerminal* pTerminal,
32  DebugServer::CommandServer* pCommandServer,
33  Networking::ITcpListener* pTcpListener,
34  int port=DefaultPort
35  )
36  : m_pBuffer(pBuffer)
37  , m_pRegistry(pRegistry)
38  , m_pParser(pParser)
39  , m_pTerminal(pTerminal)
40  , m_pProcessor(pProcessor)
41  , m_pTcpListener(pTcpListener)
42  , m_pCommandServer(pCommandServer)
43  {
44  Eegeo_ASSERT(pBuffer != NULL);
45  Eegeo_ASSERT(pRegistry != NULL);
46  Eegeo_ASSERT(pParser != NULL);
47  Eegeo_ASSERT(pTerminal != NULL);
48  Eegeo_ASSERT(pProcessor != NULL);
49  Eegeo_ASSERT(pTcpListener != NULL);
50  Eegeo_ASSERT(pCommandServer != NULL);
51 
52  m_pTcpListener->StartListening(port);
53  }
54 
56  {
57  Eegeo_DELETE m_pCommandServer;
58  Eegeo_DELETE m_pTcpListener;
59  Eegeo_DELETE m_pProcessor;
60  Eegeo_DELETE m_pTerminal;
61  Eegeo_DELETE m_pParser;
62  Eegeo_DELETE m_pRegistry;
63  Eegeo_DELETE m_pBuffer;
64  }
65 
66  void Update()
67  {
68  m_pTcpListener->Update();
69  while (!m_pBuffer->IsEmpty())
70  {
71  m_pProcessor->Update();
72  }
73  }
74 
75 
76  Commands::CommandBuffer& GetCommandBuffer() const { return *m_pBuffer; }
77  Commands::CommandRegistry& GetCommandRegistry() const { return *m_pRegistry; }
78  Commands::CommandTerminal& GetCommandTerminal() const { return *m_pTerminal; }
79  Commands::CommandProcessor& GetCommandProcessor() const { return *m_pProcessor; }
80  DebugServer::CommandServer& GetCommandServer() const { return *m_pCommandServer; }
81  Networking::ITcpListener& GetTcpListener() const { return *m_pTcpListener; }
82 
83  static CommandServerModule* BuildDefault(Networking::ITcpListener* pTcpListener)
84  {
85  Commands::CommandBuffer* pBuffer = Eegeo_NEW(Commands::CommandBuffer)();
86  Commands::CommandRegistry* pRegistry = Eegeo_NEW(Commands::CommandRegistry)();
87  Commands::CommandParser* pParser = Eegeo_NEW(Commands::CommandParser)();
88  Commands::CommandTerminal* pTerminal = Eegeo_NEW(Commands::CommandTerminal)();
89  Commands::CommandProcessor* pProcessor = Eegeo_NEW(Commands::CommandProcessor)(*pBuffer,
90  *pParser,
91  *pRegistry,
92  *pTerminal);
93 
94  CommandServer* pCommandServer = Eegeo_NEW(CommandServer)(*pTcpListener,
95  *pBuffer,
96  *pProcessor,
97  *pTerminal);
98 
99  return Eegeo_NEW(CommandServerModule)(pBuffer,
100  pRegistry,
101  pProcessor,
102  pParser,
103  pTerminal,
104  pCommandServer,
105  pTcpListener);
106  }
107 
108  private:
109  Commands::CommandBuffer* m_pBuffer;
110  Commands::CommandRegistry* m_pRegistry;
111  Commands::CommandParser* m_pParser;
112  Commands::CommandTerminal* m_pTerminal;
113  Commands::CommandProcessor* m_pProcessor;
114  Networking::ITcpListener* m_pTcpListener;
115  DebugServer::CommandServer* m_pCommandServer;
116  };
117  }
118  }
119 }