blob: 8fab28d0b36f98f7d2f592f122560da061d70ac8 [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef _HOST_H_
31#define _HOST_H_
32
Vadim Iosevich20d50d82017-09-19 11:38:15 +030033#include <memory>
34#include <future>
35#include "EventsDefinitions.h"
Vadim Iosevichd50ea462017-03-30 16:19:08 +030036#include "CommandsTcpServer.h"
37#include "EventsTcpServer.h"
38#include "CommandsHandler.h"
39#include "UdpServer.h"
40#include "HostInfo.h"
41#include "DeviceManager.h"
42
43/*
44 * Host is a class that holds the TCP and UDP server.
45 * It also holds the Device Manager.
46 */
47class Host
48{
49public:
50
51 /*
52 * Host is s singletone due to HandleOsSignals - signal is a global function that can't get a pointer to the host as an argument
53 */
54 static Host& GetHost()
55 {
56 static Host host;
57 return host;
58 }
59
Vadim Iosevichd50ea462017-03-30 16:19:08 +030060 /*
61 * StratHost starts each one of the servers it holds
62 */
Vadim Ioseviche76832c2017-11-05 09:09:14 +020063 void StartHost(unsigned int commandsTcpPort, unsigned int eventsTcpPort, unsigned int udpPortIn, unsigned int udpPortOut, unsigned int httpPort);
Vadim Iosevichd50ea462017-03-30 16:19:08 +030064
65 /*
66 * StopHost stops each one of the servers it holds
67 */
68 void StopHost();
69
70 HostInfo& GetHostInfo() { return m_hostInfo; }
Vadim Ioseviche76832c2017-11-05 09:09:14 +020071 bool GetHostUpdate(HostData& data);
Vadim Iosevichd50ea462017-03-30 16:19:08 +030072
73 DeviceManager& GetDeviceManager() { return m_deviceManager; }
74
Vadim Iosevich20d50d82017-09-19 11:38:15 +030075 // Push the given event through Events TCP Server
76 void PushEvent(const HostManagerEventBase& event) const;
77
Vadim Ioseviche76832c2017-11-05 09:09:14 +020078 // Decide whether to show host_manager menu
79 void SetMenuDisplay(bool menuDisplayOn);
80
Vadim Iosevich20d50d82017-09-19 11:38:15 +030081 // delete copy Cnstr and assignment operator
82 // keep public for better error message
83 // no move members will be declared implicitly
84 Host(const Host&) = delete;
85 Host& operator=(const Host&) = delete;
Vadim Iosevichd50ea462017-03-30 16:19:08 +030086
87private:
Vadim Iosevich20d50d82017-09-19 11:38:15 +030088 std::shared_ptr<CommandsTcpServer> m_pCommandsTcpServer;
89 std::shared_ptr<EventsTcpServer> m_pEventsTcpServer;
90 std::shared_ptr<UdpServer> m_pUdpServer;
Vadim Iosevichd50ea462017-03-30 16:19:08 +030091 HostInfo m_hostInfo;
Vadim Iosevich20d50d82017-09-19 11:38:15 +030092 std::promise<void> m_eventsTCPServerReadyPromise; // sync. of device manager with events TCP server creation
93 DeviceManager m_deviceManager; // note: it should be defined after the promise passsed to its Cnstr
Vadim Ioseviche76832c2017-11-05 09:09:14 +020094 bool m_MenuDisplayOn;
Vadim Iosevich20d50d82017-09-19 11:38:15 +030095
96 // define Cnstr to be private, part of Singleton pattern
97 Host();
Vadim Ioseviche76832c2017-11-05 09:09:14 +020098
99 // Menu display function
100 void DisplayMenu();
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300101};
102
103
104#endif // ! _HOST_H_