IMAPIOffline.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 IMAPIOFFLINE_INCLUDED
  18. #define IMAPIOFFLINE_INCLUDED
  19. #include <mapix.h>
  20. #include <mapidefs.h>
  21. namespace KC {
  22. /* interface IMAPIOfflineNotify, Notify */
  23. #define MAPIOFFLINE_ADVISE_DEFAULT (ULONG)0
  24. #define MAPIOFFLINE_UNADVISE_DEFAULT (ULONG)0
  25. #define MAPIOFFLINE_ADVISE_TYPE_STATECHANGE 1
  26. /* GetCapabilities */
  27. #define MAPIOFFLINE_CAPABILITY_OFFLINE 0x1
  28. #define MAPIOFFLINE_CAPABILITY_ONLINE 0x2
  29. /* SetCurrentState */
  30. #define MAPIOFFLINE_FLAG_BLOCK 0x00002000
  31. #define MAPIOFFLINE_FLAG_DEFAULT 0x00000000
  32. #define MAPIOFFLINE_STATE_ALL 0x003f037f
  33. /* GetCurrentState and SetCurrentState */
  34. #define MAPIOFFLINE_STATE_OFFLINE_MASK 0x00000003
  35. #define MAPIOFFLINE_STATE_OFFLINE 0x00000001
  36. #define MAPIOFFLINE_STATE_ONLINE 0x00000002
  37. enum MAPIOFFLINE_CALLBACK_TYPE {
  38. MAPIOFFLINE_CALLBACK_TYPE_NOTIFY = 0
  39. };
  40. // The MAPIOFFLINE_NOTIFY_TYPE of a notification identifies if a change in the connection state is going to take place, is taking place, or has completed.
  41. enum MAPIOFFLINE_NOTIFY_TYPE {
  42. MAPIOFFLINE_NOTIFY_TYPE_STATECHANGE_START = 1,
  43. MAPIOFFLINE_NOTIFY_TYPE_STATECHANGE = 2,
  44. MAPIOFFLINE_NOTIFY_TYPE_STATECHANGE_DONE = 3
  45. };
  46. struct MAPIOFFLINE_ADVISEINFO {
  47. ULONG ulSize; // The size of MAPIOFFLINE_ADVISEINFO
  48. ULONG ulClientToken; // A token defined by the client about a callback. It is the ulClientToken member of the MAPIOFFLINE_NOTIFY structure passed to IMAPIOfflineNotify::Notify.
  49. MAPIOFFLINE_CALLBACK_TYPE CallbackType; // Type of callback to make.
  50. IUnknown* pCallback; // Interface to use for callback. This is the client's implementation of IMAPIOfflineNotify.
  51. ULONG ulAdviseTypes; //The types of advise, as identified by the condition for advising. The only supported type is MAPIOFFLINE_ADVISE_TYPE_STATECHANGE.
  52. ULONG ulStateMask; // The only supported state is MAPIOFFLINE_STATE_ALL
  53. };
  54. struct MAPIOFFLINE_NOTIFY {
  55. ULONG ulSize; // Size of the MAPIOFFLINE_NOTIFY structure.
  56. MAPIOFFLINE_NOTIFY_TYPE NotifyType; // Type of notification
  57. ULONG ulClientToken; // A token defined by the client in the MAPIOFFLINE_ADVISEINFO structure in IMAPIOfflineMgr::Advise
  58. union {
  59. struct {
  60. ULONG ulMask; // The part of the connection state that has changed.
  61. ULONG ulStateOld; // The old connection state
  62. ULONG ulStateNew; // The new connection state
  63. } StateChange;
  64. } Info;
  65. };
  66. /*
  67. Provides information for an offline object.
  68. Class: IMAPIOffline
  69. Inherits from: IUnknown
  70. Provided by: Outlook
  71. Interface identifier: IID_IMAPIOffline
  72. Remarks:
  73. The client must implement this interface and pass a pointer to it as a member in MAPIOFFLINE_ADVISEINFO when setting up callbacks using IMAPIOfflineMgr::Advise. Subsequently, Outlook will be able to use this interface to send notification callbacks to the client.
  74. */
  75. class IMAPIOffline : public IUnknown {
  76. public:
  77. /*
  78. Sets the current state of an offline object to online or offline.
  79. Parameters:
  80. ulFlags
  81. [in] Modifies the behavior of this call. The supported values are:
  82. MAPIOFFLINE_FLAG_BLOCK
  83. Setting ulFlags to this value will block the SetCurrentState call until the state change is complete. By default the transition takes place asynchronously. When the transition is occuring asynchronously, all SetCurrentState calls will return E_PENDING until the change is complete.
  84. MAPIOFFLINE_FLAG_DEFAULT
  85. Sets the current state without blocking.
  86. ulMask
  87. [in] The part of the state to change. The only supported value is MAPIOFFLINE_STATE_OFFLINE_MASK.
  88. ulState
  89. [in] The state to change to. It must be one of these two values:
  90. MAPIOFFLINE_STATE_ONLINE
  91. MAPIOFFLINE_STATE_OFFLINE
  92. pReserved
  93. This parameter is reserved for Outlook internal use and is not supported.
  94. Return Values:
  95. S_OK
  96. The state of the offline object has been changed successfully.
  97. E_PENDING
  98. This indicates that the state of the offline object is changing asynchronously. This occurs when ulFlags is set
  99. to MAPIOFFLINE_FLAG_BLOCK in an earlier SetCurrentState call, and any subsequent SetCurrentState call will return
  100. this value until the asynchronous state change is complete.
  101. */
  102. virtual HRESULT __stdcall SetCurrentState(ULONG ulFlags, ULONG ulMask, ULONG ulState, void* pReserved) = 0;
  103. /*
  104. Gets the conditions for which callbacks are supported by an offline object.
  105. Parameters:
  106. pulCapablities
  107. [out] A bitmask of the following capability flags:
  108. MAPIOFFLINE_CAPABILITY_OFFLINE
  109. The offline object is capable of providing offline notifications.
  110. MAPIOFFLINE_CAPABILITY_ONLINE
  111. The offline object is capable of providing online notifications.
  112. Return Values:
  113. Unknown
  114. Remarks
  115. Upon opening an offline object using HrOpenOfflineObj, a client can query on IMAPIOfflineMgr to obtain a pointer
  116. to an IMAPIOffline interface, and call IMAPIOffline::GetCapabilities to find out the callbacks supported by the object.
  117. The client can then choose to set up callbacks by using IMAPIOfflineMgr.
  118. Note that, depending on the mail server for an offline object, an object that supports callbacks for going online does
  119. not necessarily support callbacks for going offline.
  120. Also note that, while an offline object may support callbacks for changes other than online/offline, the Offline State
  121. API supports only online/offline changes, and clients must check for only such capabilities.
  122. */
  123. virtual HRESULT __stdcall GetCapabilities(ULONG *pulCapabilities) = 0;
  124. /*
  125. Gets the current online or offline state of an offline object.
  126. Parameters:
  127. pulState
  128. [out] The current online or offline state of an offline object. It must be one of these two values:
  129. MAPIOFFLINE_STATE_ONLINE
  130. MAPIOFFLINE_STATE_OFFLINE
  131. Return Values:
  132. Unknown
  133. */
  134. virtual HRESULT __stdcall GetCurrentState(ULONG* pulState) = 0;
  135. };
  136. /*
  137. Supports Outlook sending notification callbacks to a client.
  138. Class: IMAPIOfflineNotify
  139. Inherits from: IUnknown
  140. Provided by: Outlook
  141. Interface identifier: IID_IMAPIOfflineNotify
  142. Remarks:
  143. The client must implement this interface and pass a pointer to it as a member in MAPIOFFLINE_ADVISEINFO when setting up callbacks using IMAPIOfflineMgr::Advise. Subsequently, Outlook will be able to use this interface to send notification callbacks to the client.
  144. */
  145. class IMAPIOfflineNotify : public IUnknown {
  146. public:
  147. /*
  148. Sends notifications to the client about changes in connection state.
  149. Parameters:
  150. pNotifyInfo
  151. [in] The notification that Outlook sends to the client. The notification indicates the part of the connection
  152. state that has changed, the old connection state, and the new connection state.
  153. Return Values:
  154. none
  155. Remarks:
  156. Outlook uses this method to send notification callbacks to a client. To make this interface available to Outlook,
  157. the client must implement this interface and pass a pointer to it as a member in MAPIOFFLINE_ADVISEINFO when
  158. setting up callbacks using IMAPIOfflineMgr::Advise.
  159. The client also passes to MAPIOFFLINE_ADVISEINFO a client token that Outlook uses in IMAPIOfflineNotify::Notify to
  160. identify the client registered for the notification callback.
  161. In general, Outlook can notify a client of online/offline changes and other connection state changes, but the Offline
  162. State API supports only notifications for online/offline changes. The client must ignore all other notifications.
  163. */
  164. virtual void __stdcall Notify(const MAPIOFFLINE_NOTIFY *pNotifyInfo) = 0;
  165. };
  166. /*
  167. Supports registering for notification callbacks about connection state changes of a user account.
  168. Class: IMAPIOfflineMgr
  169. Inherits from: IMAPIOffline
  170. Provided by: Outlook
  171. Interface identifier: IID_IMAPIOfflineMgr
  172. Remarks:
  173. Upon opening an offline object for a user account profile using HrOpenOfflineObj, a client obtains an
  174. offline object that supports IMAPIOfflineMgr.
  175. Because this interface inherits from IUnknown, the client can query this interface (by using IUnknown::QueryInterface)
  176. to obtain an object that supports IMAPIOffline. The client can then find out about the callback capabilities of the
  177. offline object (by calling IMAPIOffline::GetCapabilities), and choose to set up callbacks (by using IMAPIOfflineMgr::Advise).
  178. */
  179. class IMAPIOfflineMgr : public IMAPIOffline {
  180. public:
  181. /*
  182. Registers a client to receive callbacks on an offline object.
  183. Parameters:
  184. ulFlags
  185. [in] Flags that modify behavior. Only the value MAPIOFFLINE_ADVISE_DEFAULT is supported.
  186. pAdviseInfo
  187. [in] Information about the type of callback, when to receive a callback, a callback interface for the caller,
  188. and other details. It also contains a client token that Outlook uses in sending subsequent
  189. notification callbacks to the client caller.
  190. pulAdviseToken
  191. [out] An advise token returned to the client caller for subsequently canceling callback for the object.
  192. Return Values:
  193. S_OK
  194. The call was successful.
  195. E_INVALIDARG
  196. An invalid parameter has been specified.
  197. E_NOINTERFACE
  198. The callback interface specified in pAdviseInfo is not valid.
  199. Remarks:
  200. Upon opening an offline object using HrOpenOfflineObj, a client obtains an offline object that supports IMAPIOfflineMgr.
  201. The client can check for the kinds of callbacks supported by the object by using IMAPIOffline::GetCapabilities.
  202. The client can determine the type and other details about the callback it wants, and then call IMAPIOfflineMgr::Advise
  203. to register to receive such callbacks about the object.
  204. */
  205. virtual HRESULT __stdcall Advise(ULONG ulFlags, MAPIOFFLINE_ADVISEINFO* pAdviseInfo, ULONG* pulAdviseToken) = 0;
  206. /*
  207. Cancels callbacks for an offline object.
  208. Parameters:
  209. ulFlags
  210. [in] Flags for canceling callback. Only the value MAPIOFFLINE_UNADVISE_DEFAULT is supported.
  211. ulAdviseToken
  212. [in] An advise token that identifies the callback registration that is to be canceled.
  213. Return Values:
  214. S_OK
  215. The call was successful.
  216. Remarks:
  217. Removes the registration for the callback that was associated with ulAdviseToken returned from a prior call to
  218. IMAPIOfflineMgr::Advise. Causes the IMAPIOfflineMgr object to release its reference on the IMAPIOfflineNotify
  219. object associated with ulAdviseToken.
  220. */
  221. virtual HRESULT __stdcall Unadvise(ULONG ulFlags,ULONG ulAdviseToken) = 0;
  222. };
  223. } /* namespace */
  224. #endif //IMAPIOFFLINE_INCLUDED