ECNotifyMaster.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 ECNOTIFYMASTER_H
  18. #define ECNOTIFYMASTER_H
  19. #include <list>
  20. #include <map>
  21. #include <mutex>
  22. #include <pthread.h>
  23. #include <kopano/zcdefs.h>
  24. #include "ECSessionGroupManager.h"
  25. #include <kopano/ECUnknown.h>
  26. #include <kopano/kcodes.h>
  27. class ECNotifyClient;
  28. class ECNotifyMaster;
  29. class WSTransport;
  30. struct notification;
  31. typedef std::list<notification*> NOTIFYLIST;
  32. typedef HRESULT(ECNotifyClient::*NOTIFYCALLBACK)(ULONG,const NOTIFYLIST &);
  33. class ECNotifySink _kc_final {
  34. public:
  35. ECNotifySink(ECNotifyClient *lpClient, NOTIFYCALLBACK fnCallback);
  36. HRESULT Notify(ULONG ulConnection, const NOTIFYLIST &lNotifications) const;
  37. bool IsClient(const ECNotifyClient *) const;
  38. private:
  39. ECNotifyClient *m_lpClient;
  40. NOTIFYCALLBACK m_fnCallback;
  41. };
  42. typedef std::list<ECNotifyClient*> NOTIFYCLIENTLIST;
  43. typedef std::map<ULONG, ECNotifySink> NOTIFYCONNECTIONCLIENTMAP;
  44. typedef std::map<ULONG, NOTIFYLIST> NOTIFYCONNECTIONMAP;
  45. class ECNotifyMaster _kc_final : public ECUnknown {
  46. protected:
  47. ECNotifyMaster(SessionGroupData *lpData);
  48. virtual ~ECNotifyMaster(void);
  49. public:
  50. static HRESULT Create(SessionGroupData *lpData, ECNotifyMaster **lppMaster);
  51. virtual HRESULT ConnectToSession();
  52. virtual HRESULT AddSession(ECNotifyClient* lpClient);
  53. virtual HRESULT ReleaseSession(ECNotifyClient* lpClient);
  54. virtual HRESULT ReserveConnection(ULONG *lpulConnection);
  55. virtual HRESULT ClaimConnection(ECNotifyClient* lpClient, NOTIFYCALLBACK fnCallback, ULONG ulConnection);
  56. virtual HRESULT DropConnection(ULONG ulConnection);
  57. private:
  58. /* Threading functions */
  59. virtual HRESULT StartNotifyWatch();
  60. virtual HRESULT StopNotifyWatch();
  61. static void* NotifyWatch(void *pTmpNotifyClient);
  62. /* List of Clients attached to this master */
  63. NOTIFYCLIENTLIST m_listNotifyClients;
  64. /* List of all connections, mapped to client */
  65. NOTIFYCONNECTIONCLIENTMAP m_mapConnections;
  66. /* Connection settings */
  67. SessionGroupData *m_lpSessionGroupData;
  68. WSTransport *m_lpTransport = nullptr;
  69. ULONG m_ulConnection = 0;
  70. /* Threading information */
  71. std::recursive_mutex m_hMutex;
  72. pthread_t m_hThread;
  73. BOOL m_bThreadRunning = false;
  74. BOOL m_bThreadExit = false;
  75. };
  76. #endif /* ECNOTIFYMASTER_H */