xbmc
EventServer.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "EventClient.h"
12 #include "Socket.h"
13 #include "threads/CriticalSection.h"
14 #include "threads/Thread.h"
15 
16 #include <atomic>
17 #include <map>
18 #include <mutex>
19 #include <queue>
20 #include <vector>
21 
22 namespace EVENTSERVER
23 {
24 
25  /**********************************************************************/
26  /* UDP Event Server Class */
27  /**********************************************************************/
28  class CEventServer : private CThread
29  {
30  public:
31  static void RemoveInstance();
32  static CEventServer* GetInstance();
33 
34  CEventServer();
35  ~CEventServer() override = default;
36 
37  // IRunnable entry point for thread
38  void Process() override;
39 
40  bool Running()
41  {
42  return m_bRunning;
43  }
44 
45  void RefreshSettings()
46  {
47  std::unique_lock<CCriticalSection> lock(m_critSection);
48  m_bRefreshSettings = true;
49  }
50 
51  // start / stop server
52  void StartServer();
53  void StopServer(bool bWait);
54 
55  // get events
56  unsigned int GetButtonCode(std::string& strMapName, bool& isAxis, float& amount, bool &isJoystick);
57  bool ExecuteNextAction();
58  bool GetMousePos(float &x, float &y);
59  int GetNumberOfClients();
60 
61  protected:
62  void Cleanup();
63  void Run();
64  void ProcessPacket(SOCKETS::CAddress& addr, int packetSize);
65  void ProcessEvents();
66  void RefreshClients();
67 
68  std::map<unsigned long, std::unique_ptr<EVENTCLIENT::CEventClient>> m_clients;
69  static std::unique_ptr<CEventServer> m_pInstance;
70  std::unique_ptr<SOCKETS::CUDPSocket> m_pSocket;
71  int m_iPort;
72  int m_iListenTimeout;
73  int m_iMaxClients;
74  std::vector<uint8_t> m_pPacketBuffer;
75  std::atomic<bool> m_bRunning = false;
76  CCriticalSection m_critSection;
77  bool m_bRefreshSettings;
78  };
79 
80 }
81 
Definition: EventServer.h:22
Definition: Thread.h:44
Definition: EventServer.h:28
Definition: Socket.h:43