Allow revertion to startup reflector.
This commit is contained in:
parent
62f45b6c10
commit
8490ea46a5
6 changed files with 71 additions and 12 deletions
|
@ -68,6 +68,7 @@ m_networkParrotAddress("127.0.0.1"),
|
|||
m_networkParrotPort(0U),
|
||||
m_networkStartup(),
|
||||
m_networkInactivityTimeout(0U),
|
||||
m_networkRevert(false),
|
||||
m_networkDebug(false)
|
||||
{
|
||||
}
|
||||
|
@ -186,6 +187,8 @@ bool CConf::read()
|
|||
m_networkStartup = value;
|
||||
else if (::strcmp(key, "InactivityTimeout") == 0)
|
||||
m_networkInactivityTimeout = (unsigned int)::atoi(value);
|
||||
else if (::strcmp(key, "Revert") == 0)
|
||||
m_networkRevert = ::atoi(value) == 1;
|
||||
else if (::strcmp(key, "Debug") == 0)
|
||||
m_networkDebug = ::atoi(value) == 1;
|
||||
}
|
||||
|
@ -351,6 +354,11 @@ unsigned int CConf::getNetworkInactivityTimeout() const
|
|||
return m_networkInactivityTimeout;
|
||||
}
|
||||
|
||||
bool CConf::getNetworkRevert() const
|
||||
{
|
||||
return m_networkRevert;
|
||||
}
|
||||
|
||||
bool CConf::getNetworkDebug() const
|
||||
{
|
||||
return m_networkDebug;
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
unsigned int getNetworkParrotPort() const;
|
||||
std::string getNetworkStartup() const;
|
||||
unsigned int getNetworkInactivityTimeout() const;
|
||||
bool getNetworkRevert() const;
|
||||
bool getNetworkDebug() const;
|
||||
|
||||
private:
|
||||
|
@ -109,6 +110,7 @@ private:
|
|||
unsigned int m_networkParrotPort;
|
||||
std::string m_networkStartup;
|
||||
unsigned int m_networkInactivityTimeout;
|
||||
bool m_networkRevert;
|
||||
bool m_networkDebug;
|
||||
};
|
||||
|
||||
|
|
|
@ -292,6 +292,14 @@ WX_STATUS CWiresX::processConnect(const unsigned char* source, const unsigned ch
|
|||
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)
|
||||
{
|
||||
if (source != NULL)
|
||||
|
|
|
@ -55,7 +55,8 @@ public:
|
|||
CYSFReflector* getReflector() const;
|
||||
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);
|
||||
|
||||
|
|
|
@ -197,6 +197,9 @@ int CYSFGateway::run()
|
|||
CTimer lostTimer(1000U, 120U);
|
||||
CTimer pollTimer(1000U, 5U);
|
||||
|
||||
bool revert = m_conf.getNetworkRevert();
|
||||
std::string startup = m_conf.getNetworkStartup();
|
||||
|
||||
bool networkEnabled = m_conf.getNetworkEnabled();
|
||||
if (networkEnabled) {
|
||||
std::string fileName = m_conf.getNetworkHosts();
|
||||
|
@ -218,7 +221,6 @@ int CYSFGateway::run()
|
|||
|
||||
m_wiresX->start();
|
||||
|
||||
std::string startup = m_conf.getNetworkStartup();
|
||||
if (!startup.empty()) {
|
||||
CYSFReflector* reflector = m_wiresX->getReflector(startup);
|
||||
if (reflector != NULL) {
|
||||
|
@ -342,20 +344,57 @@ int CYSFGateway::run()
|
|||
inactivityTimer.clock(ms);
|
||||
if (inactivityTimer.isRunning() && inactivityTimer.hasExpired()) {
|
||||
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->processDisconnect();
|
||||
if (m_wiresX != NULL)
|
||||
m_wiresX->processConnect(reflector);
|
||||
|
||||
m_netNetwork->writeUnlink();
|
||||
m_netNetwork->writeUnlink();
|
||||
m_netNetwork->writeUnlink();
|
||||
m_netNetwork->clearDestination();
|
||||
m_netNetwork->writeUnlink();
|
||||
m_netNetwork->writeUnlink();
|
||||
m_netNetwork->writeUnlink();
|
||||
|
||||
lostTimer.stop();
|
||||
pollTimer.stop();
|
||||
m_netNetwork->setDestination(reflector->m_address, reflector->m_port);
|
||||
m_netNetwork->writePoll();
|
||||
m_netNetwork->writePoll();
|
||||
m_netNetwork->writePoll();
|
||||
|
||||
m_linked = false;
|
||||
lostTimer.start();
|
||||
pollTimer.start();
|
||||
} 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;
|
||||
}
|
||||
} 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();
|
||||
|
|
|
@ -41,4 +41,5 @@ ParrotAddress=127.0.0.1
|
|||
ParrotPort=42000
|
||||
# Startup=
|
||||
InactivityTimeout=10
|
||||
# Revert=0
|
||||
Debug=0
|
||||
|
|
Loading…
Reference in a new issue