Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
11 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Msg.h
  7. //
  8. // Contents: Handles inter-thread communications
  9. //
  10. // Classes: CThreadMsgProxy
  11. //
  12. // Notes:
  13. //
  14. // History: 05-Nov-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #ifndef _THREADMSG_
  18. #define _THREADMSG_
  19. // stublist for global stublist structure.
  20. typedef struct tagSTUBLIST {
  21. struct tagSTUBLIST *pNextStub; // pointer to next proxy.
  22. ULONG cRefs; // number of proxies using Stub
  23. CLSID clsidStub; // clsid for stub.
  24. HANDLE hThreadStub; // Handle of the Stubs Thread
  25. DWORD ThreadIdStub; // ThreadID to send Message to.
  26. HWND hwndStub; // HWND OF STUB.
  27. BOOL fStubTerminated; // set if this stub was force terminated.
  28. } STUBLIST;
  29. // WMs for Thread communication
  30. #define WM_THREADMESSAGE (WM_USER + 1)
  31. #define WM_CFACTTHREAD_REVOKE (WM_USER + 2)
  32. #define WM_MAINTHREAD_QUIT (WM_USER + 3)
  33. #define WM_THREADSTUBMESSAGE (WM_USER + 4)
  34. #define WM_USER_MAX 0x7FFF // maximum user message that can be defined.
  35. // alll msgs are unique bits so hndlrq and others
  36. // can keep track of out calls.
  37. typedef enum _tagThreadMsg
  38. {
  39. ThreadMsg_Initialize = 0x0001,
  40. ThreadMsg_GetHandlerInfo = 0x0002,
  41. ThreadMsg_EnumOfflineItems = 0x0004,
  42. ThreadMsg_GetItemObject = 0x0008,
  43. ThreadMsg_ShowProperties = 0x0010,
  44. ThreadMsg_SetProgressCallback = 0x0020,
  45. ThreadMsg_PrepareForSync = 0x0040,
  46. ThreadMsg_Synchronize = 0x0080,
  47. ThreadMsg_SetItemStatus = 0x0100,
  48. ThreadMsg_ShowError = 0x0200,
  49. ThreadMsg_Release = 0x0400,
  50. // Private Messages
  51. ThreadMsg_AddHandlerItems = 0x1000,
  52. ThreadMsg_CreateServer = 0X2000,
  53. ThreadMsg_SetHndlrQueue = 0x4000,
  54. ThreadMsg_SetupCallback = 0x8000,
  55. } ThreadMsg;
  56. // messages sent to toplevel stub object.
  57. typedef enum _tagStubMsg
  58. {
  59. StubMsg_CreateNewStub = 0x0001,
  60. StubMsg_Release = 0x0002,
  61. } StubMsg;
  62. class CThreadMsgProxy;
  63. class CThreadMsgStub;
  64. class CHndlrMsg;
  65. class CHndlrQueue;
  66. typedef struct _tagHandlerThreadArgs {
  67. HANDLE hEvent; // used to know when the message loop has been created.
  68. HRESULT hr; // inidicates if creation was successfull
  69. HWND hwndStub; // hwnd of stub window. This is the window messages should be posted to.
  70. } HandlerThreadArgs;
  71. // helper functions called by client and Server
  72. HRESULT CreateHandlerThread(CThreadMsgProxy **pThreadProxy,HWND hwndDlg
  73. ,REFCLSID refClsid);
  74. STDAPI InitMessageService();
  75. // WPARAM is messaging specific data
  76. typedef struct _tagMessagingInfo
  77. {
  78. HANDLE hMsgEvent; // Handle to Message Event for synchronization.
  79. DWORD dwSenderThreadID; // ThreadID of the Caller.
  80. CHndlrMsg *pCHndlrMsg; //handler message instance for this proxy.
  81. } MessagingInfo;
  82. // LPARAM is information specific to the message being sent.
  83. typedef struct _tagGenericMsg
  84. {
  85. HRESULT hr; // return value from the message.
  86. UINT ThreadMsg; // message to send.
  87. } GenericMsg;
  88. // request to stubObject to create a new stub for a proxy
  89. typedef struct _tagMSGSTUBCreateStub
  90. {
  91. GenericMsg MsgGen;
  92. CHndlrMsg *pCHndlrMsg; // on success returns a pointer to a new hndlrMsg struct.
  93. } MSGSTUBCreateStub;
  94. // Message specific structures
  95. typedef struct _tagMSGCreateServer
  96. {
  97. GenericMsg MsgGen;
  98. const CLSID *pCLSIDServer;
  99. CHndlrQueue *pHndlrQueue;
  100. HANDLERINFO *pHandlerId;
  101. DWORD dwProxyThreadId;
  102. } MSGCreateServer;
  103. // Message specific structures
  104. typedef struct _tagSetHndlrQueue
  105. {
  106. GenericMsg MsgGen;
  107. CHndlrQueue *pHndlrQueue;
  108. HANDLERINFO *pHandlerId;
  109. DWORD dwProxyThreadId;
  110. } MSGSetHndlrQueue;
  111. typedef struct _tagMSGInitialize
  112. {
  113. GenericMsg MsgGen;
  114. DWORD dwReserved;
  115. DWORD dwSyncFlags;
  116. DWORD cbCookie;
  117. const BYTE *lpCookie;
  118. } MSGInitialize;
  119. typedef struct _tagMSGGetHandlerInfo
  120. {
  121. GenericMsg MsgGen;
  122. LPSYNCMGRHANDLERINFO *ppSyncMgrHandlerInfo;
  123. } MSGGetHandlerInfo;
  124. typedef struct _tagMSGEnumOfflineItems
  125. {
  126. GenericMsg MsgGen;
  127. ISyncMgrEnumItems** ppenumOfflineItems;
  128. } MSGEnumOfflineItems;
  129. typedef struct _tagMSGGetItemObject
  130. {
  131. GenericMsg MsgGen;
  132. SYNCMGRITEMID ItemID;
  133. GUID riid;
  134. void** ppv;
  135. } MSGGetItemObject;
  136. typedef struct _tagMSGShowProperties
  137. {
  138. GenericMsg MsgGen;
  139. HWND hWndParent;
  140. SYNCMGRITEMID ItemID;
  141. } MSGShowProperties;
  142. typedef struct _tagMSGSetProgressCallback
  143. {
  144. GenericMsg MsgGen;
  145. ISyncMgrSynchronizeCallback *lpCallBack;
  146. } MSGSetProgressCallback;
  147. typedef struct _tagMSGPrepareForSync
  148. {
  149. GenericMsg MsgGen;
  150. // SetHndlrQueue Items
  151. CHndlrQueue *pHndlrQueue;
  152. HANDLERINFO *pHandlerId;
  153. // PrepareForSyncItems
  154. ULONG cbNumItems;
  155. SYNCMGRITEMID *pItemIDs;
  156. HWND hWndParent;
  157. DWORD dwReserved;
  158. } MSGPrepareForSync;
  159. typedef struct _tagMSGSynchronize
  160. {
  161. GenericMsg MsgGen;
  162. HWND hWndParent;
  163. } MSGSynchronize;
  164. typedef struct _tagMSGSetItemStatus
  165. {
  166. GenericMsg MsgGen;
  167. SYNCMGRITEMID ItemID;
  168. DWORD dwSyncMgrStatus;
  169. } MSGSetItemStatus;
  170. typedef struct _tagMSGShowErrors
  171. {
  172. GenericMsg MsgGen;
  173. HWND hWndParent;
  174. SYNCMGRERRORID ErrorID;
  175. ULONG *pcbNumItems;
  176. SYNCMGRITEMID **ppItemIDs;
  177. } MSGShowConflicts;
  178. typedef struct _tagMSGLogErrors
  179. {
  180. DWORD mask;
  181. SYNCMGRERRORID ErrorID;
  182. BOOL fHasErrorJumps;
  183. SYNCMGRITEMID ItemID;
  184. DWORD dwErrorLevel;
  185. const WCHAR *lpcErrorText;
  186. } MSGLogErrors;
  187. typedef struct _tagMSGDeleteLogErrors
  188. {
  189. HANDLERINFO *pHandlerId;
  190. SYNCMGRERRORID ErrorID;
  191. } MSGDeleteLogErrors;
  192. typedef struct _tagMSGAddItemHandler
  193. {
  194. GenericMsg MsgGen;
  195. HWND hwndList; // review, unused.
  196. DWORD *pcbNumItems;
  197. } MSGAddItemHandler;
  198. typedef struct _tagMSGSetupCallback
  199. {
  200. GenericMsg MsgGen;
  201. BOOL fSet;
  202. } MSGSetupCallback;
  203. // inherit from IOfflineSynchronize to catch any interface changes.
  204. class CThreadMsgProxy
  205. {
  206. public:
  207. CThreadMsgProxy();
  208. ~CThreadMsgProxy();
  209. STDMETHODIMP InitProxy(HWND hwndStub, DWORD ThreadId,HANDLE hThread,HWND hwndDlg,
  210. REFCLSID refClsid,STUBLIST *pStubId);
  211. STDMETHODIMP DispatchMsg(GenericMsg *genMsg,BOOL fAllowIncomingCalls,BOOL fAsync);
  212. STDMETHODIMP DispatchsStubMsg(GenericMsg *pgenMsg,BOOL fAllowIncomingCalls);
  213. //IUnknown members
  214. STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  215. STDMETHODIMP_(ULONG) AddRef();
  216. STDMETHODIMP_(ULONG) Release();
  217. // IOfflineSynchronize Methods
  218. STDMETHODIMP Initialize(DWORD dwReserved,DWORD dwSyncFlags,
  219. DWORD cbCookie,const BYTE *lpCooke);
  220. STDMETHODIMP GetHandlerInfo(LPSYNCMGRHANDLERINFO *ppSyncMgrHandlerInfo);
  221. STDMETHODIMP EnumSyncMgrItems(ISyncMgrEnumItems **ppenumOfflineItems);
  222. STDMETHODIMP GetItemObject(REFSYNCMGRITEMID ItemID,REFIID riid,void** ppv);
  223. STDMETHODIMP ShowProperties(HWND hWndParent,REFSYNCMGRITEMID ItemID);
  224. STDMETHODIMP SetProgressCallback(ISyncMgrSynchronizeCallback *lpCallBack);
  225. STDMETHODIMP PrepareForSync(ULONG cbNumItems,SYNCMGRITEMID *pItemIDs,
  226. HWND hWndParent,DWORD dwReserved);
  227. STDMETHODIMP Synchronize(HWND hWndParent);
  228. STDMETHODIMP SetItemStatus(REFSYNCMGRITEMID ItemID,DWORD dwSyncMgrStatus);
  229. STDMETHODIMP ShowError(HWND hWndParent,REFSYNCMGRERRORID ErrorID,ULONG *pcbNumItems,SYNCMGRITEMID **ppItemIDs);
  230. // Private messages
  231. STDMETHODIMP CreateServer(const CLSID *pCLSIDServer,CHndlrQueue *pHndlrQueue,HANDLERINFO *pHandlerId);
  232. STDMETHODIMP SetHndlrQueue(CHndlrQueue *pHndlrQueue,
  233. HANDLERINFO *pHandlerId,
  234. DWORD dwThreadIdProxy);
  235. STDMETHODIMP AddHandlerItems(HWND hwndList,DWORD *pcbNumItems);
  236. STDMETHODIMP SetupCallback(BOOL fSet);
  237. STDMETHODIMP SetProxyParams(HWND hwndDlg, DWORD ThreadIdProxy,
  238. CHndlrQueue *pHndlrQueue,HANDLERINFO *pHandlerId );
  239. inline STDMETHODIMP SetProxyHwndDlg(HWND hwndDlg) {
  240. m_hwndDlg = hwndDlg;
  241. return S_OK;
  242. }
  243. inline BOOL IsProxyInOutCall() { return m_dwNestCount; }
  244. STDMETHODIMP SetProxyCompletion(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);
  245. // messages sent to the toplevel stub object.
  246. STDMETHODIMP CreateNewHndlrMsg();
  247. STDMETHODIMP ReleaseStub();
  248. STDMETHODIMP TerminateHandlerThread(TCHAR *pszHandlerName,BOOL fPromptUser);
  249. private:
  250. HANDLE m_hThreadStub; // Handle of the Stubs Thread
  251. DWORD m_ThreadIdStub; // ThreadID to send Message to.
  252. HWND m_hwndStub; // HWND OF STUB.
  253. CHndlrMsg *m_pCHndlrMsg; // HndlrMsg associated with this proxy.
  254. BOOL m_fTerminatedHandler; // set to true if handler has been terminated.
  255. STUBLIST *m_pStubId; // Id of stub this proxy belongs to.
  256. HWND m_hwndDlg; // hwnd of any dialog on this thread.
  257. CLSID m_Clsid; // clsid of this handler.
  258. DWORD m_ThreadIdProxy;
  259. // Proxy Side Information
  260. CHndlrQueue *m_pHndlrQueue;
  261. HANDLERINFO * m_pHandlerId;
  262. BOOL m_fNewHndlrQueue; // set to indicate if Stub side information is out of date.
  263. DWORD m_dwNestCount; // keeps track of number of nestcount on item so can determine if in out call.
  264. MSG m_msgCompletion;
  265. BOOL m_fHaveCompletionCall;
  266. DWORD m_cRef;
  267. };
  268. #define MSGSERVICE_HWNDCLASSNAME "SyncMgr_HwndMsgService"
  269. #define DWL_THREADWNDPROCCLASS 0 // window long offset to MsgService Hwnd this ptr.
  270. LRESULT CALLBACK MsgThreadWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
  271. typedef enum _tagMSGHWNDTYPE
  272. {
  273. MSGHWNDTYPE_UNDEFINED = 0x0, // Message Service has not been initialized
  274. MSGHWNDTYPE_HANDLERTHREAD = 0x1, // Message Service if for a Handler Thread.
  275. MSGHWNDTYPE_MAINTHREAD = 0x2, // Message Service if for the Main Thread
  276. } MSGHWNDTYPE;
  277. typedef struct _tagMSGSERVICEQUEUE
  278. {
  279. struct _tagMSGSERVICEQUEUE *pNextMsg;
  280. DWORD dwNestCount; // nestcount completion should be called.
  281. MSG msg;
  282. } MSGSERVICEQUEUE;
  283. class CMsgServiceHwnd
  284. {
  285. public:
  286. HWND m_hwnd;
  287. DWORD m_dwThreadID;
  288. CHndlrMsg *m_pHndlrMsg;
  289. MSGHWNDTYPE m_MsgHwndType;
  290. MSGSERVICEQUEUE *m_pMsgServiceQueue; // queue to hold any message to process when current
  291. // cal completes.
  292. BOOL m_fInOutCall;
  293. CMsgServiceHwnd();
  294. ~CMsgServiceHwnd();
  295. inline HWND GetHwnd() { return m_hwnd; };
  296. BOOL Initialize(DWORD dwThreadID,MSGHWNDTYPE MsgHwndType);
  297. HRESULT HandleThreadMessage(MessagingInfo *pmsgInfo,GenericMsg *pgenMsg);
  298. void Destroy();
  299. };
  300. // internal functions
  301. HRESULT SendThreadMessage(DWORD idThread,UINT uMsg,WPARAM wParam,LPARAM lParam);
  302. DWORD WINAPI HandlerThread( LPVOID );
  303. HRESULT DoModalLoop(HANDLE hEvent,HANDLE hThread,HWND hwndDlg,BOOL fAllowIncomingCalls,DWORD dwTimeout);
  304. #endif // _THREADMSG_