mirror of
https://github.com/g4klx/DMRGateway
synced 2025-12-20 21:25:37 +08:00
Add a reload time for the XLX Hosts file.
This commit is contained in:
8
Conf.cpp
8
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,6 +190,8 @@ bool CConf::read()
|
||||
m_xlxNetworkId = (unsigned int)::atoi(value);
|
||||
else if (::strcmp(key, "File") == 0)
|
||||
m_xlxNetworkFile = value;
|
||||
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)
|
||||
@@ -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;
|
||||
|
||||
2
Conf.h
2
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1094,8 +1097,9 @@ bool CDMRGateway::createDMRNetwork2()
|
||||
bool CDMRGateway::createXLXNetwork()
|
||||
{
|
||||
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) {
|
||||
|
||||
@@ -25,6 +25,7 @@ Directory=./Audio
|
||||
[XLX Network]
|
||||
Enabled=1
|
||||
File=XLXHosts.txt
|
||||
ReloadTime=60
|
||||
# Local=3351
|
||||
Slot=1
|
||||
TG=6
|
||||
|
||||
@@ -26,10 +26,13 @@
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#if !defined(Reflectors_H)
|
||||
#define Reflectors_H
|
||||
|
||||
#include "Timer.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -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<CReflector*> m_reflectors;
|
||||
CTimer m_timer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user