Remove redundant poll interval defaults

This commit is contained in:
Martchus 2018-10-25 18:22:07 +02:00
parent fbad874471
commit b9a65ef113
4 changed files with 44 additions and 21 deletions

View File

@ -227,6 +227,11 @@ int Application::loadConfig()
return res; return res;
} }
// disable polling for information which is not used by any CLI operation so far
m_settings.trafficPollInterval = 0;
m_settings.devStatsPollInterval = 0;
m_settings.errorsPollInterval = 0;
return 0; return 0;
} }

View File

@ -102,19 +102,20 @@ SyncthingConnection::SyncthingConnection(const QString &syncthingUrl, const QByt
, m_hasDiskEvents(false) , m_hasDiskEvents(false)
, m_lastFileDeleted(false) , m_lastFileDeleted(false)
{ {
m_trafficPollTimer.setInterval(2000); m_trafficPollTimer.setInterval(SyncthingConnectionSettings::defaultTrafficPollInterval);
m_trafficPollTimer.setTimerType(Qt::VeryCoarseTimer); m_trafficPollTimer.setTimerType(Qt::VeryCoarseTimer);
m_trafficPollTimer.setSingleShot(true); m_trafficPollTimer.setSingleShot(true);
QObject::connect(&m_trafficPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestConnections); QObject::connect(&m_trafficPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestConnections);
m_devStatsPollTimer.setInterval(60000); m_devStatsPollTimer.setInterval(SyncthingConnectionSettings::defaultDevStatusPollInterval);
m_devStatsPollTimer.setTimerType(Qt::VeryCoarseTimer); m_devStatsPollTimer.setTimerType(Qt::VeryCoarseTimer);
m_devStatsPollTimer.setSingleShot(true); m_devStatsPollTimer.setSingleShot(true);
QObject::connect(&m_devStatsPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestDeviceStatistics); QObject::connect(&m_devStatsPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestDeviceStatistics);
m_errorsPollTimer.setInterval(30000); m_errorsPollTimer.setInterval(SyncthingConnectionSettings::defaultErrorsPollInterval);
m_errorsPollTimer.setTimerType(Qt::VeryCoarseTimer); m_errorsPollTimer.setTimerType(Qt::VeryCoarseTimer);
m_errorsPollTimer.setSingleShot(true); m_errorsPollTimer.setSingleShot(true);
QObject::connect(&m_errorsPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestErrors); QObject::connect(&m_errorsPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestErrors);
m_autoReconnectTimer.setTimerType(Qt::VeryCoarseTimer); m_autoReconnectTimer.setTimerType(Qt::VeryCoarseTimer);
m_autoReconnectTimer.setInterval(SyncthingConnectionSettings::defaultReconnectInterval);
QObject::connect(&m_autoReconnectTimer, &QTimer::timeout, this, &SyncthingConnection::autoReconnect); QObject::connect(&m_autoReconnectTimer, &QTimer::timeout, this, &SyncthingConnection::autoReconnect);
#ifdef LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED #ifdef LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED
setupTestData(); setupTestData();
@ -176,6 +177,17 @@ bool SyncthingConnection::hasOutOfSyncDirs() const
return false; return false;
} }
/*!
* \brief Sets all polling intervals (traffic, device statistics, errors) to 0 so polling is disabled.
* \remarks Does not affect the auto-reconnect and does not affect the *long* polling for the event API.
*/
void SyncthingConnection::disablePolling()
{
setTrafficPollInterval(0);
setDevStatsPollInterval(0);
setErrorsPollInterval(0);
}
/*! /*!
* \brief Connects asynchronously to Syncthing. Does nothing if already connected. * \brief Connects asynchronously to Syncthing. Does nothing if already connected.
*/ */

View File

@ -127,6 +127,7 @@ public:
int autoReconnectInterval() const; int autoReconnectInterval() const;
unsigned int autoReconnectTries() const; unsigned int autoReconnectTries() const;
void setAutoReconnectInterval(int interval); void setAutoReconnectInterval(int interval);
void disablePolling();
// getter for information retrieved from Syncthing // getter for information retrieved from Syncthing
const QString &configDir() const; const QString &configDir() const;
@ -491,8 +492,8 @@ inline void SyncthingConnection::considerAllNotificationsRead()
} }
/*! /*!
* \brief Returns the interval for polling traffic status (which currently can not be received via event API) in milliseconds. * \brief Returns the interval for polling traffic status (which can not be received via event API) in milliseconds.
* \remarks Default value is 2000 milliseconds. * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled.
*/ */
inline int SyncthingConnection::trafficPollInterval() const inline int SyncthingConnection::trafficPollInterval() const
{ {
@ -500,8 +501,8 @@ inline int SyncthingConnection::trafficPollInterval() const
} }
/*! /*!
* \brief Sets the interval for polling traffic status (which currently can not be received via event API) in milliseconds. * \brief Sets the interval for polling traffic status (which can not be received via event API) in milliseconds.
* \remarks Default value is 2000 milliseconds. * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled.
*/ */
inline void SyncthingConnection::setTrafficPollInterval(int trafficPollInterval) inline void SyncthingConnection::setTrafficPollInterval(int trafficPollInterval)
{ {
@ -512,8 +513,8 @@ inline void SyncthingConnection::setTrafficPollInterval(int trafficPollInterval)
} }
/*! /*!
* \brief Returns the interval for polling device statistics (which currently can not be received via event API) in milliseconds. * \brief Returns the interval for polling device statistics (which can not be received via event API) in milliseconds.
* \remarks Default value is 60000 milliseconds. * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled.
*/ */
inline int SyncthingConnection::devStatsPollInterval() const inline int SyncthingConnection::devStatsPollInterval() const
{ {
@ -521,8 +522,8 @@ inline int SyncthingConnection::devStatsPollInterval() const
} }
/*! /*!
* \brief Sets the interval for polling device statistics (which currently can not be received via event API) in milliseconds. * \brief Sets the interval for polling device statistics (which can not be received via event API) in milliseconds.
* \remarks Default value is 60000 milliseconds. * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled.
*/ */
inline void SyncthingConnection::setDevStatsPollInterval(int devStatsPollInterval) inline void SyncthingConnection::setDevStatsPollInterval(int devStatsPollInterval)
{ {
@ -533,8 +534,8 @@ inline void SyncthingConnection::setDevStatsPollInterval(int devStatsPollInterva
} }
/*! /*!
* \brief Returns the interval for polling Syncthing errors (which currently can not be received via event API) in milliseconds. * \brief Returns the interval for polling Syncthing errors (which can not be received via event API) in milliseconds.
* \remarks Default value is 30000 milliseconds. * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled.
*/ */
inline int SyncthingConnection::errorsPollInterval() const inline int SyncthingConnection::errorsPollInterval() const
{ {
@ -542,8 +543,8 @@ inline int SyncthingConnection::errorsPollInterval() const
} }
/*! /*!
* \brief Sets the interval for polling Syncthing errors (which currently can not be received via event API) in milliseconds. * \brief Sets the interval for polling Syncthing errors (which can not be received via event API) in milliseconds.
* \remarks Default value is 30000 milliseconds. * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled.
*/ */
inline void SyncthingConnection::setErrorsPollInterval(int errorPollInterval) inline void SyncthingConnection::setErrorsPollInterval(int errorPollInterval)
{ {
@ -555,7 +556,7 @@ inline void SyncthingConnection::setErrorsPollInterval(int errorPollInterval)
/*! /*!
* \brief Returns the reconnect interval in milliseconds. * \brief Returns the reconnect interval in milliseconds.
* \remarks Default value is 0 which indicates disabled auto-reconnect. * \remarks For default value see SyncthingConnectionSettings. A value of 0 indicates that auto-reconnect is disabled.
*/ */
inline int SyncthingConnection::autoReconnectInterval() const inline int SyncthingConnection::autoReconnectInterval() const
{ {
@ -572,7 +573,7 @@ inline unsigned int SyncthingConnection::autoReconnectTries() const
/*! /*!
* \brief Sets the reconnect interval in milliseconds. * \brief Sets the reconnect interval in milliseconds.
* \remarks Default value is 0 which indicates disabled auto-reconnect. * \remarks For default value see SyncthingConnectionSettings. A value of 0 indicates that auto-reconnect is disabled.
*/ */
inline void SyncthingConnection::setAutoReconnectInterval(int interval) inline void SyncthingConnection::setAutoReconnectInterval(int interval)
{ {

View File

@ -16,13 +16,18 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnectionSettings {
QString userName; QString userName;
QString password; QString password;
QByteArray apiKey; QByteArray apiKey;
int trafficPollInterval = 2000; int trafficPollInterval = defaultTrafficPollInterval;
int devStatsPollInterval = 60000; int devStatsPollInterval = defaultDevStatusPollInterval;
int errorsPollInterval = 30000; int errorsPollInterval = defaultErrorsPollInterval;
int reconnectInterval = 30000; int reconnectInterval = defaultReconnectInterval;
QString httpsCertPath; QString httpsCertPath;
QList<QSslError> expectedSslErrors; QList<QSslError> expectedSslErrors;
bool loadHttpsCert(); bool loadHttpsCert();
static constexpr int defaultTrafficPollInterval = 5000;
static constexpr int defaultDevStatusPollInterval = 60000;
static constexpr int defaultErrorsPollInterval = 30000;
static constexpr int defaultReconnectInterval = 0;
}; };
} // namespace Data } // namespace Data