ECMemTable.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #ifndef ECMEMTABLE_H
  18. #define ECMEMTABLE_H
  19. #include <kopano/zcdefs.h>
  20. #include <vector>
  21. #include <map>
  22. #include <mutex>
  23. #include <mapitags.h>
  24. #include <mapidefs.h>
  25. #include <kopano/ECKeyTable.h>
  26. #include <kopano/ECUnknown.h>
  27. #include <kopano/ustringutil.h>
  28. namespace KC {
  29. struct ECTableEntry {
  30. LPSPropValue lpsPropVal;
  31. BOOL fDeleted;
  32. BOOL fDirty;
  33. BOOL fNew;
  34. LPSPropValue lpsID;
  35. ULONG cValues;
  36. };
  37. struct ECMEMADVISE {
  38. ULONG ulEventMask;
  39. LPMAPIADVISESINK lpAdviseSink;
  40. //ULONG ulConnection;
  41. };
  42. typedef std::map<int, ECMEMADVISE *> ECMapMemAdvise;
  43. /* Status returned in HrGetAllWithStatus() */
  44. #define ECROW_NORMAL 0
  45. #define ECROW_ADDED 1
  46. #define ECROW_MODIFIED 2
  47. #define ECROW_DELETED 3
  48. /*
  49. * This is a client-side implementation of IMAPITable, based on
  50. * SPropValue's. You can add/delete/modify data through HrModifyRow
  51. * and you can get the data from its IMAPITable interface
  52. *
  53. * We use the ECKeyTable engine for the actual cursor/sorting system
  54. */
  55. class ECMemTableView;
  56. class _kc_export ECMemTable : public ECUnknown {
  57. protected:
  58. ECMemTable(const SPropTagArray *lpsPropTagArray, ULONG ulRowPropTag);
  59. virtual ~ECMemTable();
  60. public:
  61. static HRESULT Create(const SPropTagArray *lpsPropTagArray, ULONG ulRowPropTag, ECMemTable **lppRecipTable);
  62. _kc_hidden virtual HRESULT QueryInterface(REFIID refiid, void **iface) _kc_override;
  63. virtual HRESULT HrGetView(const ECLocale &locale, ULONG ulFlags, ECMemTableView **lpView);
  64. virtual HRESULT HrModifyRow(ULONG flags, const SPropValue *id, const SPropValue *prop, ULONG n);
  65. virtual HRESULT HrUpdateRowID(LPSPropValue lpId, LPSPropValue lpProps, ULONG cValues);
  66. virtual HRESULT HrClear();
  67. virtual HRESULT HrDeleteAll();
  68. // Get the modified, deleted and added tables in the row
  69. virtual HRESULT HrGetAllWithStatus(LPSRowSet *lppRowSet, LPSPropValue *lppIDs, LPULONG *lppulStatus);
  70. virtual HRESULT HrGetRowID(LPSPropValue lpRow, LPSPropValue *lpID);
  71. virtual HRESULT HrGetRowData(LPSPropValue lpRow, ULONG *lpcValues, LPSPropValue *lppRowData);
  72. // Update all rows as being clean, remove deleted rows
  73. virtual HRESULT HrSetClean();
  74. protected:
  75. // Data
  76. std::map<unsigned int, ECTableEntry> mapRows;
  77. std::vector<ECMemTableView *> lstViews;
  78. LPSPropTagArray lpsColumns;
  79. ULONG ulRowPropTag;
  80. std::recursive_mutex m_hDataMutex;
  81. friend class ECMemTableView;
  82. };
  83. class _kc_export ECMemTableView _kc_final : public ECUnknown {
  84. protected:
  85. _kc_hidden ECMemTableView(ECMemTable *, const ECLocale &, ULONG flags);
  86. _kc_hidden virtual ~ECMemTableView(void);
  87. public:
  88. _kc_hidden static HRESULT Create(ECMemTable *, const ECLocale &, ULONG flags, ECMemTableView **ret);
  89. virtual HRESULT QueryInterface(REFIID refiid, void **iface) _kc_override;
  90. _kc_hidden virtual HRESULT UpdateRow(ULONG update_type, ULONG id);
  91. _kc_hidden virtual HRESULT Clear(void);
  92. _kc_hidden virtual HRESULT GetLastError(HRESULT, ULONG flags, LPMAPIERROR *ret);
  93. _kc_hidden virtual HRESULT Advise(ULONG event_mask, LPMAPIADVISESINK, ULONG *conn);
  94. _kc_hidden virtual HRESULT Unadvise(ULONG conn);
  95. _kc_hidden virtual HRESULT GetStatus(ULONG *table_status, ULONG *table_type);
  96. virtual HRESULT SetColumns(const SPropTagArray *lpPropTagArray, ULONG ulFlags);
  97. virtual HRESULT QueryColumns(ULONG ulFlags, LPSPropTagArray *lpPropTagArray);
  98. _kc_hidden virtual HRESULT GetRowCount(ULONG flags, ULONG *count);
  99. _kc_hidden virtual HRESULT SeekRow(BOOKMARK origin, LONG row_coutn, LONG *rows_sought);
  100. _kc_hidden virtual HRESULT SeekRowApprox(ULONG numerator, ULONG denominator);
  101. _kc_hidden virtual HRESULT QueryPosition(ULONG *row, ULONG *numerator, ULONG *denominator);
  102. _kc_hidden virtual HRESULT FindRow(LPSRestriction, BOOKMARK origin, ULONG flags);
  103. _kc_hidden virtual HRESULT Restrict(LPSRestriction, ULONG flags);
  104. _kc_hidden virtual HRESULT CreateBookmark(BOOKMARK *pos);
  105. _kc_hidden virtual HRESULT FreeBookmark(BOOKMARK pos);
  106. _kc_hidden virtual HRESULT SortTable(const SSortOrderSet *sort_crit, ULONG flags);
  107. _kc_hidden virtual HRESULT QuerySortOrder(LPSSortOrderSet *sort_crit);
  108. virtual HRESULT QueryRows(LONG lRowCount, ULONG ulFlags, LPSRowSet *lppRows);
  109. _kc_hidden virtual HRESULT Abort(void);
  110. _kc_hidden virtual HRESULT ExpandRow(ULONG ikey_size, LPBYTE ikey, ULONG row_count, ULONG flags, LPSRowSet *rows, ULONG *more_rows);
  111. _kc_hidden virtual HRESULT CollapseRow(ULONG ikey_size, LPBYTE ikey, ULONG flags, ULONG *row_count);
  112. _kc_hidden virtual HRESULT WaitForCompletion(ULONG flags, ULONG timeout, ULONG *table_status);
  113. _kc_hidden virtual HRESULT GetCollapseState(ULONG flags, ULONG ikey_size, LPBYTE ikey, ULONG *collapse_size, LPBYTE *collapse_state);
  114. _kc_hidden virtual HRESULT SetCollapseState(ULONG flags, ULONG collapse_size, LPBYTE collapse_state, BOOKMARK *location);
  115. class _kc_hidden xMAPITable _kc_final : public IMAPITable {
  116. #include <kopano/xclsfrag/IUnknown.hpp>
  117. #include <kopano/xclsfrag/IMAPITable.hpp>
  118. } m_xMAPITable;
  119. private:
  120. _kc_hidden HRESULT __stdcall GetBinarySortKey(const SPropValue *pv, unsigned int *sortlen, unsigned char *flags, unsigned char **sortdata);
  121. _kc_hidden HRESULT ModifyRowKey(sObjectTableKey *row_item, sObjectTableKey *prev_row, ULONG *action);
  122. _kc_hidden HRESULT QueryRowData(ECObjectTableList *row_list, LPSRowSet *rows);
  123. _kc_hidden HRESULT Notify(ULONG table_event, sObjectTableKey *row_item, sObjectTableKey *prev_row);
  124. ECKeyTable * lpKeyTable;
  125. SSortOrderSet *lpsSortOrderSet = nullptr;
  126. LPSPropTagArray lpsPropTags; // Columns
  127. SRestriction *lpsRestriction = nullptr;
  128. ECMemTable * lpMemTable;
  129. ECMapMemAdvise m_mapAdvise;
  130. ULONG m_ulConnection = 1; // Next advise id
  131. ECLocale m_locale;
  132. ULONG m_ulFlags;
  133. _kc_hidden virtual HRESULT UpdateSortOrRestrict(void);
  134. };
  135. } /* namespace */
  136. #endif // ECMemTable_H