Add an inactivity timer to the gateway.

This commit is contained in:
Jonathan Naylor 2017-03-18 07:13:14 +00:00
parent 411173efdc
commit 1225e0bc87
4 changed files with 39 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -52,6 +52,7 @@ m_networkReloadTime(0U),
m_networkParrotAddress("127.0.0.1"), m_networkParrotAddress("127.0.0.1"),
m_networkParrotPort(0U), m_networkParrotPort(0U),
m_networkStartup(9999U), m_networkStartup(9999U),
m_networkInactivityTimeout(0U),
m_networkDebug(false) m_networkDebug(false)
{ {
} }
@ -134,6 +135,8 @@ bool CConf::read()
m_networkParrotPort = (unsigned int)::atoi(value); m_networkParrotPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Startup") == 0) else if (::strcmp(key, "Startup") == 0)
m_networkStartup = (unsigned int)::atoi(value); m_networkStartup = (unsigned int)::atoi(value);
else if (::strcmp(key, "InactivityTimeout") == 0)
m_networkInactivityTimeout = (unsigned int)::atoi(value);
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
m_networkDebug = ::atoi(value) == 1; m_networkDebug = ::atoi(value) == 1;
} }
@ -224,6 +227,11 @@ unsigned int CConf::getNetworkStartup() const
return m_networkStartup; return m_networkStartup;
} }
unsigned int CConf::getNetworkInactivityTimeout() const
{
return m_networkInactivityTimeout;
}
bool CConf::getNetworkDebug() const bool CConf::getNetworkDebug() const
{ {
return m_networkDebug; return m_networkDebug;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -53,6 +53,7 @@ public:
std::string getNetworkParrotAddress() const; std::string getNetworkParrotAddress() const;
unsigned int getNetworkParrotPort() const; unsigned int getNetworkParrotPort() const;
unsigned int getNetworkStartup() const; unsigned int getNetworkStartup() const;
unsigned int getNetworkInactivityTimeout() const;
bool getNetworkDebug() const; bool getNetworkDebug() const;
private: private:
@ -76,6 +77,7 @@ private:
std::string m_networkParrotAddress; std::string m_networkParrotAddress;
unsigned int m_networkParrotPort; unsigned int m_networkParrotPort;
unsigned int m_networkStartup; unsigned int m_networkStartup;
unsigned int m_networkInactivityTimeout;
bool m_networkDebug; bool m_networkDebug;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -24,6 +24,7 @@
#include "Version.h" #include "Version.h"
#include "Thread.h" #include "Thread.h"
#include "Speech.h" #include "Speech.h"
#include "Timer.h"
#include "Log.h" #include "Log.h"
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -185,6 +186,7 @@ void CP25Gateway::run()
CDMRLookup* lookup = new CDMRLookup(m_conf.getLookupName(), m_conf.getLookupTime()); CDMRLookup* lookup = new CDMRLookup(m_conf.getLookupName(), m_conf.getLookupTime());
lookup->read(); lookup->read();
CTimer inactivityTimer(1000U, m_conf.getNetworkInactivityTimeout());
CTimer lostTimer(1000U, 120U); CTimer lostTimer(1000U, 120U);
CTimer pollTimer(1000U, 5U); CTimer pollTimer(1000U, 5U);
@ -324,6 +326,7 @@ void CP25Gateway::run()
} }
remoteNetwork.writeData(buffer, len, currentAddr, currentPort); remoteNetwork.writeData(buffer, len, currentAddr, currentPort);
inactivityTimer.start();
} }
} }
@ -335,6 +338,26 @@ void CP25Gateway::run()
if (speech != NULL) if (speech != NULL)
speech->clock(ms); speech->clock(ms);
inactivityTimer.clock(ms);
if (inactivityTimer.isRunning() && inactivityTimer.hasExpired()) {
if (currentId != 9999U) {
LogMessage("Unlinking from %u due to inactivity", currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
if (speech != NULL)
speech->announce(currentId);
currentId = 9999U;
pollTimer.stop();
lostTimer.stop();
}
inactivityTimer.stop();
}
pollTimer.clock(ms); pollTimer.clock(ms);
if (pollTimer.isRunning() && pollTimer.hasExpired()) { if (pollTimer.isRunning() && pollTimer.hasExpired()) {
if (currentId != 9999U) if (currentId != 9999U)

View File

@ -1,5 +1,5 @@
[General] [General]
Callsign=G9BF Callsign=G4KLX
RptAddress=127.0.0.1 RptAddress=127.0.0.1
RptPort=32010 RptPort=32010
LocalPort=42020 LocalPort=42020
@ -20,5 +20,6 @@ Hosts=P25Hosts.txt
ReloadTime=60 ReloadTime=60
ParrotAddress=127.0.0.1 ParrotAddress=127.0.0.1
ParrotPort=42011 ParrotPort=42011
Startup=10100 # Startup=10100
InactivityTimeout=10
Debug=0 Debug=0