VANetServerImpl.h 2.94 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
/*
2
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
3
 *
4
5
6
7
8
9
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
 *       VVV  VVV     AAA        Copyright 2015-2017
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
Jonas Stienen's avatar
Jonas Stienen committed
10
 *
11
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
12
13
 */

14
15
#ifndef IW_VANET_SERVER_IMPL
#define IW_VANET_SERVER_IMPL
Jonas Stienen's avatar
Jonas Stienen committed
16
17
18
19
20
21
22
23
24
25
26
27

#include <VANetServer.h>

#include <list>
#include <vector>
#include <string>

class VistaConnectionIP;
class VistaConnectionUpdater;
class CVANetNetworkProtocol;
class VistaMutex;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
28
29
class CVANetServerImpl : public IVANetServer
{
Jonas Stienen's avatar
Jonas Stienen committed
30
31
32
33
public:
	CVANetServerImpl();
	~CVANetServerImpl();

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
34
35
	int Initialize( const std::string& sInterface, const int iServerPort, const int iFreePortMin = 10000, const int iFreePortMax = 11000, const int iMaxNumClients = -1 );
	int Initialize( const std::string& sInterface, const int iServerPort, const tPortList& liFreePorts, const int iMaxNumClients = -1 );
Jonas Stienen's avatar
Jonas Stienen committed
36
37
38
39
40
	int Finalize();
	void Reset();

	std::string GetServerAdress() const;
	int GetServerPort() const;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
41
42
	IVAInterface* GetCoreInstance() const;
	void SetCoreInstance( IVAInterface* pCore );
Jonas Stienen's avatar
Jonas Stienen committed
43
44
45

	bool IsClientConnected() const;
	int GetNumConnectedClients() const;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
46
	std::string GetClientHostname( const int iClientIndex ) const;
Jonas Stienen's avatar
Jonas Stienen committed
47

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
48
49
	bool AttachEventHandler( IVANetServer::IEventHandler* pHandler );
	bool DetachEventHandler( IVANetServer::IEventHandler* pHandler );
Jonas Stienen's avatar
Jonas Stienen committed
50

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
51
52
	bool AttachCoreEventHandler( VistaConnectionIP* pConnection );
	bool DetachCoreEventHandler( VistaConnectionIP* pConnection );
Jonas Stienen's avatar
Jonas Stienen committed
53

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
54
	void HandleClientEvent( int iEventID, VistaConnectionIP* pConnection );
Jonas Stienen's avatar
Jonas Stienen committed
55
56
57
58
59
60
61
62
63

protected:
	int AddNewClient( VistaConnectionIP* pTemporaryConnection );
	void RemoveClient( VistaConnectionIP* pConnection, int iStatusCode = 0 );
	void RemoveClient( int iClientID, int iStatusCode = 0 );
	int GetNextFreePort();

	void EmitEvent( const CEvent& oEvent );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
64

Jonas Stienen's avatar
Jonas Stienen committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
protected:
	class CConnectionObserver;
	class CConnectionAccepter;
	class CEventHandler;

	struct CClientData
	{
		VistaConnectionIP*	m_pCommandChannel;
		VistaConnectionIP*	m_pHeadChannel;
		VistaConnectionIP*	m_pEventChannel;
		std::string			m_sHost;
	};

private:
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
79
80
81
	CConnectionAccepter*	m_pConnectionAccepter;
	CConnectionObserver*	m_pConnObserver;
	CEventHandler*			m_pEventHandler;
Jonas Stienen's avatar
Jonas Stienen committed
82
83
84
85
86

	std::vector<CClientData>	m_vecClients;

	bool					m_bInitialized;
	bool					m_bRunning;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
87

Jonas Stienen's avatar
Jonas Stienen committed
88
	int						m_iMaxNumClients;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
89

Jonas Stienen's avatar
Jonas Stienen committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	IVACore*				m_pRealCore;
	CVANetNetworkProtocol*	m_pProtocol;

	std::string				m_sServerIP;
	int						m_iServerPort;

	tPortList				m_liFreePorts;

	VistaMutex*				m_pEventChannelLock;
	VistaMutex*				m_pServerChangeLock;
	VistaMutex*				m_pEventHandlerLock;

	std::list<IEventHandler*>	m_liEventHandlers;
};

105
#endif // IW_VANET_SERVER_IMPL