1
0
Fork 0

Allow revertion to startup reflector.

ycs232-kbc
Jonathan Naylor 8 years ago
parent 62f45b6c10
commit 8490ea46a5

@ -68,6 +68,7 @@ m_networkParrotAddress("127.0.0.1"),
m_networkParrotPort(0U), m_networkParrotPort(0U),
m_networkStartup(), m_networkStartup(),
m_networkInactivityTimeout(0U), m_networkInactivityTimeout(0U),
m_networkRevert(false),
m_networkDebug(false) m_networkDebug(false)
{ {
} }
@ -186,6 +187,8 @@ bool CConf::read()
m_networkStartup = value; m_networkStartup = value;
else if (::strcmp(key, "InactivityTimeout") == 0) else if (::strcmp(key, "InactivityTimeout") == 0)
m_networkInactivityTimeout = (unsigned int)::atoi(value); m_networkInactivityTimeout = (unsigned int)::atoi(value);
else if (::strcmp(key, "Revert") == 0)
m_networkRevert = ::atoi(value) == 1;
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
m_networkDebug = ::atoi(value) == 1; m_networkDebug = ::atoi(value) == 1;
} }
@ -351,6 +354,11 @@ unsigned int CConf::getNetworkInactivityTimeout() const
return m_networkInactivityTimeout; return m_networkInactivityTimeout;
} }
bool CConf::getNetworkRevert() const
{
return m_networkRevert;
}
bool CConf::getNetworkDebug() const bool CConf::getNetworkDebug() const
{ {
return m_networkDebug; return m_networkDebug;

@ -70,6 +70,7 @@ public:
unsigned int getNetworkParrotPort() const; unsigned int getNetworkParrotPort() const;
std::string getNetworkStartup() const; std::string getNetworkStartup() const;
unsigned int getNetworkInactivityTimeout() const; unsigned int getNetworkInactivityTimeout() const;
bool getNetworkRevert() const;
bool getNetworkDebug() const; bool getNetworkDebug() const;
private: private:
@ -109,6 +110,7 @@ private:
unsigned int m_networkParrotPort; unsigned int m_networkParrotPort;
std::string m_networkStartup; std::string m_networkStartup;
unsigned int m_networkInactivityTimeout; unsigned int m_networkInactivityTimeout;
bool m_networkRevert;
bool m_networkDebug; bool m_networkDebug;
}; };

@ -292,6 +292,14 @@ WX_STATUS CWiresX::processConnect(const unsigned char* source, const unsigned ch
return WXS_CONNECT; return WXS_CONNECT;
} }
void CWiresX::processConnect(CYSFReflector* reflector)
{
m_reflector = reflector;
m_status = WXSI_CONNECT;
m_timer.start();
}
void CWiresX::processDisconnect(const unsigned char* source) void CWiresX::processDisconnect(const unsigned char* source)
{ {
if (source != NULL) if (source != NULL)

@ -55,7 +55,8 @@ public:
CYSFReflector* getReflector() const; CYSFReflector* getReflector() const;
CYSFReflector* getReflector(const std::string& id); CYSFReflector* getReflector(const std::string& id);
void processDisconnect(const unsigned char* source = NULL); void processConnect(CYSFReflector* reflector);
void processDisconnect(const unsigned char* source = NULL);
void clock(unsigned int ms); void clock(unsigned int ms);

@ -197,6 +197,9 @@ int CYSFGateway::run()
CTimer lostTimer(1000U, 120U); CTimer lostTimer(1000U, 120U);
CTimer pollTimer(1000U, 5U); CTimer pollTimer(1000U, 5U);
bool revert = m_conf.getNetworkRevert();
std::string startup = m_conf.getNetworkStartup();
bool networkEnabled = m_conf.getNetworkEnabled(); bool networkEnabled = m_conf.getNetworkEnabled();
if (networkEnabled) { if (networkEnabled) {
std::string fileName = m_conf.getNetworkHosts(); std::string fileName = m_conf.getNetworkHosts();
@ -218,7 +221,6 @@ int CYSFGateway::run()
m_wiresX->start(); m_wiresX->start();
std::string startup = m_conf.getNetworkStartup();
if (!startup.empty()) { if (!startup.empty()) {
CYSFReflector* reflector = m_wiresX->getReflector(startup); CYSFReflector* reflector = m_wiresX->getReflector(startup);
if (reflector != NULL) { if (reflector != NULL) {
@ -342,20 +344,57 @@ int CYSFGateway::run()
inactivityTimer.clock(ms); inactivityTimer.clock(ms);
if (inactivityTimer.isRunning() && inactivityTimer.hasExpired()) { if (inactivityTimer.isRunning() && inactivityTimer.hasExpired()) {
if (m_linked) { if (m_linked) {
LogMessage("Disconnecting due to inactivity"); if (revert) {
CYSFReflector* reflector = m_wiresX->getReflector(startup);
if (reflector != NULL) {
LogMessage("Reverting connection to %s", reflector->m_id.c_str());
if (m_wiresX != NULL)
m_wiresX->processConnect(reflector);
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
if (m_wiresX != NULL) m_netNetwork->setDestination(reflector->m_address, reflector->m_port);
m_wiresX->processDisconnect(); m_netNetwork->writePoll();
m_netNetwork->writePoll();
m_netNetwork->writePoll();
m_netNetwork->writeUnlink(); lostTimer.start();
m_netNetwork->writeUnlink(); pollTimer.start();
m_netNetwork->writeUnlink(); } else {
m_netNetwork->clearDestination(); LogMessage("Disconnecting due to inactivity");
lostTimer.stop(); if (m_wiresX != NULL)
pollTimer.stop(); m_wiresX->processDisconnect();
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
m_netNetwork->clearDestination();
m_linked = false; lostTimer.stop();
pollTimer.stop();
m_linked = false;
}
} else {
LogMessage("Disconnecting due to inactivity");
if (m_wiresX != NULL)
m_wiresX->processDisconnect();
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
m_netNetwork->clearDestination();
lostTimer.stop();
pollTimer.stop();
m_linked = false;
}
} }
inactivityTimer.stop(); inactivityTimer.stop();

@ -41,4 +41,5 @@ ParrotAddress=127.0.0.1
ParrotPort=42000 ParrotPort=42000
# Startup= # Startup=
InactivityTimeout=10 InactivityTimeout=10
# Revert=0
Debug=0 Debug=0

Loading…
Cancel
Save