Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

ITANetAudioServer.cpp 1.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <ITANetAudioServer.h>
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioProtocol.h>

// ITA includes
#include <ITADataSource.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>

// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>

// STL
#include <cmath>
#include <cassert>

Anne's avatar
Anne committed
22
23
CITANetAudioServer::CITANetAudioServer()
	: m_pServer( NULL )
24
	, m_pSocket( NULL )
25
	, m_pConnection( NULL )
26
27
28
29
30
31
	, m_iServerPort( -1 )
{
};

CITANetAudioServer::~CITANetAudioServer()
{
32
33
	delete m_pConnection;
	delete m_pServer;
34
35
36
37
38
39
40
41
42
43
44
45
}

std::string CITANetAudioServer::GetServerAddress() const
{
	return m_sServerAddress;
}

int CITANetAudioServer::GetNetworkPort() const
{
	return m_iServerPort;
}

Anne's avatar
Anne committed
46
bool CITANetAudioServer::Start(const std::string& sAddress, int iPort)
47
48
49
50
51
52
53
54
55
56
{
	if( m_pServer )
		ITA_EXCEPT1( MODAL_EXCEPTION, "This net sample server is already started" );

	m_pServer = new VistaTCPServer( sAddress, iPort, 1 );
	m_sServerAddress = sAddress;
	m_iServerPort = iPort;

	// blocking wait for connection
	m_pSocket = m_pServer->GetNextClient();
57
58
59
60
61
62
63
	if( !m_pSocket )
		return false;
	if( m_pSocket->GetIsConnected() )
		m_pConnection = new VistaConnectionIP( m_pSocket );

	if( !m_pConnection )
		return false;
64

65
	return true;
Anne's avatar
Anne committed
66
}
67

68
VistaConnectionIP* CITANetAudioServer::GetConnection() const
Anne's avatar
Anne committed
69
{
70
	return m_pConnection;
71
72
}

Anne's avatar
Anne committed
73

74
void CITANetAudioServer::Stop()
75
{
76
77
78
	delete m_pConnection;
	m_pConnection = NULL;

79
	m_pSocket = NULL;
80

81
82
83
84
85
86
	delete m_pServer;
	m_pServer = NULL;
}

bool CITANetAudioServer::IsConnected() const
{
87
88
	return m_pConnection ? true : false;
}