VANetNetworkProtocol.cpp 115 KB
Newer Older
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
1
#include "VANetNetworkProtocol.h"
Jonas Stienen's avatar
Jonas Stienen committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

#include "VANetServerImpl.h"
#include "VANetClientImpl.h"
#include "VANetMessage.h"
#include "VANetVistaCompatibility.h"

#include <VACoreEvent.h>
#include <VACoreVersion.h>
#include <VAException.h>
#include <VAStruct.h>

#include <VistaBase/VistaExceptionBase.h>
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>

#include <assert.h>
#include <sstream>


//////////////////////////////////////////////////
//////////       Main Implementation     /////////
//////////////////////////////////////////////////

CVANetNetworkProtocol::CVANetNetworkProtocol()
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	: m_pRealCore( NULL )
	, m_pServer( NULL )
	, m_pClient( NULL )
	, m_pLastAnswerConnection( NULL )
	, m_pCommandChannel( NULL )
	, m_pHeadChannel( NULL )
	, m_oIncomingEvent()
	, m_vecEventBuffer( 128 )
	, m_iReceiveTimeout( 0 )
	, m_iExceptionHandlingMode( IVANetClient::EXC_CLIENT_THROW )
	, m_bBufferingActive( false )
	, m_bBufferSynchronisedModification( false )
	, m_pMessage( NULL )
	, m_pBufferedMessage( NULL )
	, m_nCurrentMessageMode( MESSAGE_WITH_ANSWER )
	, m_pEventMessage( NULL )
Jonas Stienen's avatar
Jonas Stienen committed
43
44
45
46
47
48
49
50
51
52
53
54
{
}
CVANetNetworkProtocol::~CVANetNetworkProtocol()
{
	if( m_pLastAnswerConnection )
		m_pLastAnswerConnection->WaitForSendFinish();

	delete m_pMessage;
	delete m_pBufferedMessage;
}

bool CVANetNetworkProtocol::InitializeAsClient( CVANetClientImpl* pClient,
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
55
56
57
58
	VistaConnectionIP* pCommandChannel,
	VistaConnectionIP* pHeadChannel,
	int iExceptionhandlingmode,
	bool bBufferSynchronisedModification )
Jonas Stienen's avatar
Jonas Stienen committed
59
60
61
62
63
64
{
	m_iExceptionHandlingMode = iExceptionhandlingmode;
	m_bBufferSynchronisedModification = bBufferSynchronisedModification;
	m_pClient = pClient;
	m_pCommandChannel = pCommandChannel;
	m_pHeadChannel = pHeadChannel;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
65

Jonas Stienen's avatar
Jonas Stienen committed
66
67
68
	m_pMessage = new CVANetMessage( m_pCommandChannel->GetByteorderSwapFlag() );
	m_pBufferedMessage = new CVANetMessage( m_pCommandChannel->GetByteorderSwapFlag() );
	m_pEventMessage = new CVANetMessage( m_pCommandChannel->GetByteorderSwapFlag() );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
69

Jonas Stienen's avatar
Jonas Stienen committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	SetExceptionHandlingMode( m_iExceptionHandlingMode );
	return true;
}

bool CVANetNetworkProtocol::InitializeAsServer( CVANetServerImpl* pServer )
{
	m_pServer = pServer;

	m_pMessage = new CVANetMessage( VistaSerializingToolset::DOES_NOT_SWAP_MULTIBYTE_VALUES );
	m_pEventMessage = new CVANetMessage( VistaSerializingToolset::DOES_NOT_SWAP_MULTIBYTE_VALUES );
	return true;
}

void CVANetNetworkProtocol::SetExceptionHandlingMode( int nMode )
{
	m_iExceptionHandlingMode = nMode;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
86
}
87

Jonas Stienen's avatar
Jonas Stienen committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
int CVANetNetworkProtocol::GetExceptionHandlingMode() const
{
	return m_iExceptionHandlingMode;
}

void CVANetNetworkProtocol::SetRealVACore( IVACore* pCore )
{
	m_pRealCore = pCore;
}

#define SERVER_FUNCTION_MAPPING(ID,FUNCTION) case (ID): { FUNCTION; break; }
//#define SERVER_FUNCTION_MAPPING(ID,FUNCTION) case (ID): { std::cout << "Processing " << #ID << std::endl; FUNCTION; break; }

void CVANetNetworkProtocol::ServerCallFunctionByMessageType( int nMessageType,
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
102
	VistaConnectionIP* pConnection )
Jonas Stienen's avatar
Jonas Stienen committed
103
104
105
106
{
	switch( nMessageType )
	{
		SERVER_FUNCTION_MAPPING( VA_NP_GET_VERSION_INFO, ServerGetVersionInfo() );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
107

Jonas Stienen's avatar
Jonas Stienen committed
108
109
110
111
112
113
114
115
116
117
118
		// Base functions		
		SERVER_FUNCTION_MAPPING( VA_NP_GET_STATE, ServerGetState() );
		SERVER_FUNCTION_MAPPING( VA_NP_INITIALIZE, ServerInitialize() );
		SERVER_FUNCTION_MAPPING( VA_NP_FINALIZE, ServerFinalize() );
		SERVER_FUNCTION_MAPPING( VA_NP_RESET, ServerReset() );

		// Module interface
		SERVER_FUNCTION_MAPPING( VA_NP_ENUMERATE_MODULES, ServerEnumerateModules() );
		SERVER_FUNCTION_MAPPING( VA_NP_CALL_MODULE, ServerCallModule() );

		// Event handling
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
119
120
		SERVER_FUNCTION_MAPPING( VA_NP_ATTACH_COREEVENT_HANDLER, ServerAttachCoreEventHandler( pConnection ) );
		SERVER_FUNCTION_MAPPING( VA_NP_DETACH_COREEVENT_HANDLER, ServerDetachCoreEventHandler( pConnection ) );
Jonas Stienen's avatar
Jonas Stienen committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

		// Directivities
		SERVER_FUNCTION_MAPPING( VA_NP_LOAD_DIRECTIVITY, ServerLoadDirectivity() );
		SERVER_FUNCTION_MAPPING( VA_NP_FREE_DIRECTIVITY, ServerFreeDirectivity() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_DIRECTIVITY_INFO, ServerGetDirectivityInfo() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_DIRECTIVITY_INFOS, ServerGetDirectivityInfos() );

		// Head-related impulse responses (HRIRs)
		SERVER_FUNCTION_MAPPING( VA_NP_LOAD_HRIR_DATASET, ServerLoadHRIRDataset() );
		SERVER_FUNCTION_MAPPING( VA_NP_FREE_HRIR_DATASET, ServerFreeHRIRDataset() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_HRIR_INFO, ServerGetHRIRInfo() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_HRIR_INFOS, ServerGetHRIRInfos() );

		// Sounds
		SERVER_FUNCTION_MAPPING( VA_NP_LOAD_SOUND, ServerLoadSound() );
		SERVER_FUNCTION_MAPPING( VA_NP_FREE_SOUND, ServerFreeSound() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUND_INFO, ServerGetSoundInfo() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUND_INFOS, ServerGetSoundInfos() );
		SERVER_FUNCTION_MAPPING( VA_NP_PLAY_SOUND, ServerPlaySound() );

		// Signal sources
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_AUDIOFILE_SIGNAL_SOURCE, ServerCreateAudiofileSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_SEQUENCER_SIGNALSOURCE, ServerCreateSequencerSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_NETWORK_STREAM_SIGNALSOURCE, ServerCreateNetworkStreamSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_ENGINE_SIGNALSOURCE, ServerCreateEngineSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_MACHINE_SIGNALSOURCE, ServerCreateMachineSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_DELETE_SIGNALSOURCE, ServerDeleteSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SIGNALSOURCE_INFO, ServerGetSignalSourceInfo() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SIGNALSOURCE_INFOS, ServerGetSignalSourceInfos() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_AUDIOFILE_SIGNALSOURCE_PLAYSTATE, ServerGetAudiofileSignalSourcePlaybackState() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_AUDIOFILE_SIGNALSOURCE_PLAYACTION, ServerSetAudiofileSignalSourcePlaybackAction() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_AUDIOFILE_SIGNALSOURCE_PLAYPOS, ServerSetAudiofileSignalSourcePlaybackPosition() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_AUDIOFILE_SIGNALSOURCE_LOOPING, ServerSetAudiofileSignalSourceIsLooping() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_AUDIOFILE_SIGNALSOURCE_LOOPING, ServerGetAudiofileSignalSourceIsLooping() );
		SERVER_FUNCTION_MAPPING( VA_NP_SEQUENCER_ADD_SOUND_PLAYBACK, ServerAddSoundPlayback() );
		SERVER_FUNCTION_MAPPING( VA_NP_SEQUENCER_REMOVE_SOUND_PLAYBACK, ServerRemoveSoundPlayback() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SIGNALSOURCE_PARAMETERS, ServerGetSignalSourceParameters() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SIGNALSOURCE_PARAMETERS, ServerSetSignalSourceParameters() );

		// Synchronization functions
		SERVER_FUNCTION_MAPPING( VA_NP_LOCK_SCENE, ServerLockScene() );
		SERVER_FUNCTION_MAPPING( VA_NP_UNLOCK_SCENE, ServerUnlockScene() );
		SERVER_FUNCTION_MAPPING( VA_NP_IS_SCENE_LOCKED, ServerIsSceneLocked() );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
164

Jonas Stienen's avatar
Jonas Stienen committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
		// Sound sources
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUND_SOURCE_IDS, ServerGetSoundSourceIDs() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_SOUNDSOURCE, ServerCreateSoundSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_SOUNDSOURCE_EXPLICIT_RENDERER, ServerCreateSoundSourceExplicitRenderer() );
		SERVER_FUNCTION_MAPPING( VA_NP_DELETE_SOUNDSOURCE, ServerDeleteSoundSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_ENABLED, ServerSetSoundSourceEnabled() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_ENABLED, ServerGetSoundSourceEnabled() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_NAME, ServerSetSoundSourceName() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_NAME, ServerGetSoundSourceName() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_SIGNALSOURCE, ServerSetSoundSourceSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_SIGNALSOURCE, ServerGetSoundSourceSignalSource() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_AURAMODE, ServerSetSoundSourceAuralizationMode() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_AURAMODE, ServerGetSoundSourceAuralizationMode() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_PARAMETERS, ServerSetSoundSourceParameters() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_PARAMETERS, ServerGetSoundSourceParameters() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_DIRECTIVITY, ServerSetSoundSourceDirectivity() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_DIRECTIVITY, ServerGetSoundSourceDirectivity() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_VOLUME, ServerSetSoundSourceVolume() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_VOLUME, ServerGetSoundSourceVolume() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_MUTED, ServerSetSoundSourceMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_IS_SOUNDSOURCE_MUTED, ServerIsSoundSourceMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_POSITION, ServerSetSoundSourcePosition() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_POSITION, ServerGetSoundSourcePosition() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_ORIENTATION_YPR, ServerSetSoundSourceOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_ORIENTATION_YPR, ServerGetSoundSourceOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_ORIENTATION_VU, ServerSetSoundSourceOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_ORIENTATION_VU, ServerGetSoundSourceOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_POSITION_ORIENT_YPR, ServerSetSoundSourcePositionOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_POSITION_ORIENT_YPR, ServerGetSoundSourcePositionOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_POSITION_ORIENT_VU, ServerSetSoundSourcePositionOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_POSITION_ORIENT_VU, ServerGetSoundSourcePositionOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_POSITION_ORIENT_VELOCITY_VU, ServerSetSoundSourcePositionOrientationVelocityVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_POSITION_ORIENT_VELOCITY_VU, ServerGetSoundSourcePositionOrientationVelocityVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_SOUNDSOURCE_POSITION_ORIENT_VELOCITY_YPR, ServerSetSoundSourcePositionOrientationVelocityYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SOUNDSOURCE_POSITION_ORIENT_VELOCITY_YPR, ServerGetSoundSourcePositionOrientationVelocityYPR() );

		// Listeners
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_IDS, ServerGetListenerIDs() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_LISTENER, ServerCreateListener() );
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_LISTENER_EXPLICIT_RENDERER, ServerCreateListenerExplicitRenderer() );
		SERVER_FUNCTION_MAPPING( VA_NP_DELETE_LISTENER, ServerDeleteListener() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_ENABLED, ServerSetListenerEnabled() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_ENABLED, ServerGetListenerEnabled() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_NAME, ServerGetListenerName() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_NAME, ServerSetListenerName() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_AURALIZATION_MODE, ServerGetListenerAuralizationMode() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_AURALIZATION_MODE, ServerSetListenerAuralizationMode() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_PARAMETERS, ServerSetListenerParameters() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_PARAMETERS, ServerGetListenerParameters() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_HRIR_DATASET, ServerGetListenerHRIRDataset() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_HRIR_DATASET, ServerSetListenerHRIRDataset() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_POSITION, ServerGetListenerPosition() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_POSITION, ServerSetListenerPosition() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_ORIENTATION_YPR, ServerGetListenerOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_ORIENTATION_YPR, ServerSetListenerOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_ORIENTATION_VU, ServerGetListenerOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_ORIENTATION_VU, ServerSetListenerOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_POSITION_ORIENT_YPR, ServerGetListenerPositionOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_POSITION_ORIENT_YPR, ServerSetListenerPositionOrientationYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_POSITION_ORIENT_VU, ServerGetListenerPositionOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_POSITION_ORIENT_VU, ServerSetListenerPositionOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_POSITION_ORIENT_VELOCITY_VU, ServerGetListenerPositionOrientationVelocityVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_POSITION_ORIENT_VELOCITY_VU, ServerSetListenerPositionOrientationVelocityVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_POSITION_ORIENT_VELOCITY_YPR, ServerGetListenerPositionOrientationVelocityYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_POSITION_ORIENT_VELOCITY_YPR, ServerSetListenerPositionOrientationVelocityYPR() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_LISTENER_REAL_WORLD_POSITION_ORIENT_VU, ServerGetListenerRealWorldHeadPositionOrientationVU() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_LISTENER_REAL_WORLD_POSITION_ORIENT_VU, ServerSetListenerRealWorldHeadPositionOrientationVU() );

		// Scene
		SERVER_FUNCTION_MAPPING( VA_NP_LOAD_SCENE, ServerLoadScene() );
		SERVER_FUNCTION_MAPPING( VA_NP_IS_SCENE_LOADED, ServerIsSceneLoaded() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_SCENE_INFO, ServerGetSceneInfo() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_PORTAL_IDS, ServerGetPortalIDs() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_PORTAL_NAME, ServerGetPortalName() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_PORTAL_NAME, ServerSetPortalName() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_PORTAL_STATE, ServerGetPortalState() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_PORTAL_STATE, ServerSetPortalState() );

		// Global functions
		SERVER_FUNCTION_MAPPING( VA_NP_GET_INPUT_GAIN, ServerGetInputGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_INPUT_GAIN, ServerSetInputGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_IS_INPUT_MUTED, ServerIsInputMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_INPUT_MUTED, ServerSetInputMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_OUTPUT_GAIN, ServerGetOutputGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_OUTPUT_GAIN, ServerSetOutputGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_IS_OUTPUT_MUTED, ServerIsOutputMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_OUTPUT_MUTED, ServerSetOutputMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_GLOBAL_AURALIZATION_MODE, ServerGetGlobalAuralizationMode() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_GLOBAL_AURALIZATION_MODE, ServerSetGlobalAuralizationMode() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_ACTIVE_LISTENER, ServerGetActiveListener() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_ACTIVE_LISTENER, ServerSetActiveListener() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_ACTIVE_LISTENER_EXPLICIT_RENDERER, ServerGetActiveListenerExplicitRenderer() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_ACTIVE_LISTENER_EXPLICIT_RENDERER, ServerSetActiveListenerExplicitRenderer() );
		SERVER_FUNCTION_MAPPING( VA_NP_GET_CORE_CLOCK, ServerGetCoreClock() );
		SERVER_FUNCTION_MAPPING( VA_NP_SET_CORE_CLOCK, ServerSetCoreClock() );
		SERVER_FUNCTION_MAPPING( VA_NP_SUBSTITUTE_MACROS, ServerSubstituteMacros() );

		SERVER_FUNCTION_MAPPING( VA_NP_RENDERER_GET_INFOS, ServerGetRenderingModuleInfos() );
		SERVER_FUNCTION_MAPPING( VA_NP_RENDERER_GET_GAIN, ServerGetRenderingModuleGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_RENDERER_SET_GAIN, ServerSetRenderingModuleGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_RENDERER_IS_MUTED, ServerIsRenderingModuleMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_RENDERER_SET_MUTED, ServerSetRenderingModuleMuted() );

		SERVER_FUNCTION_MAPPING( VA_NP_REPRODUCTION_GET_INFOS, ServerGetReproductionModuleInfos() );
		SERVER_FUNCTION_MAPPING( VA_NP_REPRODUCTION_GET_GAIN, ServerGetReproductionModuleGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_REPRODUCTION_SET_GAIN, ServerSetReproductionModuleGain() );
		SERVER_FUNCTION_MAPPING( VA_NP_REPRODUCTION_IS_MUTED, ServerIsReproductionModuleMuted() );
		SERVER_FUNCTION_MAPPING( VA_NP_REPRODUCTION_SET_MUTED, ServerSetReproductionModuleMuted() );

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
274
275
276
277
278
279
280
281
	case VA_NP_INVALID:
	default:
	{
		/** @todo: disconnect */
		std::ostringstream oStream;
		oStream << "VANetServer: Unkown Message Type " << nMessageType;
		VA_EXCEPT2( PROTOCOL_ERROR, oStream.str() );
	}
Jonas Stienen's avatar
Jonas Stienen committed
282
283
	}
}
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
284

Jonas Stienen's avatar
Jonas Stienen committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
bool CVANetNetworkProtocol::ProcessMessageFromClient( VistaConnectionIP* pConnection )
{
	assert( m_pRealCore != NULL );

	// just to avoid false connection notifies - these can happen
	if( pConnection->PendingDataSize() == 0 )
		return true;

	// Falls wir zuletzt eine Antwort gesendet haben, mssen wir nun warten,
	// bis das senden abgeschlossen ist, bevor wir die message leeren
	if( m_pLastAnswerConnection != NULL )
		m_pLastAnswerConnection->WaitForSendFinish();

	try
	{
		m_pMessage->ResetMessage();
		m_pMessage->SetConnection( pConnection );
		m_pMessage->ReadMessage();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
303
	}
Jonas Stienen's avatar
Jonas Stienen committed
304
305
	catch( VistaExceptionBase& oException )
	{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
306
		std::cerr << "VANetNetworkProtocol: caught connection exception - "
Jonas Stienen's avatar
Jonas Stienen committed
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
			<< oException.GetExceptionText() << std::endl;
		return false;
	}

	int nMessageType = m_pMessage->GetMessageType();

	// we assume an answer - if an exception occurs, or no answer is
	// sent, the value will be rewritten
	m_pMessage->SetAnswerType( VA_NP_SPECIAL_ANSWER );

	// Es kann eine gebufferete Nachricht kommen.
	// In dem fall mssen wir mehrfach Befehle parsen
	// dies tun wir, bis der MessageBuffer leer ist
	try
	{
		if( nMessageType == VA_NP_SPECIAL_BUFFERED_MESSAGE )
		{
			while( m_pMessage->GetIncomingMessageSize() > 0 )
			{
				nMessageType = m_pMessage->ReadInt();
				ServerCallFunctionByMessageType( nMessageType, pConnection );
			}
		}
		else if( nMessageType == VA_NP_SPECIAL_CLIENT_EVENT )
		{
			int nEventID = m_pMessage->ReadInt();
			m_pServer->HandleClientEvent( nEventID, pConnection );
			return true;
		}
		else
		{
			ServerCallFunctionByMessageType( nMessageType, pConnection );
		}
	}
	catch( CVAException& oException )
	{
		if( oException.GetErrorCode() == CVAException::PROTOCOL_ERROR )
			throw;

		switch( m_pMessage->GetExceptionMode() )
		{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
348
349
350
351
352
353
354
355
356
357
358
359
360
		case IVANetClient::EXC_CLIENT_THROW:
		{
			m_pMessage->SetAnswerType( VA_NP_SPECIAL_EXCEPTION );
			m_pMessage->WriteException( oException );
			m_pMessage->WriteAnswer();
			return true;
		}
		case IVANetClient::EXC_SERVER_PRINT:
		{
			std::cerr << "[IVANetServer]: Caught and swallowed exception :\n"
				<< oException.ToString() << std::endl;
			return true;
		}
Jonas Stienen's avatar
Jonas Stienen committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
		}
	}

	if( m_pMessage->GetOutgoingMessageHasData() )
	{
		m_pMessage->WriteAnswer();
	}
	else if( m_pMessage->GetExceptionMode() == IVANetClient::EXC_CLIENT_THROW )
	{
		m_pMessage->SetAnswerType( VA_NP_SPECIAL_NO_EXCEPTION );
		m_pMessage->WriteAnswer();
	}

	return true;
}

bool CVANetNetworkProtocol::GetBufferSynchronisedModification() const
{
	return m_bBufferSynchronisedModification;
}

void CVANetNetworkProtocol::SetBufferSynchronisedModifications( const bool bSet )
{
	m_bBufferSynchronisedModification = bSet;
}

void CVANetNetworkProtocol::ClientPrepareMessageBuffering()
{
	if( m_bBufferSynchronisedModification == false )
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
390
		return;
Jonas Stienen's avatar
Jonas Stienen committed
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

	// @todo: how to handle this? ignore, still buffer command, abort?
	if( m_bBufferingActive == true )
		return; // we are already buffering

	m_pBufferedMessage->ResetMessage();
	m_pBufferedMessage->SetConnection( m_pCommandChannel );
	m_pBufferedMessage->SetExceptionMode( IVANetClient::EXC_CLIENT_THROW );
	m_pBufferedMessage->SetMessageType( VA_NP_SPECIAL_BUFFERED_MESSAGE );

	m_bBufferingActive = true;
}

int CVANetNetworkProtocol::ClientEndMessageBuffering()
{
	assert( m_bBufferingActive );

	m_bBufferingActive = false;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
409

Jonas Stienen's avatar
Jonas Stienen committed
410
411
412
413
414
415
416
417
418
419
420
	int iRet = -1;
	try
	{
		m_pBufferedMessage->SetExceptionMode( m_iExceptionHandlingMode );
		m_pBufferedMessage->WriteMessage();

		m_pBufferedMessage->ReadAnswer();
		iRet = m_pBufferedMessage->ReadInt();
	}
	catch( const VistaExceptionBase& oException )
	{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
421
		std::cerr << "VANetNetworkProtocol: caught exception during ClientEndMessageBuffering - "
Jonas Stienen's avatar
Jonas Stienen committed
422
423
424
425
426
427
428
			<< oException.GetExceptionText() << std::endl;
	}

	return iRet;
}

int CVANetNetworkProtocol::ClientProcessEventMessageFromServer( VistaConnectionIP* pConnection,
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
429
	std::list<IVACoreEventHandler*> liCoreEventHandler )
Jonas Stienen's avatar
Jonas Stienen committed
430
431
432
433
{
	VANetCompat::sint32 iSize = 0;
	VANetCompat::sint32 iType = VA_EVENT_FAIL;
	m_pEventMessage->SetConnection( pConnection );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
434

Jonas Stienen's avatar
Jonas Stienen committed
435
436
437
438
439
440
	try
	{
		m_pEventMessage->ReadMessage();

		switch( m_pEventMessage->GetMessageType() )
		{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
441
442
443
444
445
		case VA_EVENT_CORE_EVENT:
		{
			CVACoreEvent oEvent = m_pEventMessage->ReadCoreEvent();
			for( std::list<IVACoreEventHandler*>::iterator itHandler = liCoreEventHandler.begin();
				itHandler != liCoreEventHandler.end(); ++itHandler )
Jonas Stienen's avatar
Jonas Stienen committed
446
			{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
447
				( *itHandler )->HandleVACoreEvent( &oEvent );
Jonas Stienen's avatar
Jonas Stienen committed
448
			}
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
449
450
451
452
453
454
455
456
457
458
459
			break;
		}
		case VA_EVENT_NET_EVENT:
		{
			m_pClient->ProcessNetEvent( m_pEventMessage->ReadInt() );
			break;
		}
		default:
		{
			VA_EXCEPT2( PROTOCOL_ERROR, std::string( "Unknown event message type" ) );
		}
Jonas Stienen's avatar
Jonas Stienen committed
460
461
462
463
464
		}
	}
	catch( VistaExceptionBase& oException )
	{
		VA_EXCEPT2( PROTOCOL_ERROR,
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
465
466
467
			std::string( "VANetNetworkProtocol: caught connection exception - " +
			oException.GetExceptionText() ) );
	}
Jonas Stienen's avatar
Jonas Stienen committed
468
469
470
471
472

	return m_pEventMessage->GetMessageType();
}


Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
473
474
void CVANetNetworkProtocol::ServerPrepareEventMessage( const CVACoreEvent* pEvent,
	CVANetMessage* pMessage )
Jonas Stienen's avatar
Jonas Stienen committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
{
	pMessage->ResetMessage();
	pMessage->SetMessageType( VA_EVENT_CORE_EVENT );
	pMessage->WriteCoreEvent( *pEvent );
}

void CVANetNetworkProtocol::HandleConnectionClose( VistaConnectionIP* pConnection )
{
	if( m_pLastAnswerConnection = pConnection )
		m_pLastAnswerConnection = NULL;
	if( m_pMessage->GetConnection() == pConnection )
		m_pMessage->ClearConnection();
}

CVANetMessage* CVANetNetworkProtocol::ServerGetMessage()
{
	return m_pMessage;
}
void CVANetNetworkProtocol::ServerSendAnswer( CVANetMessage* pMessage )
{
	// nothing to do
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
498
499
CVANetMessage* CVANetNetworkProtocol::ClientInitMessage( int nCommandId,
	MESSAGE_MODE eMessageMode )
Jonas Stienen's avatar
Jonas Stienen committed
500
501
502
503
504
505
506
507
508
509
510
{
	m_nCurrentMessageMode = eMessageMode;
	if( eMessageMode == MESSAGE_ALLOWS_BUFFERING && m_bBufferingActive )
	{
		m_pBufferedMessage->WriteInt( nCommandId );
		return m_pBufferedMessage;
	}
	else
	{
		m_pMessage->ResetMessage();
		m_pMessage->SetConnection( m_pCommandChannel );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
511
		m_pMessage->SetMessageType( nCommandId );
Jonas Stienen's avatar
Jonas Stienen committed
512
513
514
515
516
517
518
519
520
521
		return m_pMessage;
	}
}
void CVANetNetworkProtocol::ClientSendCommand( CVANetMessage* pMessage )
{
	if( pMessage != m_pBufferedMessage )
	{
		int nExceptionMode;
		switch( m_nCurrentMessageMode )
		{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
522
523
524
525
526
		case MESSAGE_WITH_ANSWER:
		case MESSAGE_ENFORCED_EXCEPTION:
		{
			nExceptionMode = IVANetClient::EXC_CLIENT_THROW;
			break;
Jonas Stienen's avatar
Jonas Stienen committed
527
		}
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
528
529
530
531
532
533
534
535
		case MESSAGE_CONDITIONAL_EXCEPTION:
		case MESSAGE_ALLOWS_BUFFERING:
		{
			nExceptionMode = m_iExceptionHandlingMode;
			break;
		}
		}

Jonas Stienen's avatar
Jonas Stienen committed
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
		try
		{
			pMessage->SetExceptionMode( nExceptionMode );
			pMessage->WriteMessage();

			if( m_nCurrentMessageMode == MESSAGE_WITH_ANSWER )
			{
				pMessage->ReadAnswer();
				if( pMessage->GetAnswerType() == VA_NP_SPECIAL_EXCEPTION )
				{
					throw( pMessage->ReadException() );
				}
				else
				{
					assert( pMessage->GetAnswerType() == VA_NP_SPECIAL_ANSWER );
				}
			}
			else if( nExceptionMode == IVANetClient::EXC_CLIENT_THROW )
			{
				pMessage->ReadAnswer();
				if( pMessage->GetAnswerType() == VA_NP_SPECIAL_EXCEPTION )
				{
					throw( pMessage->ReadException() );
				}
				else
				{
					assert( pMessage->GetAnswerType() == VA_NP_SPECIAL_NO_EXCEPTION );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
563
				}
Jonas Stienen's avatar
Jonas Stienen committed
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
			}
		}
		catch( const VistaExceptionBase& )
		{
			//@todo
		}
	}
}


/* +----------------------------------------------------------+ *
 * |                                                          | *
 * |   Base functions                                         | *
 * |                                                          | *
 * +----------------------------------------------------------+ */

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
580
581
582
void CVANetNetworkProtocol::ClientGetVersionInfo( CVACoreVersionInfo* pVersionInfo )
{
	if( !pVersionInfo ) return;
583
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_VERSION_INFO,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
584
585
586
587
588
589
590
591
592
593
	ClientSendCommand( pMsg );

	*pVersionInfo = pMsg->ReadCoreVersionInfo();
}

void CVANetNetworkProtocol::ServerGetVersionInfo()
{
	CVANetMessage* pMsg = ServerGetMessage();

	CVACoreVersionInfo oVersionInfo;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
594
	m_pRealCore->GetVersionInfo( &oVersionInfo );
Jonas Stienen's avatar
Jonas Stienen committed
595
596
597
598
599
600

	pMsg->WriteCoreVersionInfo( oVersionInfo );
}

int CVANetNetworkProtocol::ClientGetState()
{
601
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_STATE,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
602
603
604
605
606
	ClientSendCommand( pMsg );

	return pMsg->ReadInt();
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
607
void CVANetNetworkProtocol::ServerGetState()
Jonas Stienen's avatar
Jonas Stienen committed
608
609
610
611
612
613
614
615
{
	CVANetMessage* pMsg = ServerGetMessage();
	int iState = m_pRealCore->GetState();
	pMsg->WriteInt( iState );
}

void CVANetNetworkProtocol::ClientInitialize()
{
616
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_INITIALIZE,		MESSAGE_ENFORCED_EXCEPTION );
Jonas Stienen's avatar
Jonas Stienen committed
617
618
619
620
621
622
623
624
625
626
	ClientSendCommand( pMsg );
}

void CVANetNetworkProtocol::ServerInitialize()
{
	m_pRealCore->Initialize();
}

void CVANetNetworkProtocol::ClientFinalize()
{
627
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_FINALIZE,		MESSAGE_ENFORCED_EXCEPTION );
Jonas Stienen's avatar
Jonas Stienen committed
628
629
630
631
632
633
634
635
636
637
	ClientSendCommand( pMsg );
}

void CVANetNetworkProtocol::ServerFinalize()
{
	m_pRealCore->Finalize();
}

void CVANetNetworkProtocol::ClientReset()
{
638
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_RESET,		MESSAGE_ENFORCED_EXCEPTION );
Jonas Stienen's avatar
Jonas Stienen committed
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
	ClientSendCommand( pMsg );

}

void CVANetNetworkProtocol::ServerReset()
{
	m_pRealCore->Reset();
}


/* +----------------------------------------------------------+ *
 * |                                                          | *
 * |   Event handling                                         | *
 * |                                                          | *
 * +----------------------------------------------------------+ */

void CVANetNetworkProtocol::ClientAttachCoreEventHandler()
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
656
{
657
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_ATTACH_COREEVENT_HANDLER,		MESSAGE_ENFORCED_EXCEPTION );
Jonas Stienen's avatar
Jonas Stienen committed
658
659
660
661
662
663
664
665
666
667
	ClientSendCommand( pMsg );
}

void CVANetNetworkProtocol::ServerAttachCoreEventHandler( VistaConnectionIP* pConn )
{
	m_pServer->AttachCoreEventHandler( pConn );
}

void CVANetNetworkProtocol::ClientDetachCoreEventHandler()
{
668
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_DETACH_COREEVENT_HANDLER,		MESSAGE_ENFORCED_EXCEPTION );
Jonas Stienen's avatar
Jonas Stienen committed
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
	ClientSendCommand( pMsg );
}

void CVANetNetworkProtocol::ServerDetachCoreEventHandler( VistaConnectionIP* pConn )
{
	m_pServer->DetachCoreEventHandler( pConn );
}


/* +----------------------------------------------------------+ *
 * |                                                          | *
 * |   Module interface                                       | *
 * |                                                          | *
 * +----------------------------------------------------------+ */

684
685
686
void CVANetNetworkProtocol::ClientEnumerateModules( std::vector<CVAModuleInfo>& m_viModuleInfos )
{
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_ENUMERATE_MODULES,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
687
688
689
690
691
	ClientSendCommand( pMsg );

	int nModules = pMsg->ReadInt();

	m_viModuleInfos.clear();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
692
	m_viModuleInfos.resize( nModules );
Jonas Stienen's avatar
Jonas Stienen committed
693

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
694
695
	for( int i = 0; i < nModules; i++ )
		pMsg->ReadModuleInfo( m_viModuleInfos[ i ] );
Jonas Stienen's avatar
Jonas Stienen committed
696
697
}

698
699
void CVANetNetworkProtocol::ServerEnumerateModules()
{
Jonas Stienen's avatar
Jonas Stienen committed
700
701
702
	CVANetMessage* pMsg = ServerGetMessage();

	std::vector<CVAModuleInfo> viModules;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
703
704
705
706
707
	m_pRealCore->EnumerateModules( viModules );

	pMsg->WriteInt( ( int ) viModules.size() );
	for( int i = 0; i < ( int ) viModules.size(); i++ )
		pMsg->WriteModuleInfo( viModules[ i ] );
Jonas Stienen's avatar
Jonas Stienen committed
708
709
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
710
711
712
713
714
void CVANetNetworkProtocol::ClientCallModule( const std::string& sModuleName, const CVAStruct& oArgs, CVAStruct& oReturn )
{
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_CALL_MODULE, MESSAGE_WITH_ANSWER );
	pMsg->WriteString( sModuleName );
	pMsg->WriteVAStruct( oArgs );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
715

Jonas Stienen's avatar
Jonas Stienen committed
716
717
	ClientSendCommand( pMsg );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
718
	pMsg->ReadVAStruct( oReturn );
Jonas Stienen's avatar
Jonas Stienen committed
719
720
721
722
723
724
725
726
727
}

void CVANetNetworkProtocol::ServerCallModule()
{
	CVANetMessage* pMsg = ServerGetMessage();

	std::string sModuleName = pMsg->ReadString();
	CVAStruct oArgs, oReturn;
	pMsg->ReadVAStruct( oArgs );
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
728

Jonas Stienen's avatar
Jonas Stienen committed
729
730
	m_pRealCore->CallModule( sModuleName, oArgs, oReturn );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
731
	pMsg->WriteVAStruct( oReturn );
Jonas Stienen's avatar
Jonas Stienen committed
732
733
734
735
736
737
738
739
740
}

/* +----------------------------------------------------------+ *
 * |                                                          | *
 * |   Directivities                                          | *
 * |                                                          | *
 * +----------------------------------------------------------+ */

int CVANetNetworkProtocol::ClientLoadDirectivity( const std::string& sFilename, const std::string& sName )
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
741
{
742
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_LOAD_DIRECTIVITY,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
	pMsg->WriteString( sFilename );
	pMsg->WriteString( sName );

	ClientSendCommand( pMsg );

	return pMsg->ReadInt();
}

void CVANetNetworkProtocol::ServerLoadDirectivity()
{
	CVANetMessage* pMsg = ServerGetMessage();

	std::string sFilename = pMsg->ReadString();
	std::string sName = pMsg->ReadString();

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
758
	int iDirID = m_pRealCore->LoadDirectivity( sFilename, sName );
Jonas Stienen's avatar
Jonas Stienen committed
759
760
761
762

	pMsg->WriteInt( iDirID );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
763
bool CVANetNetworkProtocol::ClientFreeDirectivity( int iDirID )
Jonas Stienen's avatar
Jonas Stienen committed
764
{
765
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_FREE_DIRECTIVITY,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
766
767
768
769
770
771
772
773
774
775
776
777
	pMsg->WriteInt( iDirID );

	ClientSendCommand( pMsg );

	return pMsg->ReadBool();
}

void CVANetNetworkProtocol::ServerFreeDirectivity()
{
	CVANetMessage* pMsg = ServerGetMessage();

	int iDirID = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
778

Jonas Stienen's avatar
Jonas Stienen committed
779
780
781
782
	bool bRes = m_pRealCore->FreeDirectivity( iDirID );
	pMsg->WriteBool( bRes );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
783
CVADirectivityInfo CVANetNetworkProtocol::ClientGetDirectivityInfo( int iDirID )
Jonas Stienen's avatar
Jonas Stienen committed
784
{
785
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_DIRECTIVITY_INFO,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
786
787
788
789
790
791
792
793
794
795
796
797
798
	pMsg->WriteInt( iDirID );

	ClientSendCommand( pMsg );

	CVADirectivityInfo oDirInfo = pMsg->ReadDirectivityInfo();
	return oDirInfo;
}

void CVANetNetworkProtocol::ServerGetDirectivityInfo()
{
	CVANetMessage* pMsg = ServerGetMessage();

	int iDirID = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
799
800

	CVADirectivityInfo oDirInfo = m_pRealCore->GetDirectivityInfo( iDirID );
Jonas Stienen's avatar
Jonas Stienen committed
801
802
803
804

	pMsg->WriteDirectivityInfo( oDirInfo );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
805
void CVANetNetworkProtocol::ClientGetDirectivityInfos( std::vector<CVADirectivityInfo>& vdiDest )
Jonas Stienen's avatar
Jonas Stienen committed
806
{
807
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_DIRECTIVITY_INFOS,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
808
809
810
811
812

	ClientSendCommand( pMsg );

	vdiDest.clear();
	int iNumDirectivities = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
813
	for( int i = 0; i < iNumDirectivities; i++ )
Jonas Stienen's avatar
Jonas Stienen committed
814
815
816
817
818
819
820
821
		vdiDest.push_back( pMsg->ReadDirectivityInfo() );
}

void CVANetNetworkProtocol::ServerGetDirectivityInfos()
{
	CVANetMessage* pMsg = ServerGetMessage();

	std::vector<CVADirectivityInfo> vInfos;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
822
823
824
825
826
	m_pRealCore->GetDirectivityInfos( vInfos );

	pMsg->WriteInt( ( int ) vInfos.size() );
	for( size_t i = 0; i < vInfos.size(); i++ )
		pMsg->WriteDirectivityInfo( vInfos[ i ] );
Jonas Stienen's avatar
Jonas Stienen committed
827
828
829
830
831
832
833
834
835
}


/* +----------------------------------------------------------+ *
 * |                                                          | *
 * |   Head-related impulse responses (HRIRs)                 | *
 * |                                                          | *
 * +----------------------------------------------------------+ */

836
837
838
int CVANetNetworkProtocol::ClientLoadHRIRDataset( const std::string& sFilename,	const std::string& sName )
{
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_LOAD_HRIR_DATASET,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
839

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
840
841
	pMsg->WriteString( sFilename );
	pMsg->WriteString( sName );
Jonas Stienen's avatar
Jonas Stienen committed
842
843
844
845
846
847

	ClientSendCommand( pMsg );

	return pMsg->ReadInt();
}

848
849
void CVANetNetworkProtocol::ServerLoadHRIRDataset()
{
Jonas Stienen's avatar
Jonas Stienen committed
850
851
852
853
854
	CVANetMessage* pMsg = ServerGetMessage();

	std::string sFilename = pMsg->ReadString();
	std::string sName = pMsg->ReadString();

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
855
	int iHRIRID = m_pRealCore->LoadHRIRDataset( sFilename, sName );
Jonas Stienen's avatar
Jonas Stienen committed
856
857
858
859

	pMsg->WriteInt( iHRIRID );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
860
bool CVANetNetworkProtocol::ClientFreeHRIRDataset( int iHRIRID )
Jonas Stienen's avatar
Jonas Stienen committed
861
{
862
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_FREE_HRIR_DATASET,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
863
864
865
866
867
868
869
870
871
872
873
874
875
876

	pMsg->WriteInt( iHRIRID );

	ClientSendCommand( pMsg );

	return pMsg->ReadBool();
}

void CVANetNetworkProtocol::ServerFreeHRIRDataset()
{
	CVANetMessage* pMsg = ServerGetMessage();

	int iHRIRID = pMsg->ReadInt();

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
877
	bool bResult = m_pRealCore->FreeHRIRDataset( iHRIRID );
Jonas Stienen's avatar
Jonas Stienen committed
878
879
880
881

	pMsg->WriteBool( bResult );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
882
CVAHRIRInfo CVANetNetworkProtocol::ClientGetHRIRInfo( int iHRIRID )
Jonas Stienen's avatar
Jonas Stienen committed
883
{
884
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_HRIR_INFO,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
885
886
887
888
889
890
891
892
893
894
895
896
897
	pMsg->WriteInt( iHRIRID );

	ClientSendCommand( pMsg );

	CVAHRIRInfo oHRIRInfo = pMsg->ReadHRIRInfo();
	return oHRIRInfo;
}

void CVANetNetworkProtocol::ServerGetHRIRInfo()
{
	CVANetMessage* pMsg = ServerGetMessage();

	int iHRIRID = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
898
899

	CVAHRIRInfo oHRIRInfo = m_pRealCore->GetHRIRInfo( iHRIRID );
Jonas Stienen's avatar
Jonas Stienen committed
900
901
902
903

	pMsg->WriteHRIRInfo( oHRIRInfo );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
904
void CVANetNetworkProtocol::ClientGetHRIRInfos( std::vector<CVAHRIRInfo>& vhiDest )
Jonas Stienen's avatar
Jonas Stienen committed
905
{
906
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_HRIR_INFOS,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
907
908
909
910
911

	ClientSendCommand( pMsg );

	vhiDest.clear();
	int iNumHRIRs = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
912
	for( int i = 0; i < iNumHRIRs; i++ )
Jonas Stienen's avatar
Jonas Stienen committed
913
914
915
916
917
918
919
920
		vhiDest.push_back( pMsg->ReadHRIRInfo() );
}

void CVANetNetworkProtocol::ServerGetHRIRInfos()
{
	CVANetMessage* pMsg = ServerGetMessage();

	std::vector<CVAHRIRInfo> vInfos;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
921
922
923
924
925
	m_pRealCore->GetHRIRInfos( vInfos );

	pMsg->WriteInt( ( int ) vInfos.size() );
	for( size_t i = 0; i < vInfos.size(); i++ )
		pMsg->WriteHRIRInfo( vInfos[ i ] );
Jonas Stienen's avatar
Jonas Stienen committed
926
927
928
929
930
931
932
933
934
}


/* +--------------------+
   |                    |
   |      Sounds        |
   |                    |
   +--------------------+ */

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
935
int CVANetNetworkProtocol::ClientLoadSound( const std::string& sFilename, const std::string& sName )
Jonas Stienen's avatar
Jonas Stienen committed
936
{
937
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_LOAD_SOUND,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
	pMsg->WriteString( sFilename );
	pMsg->WriteString( sName );

	ClientSendCommand( pMsg );

	return pMsg->ReadInt();
}

void CVANetNetworkProtocol::ServerLoadSound()
{
	CVANetMessage* pMsg = ServerGetMessage();

	std::string sFilename = pMsg->ReadString();
	std::string sName = pMsg->ReadString();

	int iSoundID = m_pRealCore->LoadSound( sFilename, sName );

	pMsg->WriteInt( iSoundID );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
958
bool CVANetNetworkProtocol::ClientFreeSound( int iSoundID )
Jonas Stienen's avatar
Jonas Stienen committed
959
{
960
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_FREE_SOUND,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
	pMsg->WriteInt( iSoundID );

	ClientSendCommand( pMsg );

	return pMsg->ReadBool();
}

void CVANetNetworkProtocol::ServerFreeSound()
{
	CVANetMessage* pMsg = ServerGetMessage();

	int iID = pMsg->ReadInt();

	bool bResult = m_pRealCore->FreeSound( iID );

	pMsg->WriteBool( bResult );
}

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
979
CVASoundInfo CVANetNetworkProtocol::ClientGetSoundInfo( int iSoundID )
Jonas Stienen's avatar
Jonas Stienen committed
980
{
981
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_SOUND_INFO,		MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
982
983
984
985
986
987
988
989
990
991
992
993
994
	pMsg->WriteInt( iSoundID );

	ClientSendCommand( pMsg );

	CVASoundInfo oSoundInfo = pMsg->ReadSoundInfo();
	return oSoundInfo;
}

void CVANetNetworkProtocol::ServerGetSoundInfo()
{
	CVANetMessage* pMsg = ServerGetMessage();

	int iSoundID = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
995
996

	CVASoundInfo oSoundInfo = m_pRealCore->GetSoundInfo( iSoundID );
Jonas Stienen's avatar
Jonas Stienen committed
997
998
999
1000

	pMsg->WriteSoundInfo( oSoundInfo );
}