VANetNetworkProtocol.cpp 116 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

		// 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() );
143
		SERVER_FUNCTION_MAPPING( VA_NP_CREATE_TTS_SIGNAL_SOURCE, ServerCreateTextToSpeechSignalSource() );
Jonas Stienen's avatar
Jonas Stienen committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
		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
165

Jonas Stienen's avatar
Jonas Stienen committed
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
274
		// 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
275
276
277
278
279
280
281
282
	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
283
284
	}
}
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
285

Jonas Stienen's avatar
Jonas Stienen committed
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
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
304
	}
Jonas Stienen's avatar
Jonas Stienen committed
305
306
	catch( VistaExceptionBase& oException )
	{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
307
		std::cerr << "VANetNetworkProtocol: caught connection exception - "
Jonas Stienen's avatar
Jonas Stienen committed
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
348
			<< 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
349
350
351
352
353
354
355
356
357
358
359
360
361
		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
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
390
		}
	}

	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
391
		return;
Jonas Stienen's avatar
Jonas Stienen committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

	// @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
410

Jonas Stienen's avatar
Jonas Stienen committed
411
412
413
414
415
416
417
418
419
420
421
	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
422
		std::cerr << "VANetNetworkProtocol: caught exception during ClientEndMessageBuffering - "
Jonas Stienen's avatar
Jonas Stienen committed
423
424
425
426
427
428
429
			<< oException.GetExceptionText() << std::endl;
	}

	return iRet;
}

int CVANetNetworkProtocol::ClientProcessEventMessageFromServer( VistaConnectionIP* pConnection,
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
430
	std::list<IVACoreEventHandler*> liCoreEventHandler )
Jonas Stienen's avatar
Jonas Stienen committed
431
432
433
434
{
	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
435

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

		switch( m_pEventMessage->GetMessageType() )
		{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
442
443
444
445
446
		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
447
			{
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
448
				( *itHandler )->HandleVACoreEvent( &oEvent );
Jonas Stienen's avatar
Jonas Stienen committed
449
			}
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
450
451
452
453
454
455
456
457
458
459
460
			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
461
462
463
464
465
		}
	}
	catch( VistaExceptionBase& oException )
	{
		VA_EXCEPT2( PROTOCOL_ERROR,
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
466
467
468
			std::string( "VANetNetworkProtocol: caught connection exception - " +
			oException.GetExceptionText() ) );
	}
Jonas Stienen's avatar
Jonas Stienen committed
469
470
471
472
473

	return m_pEventMessage->GetMessageType();
}


Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
474
475
void CVANetNetworkProtocol::ServerPrepareEventMessage( const CVACoreEvent* pEvent,
	CVANetMessage* pMessage )
Jonas Stienen's avatar
Jonas Stienen committed
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
{
	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
499
500
CVANetMessage* CVANetNetworkProtocol::ClientInitMessage( int nCommandId,
	MESSAGE_MODE eMessageMode )
Jonas Stienen's avatar
Jonas Stienen committed
501
502
503
504
505
506
507
508
509
510
511
{
	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
512
		m_pMessage->SetMessageType( nCommandId );
Jonas Stienen's avatar
Jonas Stienen committed
513
514
515
516
517
518
519
520
521
522
		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
523
524
525
526
527
		case MESSAGE_WITH_ANSWER:
		case MESSAGE_ENFORCED_EXCEPTION:
		{
			nExceptionMode = IVANetClient::EXC_CLIENT_THROW;
			break;
Jonas Stienen's avatar
Jonas Stienen committed
528
		}
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
529
530
531
532
533
534
535
536
		case MESSAGE_CONDITIONAL_EXCEPTION:
		case MESSAGE_ALLOWS_BUFFERING:
		{
			nExceptionMode = m_iExceptionHandlingMode;
			break;
		}
		}

Jonas Stienen's avatar
Jonas Stienen committed
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
563
		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
564
				}
Jonas Stienen's avatar
Jonas Stienen committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
			}
		}
		catch( const VistaExceptionBase& )
		{
			//@todo
		}
	}
}


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

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
581
582
583
void CVANetNetworkProtocol::ClientGetVersionInfo( CVACoreVersionInfo* pVersionInfo )
{
	if( !pVersionInfo ) return;
584
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_VERSION_INFO, MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
585
586
587
588
589
590
591
592
593
594
	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
595
	m_pRealCore->GetVersionInfo( &oVersionInfo );
Jonas Stienen's avatar
Jonas Stienen committed
596
597
598
599
600
601

	pMsg->WriteCoreVersionInfo( oVersionInfo );
}

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

	return pMsg->ReadInt();
}

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

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

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

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

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

void CVANetNetworkProtocol::ClientReset()
{
639
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_RESET, MESSAGE_ENFORCED_EXCEPTION );
Jonas Stienen's avatar
Jonas Stienen committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
	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
657
{
658
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_ATTACH_COREEVENT_HANDLER, MESSAGE_ENFORCED_EXCEPTION );
Jonas Stienen's avatar
Jonas Stienen committed
659
660
661
662
663
664
665
666
667
668
	ClientSendCommand( pMsg );
}

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

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

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


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

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

	int nModules = pMsg->ReadInt();

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

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

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

	std::vector<CVAModuleInfo> viModules;
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
704
705
706
707
708
	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
709
710
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
711
712
713
714
715
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
716

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

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

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
729

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

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

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

int CVANetNetworkProtocol::ClientLoadDirectivity( const std::string& sFilename, const std::string& sName )
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
742
{
743
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_LOAD_DIRECTIVITY, MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
	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
759
	int iDirID = m_pRealCore->LoadDirectivity( sFilename, sName );
Jonas Stienen's avatar
Jonas Stienen committed
760
761
762
763

	pMsg->WriteInt( iDirID );
}

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

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

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

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

	pMsg->WriteDirectivityInfo( oDirInfo );
}

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

	ClientSendCommand( pMsg );

	vdiDest.clear();
	int iNumDirectivities = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
814
	for( int i = 0; i < iNumDirectivities; i++ )
Jonas Stienen's avatar
Jonas Stienen committed
815
816
817
818
819
820
821
822
		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
823
824
825
826
827
	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
828
829
830
831
832
833
834
835
836
}


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

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

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

	ClientSendCommand( pMsg );

	return pMsg->ReadInt();
}

849
850
void CVANetNetworkProtocol::ServerLoadHRIRDataset()
{
Jonas Stienen's avatar
Jonas Stienen committed
851
852
853
854
855
	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
856
	int iHRIRID = m_pRealCore->LoadHRIRDataset( sFilename, sName );
Jonas Stienen's avatar
Jonas Stienen committed
857
858
859
860

	pMsg->WriteInt( iHRIRID );
}

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

	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
878
	bool bResult = m_pRealCore->FreeHRIRDataset( iHRIRID );
Jonas Stienen's avatar
Jonas Stienen committed
879
880
881
882

	pMsg->WriteBool( bResult );
}

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

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

	pMsg->WriteHRIRInfo( oHRIRInfo );
}

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

	ClientSendCommand( pMsg );

	vhiDest.clear();
	int iNumHRIRs = pMsg->ReadInt();
Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
913
	for( int i = 0; i < iNumHRIRs; i++ )
Jonas Stienen's avatar
Jonas Stienen committed
914
915
916
917
918
919
920
921
		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
922
923
924
925
926
	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
927
928
929
930
931
932
933
934
935
}


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

Dipl.-Ing. Jonas Stienen's avatar
Style    
Dipl.-Ing. Jonas Stienen committed
936
int CVANetNetworkProtocol::ClientLoadSound( const std::string& sFilename, const std::string& sName )
Jonas Stienen's avatar
Jonas Stienen committed
937
{
938
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_LOAD_SOUND, MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
	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
959
bool CVANetNetworkProtocol::ClientFreeSound( int iSoundID )
Jonas Stienen's avatar
Jonas Stienen committed
960
{
961
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_FREE_SOUND, MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
	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
980
CVASoundInfo CVANetNetworkProtocol::ClientGetSoundInfo( int iSoundID )
Jonas Stienen's avatar
Jonas Stienen committed
981
{
982
	CVANetMessage* pMsg = ClientInitMessage( VA_NP_GET_SOUND_INFO, MESSAGE_WITH_ANSWER );
Jonas Stienen's avatar
Jonas Stienen committed
983
984
985
986
987
988
989
990
991
992
993
994
995
	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
996
997

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

	pMsg->WriteSoundInfo( oSoundInfo );
}