Commit 2485a02d authored by moret's avatar moret
Browse files

Add JackNetInterface class hierarchy to share code between slave/master

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2773 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 56ad4a93
......@@ -27,7 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackPlatformThread.h"
#include "jack.h"
#include "jslist.h"
#include "JackNetSlaveInterface.h"
#include "JackNetInterface.h"
namespace Jack
{
......
......@@ -40,8 +40,6 @@ namespace Jack
{
jack_log ( "JackNetDriver::JackNetDriver ip %s, port %d", ip, port );
fMulticastIP = new char[strlen ( ip ) + 1];
strcpy ( fMulticastIP, ip );
fParams.fMtu = mtu;
fParams.fSendMidiChannels = midi_input_ports;
fParams.fReturnMidiChannels = midi_output_ports;
......@@ -57,7 +55,6 @@ namespace Jack
JackNetDriver::~JackNetDriver()
{
fSocket.Close();
delete[] fMidiCapturePortList;
delete[] fMidiPlaybackPortList;
#ifdef JACK_MONITOR
......
......@@ -22,7 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define __JackNetDriver__
#include "JackAudioDriver.h"
#include "JackNetSlaveInterface.h"
#include "JackNetInterface.h"
#ifdef JACK_MONITOR
#include "JackFrameTimer.h"
......
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2008 Romain Moret at Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __JackNetInterface__
#define __JackNetInterface__
#include "JackNetTool.h"
namespace Jack
{
/**
\Brief This class describes the basic Net Interface, used by both master and slave
*/
class EXPORT JackNetInterface
{
protected:
session_params_t fParams;
JackNetSocket fSocket;
char* fMulticastIP;
uint fNSubProcess;
//headers
packet_header_t fTxHeader;
packet_header_t fRxHeader;
//network buffers
char* fTxBuffer;
char* fRxBuffer;
char* fTxData;
char* fRxData;
//jack buffers
NetMidiBuffer* fNetMidiCaptureBuffer;
NetMidiBuffer* fNetMidiPlaybackBuffer;
NetAudioBuffer* fNetAudioCaptureBuffer;
NetAudioBuffer* fNetAudioPlaybackBuffer;
//sizes
int fAudioRxLen;
int fAudioTxLen;
int fPayloadSize;
void SetParams();
//virtual methods : depends on the sub class master/slave
virtual bool Init() = 0;
virtual int SyncRecv() = 0;
virtual int SyncSend() = 0;
virtual int DataRecv() = 0;
virtual int DataSend() = 0;
virtual int Send ( size_t size, int flags ) = 0;
virtual int Recv ( size_t size, int flags ) = 0;
JackNetInterface()
{}
JackNetInterface ( const char* ip, int port );
JackNetInterface ( session_params_t& params, JackNetSocket& socket );
public:
~JackNetInterface();
};
/**
\Brief This class describes the Net Interface for slaves (NetDriver and NetAdapter)
*/
class EXPORT JackNetSlaveInterface : public JackNetInterface
{
protected:
bool Init();
net_status_t GetNetMaster();
net_status_t SendMasterStartSync();
int SyncRecv();
int SyncSend();
int DataRecv();
int DataSend();
int Recv ( size_t size, int flags );
int Send ( size_t size, int flags );
public:
JackNetSlaveInterface()
{}
JackNetSlaveInterface ( const char* ip, int port ) : JackNetInterface ( ip, port )
{
fTxHeader.fDataStream = 'r';
fRxHeader.fDataStream = 's';
}
~JackNetSlaveInterface()
{}
};
/**
\Brief This class describes the Net Interface for masters (NetMaster)
*/
class EXPORT JackNetMasterInterface : public JackNetInterface
{
protected:
bool fRunning;
bool Init();
void Exit();
int SyncRecv();
int SyncSend();
int DataRecv();
int DataSend();
int Send ( size_t size, int flags );
int Recv ( size_t size, int flags );
public:
JackNetMasterInterface() : fRunning ( false )
{}
JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket ) : JackNetInterface ( params, socket )
{
fTxHeader.fDataStream = 's';
fRxHeader.fDataStream = 'r';
}
~JackNetMasterInterface()
{}
};
}
#endif
This diff is collapsed.
......@@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef __JACKNETMANAGER_H__
#define __JACKNETMANAGER_H__
#include "JackNetTool.h"
#include "JackNetInterface.h"
#include "thread.h"
#include "jack.h"
#include "jslist.h"
......@@ -34,18 +34,12 @@ namespace Jack
\Brief This class describes a Net Master
*/
class JackNetMaster
class JackNetMaster : public JackNetMasterInterface
{
friend class JackNetMasterManager;
friend class JackNetMasterManager;
private:
static int SetProcess ( jack_nframes_t nframes, void* arg );
JackNetMasterManager* fMasterManager;
session_params_t fParams;
JackNetSocket fSocket;
uint fNSubProcess;
bool fRunning;
//jack client
jack_client_t* fJackClient;
const char* fClientName;
......@@ -60,27 +54,6 @@ namespace Jack
int fSyncState;
net_transport_data_t fTransportData;
//network headers
packet_header_t fTxHeader;
packet_header_t fRxHeader;
//network buffers
char* fTxBuffer;
char* fRxBuffer;
char* fTxData;
char* fRxData;
//jack buffers
NetAudioBuffer* fNetAudioCaptureBuffer;
NetAudioBuffer* fNetAudioPlaybackBuffer;
NetMidiBuffer* fNetMidiCaptureBuffer;
NetMidiBuffer* fNetMidiPlaybackBuffer;
//sizes
int fAudioTxLen;
int fAudioRxLen;
int fPayloadSize;
//monitoring
#ifdef JACK_MONITOR
jack_time_t fPeriodUsecs;
......@@ -88,16 +61,15 @@ namespace Jack
#endif
bool Init();
int AllocPorts();
void FreePorts();
void Exit();
int SetSyncPacket();
int Send ( char* buffer, size_t size, int flags );
int Recv ( size_t size, int flags );
int Process();
public:
JackNetMaster ( JackNetMasterManager* manager, session_params_t& params );
JackNetMaster ( JackNetSocket& socket, session_params_t& params );
~JackNetMaster ();
};
......@@ -134,8 +106,6 @@ namespace Jack
public:
JackNetMasterManager ( jack_client_t* jack_client, const JSList* params );
~JackNetMasterManager();
void Exit();
};
}
......
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2008 Romain Moret at Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __JackNetSlaveInterface__
#define __JackNetSlaveInterface__
#include "JackNetTool.h"
#ifdef JACK_MONITOR
#include "JackFrameTimer.h"
#endif
namespace Jack
{
/**
\Brief This class describes the Net Interface for slaves (NetDriver and NetAdapter)
*/
class EXPORT JackNetSlaveInterface
{
protected:
session_params_t fParams;
char* fMulticastIP;
JackNetSocket fSocket;
uint fNSubProcess;
//headers
packet_header_t fTxHeader;
packet_header_t fRxHeader;
//network buffers
char* fTxBuffer;
char* fRxBuffer;
char* fTxData;
char* fRxData;
//jack buffers
NetMidiBuffer* fNetMidiCaptureBuffer;
NetMidiBuffer* fNetMidiPlaybackBuffer;
NetAudioBuffer* fNetAudioCaptureBuffer;
NetAudioBuffer* fNetAudioPlaybackBuffer;
//sizes
int fAudioRxLen;
int fAudioTxLen;
int fPayloadSize;
//sub processes
bool Init();
net_status_t GetNetMaster();
net_status_t SendMasterStartSync();
int SetParams();
int SyncRecv();
int SyncSend();
int DataRecv();
int DataSend();
//network operations
int Recv ( size_t size, int flags );
int Send ( size_t size, int flags );
public:
JackNetSlaveInterface();
JackNetSlaveInterface ( const char* ip, int port ) : fMulticastIP ( NULL ), fSocket ( ip, port )
{}
~JackNetSlaveInterface();
};
}
#endif
......@@ -60,11 +60,30 @@ namespace Jack
memset ( &fRecvAddr.sin_zero, 0, 8 );
}
JackNetUnixSocket::JackNetUnixSocket ( const JackNetUnixSocket& socket )
{
fSockfd = socket.fSockfd;
fPort = socket.fPort;
fSendAddr = socket.fSendAddr;
fRecvAddr = socket.fRecvAddr;
}
JackNetUnixSocket::~JackNetUnixSocket()
{
Close();
}
JackNetUnixSocket& JackNetUnixSocket::operator= ( const JackNetUnixSocket& socket )
{
if ( this != &socket )
{
fSockfd = 0;
fPort = socket.fPort;
fSendAddr = socket.fSendAddr;
fRecvAddr = socket.fRecvAddr;
}
}
//socket***********************************************************************************************************
int JackNetUnixSocket::NewSocket()
{
......
......@@ -48,8 +48,11 @@ namespace Jack
public:
JackNetUnixSocket();
JackNetUnixSocket ( const char* ip, int port );
JackNetUnixSocket ( const JackNetUnixSocket& );
~JackNetUnixSocket();
JackNetUnixSocket& operator= ( const JackNetUnixSocket& socket );
//socket management
int NewSocket();
int Bind();
......
......@@ -129,11 +129,30 @@ namespace Jack
memset ( &fRecvAddr.sin_zero, 0, 8 );
}
JackNetWinSocket::JackNetWinSocket ( const JackNetWinSocket& socket )
{
fSockfd = 0;
fPort = socket.fPort;
fSendAddr = socket.fSendAddr;
fRecvAddr = socket.fRecvAddr;
}
JackNetWinSocket::~JackNetWinSocket()
{
Close();
}
JackNetWinSocket& JackNetWinSocket::operator= ( const JackNetWinSocket& socket )
{
if ( this != &socket )
{
fSockfd = 0;
fPort = socket.fPort;
fSendAddr = socket.fSendAddr;
fRecvAddr = socket.fRecvAddr;
}
}
//socket***********************************************************************************************************
int JackNetWinSocket::NewSocket()
{
......@@ -244,13 +263,6 @@ namespace Jack
return SetOption ( IPPROTO_IP, 12, &multicast_req, sizeof ( multicast_req ) );
}
void JackNetWinSocket::CopyParams ( JackNetWinSocket* socket )
{
fPort = socket->fPort;
fSendAddr = socket->fSendAddr;
fRecvAddr = socket->fRecvAddr;
}
//options************************************************************************************************************
int JackNetWinSocket::SetOption ( int level, int optname, const void* optval, SOCKLEN optlen )
{
......@@ -268,7 +280,7 @@ namespace Jack
//negative timeout, or exceeding 10s, return
if ( ( usec < 0 ) || ( usec > 10000000 ) )
return SOCKET_ERROR;
int time = usec / 1000;
int time = usec / 1000;
return SetOption ( SOL_SOCKET, SO_RCVTIMEO, &time, sizeof ( time ) );
}
......
......@@ -49,8 +49,11 @@ namespace Jack
public:
JackNetWinSocket();
JackNetWinSocket ( const char* ip, int port );
JackNetWinSocket ( const JackNetWinSocket& );
~JackNetWinSocket();
JackNetWinSocket& operator= ( const JackNetWinSocket& );
//socket management
int NewSocket();
int Bind();
......@@ -74,7 +77,6 @@ namespace Jack
//utility
int GetName ( char* name );
int JoinMCastGroup ( const char* mcast_ip );
void CopyParams ( JackNetWinSocket* socket );
//options management
int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen );
......
// Generated by ResEdit 1.4.3
// Copyright (C) 2006-2008
// http://www.resedit.net
#include "resource.h"
#include "afxres.h"
//
// Version Information resources
//
LANGUAGE LANG_FRENCH, SUBLANG_DEFAULT
1 VERSIONINFO
FILEVERSION 1,9,0,0
PRODUCTVERSION 1,9,0,0
FILEOS VOS_UNKNOWN
FILETYPE VFT_DLL
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040c04b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Grame\0"
VALUE "FileDescription", "Jackmp Net Adapter for Windows\0"
VALUE "FileVersion", "1, 9, 0, 0\0"
VALUE "InternalName", "jack_netadapter\0"
VALUE "LegalCopyright", "Copyright Grame 2006-2008\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "jack_netadapter.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "jack_netadapter\0"
VALUE "ProductVersion", "1, 9, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 1036, 1200
END
END
......@@ -124,7 +124,6 @@
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add directory="." />
<Add directory="..\common" />
<Add directory="..\common\jack" />
......@@ -167,7 +166,7 @@
<Unit filename="..\common\JackMessageBuffer.cpp" />
<Unit filename="..\common\JackMidiAPI.cpp" />
<Unit filename="..\common\JackMidiPort.cpp" />
<Unit filename="..\common\JackNetSlaveInterface.cpp" />
<Unit filename="..\common\JackNetInterface.cpp" />
<Unit filename="..\common\JackNetTool.cpp" />
<Unit filename="..\common\JackPort.cpp" />
<Unit filename="..\common\JackPortType.cpp" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment