CProtocols::m_Protocols is std::unique_ptr<CProtocol>

pull/1/head
Tom Early 5 years ago
parent d19444c911
commit f3ebea79ba

@ -130,11 +130,12 @@ do
ps -aux | grep -e xlxd -e xrfd -e ambed | grep -v grep ps -aux | grep -e xlxd -e xrfd -e ambed | grep -v grep
fi fi
echo echo
echo " Reflector Administration, Version #200716" echo " Reflector Administration, Version #200723"
echo echo
echo "ls : List the configuration file" echo "ls : List the configuration file"
echo "cl : Clean (remove) compiled objects and executables" echo "cl : Clean (remove) compiled objects and executables"
echo "gp : Pull the latest software from the repo" echo "gp : Pull the latest software from the repo"
echo "br : Change git branch to <value>"
echo "co : Compile the system executable(s)" echo "co : Compile the system executable(s)"
if [ -e $xlxserv ] || [ -e $xrfserv ]; then if [ -e $xlxserv ] || [ -e $xrfserv ]; then
if [ -e $xlxserv ] && [ -e $xrfserv ]; then if [ -e $xlxserv ] && [ -e $xrfserv ]; then
@ -195,6 +196,11 @@ do
git pull git pull
echo echo
read -p "<Enter> to continue: " ans read -p "<Enter> to continue: " ans
elif [[ "$key" == br* ]]; then
echo
git checkout "$value"
echo
read -p "<Enter> to continue: " ans
elif [[ "$key" == rr* ]]; then elif [[ "$key" == rr* ]]; then
if [[ "$callsign" == XLX* ]] && [ -e $xlxserv ]; then if [[ "$callsign" == XLX* ]] && [ -e $xlxserv ]; then
sudo systemctl restart xlxd sudo systemctl restart xlxd

@ -36,7 +36,7 @@
bool CDcsProtocol::Init(void) bool CDcsProtocol::Init(void)
{ {
// base class // base class
if (! Initialize("DCS", DCS_PORT, DSTAR_IPV4, DSTAR_IPV6)) if (! CProtocol::Initialize("DCS", DCS_PORT, DSTAR_IPV4, DSTAR_IPV6))
return false; return false;
// update time // update time

@ -35,10 +35,10 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CDextraProtocol::Init(void) bool CDextraProtocol::Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6)
{ {
// base class // base class
if (! Initialize("XRF", DEXTRA_PORT, DSTAR_IPV4, DSTAR_IPV6)) if (! CProtocol::Initialize(type, port, has_ipv4, has_ipv6))
return false; return false;
// update time // update time

@ -59,7 +59,7 @@ class CDextraProtocol : public CProtocol
{ {
public: public:
// initialization // initialization
bool Init(void); bool Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
// task // task
void Task(void); void Task(void);

@ -54,10 +54,10 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 };
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CDmrmmdvmProtocol::Init(void) bool CDmrmmdvmProtocol::Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6)
{ {
// base class // base class
if (! Initialize(nullptr, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) if (! CProtocol::Initialize(type, port, has_ipv4, has_ipv6))
return false; return false;
// update time // update time

@ -67,7 +67,7 @@ class CDmrmmdvmProtocol : public CProtocol
{ {
public: public:
// initialization // initialization
bool Init(void); bool Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
// task // task
void Task(void); void Task(void);

@ -47,10 +47,10 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 };
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CDmrplusProtocol::Init() bool CDmrplusProtocol::Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6)
{ {
// base class // base class
if (! Initialize(nullptr, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) if (! CProtocol::Initialize(type, port, has_ipv4, has_ipv6))
return false; return false;
// update time // update time

@ -57,7 +57,7 @@ class CDmrplusProtocol : public CProtocol
{ {
public: public:
// initialization // initialization
bool Init(); bool Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
// task // task
void Task(void); void Task(void);

@ -34,10 +34,10 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CDplusProtocol::Init(void) bool CDplusProtocol::Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6)
{ {
// base class // base class
if (! Initialize("REF", DPLUS_PORT, DSTAR_IPV4, DSTAR_IPV6)) if (! CProtocol::Initialize(type, port, has_ipv4, has_ipv6))
return false; return false;
// update time // update time

@ -52,7 +52,7 @@ class CDplusProtocol : public CProtocol
{ {
public: public:
// initialization // initialization
bool Init(void); bool Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
// task // task
void Task(void); void Task(void);

@ -38,7 +38,7 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CG3Protocol::Init(void) bool CG3Protocol::Initalize(const char */*type*/, const uint16 /*port*/, const bool /*has_ipv4*/, const bool /*has_ipv6*/)
{ {
ReadOptions(); ReadOptions();

@ -67,7 +67,7 @@ public:
CG3Protocol() : m_GwAddress(0u), m_Modules("*"), m_LastModTime(0) {} CG3Protocol() : m_GwAddress(0u), m_Modules("*"), m_LastModTime(0) {}
// initialization // initialization
bool Init(void); bool Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
// close // close
void Close(void); void Close(void);

@ -77,7 +77,7 @@ public:
virtual ~CProtocol(); virtual ~CProtocol();
// initialization // initialization
bool Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6); virtual bool Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
virtual void Close(void); virtual void Close(void);
// queue // queue

@ -43,16 +43,7 @@
CProtocols::~CProtocols() CProtocols::~CProtocols()
{ {
m_Mutex.lock(); Close();
{
for ( auto it=m_Protocols.begin(); it!=m_Protocols.end(); it++)
{
(*it)->Close();
delete *it;
}
m_Protocols.clear();
}
m_Mutex.unlock();
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@ -62,88 +53,40 @@ bool CProtocols::Init(void)
{ {
m_Mutex.lock(); m_Mutex.lock();
{ {
auto dextra = new CDextraProtocol; m_Protocols.emplace_back(std::unique_ptr<CDextraProtocol>(new CDextraProtocol));
if (dextra->Init()) if (! m_Protocols.back()->Initialize("XRF", DEXTRA_PORT, DSTAR_IPV4, DSTAR_IPV6))
m_Protocols.push_back(dextra);
else
{
delete dextra;
return false; return false;
}
m_Protocols.emplace_back(std::unique_ptr<CDplusProtocol>(new CDplusProtocol));
// create and initialize DPLUS if (! m_Protocols.back()->Initialize("REF", DPLUS_PORT, DSTAR_IPV4, DSTAR_IPV6))
auto dplus = new CDplusProtocol;
if (dplus->Init())
m_Protocols.push_back(dplus);
else
{
delete dplus;
return false; return false;
}
// create and initialize DCS m_Protocols.emplace_back(std::unique_ptr<CDcsProtocol>(new CDcsProtocol));
auto dcs = new CDcsProtocol; if (! m_Protocols.back()->Initialize("DCS", DCS_PORT, DSTAR_IPV4, DSTAR_IPV6))
if (dcs->Init())
m_Protocols.push_back(dcs);
else
{
delete dcs;
return false; return false;
}
#ifndef NO_XLX #ifndef NO_XLX
// create and initialize XLX - interlink m_Protocols.emplace_back(std::unique_ptr<CDmrmmdvmProtocol>(new CDmrmmdvmProtocol));
auto xlx = new CXlxProtocol; if (! m_Protocols.back()->Initialize(nullptr, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6))
if (xlx->Init())
m_Protocols.push_back(xlx);
else
{
delete xlx;
return false; return false;
}
// create and initialize DMRPLUS m_Protocols.emplace_back(std::unique_ptr<CDmrplusProtocol>(new CDmrplusProtocol));
auto dmrplus = new CDmrplusProtocol; if (! m_Protocols.back()->Initialize(nullptr, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6))
if (dmrplus->Init())
m_Protocols.push_back(dmrplus);
else
{
delete dmrplus;
return false; return false;
}
// create and initialize DMRMMDVM m_Protocols.emplace_back(std::unique_ptr<CYsfProtocol>(new CYsfProtocol));
auto dmrmmdvm = new CDmrmmdvmProtocol; if (! m_Protocols.back()->Initialize("YSF", YSF_PORT, DMR_IPV4, DMR_IPV6))
if (dmrmmdvm->Init())
m_Protocols.push_back(dmrmmdvm);
else
{
delete dmrmmdvm;
return false; return false;
}
// create and initialize YSF m_Protocols.emplace_back(std::unique_ptr<CXlxProtocol>(new CXlxProtocol));
auto ysf = new CYsfProtocol; if (! m_Protocols.back()->Initialize("XLX", XLX_PORT, DMR_IPV4, DMR_IPV6))
if (ysf->Init())
m_Protocols.push_back(ysf);
else
{
delete ysf;
return false; return false;
}
#endif #endif
#ifndef NO_G3 #ifndef NO_G3
// create and initialize G3 m_Protocols.emplace_back(std::unique_ptr<CG3Protocol>(new CG3Protocol));
auto g3 = new CG3Protocol; if (! m_Protocols.back()->Initialize("XLX", G3_PORT, DMR_IPV4, DMR_IPV6))
if (g3->Init()) return false;
m_Protocols.push_back(g3);
else
{
delete g3;
return true;
}
#endif #endif
} }
@ -156,13 +99,6 @@ bool CProtocols::Init(void)
void CProtocols::Close(void) void CProtocols::Close(void)
{ {
m_Mutex.lock(); m_Mutex.lock();
{ m_Protocols.clear();
for ( auto it=m_Protocols.begin(); it!=m_Protocols.end(); it++)
{
(*it)->Close();
delete *it;
}
m_Protocols.clear();
}
m_Mutex.unlock(); m_Mutex.unlock();
} }

@ -44,15 +44,17 @@ public:
// initialization // initialization
bool Init(void); bool Init(void);
void Close(void); void Close(void);
void Lock(void) { m_Mutex.lock(); }
void Unlock(void) { m_Mutex.unlock(); }
// pass-thru // pass-thru
std::list<CProtocol *>::iterator begin() { return m_Protocols.begin(); } std::list<std::unique_ptr<CProtocol>>::iterator begin() { return m_Protocols.begin(); }
std::list<CProtocol *>::iterator end() { return m_Protocols.end(); } std::list<std::unique_ptr<CProtocol>>::iterator end() { return m_Protocols.end(); }
protected: protected:
// data // data
std::mutex m_Mutex; std::mutex m_Mutex;
std::list<CProtocol *> m_Protocols; std::list<std::unique_ptr<CProtocol>> m_Protocols;
}; };

@ -347,6 +347,7 @@ void CReflector::RouterThread(CReflector *This, CPacketStream *streamIn)
packet->SetModuleId(uiModuleId); packet->SetModuleId(uiModuleId);
// iterate on all protocols // iterate on all protocols
This->m_Protocols.Lock();
for ( auto it=This->m_Protocols.begin(); it!=This->m_Protocols.end(); it++ ) for ( auto it=This->m_Protocols.begin(); it!=This->m_Protocols.end(); it++ )
{ {
// duplicate packet // duplicate packet
@ -366,6 +367,7 @@ void CReflector::RouterThread(CReflector *This, CPacketStream *streamIn)
queue->push(packetClone); queue->push(packetClone);
(*it)->ReleaseQueue(); (*it)->ReleaseQueue();
} }
This->m_Protocols.Unlock();
// done // done
delete packet; delete packet;
packet = nullptr; packet = nullptr;

@ -35,9 +35,9 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CXlxProtocol::Init(void) bool CXlxProtocol::Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6)
{ {
if (! Initialize("XLX", XLX_PORT, XLX_IPV4, XLX_IPV6)) if (! CProtocol::Initialize(type, port, has_ipv4, has_ipv6))
return false; return false;
// update time // update time

@ -41,7 +41,7 @@ class CXlxProtocol : public CDextraProtocol
{ {
public: public:
// initialization // initialization
bool Init(void); bool Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
// task // task
void Task(void); void Task(void);

@ -45,10 +45,10 @@ CYsfProtocol::CYsfProtocol()
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CYsfProtocol::Init(void) bool CYsfProtocol::Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6)
{ {
// base class // base class
if (! Initialize("YSF", YSF_PORT, YSF_IPV4, YSF_IPV6)) if (! CProtocol::Initialize(type, port, has_ipv4, has_ipv6))
return false; return false;
// init the wiresx cmd handler // init the wiresx cmd handler

@ -74,10 +74,10 @@ public:
CYsfProtocol(); CYsfProtocol();
// destructor // destructor
virtual ~CYsfProtocol() {}; ~CYsfProtocol() {}
// initialization // initialization
bool Init(void); bool Initalize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6);
void Close(void); void Close(void);
// task // task

Loading…
Cancel
Save

Powered by TurnKey Linux.