CProtocol::Initialize parameters

pull/1/head
Tom Early 6 years ago
parent 7fff1c7e37
commit 869349709a

@ -103,7 +103,15 @@ bool CCodecStream::Init(uint16 uiPort)
}
// create socket address, family based on transcoder listen address
#ifdef LISTEN_IPV4
#ifdef LISTEN_IPV6
s = (AF_INET == m_Ip.GetFamily()) ? g_Reflector.GetListenIPv4() : g_Reflector.GetListenIPv6();
#else
s = g_Reflector.GetListenIPv4();
#endif
#else
s = g_Reflector.GetListenIPv6();
#endif
CIp ip(m_Ip.GetFamily(), m_uiPort, s);
// create our socket

@ -36,7 +36,7 @@
bool CDcsProtocol::Init(void)
{
// base class
if (! Initialize("DCS", DCS_PORT))
if (! Initialize("DCS", DCS_PORT, DSTAR_IPV4, DSTAR_IPV6))
return false;
// update time
@ -61,8 +61,8 @@ void CDcsProtocol::Task(void)
CDvFramePacket *Frame;
// handle incoming packets
#ifdef DSTAR_IPV6
#ifdef DSTAR_IPV4
#if DSTAR_IPV6==true
#if DSTAR_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )

@ -38,7 +38,7 @@
bool CDextraProtocol::Init(void)
{
// base class
if (! Initialize("XRF", DEXTRA_PORT))
if (! Initialize("XRF", DEXTRA_PORT, DSTAR_IPV4, DSTAR_IPV6))
return false;
// update time
@ -64,8 +64,8 @@ void CDextraProtocol::Task(void)
CDvLastFramePacket *LastFrame;
// any incoming packet ?
#ifdef DSTAR_IPV6
#ifdef DSTAR_IPV4
#if DSTAR_IPV6==true
#if DSTAR_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )

@ -57,7 +57,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 };
bool CDmrmmdvmProtocol::Init(void)
{
// base class
if (! Initialize(NULL, DMRMMDVM_PORT))
if (! Initialize(NULL, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6))
return false;
// update time
@ -90,8 +90,8 @@ void CDmrmmdvmProtocol::Task(void)
CDvLastFramePacket *LastFrame;
// handle incoming packets
#ifdef DMR_IPV6
#ifdef DMR_IPV4
#if DMR_IPV6==true
#if DMR_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )

@ -50,7 +50,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 };
bool CDmrplusProtocol::Init()
{
// base class
if (! Initialize(NULL, DMRPLUS_PORT))
if (! Initialize(NULL, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6))
return false;
// update time
@ -79,8 +79,8 @@ void CDmrplusProtocol::Task(void)
CDvFramePacket *Frames[3];
// handle incoming packets
#ifdef DMR_IPV6
#ifdef DMR_IPV4
#if DMR_IPV6==true
#if DMR_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )

@ -37,7 +37,7 @@
bool CDplusProtocol::Init(void)
{
// base class
if (! Initialize("REF", DPLUS_PORT))
if (! Initialize("REF", DPLUS_PORT, DSTAR_IPV4, DSTAR_IPV6))
return false;
// update time
@ -62,8 +62,8 @@ void CDplusProtocol::Task(void)
CDvLastFramePacket *LastFrame;
// handle incoming packets
#ifdef DSTAR_IPV6
#ifdef DSTAR_IPV4
#if DSTAR_IPV6==true
#if DSTAR_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )

@ -66,7 +66,7 @@ CProtocol::~CProtocol()
////////////////////////////////////////////////////////////////////////////////////////
// initialization
bool CProtocol::Initialize(const char *type, uint16 port)
bool CProtocol::Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6)
{
// init reflector apparent callsign
m_ReflectorCallsign = g_Reflector.GetCallsign();
@ -80,15 +80,20 @@ bool CProtocol::Initialize(const char *type, uint16 port)
// create our sockets
#ifdef LISTEN_IPV4
if (has_ipv4)
{
CIp ip4(AF_INET, port, g_Reflector.GetListenIPv4());
if ( ip4.IsSet() )
{
if (! m_Socket4.Open(ip4))
return false;
}
}
#endif
#ifdef LISTEN_IPV6
if (has_ipv6)
{
CIp ip6(AF_INET6, port, g_Reflector.GetListenIPv6());
if ( ip6.IsSet() )
{
@ -98,6 +103,7 @@ bool CProtocol::Initialize(const char *type, uint16 port)
return false;
}
}
}
#endif
// start thread;
@ -105,12 +111,8 @@ bool CProtocol::Initialize(const char *type, uint16 port)
if (m_pThread == NULL)
{
std::cerr << "Could not start DCS thread!" << std::endl;
#ifdef LISTEN_IPV4
m_Socket4.Close();
#endif
#ifdef LISTEN_IPV6
m_Socket6.Close();
#endif
return false;
}
@ -135,12 +137,8 @@ void CProtocol::Close(void)
delete m_pThread;
m_pThread = NULL;
}
#ifdef LISTEN_IPV4
m_Socket4.Close();
#endif
#ifdef LISTEN_IPV6
m_Socket6.Close();
#endif
}
////////////////////////////////////////////////////////////////////////////////////////
@ -307,21 +305,16 @@ uint32 CProtocol::ModuleToDmrDestId(char m) const
////////////////////////////////////////////////////////////////////////////////////////
// Receivers
#ifdef LISTEN_IPV6
bool CProtocol::Receive6(CBuffer &buf, CIp &ip, int time_ms)
{
return m_Socket6.Receive(buf, ip, time_ms);
}
#endif
#ifdef LISTEN_IPV4
bool CProtocol::Receive4(CBuffer &buf, CIp &ip, int time_ms)
{
return m_Socket4.Receive(buf, ip, time_ms);
}
#endif
#if defined(LISTEN_IPV4) && defined(LISTEN_IPV6)
bool CProtocol::ReceiveDS(CBuffer &buf, CIp &ip, int time_ms)
{
auto fd4 = m_Socket4.GetSocket();
@ -358,7 +351,6 @@ bool CProtocol::ReceiveDS(CBuffer &buf, CIp &ip, int time_ms)
else
return m_Socket6.ReceiveFrom(buf, ip);
}
#endif
////////////////////////////////////////////////////////////////////////////////////////
// dual stack senders
@ -366,16 +358,12 @@ bool CProtocol::ReceiveDS(CBuffer &buf, CIp &ip, int time_ms)
void CProtocol::Send(const CBuffer &buf, const CIp &Ip) const
{
switch (Ip.GetFamily()) {
#ifdef LISTEN_IPV4
case AF_INET:
m_Socket4.Send(buf, Ip);
break;
#endif
#ifdef LISTEN_IPV6
case AF_INET6:
m_Socket6.Send(buf, Ip);
break;
#endif
default:
std::cerr << "Wrong family: " << Ip.GetFamily() << std::endl;
break;
@ -385,16 +373,12 @@ void CProtocol::Send(const CBuffer &buf, const CIp &Ip) const
void CProtocol::Send(const char *buf, const CIp &Ip) const
{
switch (Ip.GetFamily()) {
#ifdef LISTEN_IPV4
case AF_INET:
m_Socket4.Send(buf, Ip);
break;
#endif
#ifdef LISTEN_IPV6
case AF_INET6:
m_Socket6.Send(buf, Ip);
break;
#endif
default:
std::cerr << "ERROR: wrong family: " << Ip.GetFamily() << std::endl;
break;
@ -404,16 +388,12 @@ void CProtocol::Send(const char *buf, const CIp &Ip) const
void CProtocol::Send(const CBuffer &buf, const CIp &Ip, uint16_t port) const
{
switch (Ip.GetFamily()) {
#ifdef LISTEN_IPV4
case AF_INET:
m_Socket4.Send(buf, Ip, port);
break;
#endif
#ifdef LISTEN_IPV6
case AF_INET6:
m_Socket6.Send(buf, Ip, port);
break;
#endif
default:
std::cerr << "Wrong family: " << Ip.GetFamily() << " on port " << port << std::endl;
break;
@ -423,16 +403,12 @@ void CProtocol::Send(const CBuffer &buf, const CIp &Ip, uint16_t port) const
void CProtocol::Send(const char *buf, const CIp &Ip, uint16_t port) const
{
switch (Ip.GetFamily()) {
#ifdef LISTEN_IPV4
case AF_INET:
m_Socket4.Send(buf, Ip, port);
break;
#endif
#ifdef LISTEN_IPV6
case AF_INET6:
m_Socket6.Send(buf, Ip, port);
break;
#endif
default:
std::cerr << "Wrong family: " << Ip.GetFamily() << " on port " << port << std::endl;
break;

@ -77,7 +77,7 @@ public:
virtual ~CProtocol();
// initialization
bool Initialize(const char *, uint16);
bool Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
virtual void Close(void);
// queue
@ -122,15 +122,9 @@ protected:
virtual char DmrDstIdToModule(uint32) const;
virtual uint32 ModuleToDmrDestId(char) const;
#ifdef LISTEN_IPV6
bool Receive6(CBuffer &buf, CIp &Ip, int time_ms);
#endif
#ifdef LISTEN_IPV4
bool Receive4(CBuffer &buf, CIp &Ip, int time_ms);
#endif
#if defined(LISTEN_IPV4) && defined(LISTEN_IPV6)
bool ReceiveDS(CBuffer &buf, CIp &Ip, int time_ms);
#endif
void Send(const CBuffer &buf, const CIp &Ip) const;
void Send(const char *buf, const CIp &Ip) const;
@ -138,12 +132,8 @@ protected:
void Send(const char *buf, const CIp &Ip, uint16 port) const;
// socket
#ifdef LISTEN_IPV4
CUdpSocket m_Socket4;
#endif
#ifdef LISTEN_IPV6
CUdpSocket m_Socket6;
#endif
// streams
std::list<CPacketStream *> m_Streams;

@ -69,7 +69,7 @@ CTranscoder::~CTranscoder()
bool CTranscoder::Init(void)
{
// create port to the transcoder
// create address to the transcoder
auto s = g_Reflector.GetTranscoderIp();
m_Ip.Initialize(strchr(s, ':') ? AF_INET6 : AF_INET, TRANSCODER_PORT, s);
@ -81,7 +81,15 @@ bool CTranscoder::Init(void)
}
// now open the transcoder port
#ifdef LISTEN_IPV4
#ifdef LISTEN_IPV6
s = (AF_INET == m_Ip.GetFamily()) ? g_Reflector.GetListenIPv4() : g_Reflector.GetListenIPv6();
#else
s = g_Reflector.GetListenIPv4();
#endif
#else
s = g_Reflector.GetListenIPv6();
#endif
CIp tc(m_Ip.GetFamily(), TRANSCODER_PORT, s);
// create our socket

@ -31,10 +31,7 @@
////////////////////////////////////////////////////////////////////////////////////////
// constructor
CUdpSocket::CUdpSocket()
{
m_fd = -1;
}
CUdpSocket::CUdpSocket() : m_fd(-1) {}
////////////////////////////////////////////////////////////////////////////////////////
// destructor

@ -37,7 +37,7 @@
bool CXlxProtocol::Init(void)
{
if (! Initialize("XLX", XLX_PORT))
if (! Initialize("XLX", XLX_PORT, XLX_IPV4, XLX_IPV6))
return false;
// update time
@ -63,8 +63,8 @@ void CXlxProtocol::Task(void)
CDvLastFramePacket *LastFrame;
// any incoming packet ?
#ifdef XLX_IPV6
#ifdef XLX_IPV4
#if XLX_IPV6==true
#if XLX_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )

@ -48,7 +48,7 @@ CYsfProtocol::CYsfProtocol()
bool CYsfProtocol::Init(void)
{
// base class
if (! Initialize("YSF", YSF_PORT))
if (! Initialize("YSF", YSF_PORT, YSF_IPV4, YSF_IPV6))
return false;
// init the wiresx cmd handler
@ -101,8 +101,8 @@ void CYsfProtocol::Task(void)
}
// handle incoming packets
#ifdef YSF_IPV6
#ifdef YSF_IPV4
#if YSF_IPV6==true
#if YSF_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )

@ -51,7 +51,7 @@
#if ! defined(LISTEN_IPV4) && ! defined(LISTEN_IPV6) && ! defined(CALLSIGN)
#define CALLSIGN "XLX797"
#define LISTEN_IPV4 "10.1.10.61"
#define LISTEN_IPV6 "any"
#define LISTEN_IPV6 "::"
#define TRANSCODER_IP "127.0.0.1"
#endif
@ -60,19 +60,15 @@
#endif
//// Module configuration
#ifdef LISTEN_IPV4
#define DSTAR_IPV4
#define DMR_IPV4
#define YSF_IPV4
#define XLX_IPV4
#endif
#ifdef LISTEN_IPV6
#define DSTAR_IPV6
//#define DMR_IPV6 // these are off beacuse there are none available for IPv6
//#define YSF_IPV6
//#define XLX_IPV6
#endif
#define DSTAR_IPV4 true
#define DMR_IPV4 true
#define YSF_IPV4 true
#define XLX_IPV4 true
#define DSTAR_IPV6 true
#define DMR_IPV6 false
#define YSF_IPV6 false
#define XLX_IPV6 false
// version -----------------------------------------------------

Loading…
Cancel
Save

Powered by TurnKey Linux.