From 1225e0bc87bb20dc43db13017576f88b2fcaef27 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 18 Mar 2017 07:13:14 +0000 Subject: [PATCH] Add an inactivity timer to the gateway. --- P25Gateway/Conf.cpp | 10 +++++++++- P25Gateway/Conf.h | 4 +++- P25Gateway/P25Gateway.cpp | 25 ++++++++++++++++++++++++- P25Gateway/P25Gateway.ini | 5 +++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/P25Gateway/Conf.cpp b/P25Gateway/Conf.cpp index f078617..6df825f 100644 --- a/P25Gateway/Conf.cpp +++ b/P25Gateway/Conf.cpp @@ -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 * 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_networkParrotPort(0U), m_networkStartup(9999U), +m_networkInactivityTimeout(0U), m_networkDebug(false) { } @@ -134,6 +135,8 @@ bool CConf::read() m_networkParrotPort = (unsigned int)::atoi(value); else if (::strcmp(key, "Startup") == 0) m_networkStartup = (unsigned int)::atoi(value); + else if (::strcmp(key, "InactivityTimeout") == 0) + m_networkInactivityTimeout = (unsigned int)::atoi(value); else if (::strcmp(key, "Debug") == 0) m_networkDebug = ::atoi(value) == 1; } @@ -224,6 +227,11 @@ unsigned int CConf::getNetworkStartup() const return m_networkStartup; } +unsigned int CConf::getNetworkInactivityTimeout() const +{ + return m_networkInactivityTimeout; +} + bool CConf::getNetworkDebug() const { return m_networkDebug; diff --git a/P25Gateway/Conf.h b/P25Gateway/Conf.h index 24623b5..45594f3 100644 --- a/P25Gateway/Conf.h +++ b/P25Gateway/Conf.h @@ -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 * it under the terms of the GNU General Public License as published by @@ -53,6 +53,7 @@ public: std::string getNetworkParrotAddress() const; unsigned int getNetworkParrotPort() const; unsigned int getNetworkStartup() const; + unsigned int getNetworkInactivityTimeout() const; bool getNetworkDebug() const; private: @@ -76,6 +77,7 @@ private: std::string m_networkParrotAddress; unsigned int m_networkParrotPort; unsigned int m_networkStartup; + unsigned int m_networkInactivityTimeout; bool m_networkDebug; }; diff --git a/P25Gateway/P25Gateway.cpp b/P25Gateway/P25Gateway.cpp index be3e4d9..435161e 100644 --- a/P25Gateway/P25Gateway.cpp +++ b/P25Gateway/P25Gateway.cpp @@ -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 * it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include "Version.h" #include "Thread.h" #include "Speech.h" +#include "Timer.h" #include "Log.h" #if defined(_WIN32) || defined(_WIN64) @@ -185,6 +186,7 @@ void CP25Gateway::run() CDMRLookup* lookup = new CDMRLookup(m_conf.getLookupName(), m_conf.getLookupTime()); lookup->read(); + CTimer inactivityTimer(1000U, m_conf.getNetworkInactivityTimeout()); CTimer lostTimer(1000U, 120U); CTimer pollTimer(1000U, 5U); @@ -324,6 +326,7 @@ void CP25Gateway::run() } remoteNetwork.writeData(buffer, len, currentAddr, currentPort); + inactivityTimer.start(); } } @@ -335,6 +338,26 @@ void CP25Gateway::run() if (speech != NULL) 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); if (pollTimer.isRunning() && pollTimer.hasExpired()) { if (currentId != 9999U) diff --git a/P25Gateway/P25Gateway.ini b/P25Gateway/P25Gateway.ini index c2dc737..a0cff5d 100644 --- a/P25Gateway/P25Gateway.ini +++ b/P25Gateway/P25Gateway.ini @@ -1,5 +1,5 @@ [General] -Callsign=G9BF +Callsign=G4KLX RptAddress=127.0.0.1 RptPort=32010 LocalPort=42020 @@ -20,5 +20,6 @@ Hosts=P25Hosts.txt ReloadTime=60 ParrotAddress=127.0.0.1 ParrotPort=42011 -Startup=10100 +# Startup=10100 +InactivityTimeout=10 Debug=0