SessionGroupData.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <new>
  18. #include <kopano/platform.h>
  19. #include <kopano/lockhelper.hpp>
  20. #include <mapicode.h>
  21. #include <mapix.h>
  22. #include "ClientUtil.h"
  23. #include "ECNotifyMaster.h"
  24. #include "ECSessionGroupManager.h"
  25. #include "SessionGroupData.h"
  26. #include "WSTransport.h"
  27. SessionGroupData::SessionGroupData(ECSESSIONGROUPID ecSessionGroupId,
  28. ECSessionGroupInfo *lpInfo, const sGlobalProfileProps &sProfileProps) :
  29. m_ecSessionGroupId(ecSessionGroupId), m_sProfileProps(sProfileProps)
  30. {
  31. if (lpInfo == nullptr)
  32. return;
  33. m_ecSessionGroupInfo.strServer = lpInfo->strServer;
  34. m_ecSessionGroupInfo.strProfile = lpInfo->strProfile;
  35. }
  36. SessionGroupData::~SessionGroupData(void)
  37. {
  38. if (m_lpNotifyMaster)
  39. m_lpNotifyMaster->Release();
  40. }
  41. HRESULT SessionGroupData::Create(ECSESSIONGROUPID ecSessionGroupId, ECSessionGroupInfo *lpInfo, const sGlobalProfileProps &sProfileProps, SessionGroupData **lppData)
  42. {
  43. HRESULT hr = hrSuccess;
  44. auto lpData = new(std::nothrow) SessionGroupData(ecSessionGroupId, lpInfo, sProfileProps);
  45. if (lpData == nullptr)
  46. return MAPI_E_NOT_ENOUGH_MEMORY;
  47. lpData->AddRef();
  48. *lppData = lpData;
  49. return hr;
  50. }
  51. HRESULT SessionGroupData::GetOrCreateNotifyMaster(ECNotifyMaster **lppMaster)
  52. {
  53. HRESULT hr = hrSuccess;
  54. scoped_rlock lock(m_hMutex);
  55. if (!m_lpNotifyMaster)
  56. hr = ECNotifyMaster::Create(this, &m_lpNotifyMaster);
  57. *lppMaster = m_lpNotifyMaster;
  58. return hr;
  59. }
  60. HRESULT SessionGroupData::GetTransport(WSTransport **lppTransport)
  61. {
  62. HRESULT hr;
  63. WSTransport *lpTransport = NULL;
  64. hr = WSTransport::Create(MDB_NO_DIALOG, &lpTransport);
  65. if (hr != hrSuccess)
  66. return hr;
  67. hr = lpTransport->HrLogon(m_sProfileProps);
  68. if (hr != hrSuccess)
  69. return hr;
  70. // Since we are doing request that take max EC_SESSION_KEEPALIVE_TIME, set timeout to that plus 10 seconds
  71. lpTransport->HrSetRecvTimeout(EC_SESSION_KEEPALIVE_TIME + 10);
  72. *lppTransport = lpTransport;
  73. return hrSuccess;
  74. }
  75. ECSESSIONGROUPID SessionGroupData::GetSessionGroupId()
  76. {
  77. return m_ecSessionGroupId;
  78. }
  79. ULONG SessionGroupData::AddRef()
  80. {
  81. scoped_rlock lock(m_hRefMutex);
  82. return ++m_cRef;
  83. }
  84. ULONG SessionGroupData::Release()
  85. {
  86. scoped_rlock lock(m_hRefMutex);
  87. return --m_cRef;
  88. }
  89. BOOL SessionGroupData::IsOrphan()
  90. {
  91. return m_cRef == 0;
  92. }