Add a reload time for the XLX Hosts file.

This commit is contained in:
Jonathan Naylor
2017-09-26 13:08:35 +01:00
parent 82e6b90454
commit a057f757ab
6 changed files with 39 additions and 6 deletions

View File

@@ -89,6 +89,7 @@ m_dmrNetwork2PassAllTG(),
m_xlxNetworkEnabled(false), m_xlxNetworkEnabled(false),
m_xlxNetworkId(0U), m_xlxNetworkId(0U),
m_xlxNetworkFile(), m_xlxNetworkFile(),
m_xlxNetworkReloadTime(0U),
m_xlxNetworkLocal(0U), m_xlxNetworkLocal(0U),
m_xlxNetworkSlot(1U), m_xlxNetworkSlot(1U),
m_xlxNetworkTG(8U), m_xlxNetworkTG(8U),
@@ -189,6 +190,8 @@ bool CConf::read()
m_xlxNetworkId = (unsigned int)::atoi(value); m_xlxNetworkId = (unsigned int)::atoi(value);
else if (::strcmp(key, "File") == 0) else if (::strcmp(key, "File") == 0)
m_xlxNetworkFile = value; m_xlxNetworkFile = value;
else if (::strcmp(key, "ReloadTime") == 0)
m_xlxNetworkReloadTime = (unsigned int)::atoi(value);
else if (::strcmp(key, "Local") == 0) else if (::strcmp(key, "Local") == 0)
m_xlxNetworkLocal = (unsigned int)::atoi(value); m_xlxNetworkLocal = (unsigned int)::atoi(value);
else if (::strcmp(key, "Slot") == 0) else if (::strcmp(key, "Slot") == 0)
@@ -478,6 +481,11 @@ std::string CConf::getXLXNetworkFile() const
return m_xlxNetworkFile; return m_xlxNetworkFile;
} }
unsigned int CConf::getXLXNetworkReloadTime() const
{
return m_xlxNetworkReloadTime;
}
unsigned int CConf::getXLXNetworkLocal() const unsigned int CConf::getXLXNetworkLocal() const
{ {
return m_xlxNetworkLocal; return m_xlxNetworkLocal;

2
Conf.h
View File

@@ -123,6 +123,7 @@ public:
bool getXLXNetworkEnabled() const; bool getXLXNetworkEnabled() const;
unsigned int getXLXNetworkId() const; unsigned int getXLXNetworkId() const;
std::string getXLXNetworkFile() const; std::string getXLXNetworkFile() const;
unsigned int getXLXNetworkReloadTime() const;
unsigned int getXLXNetworkLocal() const; unsigned int getXLXNetworkLocal() const;
unsigned int getXLXNetworkSlot() const; unsigned int getXLXNetworkSlot() const;
unsigned int getXLXNetworkTG() const; unsigned int getXLXNetworkTG() const;
@@ -189,6 +190,7 @@ private:
bool m_xlxNetworkEnabled; bool m_xlxNetworkEnabled;
unsigned int m_xlxNetworkId; unsigned int m_xlxNetworkId;
std::string m_xlxNetworkFile; std::string m_xlxNetworkFile;
unsigned int m_xlxNetworkReloadTime;
unsigned int m_xlxNetworkLocal; unsigned int m_xlxNetworkLocal;
unsigned int m_xlxNetworkSlot; unsigned int m_xlxNetworkSlot;
unsigned int m_xlxNetworkTG; unsigned int m_xlxNetworkTG;

View File

@@ -768,6 +768,9 @@ int CDMRGateway::run()
if (m_xlxNetwork != NULL) if (m_xlxNetwork != NULL)
m_xlxNetwork->clock(ms); m_xlxNetwork->clock(ms);
if (m_xlxReflectors != NULL)
m_xlxReflectors->clock(ms);
if (voice != NULL) if (voice != NULL)
voice->clock(ms); voice->clock(ms);
@@ -1094,8 +1097,9 @@ bool CDMRGateway::createDMRNetwork2()
bool CDMRGateway::createXLXNetwork() bool CDMRGateway::createXLXNetwork()
{ {
std::string fileName = m_conf.getXLXNetworkFile(); std::string fileName = m_conf.getXLXNetworkFile();
unsigned int reloadTime = m_conf.getXLXNetworkReloadTime();
m_xlxReflectors = new CReflectors(fileName); m_xlxReflectors = new CReflectors(fileName, reloadTime);
bool ret = m_xlxReflectors->load(); bool ret = m_xlxReflectors->load();
if (!ret) { if (!ret) {

View File

@@ -25,6 +25,7 @@ Directory=./Audio
[XLX Network] [XLX Network]
Enabled=1 Enabled=1
File=XLXHosts.txt File=XLXHosts.txt
ReloadTime=60
# Local=3351 # Local=3351
Slot=1 Slot=1
TG=6 TG=6

View File

@@ -26,10 +26,13 @@
#include <cstring> #include <cstring>
#include <cctype> #include <cctype>
CReflectors::CReflectors(const std::string& hostsFile) : CReflectors::CReflectors(const std::string& hostsFile, unsigned int reloadTime) :
m_hostsFile(hostsFile), m_hostsFile(hostsFile),
m_reflectors() m_reflectors(),
m_timer(1000U, reloadTime * 60U)
{ {
if (reloadTime > 0U)
m_timer.start();
} }
CReflectors::~CReflectors() CReflectors::~CReflectors()
@@ -95,3 +98,13 @@ CReflector* CReflectors::find(unsigned int id)
return NULL; return NULL;
} }
void CReflectors::clock(unsigned int ms)
{
m_timer.clock(ms);
if (m_timer.isRunning() && m_timer.hasExpired()) {
load();
m_timer.start();
}
}

View File

@@ -19,6 +19,8 @@
#if !defined(Reflectors_H) #if !defined(Reflectors_H)
#define Reflectors_H #define Reflectors_H
#include "Timer.h"
#include <vector> #include <vector>
#include <string> #include <string>
@@ -42,16 +44,19 @@ public:
class CReflectors { class CReflectors {
public: public:
CReflectors(const std::string& hostsFile); CReflectors(const std::string& hostsFile, unsigned int reloadTime);
~CReflectors(); ~CReflectors();
bool load(); bool load();
CReflector* find(unsigned int id); CReflector* find(unsigned int id);
void clock(unsigned int ms);
private: private:
std::string m_hostsFile; std::string m_hostsFile;
std::vector<CReflector*> m_reflectors; std::vector<CReflector*> m_reflectors;
CTimer m_timer;
}; };
#endif #endif