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.

303 lines
17 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Hndlrq.h
  7. //
  8. // Contents: Keeps tracks of Handlers and UI assignments
  9. //
  10. // Classes: CHndlrQueue
  11. //
  12. // Notes:
  13. //
  14. // History: 05-Nov-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #ifndef _HANDLERQUEUE_
  18. #define _HANDLERQUEUE_
  19. // For Choice dialog If same item is added again first one their wins.
  20. // This handles the case if user previously chose properties. duplicate items
  21. // will be set to not synchronize even if the preference is set. this is
  22. // the defined behavior for AddHandlerItemsToQueue.
  23. //
  24. // Progress dialog all items get synchronized as they were added. To move
  25. // items to the Progress queue always use the TransferQueueData method. If Item
  26. // was previously skipped what should we do?
  27. // Also need routines for registering Choice and Progress dialogs.
  28. class CBaseDlg;
  29. class CChoiceDlg;
  30. class CLock;
  31. class CThreadMsgProxy;
  32. class CHndlrMsg;
  33. // state the handler should go to next
  34. // note: any items with a HandlerState other than choice in a TransferQueueData
  35. // will be released asserting the HANDLERSTATE_RELEASE or HANDLERSTATE_DEAD
  36. // state is set.
  37. typedef enum _tagHANDLERSTATE
  38. {
  39. HANDLERSTATE_NEW = 0x00, // state is initialized to this.
  40. HANDLERSTATE_CREATE = 0x01, // state is initialized to this.
  41. HANDLERSTATE_INCREATE = 0x02, // state is initialized to this.
  42. HANDLERSTATE_INITIALIZE = 0x03, // set after a successfull creation.
  43. HANDLERSTATE_ININITIALIZE = 0x04, // set during initialization call
  44. HANDLERSTATE_ADDHANDLERTEMS = 0x05, // items need to be enumerated
  45. HANDLERSTATE_INADDHANDLERITEMS = 0x06, // in the items enumerator
  46. HANDLERSTATE_PREPAREFORSYNC = 0x07, // set during queue tranfers
  47. HANDLERSTATE_INPREPAREFORSYNC = 0x08, // handler is currently in a prepfosync call.
  48. HANDLERSTATE_INSETCALLBACK = 0x09, // within a setcallback call.
  49. HANDLERSTATE_SYNCHRONIZE = 0x0A, // Prepare for Sync set this if successfull
  50. HANDLERSTATE_INSYNCHRONIZE = 0x0B, // item is currently in a synchronize call
  51. HANDLERSTATE_HASERRORJUMPS = 0x0C, // if synchronize returned but error has jumps
  52. HANDLERSTATE_INHASERRORJUMPS = 0x0D, // this handleris in a has jumps call
  53. HANDLERSTATE_RELEASE = 0x0E, // Handler can be released, set on error or after success
  54. HANDLERSTATE_TRANSFERRELEASE = 0x0F, // Handler can be released, was transferred into the queue but nothing to do.
  55. HANDLERSTATE_DEAD = 0x10, // handler has been released. Data Stays around.
  56. } HANDLERSTATE;
  57. typedef enum _tagQUEUETYPE
  58. {
  59. QUEUETYPE_CHOICE = 0x1, //
  60. QUEUETYPE_PROGRESS = 0x2, //
  61. QUEUETYPE_SETTINGS = 0x3, //
  62. } QUEUETYPE;
  63. // Job info list is assigned to each new item added to the hndlrqueu
  64. // keeps track of number of handlers attached to JobInfo, Initialize
  65. // flags, schedule name
  66. // Progress queue keeps a linked list.
  67. typedef struct _JOBINFO {
  68. struct _JOBINFO *pNextJobInfo;
  69. struct _JOBINFO *pTransferJobInfo; // used in queue transfer.
  70. DWORD cRefs;
  71. DWORD dwSyncFlags; // standard sync flags
  72. TCHAR szScheduleName[MAX_PATH + 1];
  73. BOOL fCanMakeConnection; // Job is allowed to dial the connection.
  74. BOOL fTriedConnection; // Job already tried to dial the connection.
  75. DWORD cbNumConnectionObjs;
  76. CONNECTIONOBJ *pConnectionObj[1]; // array of cbNumConnecObjs associated with this job.
  77. } JOBINFO;
  78. typedef struct _ITEMLIST
  79. {
  80. struct _ITEMLIST* pnextItem;
  81. WORD wItemId; // Id that uniquely identifies Item within a handler.
  82. void *pHandlerInfo; // pointer to the handler that owns this item
  83. SYNCMGRITEM offlineItem; // enumerator structure item returned
  84. BOOL fItemCancelled; // when set poper code should be returned to progress.
  85. BOOL fDuplicateItem; // when set to true indicates there was already an existing item of this handler and item.
  86. BOOL fIncludeInProgressBar; // if set to true items ProgValues are added to the progress bar.
  87. BOOL fProgressBarHandled; // Used internally by GetProgressInfo for calculating num items of num items completed
  88. INT iProgValue; // current progress value.
  89. INT iProgMaxValue; // current progress max value.
  90. BOOL fProgValueDirty; // set to true if Normalized Progress Value needs to be recalced.
  91. INT iProgValueNormalized; // current progress value normalized
  92. DWORD dwStatusType; // status type from last callback.
  93. BOOL fHiddenItem; // flag set it Item was added by ShowErrors returning nonItem.
  94. BOOL fSynchronizingItem; // flag set while item has been selected for prepareForSync/synchronize.
  95. } ITEMLIST;
  96. typedef ITEMLIST* LPITEMLIST;
  97. typedef struct _HANDLERINFO {
  98. struct _HANDLERINFO *pNextHandler;
  99. DWORD dwCallNestCount;
  100. struct _HANDLERINFO *pHandlerId; // Id that uniquely identifies this instance of the Handler
  101. CLSID clsidHandler; // CLSID of the handler Handler
  102. DWORD dwRegistrationFlags; // flags as item is registered
  103. SYNCMGRHANDLERINFO SyncMgrHandlerInfo; // copy of handler info GetHandlerInfo Call
  104. HANDLERSTATE HandlerState;
  105. HWND hWndCallback; // hWnd to send callback information to.
  106. BOOL fHasErrorJumps; // BOOL if can call ShowErrors then don't release on completion of sync.
  107. BOOL fInShowErrorCall; // bool to indicate if handler is currently handling a ShowError Call.
  108. BOOL fInTerminateCall; // bool to indicate if handler is currently handling a ShowError Call.
  109. CThreadMsgProxy *pThreadProxy;
  110. DWORD dwOutCallMessages; // out call messages we are currenlty handling.
  111. WORD wItemCount;
  112. BOOL fCancelled; // This Handler was Cancelled by the User.
  113. BOOL fRetrySync; // retrySync was requested while before this items synchronization was done.
  114. LPITEMLIST pFirstItem; // ptr to first Item of the handler in the list.
  115. JOBINFO *pJobInfo;
  116. } HANDLERINFO;
  117. typedef HANDLERINFO* LPHANDLERINFO;
  118. #define MAXPROGRESSVALUE 3000 // maximum absolute progress bar value
  119. class CHndlrQueue : CLockHandler {
  120. private:
  121. // review when eat up all the available IDs
  122. LPHANDLERINFO m_pFirstHandler;
  123. JOBINFO *m_pFirstJobInfo; // pointer to first job.
  124. HWND m_hwndDlg; // hwnd to dialog that owns the queue.
  125. CBaseDlg *m_pDlg; // pointer to dialog that owns the queue.
  126. WORD m_wHandlerCount; // number of handlers in this queue
  127. QUEUETYPE m_QueueType; // type of queue this is.
  128. DWORD m_dwQueueThreadId; // Thread that queue was created on.
  129. DWORD m_dwShowErrororOutCallCount; // number of handlers currently stuck in a ShowError Call.
  130. BOOL m_fInCancelCall; // Don't allow Cancel to be re-entrant
  131. DWORD m_cRefs;
  132. BOOL m_fItemsMissing; // set if any handlers have missing items.
  133. INT m_iNormalizedMax; // last calculated Max Value in GetProgressInfo
  134. BOOL m_fNumItemsCompleteNeedsARecalc; // Need to recalulate the number of items complete.
  135. BOOL m_iItemCount; // Total Number of Items as shown in progress.
  136. BOOL m_iCompletedItems; // Number of Completed Items..
  137. ULONG m_ulProgressItemCount; // total count of Items in cache included with progress.
  138. public:
  139. CHndlrQueue(QUEUETYPE QueueType,CBaseDlg *pDlg);
  140. ~CHndlrQueue();
  141. STDMETHODIMP_(ULONG) AddRef();
  142. STDMETHODIMP_(ULONG) Release();
  143. // main queue routines
  144. STDMETHODIMP AddHandler(HANDLERINFO **ppHandlerId,JOBINFO *pJobInfo,DWORD dwRegistrationFlags);
  145. STDMETHODIMP Cancel(void);
  146. STDMETHODIMP ForceKillHandlers(BOOL *pfItemToKill);
  147. STDMETHODIMP TransferQueueData(CHndlrQueue *pQueueMoveFrom);
  148. STDMETHODIMP SetQueueHwnd(CBaseDlg *pDlg);
  149. STDMETHODIMP ReleaseCompletedHandlers(void);
  150. BOOL AreAnyItemsSelectedInQueue(); // walks through seeing if any items are selected for sync.
  151. STDMETHODIMP FreeAllHandlers(void); // frees all handlers associated with the queue.
  152. STDMETHODIMP GetHandlerInfo(REFCLSID clsidHandler,LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo);
  153. STDMETHODIMP GetHandlerInfo(HANDLERINFO *pHandlerId,LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo);
  154. STDMETHODIMP GetItemDataAtIndex(HANDLERINFO *pHandlerId,WORD wItemID,CLSID *pclsidHandler,
  155. SYNCMGRITEM* offlineItem,BOOL *pfHiddenItem);
  156. STDMETHODIMP GetItemDataAtIndex(HANDLERINFO *pHandlerId,REFSYNCMGRITEMID ItemID,CLSID *pclsidHandler,
  157. SYNCMGRITEM* offlineItem,BOOL *pfHiddenItem);
  158. // new methods for walking through ListView relying on clsid and itemID
  159. STDMETHODIMP FindFirstItemInState(HANDLERSTATE hndlrState,HANDLERINFO **ppHandlerId,WORD *wItemID);
  160. STDMETHODIMP FindNextItemInState(HANDLERSTATE hndlrState,HANDLERINFO *pLastHandlerId,WORD wLastItemID,
  161. HANDLERINFO **ppHandlerId,WORD *wItemID);
  162. STDMETHODIMP SetItemState(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID,DWORD dwState);
  163. STDMETHODIMP ItemHasProperties(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID); // determines if there are properties associated with this item.
  164. STDMETHODIMP ShowProperties(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID,HWND hwndParent); // show properties for this listView Item.
  165. STDMETHODIMP ReEnumHandlerItems(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID);
  166. STDMETHODIMP SkipItem(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID); // skip this item
  167. // methods for handling the progress and Items complete
  168. STDMETHODIMP GetProgressInfo(INT *iProgValue,INT *iMaxValue,INT *iNumItemsComplete,
  169. INT *iNumItemsTotal);
  170. STDMETHODIMP SetItemProgressInfo(HANDLERINFO *pHandlerId,WORD wItemID,
  171. LPSYNCMGRPROGRESSITEM pSyncProgressItem,
  172. BOOL *pfProgressChanged);
  173. STDMETHODIMP RemoveFinishedProgressItems(); // walks through list marking any
  174. // finished items as fIncludeInProgressBar==FALSE;
  175. STDMETHODIMP PersistChoices(void); // persists choices for next time.
  176. // For finding Handlers that meet specific state requirements
  177. STDMETHODIMP FindFirstHandlerInState(HANDLERSTATE hndlrState,
  178. REFCLSID clsidHandler,HANDLERINFO **ppHandlerId,CLSID *pMatchHandlerClsid);
  179. STDMETHODIMP FindNextHandlerInState(HANDLERINFO *pLastHandlerID,
  180. REFCLSID clsidHandler,HANDLERSTATE hndlrState,HANDLERINFO **ppHandlerId
  181. ,CLSID *pMatchHandlerClsid);
  182. // functions for calling through the items proxy.
  183. STDMETHODIMP CreateServer(HANDLERINFO *pHandlerId, const CLSID *pCLSIDServer);
  184. STDMETHODIMP Initialize(HANDLERINFO *pHandlerId,DWORD dwReserved,DWORD dwSyncFlags,
  185. DWORD cbCookie,const BYTE *lpCooke);
  186. STDMETHODIMP AddHandlerItemsToQueue(HANDLERINFO *pHandlerId,DWORD *pcbNumItems);
  187. STDMETHODIMP GetItemObject(HANDLERINFO *pHandlerId,WORD wItemID,REFIID riid,void** ppv);
  188. STDMETHODIMP SetUpProgressCallback(HANDLERINFO *pHandlerId,BOOL fSet,HWND hwnd); // TRUE == create, FALSE == destroy. Callback info should be sent to specified hwnd.
  189. STDMETHODIMP PrepareForSync(HANDLERINFO *pHandlerId,HWND hWndParent);
  190. STDMETHODIMP Synchronize(HANDLERINFO *pHandlerId,HWND hWndParent);
  191. STDMETHODIMP ShowError(HANDLERINFO *pHandlerId,HWND hWndParent,REFSYNCMGRERRORID ErrorID);
  192. // callback proxy functions
  193. STDMETHODIMP IsAllHandlerInstancesCancelCompleted(REFCLSID clsidHandler);
  194. // functions called from Handler Thread
  195. STDMETHODIMP SetHandlerInfo(HANDLERINFO *pHandlerId,LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo);
  196. STDMETHODIMP AddItemToHandler(HANDLERINFO *pHandlerId,LPSYNCMGRITEM pOffineItem);
  197. STDMETHODIMP Progress(HANDLERINFO *pHandlerId,REFSYNCMGRITEMID ItemID,LPSYNCMGRPROGRESSITEM lpSyncProgressItem);
  198. STDMETHODIMP LogError(HANDLERINFO *pHandlerId,DWORD dwErrorLevel,const WCHAR *lpcErrorText,LPSYNCMGRLOGERRORINFO lpSyncLogError);
  199. STDMETHODIMP DeleteLogError(HANDLERINFO *pHandlerId,REFSYNCMGRERRORID ErrorID,DWORD dwReserved);
  200. void CallCompletionRoutine(HANDLERINFO *pHandlerId,DWORD dwThreadMsg,HRESULT hr,
  201. ULONG cbNumItems,SYNCMGRITEMID *pItemIDs);
  202. // internal queue handler of method calls with completion
  203. // routines. can be called on either handler or dlg owner thread
  204. // on error from calls completion routine is still invoked for
  205. // the convenience of the caller to never have to worry about it.
  206. STDMETHODIMP PrepareForSyncCompleted(LPHANDLERINFO pHandlerInfo,HRESULT hCallResult);
  207. STDMETHODIMP SynchronizeCompleted(LPHANDLERINFO pHandlerInfo,HRESULT hCallResult);
  208. STDMETHODIMP ShowErrorCompleted(LPHANDLERINFO pHandlerInfo,HRESULT hCallResult,ULONG cbNumItems,SYNCMGRITEMID *pItemIDs);
  209. STDMETHODIMP AddQueueJobInfo(DWORD dwSyncFlags, DWORD cbNumConnectionNames,
  210. TCHAR **ppConnectionNames,TCHAR *pszScheduleName,BOOL fCanMakeConnection
  211. ,JOBINFO **ppJobInfo);
  212. DWORD ReleaseJobInfoExt(JOBINFO *pJobInfo);
  213. // state transition functions
  214. STDMETHODIMP CancelQueue(void); // put queue into cancel mode.
  215. STDMETHODIMP ScrambleIdleHandlers(REFCLSID clsidLastHandler);
  216. // Handler dial support functinos
  217. STDMETHODIMP BeginSyncSession();
  218. STDMETHODIMP EndSyncSession();
  219. STDMETHODIMP SortHandlersByConnection();
  220. STDMETHODIMP EstablishConnection( LPHANDLERINFO pHandlerID,
  221. WCHAR const * lpwszConnection,
  222. DWORD dwReserved );
  223. private:
  224. // private functions for finding proper handlers and items.
  225. LPITEMLIST AllocNewHandlerItem(LPHANDLERINFO pHandlerInfo,SYNCMGRITEM *pOfflineItem);
  226. STDMETHODIMP LookupHandlerFromId(HANDLERINFO *pHandlerId,LPHANDLERINFO *pHandlerInfo);
  227. STDMETHODIMP FindItemData(CLSID clsidHandler,REFSYNCMGRITEMID OfflineItemID,
  228. HANDLERSTATE hndlrStateFirst,HANDLERSTATE hndlrStateLast,
  229. LPHANDLERINFO *ppHandlerInfo,LPITEMLIST *ppItem);
  230. BOOL IsItemAlreadyInList(CLSID clsidHandler,REFSYNCMGRITEMID ItemID,
  231. HANDLERINFO *pHandlerId,
  232. LPHANDLERINFO *ppHandlerMatched,
  233. LPITEMLIST *ppItemListMatch);
  234. STDMETHODIMP MoveHandler(CHndlrQueue *pQueueMoveFrom,
  235. LPHANDLERINFO pHandlerInfoMoveFrom,HANDLERINFO **pHandlerId,
  236. CLock *pclockQueue);
  237. DWORD GetSelectedItemsInHandler(LPHANDLERINFO pHandlerInfo,ULONG *cbCount,
  238. SYNCMGRITEMID* pItems);
  239. BOOL IsItemCompleted(LPHANDLERINFO pHandler,LPITEMLIST pItem);
  240. STDMETHODIMP ReleaseHandlers(HANDLERSTATE HandlerState); // Releases handlers that are no longer neededfs
  241. // items to handle maintain JobInfo items.
  242. STDMETHODIMP CreateJobInfo(JOBINFO **ppJobInfo,DWORD cbNumConnectionNames);
  243. DWORD AddRefJobInfo(JOBINFO *pJobInfo);
  244. DWORD ReleaseJobInfo(JOBINFO *pJobInfo);
  245. STDMETHODIMP ForceCompleteOutCalls(LPHANDLERINFO pCurHandler);
  246. // connection help routines
  247. STDMETHODIMP OpenConnection(JOBINFO *pJobInfo);
  248. // helper function for setting item ProgressInfo
  249. STDMETHODIMP SetItemProgressInfo(LPITEMLIST pItem,
  250. LPSYNCMGRPROGRESSITEM pSyncProgressItem,
  251. BOOL *pfProgressChanged);
  252. STDMETHODIMP SetItemProgressValues(LPITEMLIST pItem,INT iProgValue,INT iProgMaxValue);
  253. friend CHndlrMsg;
  254. };
  255. // helper functions
  256. BOOL IsValidSyncProgressItem(LPSYNCMGRPROGRESSITEM lpProgItem);
  257. BOOL IsValidSyncLogErrorInfo(DWORD dwErrorLevel,const WCHAR *lpcErrorText,LPSYNCMGRLOGERRORINFO lpSyncLogError);
  258. #endif // _HANDLERQUEUE_