ECEnumFBBlock.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/ECInterfaceDefs.h>
  20. #include "ECEnumFBBlock.h"
  21. #include "freebusyutil.h"
  22. #include <kopano/stringutil.h>
  23. namespace KC {
  24. /**
  25. * @param[in] lpFBBlock Pointer to a list of free/busy blocks
  26. */
  27. ECEnumFBBlock::ECEnumFBBlock(ECFBBlockList* lpFBBlock)
  28. {
  29. FBBlock_1 sBlock;
  30. lpFBBlock->Reset();
  31. while(lpFBBlock->Next(&sBlock) == hrSuccess)
  32. m_FBBlock.Add(&sBlock);
  33. }
  34. /**
  35. * Create ECEnumFBBlock object
  36. *
  37. * @param[in] lpFBBlock Pointer to a list of free/busy blocks
  38. * @param[out] lppEnumFBBlock Address of the pointer that receives the object ECEnumFBBlock pointer
  39. */
  40. HRESULT ECEnumFBBlock::Create(ECFBBlockList* lpFBBlock, ECEnumFBBlock **lppEnumFBBlock)
  41. {
  42. HRESULT hr = hrSuccess;
  43. auto lpEnumFBBlock = new(std::nothrow) ECEnumFBBlock(lpFBBlock);
  44. if (lpEnumFBBlock == nullptr)
  45. return MAPI_E_NOT_ENOUGH_MEMORY;
  46. hr = lpEnumFBBlock->QueryInterface(IID_ECEnumFBBlock, (void **)lppEnumFBBlock);
  47. if(hr != hrSuccess)
  48. delete lpEnumFBBlock;
  49. return hr;
  50. }
  51. /**
  52. * This method returns a pointer to a specified interface on an object to which a client
  53. * currently holds an interface pointer.
  54. *
  55. * @param[in] iid Identifier of the interface being requested.
  56. * @param[out] ppvObject Address of the pointer that receives the interface pointer requested in riid.
  57. *
  58. * @retval hrSuccess Indicates that the interface is supported.
  59. * @retval MAPI_E_INTERFACE_NOT_SUPPORTED Indicates that the interface is not supported.
  60. */
  61. HRESULT ECEnumFBBlock::QueryInterface(REFIID refiid , void** lppInterface)
  62. {
  63. REGISTER_INTERFACE2(ECEnumFBBlock, this);
  64. REGISTER_INTERFACE2(ECUnknown, this);
  65. REGISTER_INTERFACE2(IEnumFBBlock, &this->m_xEnumFBBlock);
  66. REGISTER_INTERFACE2(IUnknown, &this->m_xEnumFBBlock);
  67. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  68. }
  69. /*! @copydoc IEnumFBBlock::Next */
  70. HRESULT ECEnumFBBlock::Next(LONG celt, FBBlock_1 *pblk, LONG *pcfetch)
  71. {
  72. LONG cEltFound = 0;
  73. for (LONG i = 0; i < celt; ++i) {
  74. if(m_FBBlock.Next(&pblk[i]) != hrSuccess)
  75. break;
  76. ++cEltFound;
  77. }
  78. if(pcfetch)
  79. *pcfetch = cEltFound;
  80. return cEltFound == 0;
  81. }
  82. /*! @copydoc IEnumFBBlock::Skip */
  83. HRESULT ECEnumFBBlock::Skip(LONG celt)
  84. {
  85. return m_FBBlock.Skip(celt);
  86. }
  87. /*! @copydoc IEnumFBBlock::Reset */
  88. HRESULT ECEnumFBBlock::Reset()
  89. {
  90. return m_FBBlock.Reset();
  91. }
  92. /*! @copydoc IEnumFBBlock::Restrict */
  93. HRESULT ECEnumFBBlock::Restrict(FILETIME ftmStart, FILETIME ftmEnd)
  94. {
  95. LONG rtmStart = 0;
  96. LONG rtmEnd = 0;
  97. FileTimeToRTime(&ftmStart, &rtmStart);
  98. FileTimeToRTime(&ftmEnd, &rtmEnd);
  99. return m_FBBlock.Restrict(rtmStart, rtmEnd);
  100. }
  101. DEF_HRMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, QueryInterface, (REFIID, refiid), (void**, lppInterface))
  102. DEF_ULONGMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, AddRef, (void))
  103. DEF_ULONGMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, Release, (void))
  104. DEF_HRMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, Next, (LONG, celt), (FBBlock_1 *, pblk), (LONG *, pcfetch))
  105. DEF_HRMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, Skip, (LONG, celt))
  106. DEF_HRMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, Reset, (void))
  107. DEF_HRMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, Clone, (IEnumFBBlock **, ppclone))
  108. DEF_HRMETHOD1(TRACE_MAPI, ECEnumFBBlock, EnumFBBlock, Restrict, (FILETIME, ftmStart), (FILETIME, ftmEnd))
  109. } /* namespace */