ECTableManager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 TABLEMANAGER_H
  18. #define TABLEMANAGER_H
  19. #include <kopano/zcdefs.h>
  20. #include <map>
  21. #include "ECDatabase.h"
  22. #include "ECGenericObjectTable.h"
  23. #include <kopano/kcodes.h>
  24. namespace KC {
  25. class ECSession;
  26. class ECSessionManager;
  27. /*
  28. * The table manager is responsible for opening tables, and providing
  29. * access to open tables by a handle ID for each table, and updating tables when
  30. * a change is made to the underlying data and sending notifications to clients
  31. * which require table update notifications.
  32. *
  33. * Each session has its own table manager. This could be optimised in the future
  34. * by having one large table manager, with each table having multiple cursors for
  35. * each user that has the table open. This would save memory on overlapping tables
  36. * (probably resulting in around 30% less memory usage for the server).
  37. */
  38. struct TABLE_ENTRY {
  39. enum TABLE_TYPE {
  40. TABLE_TYPE_GENERIC, TABLE_TYPE_OUTGOINGQUEUE, TABLE_TYPE_MULTISTORE, TABLE_TYPE_USERSTORES,
  41. TABLE_TYPE_SYSTEMSTATS, TABLE_TYPE_THREADSTATS, TABLE_TYPE_USERSTATS, TABLE_TYPE_SESSIONSTATS, TABLE_TYPE_COMPANYSTATS, TABLE_TYPE_SERVERSTATS,
  42. TABLE_TYPE_MAILBOX,
  43. };
  44. TABLE_TYPE ulTableType;
  45. union __sTable {
  46. struct __sGeneric {
  47. unsigned int ulParentId;
  48. unsigned int ulObjectType;
  49. unsigned int ulObjectFlags;
  50. } sGeneric ;
  51. struct __sOutgoingQueue {
  52. unsigned int ulStoreId;
  53. unsigned int ulFlags;
  54. } sOutgoingQueue;
  55. } sTable;
  56. ECGenericObjectTable *lpTable; // Actual table object
  57. unsigned int ulSubscriptionId; // Subscription ID for table event subscription on session manager
  58. };
  59. typedef std::map<unsigned int, TABLE_ENTRY *> TABLEENTRYMAP;
  60. class ECTableManager _kc_final {
  61. public:
  62. ECTableManager(ECSession *lpSession);
  63. ~ECTableManager();
  64. ECRESULT OpenGenericTable(unsigned int ulParent, unsigned int ulObjType, unsigned int ulFlags, unsigned int *lpulTableId, bool fLoad = true);
  65. ECRESULT OpenOutgoingQueueTable(unsigned int ulStoreId, unsigned int *lpulTableId);
  66. ECRESULT OpenABTable(unsigned int ulParent, unsigned int ulParentType, unsigned int ulObjType, unsigned int ulFlags, unsigned int *lpulTableId);
  67. ECRESULT OpenMultiStoreTable(unsigned int ulObjType, unsigned int ulFlags, unsigned int *lpulTableId);
  68. ECRESULT OpenUserStoresTable(unsigned int ulFlags, unsigned int *lpulTableId);
  69. ECRESULT OpenStatsTable(unsigned int ulTableType, unsigned int ulFlags, unsigned int *lpulTableId);
  70. ECRESULT OpenMailBoxTable(unsigned int ulflags, unsigned int *lpulTableId);
  71. ECRESULT GetTable(unsigned int lpulTableId, ECGenericObjectTable **lppTable);
  72. ECRESULT CloseTable(unsigned int lpulTableId);
  73. ECRESULT UpdateOutgoingTables(ECKeyTable::UpdateType ulType, unsigned int ulStoreId, std::list<unsigned int> &lstObjId, unsigned int ulFlags, unsigned int ulObjType);
  74. ECRESULT UpdateTables(ECKeyTable::UpdateType ulType, unsigned int ulFlags, unsigned int ulObjId, std::list<unsigned int> &lstChildId, unsigned int ulObjType);
  75. ECRESULT GetStats(unsigned int *lpulTables, unsigned int *lpulObjectSize);
  76. private:
  77. static void * SearchThread(void *lpParam);
  78. void AddTableEntry(TABLE_ENTRY *lpEntry, unsigned int *lpulTableId);
  79. ECSession *lpSession;
  80. TABLEENTRYMAP mapTable;
  81. unsigned int ulNextTableId = 1;
  82. std::recursive_mutex hListMutex;
  83. };
  84. } /* namespace */
  85. #endif // TABLEMANAGER_H