Commit 6f46689c authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Progress

parent d1d8e436
......@@ -16,7 +16,6 @@
#include <VANetDefinitions.h>
#include <VABaseDefinitions.h>
#include <VABase.h>
#include <VASamples.h>
......
......@@ -17,7 +17,7 @@
#include <VANetDefinitions.h>
#include <string>
class IVACore;
class IVAInterface;
class CVANetNetworkProtocol;
/**
......@@ -75,7 +75,7 @@ public:
virtual ~IVANetClient();
// Client-seitige VACore-Instanz zurckgeben
virtual IVACore* GetCoreInstance() const = 0;
virtual IVAInterface* GetCoreInstance() const = 0;
// Gibt zurck, ob eine Verbindung zu einem Server besteht
virtual bool IsConnected() const = 0;
......@@ -86,9 +86,9 @@ public:
// Client initialisieren und mit einem Server verbinden
// (Rckgabe: Statuscode)
virtual int Initialize( const std::string& sServerAddress, int iServerPort = VANET_DEFAULT_PORT, int iHeadChannelMode = VA_HC_USE_EXISTING, int IExceptionHandlingMode = EXC_CLIENT_THROW, bool bBufferSynchronizedCommands = true ) = 0;
virtual int Initialize( const std::string& sServerAddress, const int iServerPort = VANET_DEFAULT_PORT, const int iHeadChannelMode = VA_HC_USE_EXISTING, const int IExceptionHandlingMode = EXC_CLIENT_THROW, const bool bBufferSynchronizedCommands = true ) = 0;
virtual void SetExceptionHandlingMode( int nMode ) = 0;
virtual void SetExceptionHandlingMode( const int nMode ) = 0;
virtual int GetExceptionhandlingMode() const = 0;
// Vorhandene Serververbindung beenden
......@@ -105,8 +105,8 @@ public:
EVENT_SERVER_LOST // Ungewollter Verbindungsabbruch
};
int iType; // Typ der Ereignisses
std::string sServer; //
int iType;
inline CEvent()
: iType( EVENT_NOTHING )
......
......@@ -15,10 +15,7 @@
#include "VANetNetworkProtocol.h"
#include "VANetVistaCompatibility.h"
#include <VAException.h>
#include <VACore.h>
#include <VACoreEvent.h>
#include <VAStruct.h>
#include <VA.h>
// ViSTA includes
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
......@@ -32,10 +29,6 @@
#include <algorithm>
#include <cassert>
// Windows workaround
#ifdef PlaySound
#undef PlaySound
#endif
// Ensures that any possible call to the client
// is executed stricly serial. No two commands may
......@@ -51,11 +44,11 @@
/////// NetworkedVACore ////////
////////////////////////////////////////////////
class CVANetClientImpl::CNetworkedVACore : public IVACore
class CVANetClientImpl::CNetworkedVACore : public IVAInterface
{
public:
inline CNetworkedVACore( CVANetNetworkProtocol* pProtocol, CVANetClientImpl* pParent, VistaConnectionIP* pCommandChannel, VistaConnectionIP* pHeadChannel )
: IVACore()
: IVAInterface()
, m_pParent( pParent )
, m_pCommandChannel( pCommandChannel )
, m_pHeadChannel( pHeadChannel )
......@@ -65,217 +58,131 @@ public:
m_pHeadMutex = new VistaMutex;
else
m_pHeadMutex = &m_oCommandMutex;
}
};
inline ~CNetworkedVACore()
{
if( m_pHeadChannel )
delete m_pHeadMutex;
}
};
inline VistaMutex* GetCommandMutex() { return &m_oCommandMutex; }
inline VistaMutex* GetHeadMutex() { return m_pHeadMutex; }
inline VistaMutex* GetCommandMutex()
{
return &m_oCommandMutex;
};
/* +----------------------------------------------------------+ *
* | | *
* | Base functions | *
* | | *
* +----------------------------------------------------------+ */
inline VistaMutex* GetHeadMutex()
{
return m_pHeadMutex;
};
inline virtual void GetVersionInfo( CVACoreVersionInfo* pVersionInfo ) const
inline void GetVersionInfo( CVAVersionInfo* pVersionInfo ) const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetVersionInfo( pVersionInfo );
}
};
inline virtual void SetDebugStream( std::ostream* )
inline void SetDebugStream( std::ostream* )
{
// Hinweis: Diese Funktion macht keinen Sinn ber Netzwerk. Ausnahme, Baby!
VA_EXCEPT2( NOT_IMPLEMENTED, "This function is not available when operating on a remote server" );
}
VA_EXCEPT_NOT_IMPLEMENTED;
};
inline virtual int GetState() const
inline int GetState() const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetState();
}
};
inline virtual void Initialize()
inline void Initialize()
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientInitialize();
}
};
inline virtual void Finalize()
inline void Finalize()
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientFinalize();
}
};
inline virtual void Reset()
inline void Reset()
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientReset();
}
/* +----------------------------------------------------------+ *
* | | *
* | Event handling | *
* | | *
* +----------------------------------------------------------+ */
};
inline virtual void AttachCoreEventHandler( IVACoreEventHandler* pCoreEventHandler )
inline void AttachCoreEventHandler( IVAEventHandler* pEventHandler )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pParent->AttachCoreEventHandler( pCoreEventHandler );
}
m_pParent->AttachCoreEventHandler( pEventHandler );
};
inline virtual void DetachCoreEventHandler( IVACoreEventHandler* pCoreEventHandler )
inline void DetachCoreEventHandler( IVAEventHandler* pEventHandler )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pParent->DetachCoreEventHandler( pCoreEventHandler );
}
m_pParent->DetachCoreEventHandler( pEventHandler );
};
/* +----------------------------------------------------------+ *
* | | *
* | Module interface | *
* | | *
* +----------------------------------------------------------+ */
virtual void EnumerateModules( std::vector<CVAModuleInfo>& viModuleInfos ) const {
inline void GetModules( std::vector< CVAModuleInfo >& viModuleInfos ) const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientEnumerateModules( viModuleInfos );
}
m_pProtocol->ClientGetModules( viModuleInfos );
};
virtual void CallModule( const std::string& sModuleName, const CVAStruct& oArgs, CVAStruct& oReturn )
inline CVAStruct CallModule( const std::string& sModuleName, const CVAStruct& oArgs )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientCallModule( sModuleName, oArgs, oReturn );
}
return m_pProtocol->ClientCallModule( sModuleName, oArgs );
};
/* +----------------------------------------------------------+ *
* | | *
* | Directivities | *
* | | *
* +----------------------------------------------------------+ */
virtual int LoadDirectivity( const std::string& sFilename,
const std::string& sName = "" ) {
inline int CreateDirectivityFromParameters( const CVAStruct& oParams, const std::string& sName /* = "" */ )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientLoadDirectivity( sFilename, sName );
}
return m_pProtocol->ClientCreateDirectivityFromParameters( oParams, sName );
};
virtual bool FreeDirectivity( int iDirID ) {
inline bool DeleteDirectivity( const int iID )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientFreeDirectivity( iDirID );
}
return m_pProtocol->ClientDeleteDirectivity( iID );
};
virtual CVADirectivityInfo GetDirectivityInfo( int iDirID ) const {
inline CVADirectivityInfo GetDirectivityInfo( const int iDirID ) const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetDirectivityInfo( iDirID );
}
};
virtual void GetDirectivityInfos( std::vector<CVADirectivityInfo>& vdiDest ) const {
inline void GetDirectivityInfos( std::vector<CVADirectivityInfo>& vdiDest ) const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientGetDirectivityInfos( vdiDest );
}
/* +----------------------------------------------------------+ *
* | | *
* | Head-related impulse responses (HRIRs) | *
* | | *
* +----------------------------------------------------------+ */
int LoadHRIRDataset( const std::string& sFilename,
const std::string& sName = "" ) {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientLoadHRIRDataset( sFilename, sName );
}
bool FreeHRIRDataset( int iHRIRID ) {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientFreeHRIRDataset( iHRIRID );
}
CVAHRIRInfo GetHRIRInfo( int iHRIRID ) const {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetHRIRInfo( iHRIRID );
}
void GetHRIRInfos( std::vector<CVAHRIRInfo>& vhiDest ) const {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientGetHRIRInfos( vhiDest );
}
/* +----------------------------------------------------------+ *
* | | *
* | Sounds | *
* | | *
* +----------------------------------------------------------+ */
virtual int LoadSound( const std::string& sFilename,
const std::string& sName = "" ) {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientLoadSound( sFilename, sName );
}
virtual bool FreeSound( int iSoundID ) {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientFreeSound( iSoundID );
}
virtual CVASoundInfo GetSoundInfo( int iSoundID ) const {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetSoundInfo( iSoundID );
}
virtual void GetSoundInfos( std::vector<CVASoundInfo>& vsiDest ) const {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetSoundInfos( vsiDest );
}
virtual int PlaySound( int iSoundID, double dVolume = 1.0 ) const {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientPlaySound( iSoundID, dVolume );
}
/* +----------------------------------------------------------+ *
* | | *
* | Signal sources | *
* | | *
* +----------------------------------------------------------+ */
};
virtual inline std::string CreateAudiofileSignalSource( const std::string& sFilename,
const std::string& sName = "" ) {
inline std::string CreateSignalSourceBufferFromParameters( const CVAStruct& oParams, const std::string& sName /* = "" */ )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientCreateAudiofileSignalSource( sFilename, sName );
return m_pProtocol->ClientCreateSignalSourceBufferFromParameters( oParams, sName );
};
virtual inline std::string CreateTextToSpeechSignalSource( const std::string& sName = "" )
inline std::string CreateTextToSpeechSignalSource( const std::string& sName = "" )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
......@@ -364,58 +271,41 @@ public:
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetAudiofileSignalSourceIsLooping( sSignalSourceID );
return m_pProtocol->ClientGetSignalSourceBufferLooping( sSignalSourceID );
}
virtual void SetAudiofileSignalSourceIsLooping( const std::string& sSignalSourceID, bool bLooping )
virtual void SetSignalSourceBufferLooping( const std::string& sSignalSourceID, const bool bLooping )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientSetAudiofileSignalSourceIsLooping( sSignalSourceID, bLooping );
}
virtual int AddSoundPlayback( const std::string& sSignalSourceID, int iSoundID, int iFlags, double dTimecode = 0 ) {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientAddSoundPlayback( sSignalSourceID, iSoundID, iFlags, dTimecode );
}
virtual bool RemoveSoundPlayback( int iPlaybackID ) {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientRemoveSoundPlayback( iPlaybackID );
}
m_pProtocol->ClientSetSignalSourceBufferLooping( sSignalSourceID, bLooping );
};
virtual void SetSignalSourceParameters( const std::string& sSignalSourceID, const CVAStruct& oParams )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientSetSignalSourceParameters( sSignalSourceID, oParams );
}
};
virtual CVAStruct GetSignalSourceParameters( const std::string& sSignalSourceID, const CVAStruct& oParams ) const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetSignalSourceParameters( sSignalSourceID, oParams );
}
/* +----------------------------------------------------------+ *
* | | *
* | Synchronization functions | *
* | | *
* +----------------------------------------------------------+ */
};
virtual bool IsSceneLocked() const {
virtual bool IsSceneLocked() const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientIsSceneLocked();
}
return m_pProtocol->ClientGetUpdateLocked();
};
virtual void LockScene() {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientLockScene();
m_pProtocol->ClientLockUpdate();
}
virtual int UnlockScene() {
......@@ -724,7 +614,7 @@ public:
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientSetListenerEnabled( iListenerID, bEnabled );
return m_pProtocol->ClientSetSoundReceiverEnabled( iListenerID, bEnabled );
}
virtual bool GetListenerEnabled( int iListenerID ) const
......@@ -737,13 +627,13 @@ public:
virtual std::string GetListenerName( int iListenerID ) const{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetListenerName( iListenerID );
return m_pProtocol->ClientGetSoundReceiverName( iListenerID );
}
virtual void SetListenerName( int iListenerID, const std::string& sName ) {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientSetListenerName( iListenerID, sName );
m_pProtocol->ClientSetSoundReceiverName( iListenerID, sName );
}
virtual int GetListenerAuralizationMode( int iListenerID ) const{
......@@ -942,16 +832,18 @@ public:
return m_pProtocol->ClientGetSceneInfo();
}
virtual void GetPortalIDs( std::vector<int>& vPortalIDs ) {
inline void GetPortalIDs( std::vector<int>& viIDs )
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
m_pProtocol->ClientGetPortalIDs( vPortalIDs );
m_pProtocol->ClientGetPortalIDs( viIDs );
}
virtual std::string GetPortalName( int iPortalID ) const {
inline std::string GetPortalName( const int iID ) const
{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientGetPortalName( iPortalID );
return m_pProtocol->ClientGetPortalName( iID );
}
virtual void SetPortalName( int iPortalID, const std::string& sName ) {
......@@ -981,7 +873,7 @@ public:
virtual bool IsInputMuted() const {
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientIsInputMuted();
return m_pProtocol->ClientGetInputMuted();
}
virtual void SetInputMuted( bool bMuted ) {
......@@ -1017,7 +909,7 @@ public:
virtual bool IsOutputMuted() const{
VA_REQUIRE_CONNECTED;
VA_MUTAL_EXCLUDE;
return m_pProtocol->ClientIsOutputMuted();
return m_pProtocol->ClientGetOutputMuted();
}
virtual void SetOutputMuted( bool bMuted ) {
......@@ -1175,20 +1067,20 @@ public:
SetThreadName( "VA-Server Connection Observer" );
}
inline void AttachCoreEventHandler( IVACoreEventHandler* pCoreEventHandler )
inline void AttachCoreEventHandler( IVAEventHandler* pCoreEventHandler )
{
VistaMutexLock oLock( m_oHandlerListLock );
std::list<IVACoreEventHandler*>::iterator itEntry = std::find( m_liCoreEventHandlers.begin(), m_liCoreEventHandlers.end(), pCoreEventHandler );
std::list<IVAEventHandler*>::iterator itEntry = std::find( m_liCoreEventHandlers.begin(), m_liCoreEventHandlers.end(), pCoreEventHandler );
if( itEntry != m_liCoreEventHandlers.end() )
return;
m_liCoreEventHandlers.push_back( pCoreEventHandler );
};
inline void DetachCoreEventHandler( IVACoreEventHandler* pCoreEventHandler )
inline void DetachCoreEventHandler( IVAEventHandler* pCoreEventHandler )
{
VistaMutexLock oLock( m_oHandlerListLock );
std::list<IVACoreEventHandler*>::iterator itEntry = std::find( m_liCoreEventHandlers.begin(), m_liCoreEventHandlers.end(), pCoreEventHandler );
std::list<IVAEventHandler*>::iterator itEntry = std::find( m_liCoreEventHandlers.begin(), m_liCoreEventHandlers.end(), pCoreEventHandler );
if( itEntry == m_liCoreEventHandlers.end() )
return;
......@@ -1212,8 +1104,8 @@ public:
oChannelLock.Unlock();
IndicateLoopEnd();
m_pParent->ProcessEventChannelError();
}
}
}
#ifdef VANET_CLIENT_VERBOSE
catch( VistaExceptionBase& oException )
{
......@@ -1237,7 +1129,7 @@ public:
m_pParent->ProcessEventChannelError();
}
return false;
};
};
inline virtual void PreLoop()
{
......@@ -1257,10 +1149,10 @@ private:
CVANetClientImpl* m_pParent;
VistaConnectionIP* m_pEventChannel;
CVANetNetworkProtocol* m_pProtocol;
std::list<IVACoreEventHandler*> m_liCoreEventHandlers;
std::list<IVAEventHandler*> m_liCoreEventHandlers;
VistaMutex m_oHandlerListLock;
VistaMutex* m_pEventChannelLock;
};
};
......@@ -1284,16 +1176,19 @@ CVANetClientImpl::CVANetClientImpl()
{
}
CVANetClientImpl::~CVANetClientImpl() {
CVANetClientImpl::~CVANetClientImpl()
{
Disconnect();
Cleanup();
}
IVACore* CVANetClientImpl::GetCoreInstance() const {
IVAInterface* CVANetClientImpl::GetCoreInstance() const
{
return m_pVACore;
}
bool CVANetClientImpl::IsConnected() const {
bool CVANetClientImpl::IsConnected() const
{
if( m_bShutdownFlag == true )
{
const_cast< CVANetClientImpl* >( this )->Disconnect();
......@@ -1302,14 +1197,13 @@ bool CVANetClientImpl::IsConnected() const {
return ( m_bConnected && m_pCommandChannel && m_pCommandChannel->GetIsConnected() );
}
std::string CVANetClientImpl::GetServerAddress() const {
std::string CVANetClientImpl::GetServerAddress() const
{
return m_sServerIP;
}
int CVANetClientImpl::Initialize( const std::string& sServerAddress, int iServerPort,
int iHeadChannelMode,
int IExceptionHandlingMode,
bool bBufferSynchronizedCommands ) {
int CVANetClientImpl::Initialize( const std::string& sServerAddress, const int iServerPort, const int iHeadChannelMode, const int IExceptionHandlingMode, const bool bBufferSynchronizedCommands )
{
if( IVistaTimerImp::GetSingleton() == NULL )
IVistaTimerImp::SetSingleton( new VistaDefaultTimerImp );
......@@ -1344,8 +1238,7 @@ int CVANetClientImpl::Initialize( const std::string& sServerAddress, int iServer
VANetCompat::sint32 nMinor = -1;
oRequestConnection.ReadInt32( nMajor );
oRequestConnection.ReadInt32( nMinor );
if( nMajor != CVANetNetworkProtocol::VA_NET_PROTOCOL_VERSION_MAJOR
|| nMinor != CVANetNetworkProtocol::VA_NET_PROTOCOL_VERSION_MINOR )
if( nMajor != CVANetNetworkProtocol::VA_NET_PROTOCOL_VERSION_MAJOR || nMinor != CVANetNetworkProtocol::VA_NET_PROTOCOL_VERSION_MINOR )
{
oRequestConnection.WriteBool( false );
oRequestConnection.WaitForSendFinish();
......@@ -1374,7 +1267,7 @@ int CVANetClientImpl::Initialize( const std::string& sServerAddress, int iServer
// server responded, but it doesn't accept any more connections
Cleanup();
return VA_SERVICE_IN_USE;
}
}
m_pCommandChannel = new VistaConnectionIP( VistaConnectionIP::CT_TCP, m_sServerIP, iCommandChannelPort );
#ifdef VANET_CLIENT_SHOW_RAW_TRAFFIC
m_pCommandChannel->SetShowRawSendAndReceive( true );
......@@ -1578,21 +1471,21 @@ void CVANetClientImpl::Cleanup()
}
void CVANetClientImpl::AttachCoreEventHandler( IVACoreEventHandler* pCoreEventHandler )
void CVANetClientImpl::AttachCoreEventHandler( IVAEventHandler* pCoreEventHandler )
{
if( IsConnected() == false ) VA_EXCEPT2( MODAL_ERROR, "Not connected." );
assert( m_pEventReceiver != NULL );
m_pEventReceiver->AttachCoreEventHandler( pCoreEventHandler );
m_pProtocol->ClientAttachCoreEventHandler();
m_pProtocol->ClientAttachEventHandler();
}
void CVANetClientImpl::DetachCoreEventHandler( IVACoreEventHandler* pCoreEventHandler )
void CVANetClientImpl::DetachCoreEventHandler( IVAEventHandler* pCoreEventHandler )
{
if( IsConnected() == false ) VA_EXCEPT2( MODAL_ERROR, "Not connected." );
assert( m_pEventReceiver != NULL );
m_pEventReceiver->DetachCoreEventHandler( pCoreEventHandler );
m_pProtocol->ClientDetachCoreEventHandler();