ECSyncSettings.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <kopano/platform.h>
  18. #include <mutex>
  19. #include <kopano/lockhelper.hpp>
  20. #include "ECSyncSettings.h"
  21. #include <mapix.h>
  22. #include <kopano/ECLogger.h>
  23. ECSyncSettings* ECSyncSettings::GetInstance()
  24. {
  25. scoped_lock lock(s_hMutex);
  26. if (s_lpInstance == NULL)
  27. s_lpInstance = new ECSyncSettings;
  28. return s_lpInstance;
  29. }
  30. ECSyncSettings::ECSyncSettings(void) :
  31. m_ulSyncLogLevel(EC_LOGLEVEL_INFO)
  32. {
  33. char *env = getenv("KOPANO_SYNC_LOGLEVEL");
  34. if (env && env[0] != '\0') {
  35. unsigned loglevel = strtoul(env, NULL, 10);
  36. if (loglevel > 0) {
  37. m_ulSyncLog = 1;
  38. m_ulSyncLogLevel = loglevel;
  39. }
  40. }
  41. env = getenv("KOPANO_STREAM_TIMEOUT");
  42. if (env && env[0] != '\0')
  43. m_ulStreamTimeout = strtoul(env, NULL, 10);
  44. env = getenv("KOPANO_STREAM_BUFFERSIZE");
  45. if (env && env[0] != '\0')
  46. m_ulStreamBufferSize = strtoul(env, NULL, 10);
  47. env = getenv("KOPANO_STREAM_BATCHSIZE");
  48. if (env && env[0] != '\0')
  49. m_ulStreamBatchSize = strtoul(env, NULL, 10);
  50. }
  51. bool ECSyncSettings::SyncLogEnabled() const {
  52. return ContinuousLogging() ? true : m_ulSyncLog != 0;
  53. }
  54. ULONG ECSyncSettings::SyncLogLevel() const {
  55. return ContinuousLogging() ? EC_LOGLEVEL_DEBUG : m_ulSyncLogLevel;
  56. }
  57. bool ECSyncSettings::ContinuousLogging() const {
  58. return m_ulSyncOpts & EC_SYNC_OPT_CONTINUOUS;
  59. }
  60. bool ECSyncSettings::SyncStreamEnabled() const {
  61. return m_ulSyncOpts & EC_SYNC_OPT_STREAM;
  62. }
  63. bool ECSyncSettings::ChangeNotificationsEnabled() const {
  64. return m_ulSyncOpts & EC_SYNC_OPT_CHANGENOTIF;
  65. }
  66. bool ECSyncSettings::StateCollectorEnabled() const {
  67. return m_ulSyncOpts & EC_SYNC_OPT_STATECOLLECT;
  68. }
  69. ULONG ECSyncSettings::StreamTimeout() const {
  70. return m_ulStreamTimeout;
  71. }
  72. ULONG ECSyncSettings::StreamBufferSize() const {
  73. return m_ulStreamBufferSize;
  74. }
  75. ULONG ECSyncSettings::StreamBatchSize() const {
  76. return m_ulStreamBatchSize;
  77. }
  78. /**
  79. * Enable/disable the synclog.
  80. * @param[in] bEnable Set to true to enable the synclog.
  81. * @retval The previous value.
  82. */
  83. bool ECSyncSettings::EnableSyncLog(bool bEnable) {
  84. bool bPrev = SyncLogEnabled();
  85. m_ulSyncLog = (bEnable ? 1 : 0);
  86. return bPrev;
  87. }
  88. /**
  89. * Set the synclog loglevel.
  90. * @param[in] ulLogLevel The new loglevel.
  91. * @retval The previous loglevel.
  92. * @note The loglevel returned by this function can differ
  93. * from the level returned by SyncLogLevel() when
  94. * continuous logging is enabled, in which case
  95. * SyncLogLevel() will always return EC_LOGLEVEL_DEBUG.
  96. */
  97. ULONG ECSyncSettings::SetSyncLogLevel(ULONG ulLogLevel) {
  98. ULONG ulPrev = m_ulSyncLogLevel;
  99. if (ulLogLevel >= EC_LOGLEVEL_FATAL && ulLogLevel <= EC_LOGLEVEL_DEBUG)
  100. m_ulSyncLogLevel = ulLogLevel;
  101. return ulPrev;
  102. }
  103. /**
  104. * Set the sync options.
  105. * @param[in] ulOptions The options to enable
  106. * @retval The previous value.
  107. */
  108. ULONG ECSyncSettings::SetSyncOptions(ULONG ulOptions) {
  109. ULONG ulPrev = m_ulSyncOpts;
  110. m_ulSyncOpts = ulOptions;
  111. return ulPrev;
  112. }
  113. /**
  114. * Set the stream timeout.
  115. * This is the timeout used by the asynchronous components. This has nothing
  116. * to do with network timeouts.
  117. * @param[in] ulTimeout The new timeout in milliseconds
  118. * @retval The previous value.
  119. * @note No validation of the passed value is performed. So setting
  120. * this to an insane value will result in insane behavior.
  121. */
  122. ULONG ECSyncSettings::SetStreamTimeout(ULONG ulTimeout) {
  123. ULONG ulPrev = m_ulStreamTimeout;
  124. m_ulStreamTimeout = ulTimeout;
  125. return ulPrev;
  126. }
  127. /**
  128. * Set the stream buffer size.
  129. * This is the size of the buffer that is used to transfer data from the
  130. * exporter to the importer.
  131. * @param[in] ulBufferSize The new buffer size in bytes.
  132. * @retval The previous value.
  133. * @note No validation of the passed value is performed. So setting
  134. * this to an insane value will result in insane behavior.
  135. */
  136. ULONG ECSyncSettings::SetStreamBufferSize(ULONG ulBufferSize) {
  137. ULONG ulPrev = m_ulStreamBufferSize;
  138. m_ulStreamBufferSize = ulBufferSize;
  139. return ulPrev;
  140. }
  141. /**
  142. * Set the stream batch size.
  143. * This is the number of messages that is requested by the exporter from the
  144. * server in one batch.
  145. * @param[in] ulTimeout The new size in messages
  146. * @retval The previous value.
  147. * @note No validation of the passed value is performed. So setting
  148. * this to an insane value will result in insane behavior.
  149. */
  150. ULONG ECSyncSettings::SetStreamBatchSize(ULONG ulBatchSize) {
  151. ULONG ulPrev = m_ulStreamBatchSize;
  152. m_ulStreamBatchSize = ulBatchSize;
  153. return ulPrev;
  154. }
  155. std::mutex ECSyncSettings::s_hMutex;
  156. ECSyncSettings* ECSyncSettings::s_lpInstance = NULL;
  157. ECSyncSettings::__initializer::~__initializer() {
  158. delete ECSyncSettings::s_lpInstance;
  159. }
  160. ECSyncSettings::__initializer ECSyncSettings::__i;