From a057f757abd80d48331fbc288cd912feb4223aeb Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 26 Sep 2017 13:08:35 +0100 Subject: [PATCH] Add a reload time for the XLX Hosts file. --- Conf.cpp | 10 +++++++++- Conf.h | 2 ++ DMRGateway.cpp | 8 ++++++-- DMRGateway.ini | 1 + Reflectors.cpp | 17 +++++++++++++++-- Reflectors.h | 7 ++++++- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index f74bb40..88c6ca3 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -89,6 +89,7 @@ m_dmrNetwork2PassAllTG(), m_xlxNetworkEnabled(false), m_xlxNetworkId(0U), m_xlxNetworkFile(), +m_xlxNetworkReloadTime(0U), m_xlxNetworkLocal(0U), m_xlxNetworkSlot(1U), m_xlxNetworkTG(8U), @@ -189,7 +190,9 @@ bool CConf::read() m_xlxNetworkId = (unsigned int)::atoi(value); else if (::strcmp(key, "File") == 0) m_xlxNetworkFile = value; - else if (::strcmp(key, "Local") == 0) + else if (::strcmp(key, "ReloadTime") == 0) + m_xlxNetworkReloadTime = (unsigned int)::atoi(value); + else if (::strcmp(key, "Local") == 0) m_xlxNetworkLocal = (unsigned int)::atoi(value); else if (::strcmp(key, "Slot") == 0) m_xlxNetworkSlot = (unsigned int)::atoi(value); @@ -478,6 +481,11 @@ std::string CConf::getXLXNetworkFile() const return m_xlxNetworkFile; } +unsigned int CConf::getXLXNetworkReloadTime() const +{ + return m_xlxNetworkReloadTime; +} + unsigned int CConf::getXLXNetworkLocal() const { return m_xlxNetworkLocal; diff --git a/Conf.h b/Conf.h index e208b41..8f58171 100644 --- a/Conf.h +++ b/Conf.h @@ -123,6 +123,7 @@ public: bool getXLXNetworkEnabled() const; unsigned int getXLXNetworkId() const; std::string getXLXNetworkFile() const; + unsigned int getXLXNetworkReloadTime() const; unsigned int getXLXNetworkLocal() const; unsigned int getXLXNetworkSlot() const; unsigned int getXLXNetworkTG() const; @@ -189,6 +190,7 @@ private: bool m_xlxNetworkEnabled; unsigned int m_xlxNetworkId; std::string m_xlxNetworkFile; + unsigned int m_xlxNetworkReloadTime; unsigned int m_xlxNetworkLocal; unsigned int m_xlxNetworkSlot; unsigned int m_xlxNetworkTG; diff --git a/DMRGateway.cpp b/DMRGateway.cpp index 32eaa78..9d44285 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -768,6 +768,9 @@ int CDMRGateway::run() if (m_xlxNetwork != NULL) m_xlxNetwork->clock(ms); + if (m_xlxReflectors != NULL) + m_xlxReflectors->clock(ms); + if (voice != NULL) voice->clock(ms); @@ -1093,9 +1096,10 @@ bool CDMRGateway::createDMRNetwork2() 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(); if (!ret) { diff --git a/DMRGateway.ini b/DMRGateway.ini index 275e780..1a802ea 100644 --- a/DMRGateway.ini +++ b/DMRGateway.ini @@ -25,6 +25,7 @@ Directory=./Audio [XLX Network] Enabled=1 File=XLXHosts.txt +ReloadTime=60 # Local=3351 Slot=1 TG=6 diff --git a/Reflectors.cpp b/Reflectors.cpp index 4c0f428..ef6d338 100644 --- a/Reflectors.cpp +++ b/Reflectors.cpp @@ -26,10 +26,13 @@ #include #include -CReflectors::CReflectors(const std::string& hostsFile) : +CReflectors::CReflectors(const std::string& hostsFile, unsigned int reloadTime) : m_hostsFile(hostsFile), -m_reflectors() +m_reflectors(), +m_timer(1000U, reloadTime * 60U) { + if (reloadTime > 0U) + m_timer.start(); } CReflectors::~CReflectors() @@ -95,3 +98,13 @@ CReflector* CReflectors::find(unsigned int id) return NULL; } + +void CReflectors::clock(unsigned int ms) +{ + m_timer.clock(ms); + + if (m_timer.isRunning() && m_timer.hasExpired()) { + load(); + m_timer.start(); + } +} diff --git a/Reflectors.h b/Reflectors.h index 4bc62b3..cac5f84 100644 --- a/Reflectors.h +++ b/Reflectors.h @@ -19,6 +19,8 @@ #if !defined(Reflectors_H) #define Reflectors_H +#include "Timer.h" + #include #include @@ -42,16 +44,19 @@ public: class CReflectors { public: - CReflectors(const std::string& hostsFile); + CReflectors(const std::string& hostsFile, unsigned int reloadTime); ~CReflectors(); bool load(); CReflector* find(unsigned int id); + void clock(unsigned int ms); + private: std::string m_hostsFile; std::vector m_reflectors; + CTimer m_timer; }; #endif