Source code of Windows XP (NT5)
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.

5564 lines
168 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Hndlrq.cpp
  7. //
  8. // Contents: Implements class for keeping track of handlers
  9. // and the UI associated with them
  10. //
  11. // Classes: CHndlrQueue
  12. //
  13. // Notes:
  14. //
  15. // History: 05-Nov-97 rogerg Created.
  16. //
  17. //--------------------------------------------------------------------------
  18. #include "precomp.h"
  19. #define HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE 10
  20. // called to set up the JobInfo on a choice queue.
  21. STDMETHODIMP CHndlrQueue::AddQueueJobInfo(DWORD dwSyncFlags,DWORD cbNumConnectionNames,
  22. TCHAR **ppConnectionNames,
  23. TCHAR *pszScheduleName,BOOL fCanMakeConnection
  24. ,JOBINFO **pJobInfo)
  25. {
  26. HRESULT hr = E_UNEXPECTED;
  27. TCHAR *pszConnectionName;
  28. TCHAR **pszConnectionNameArray;
  29. CLock clockqueue(this);
  30. *pJobInfo = NULL;
  31. Assert(m_QueueType == QUEUETYPE_CHOICE);
  32. if (m_QueueType != QUEUETYPE_CHOICE)
  33. {
  34. return E_UNEXPECTED;
  35. }
  36. clockqueue.Enter();
  37. Assert(NULL == m_pFirstJobInfo);
  38. // fix up connections so have at least one connection/job.
  39. // this currently happens on an UpdateItems.
  40. if (NULL == ppConnectionNames || 0 == cbNumConnectionNames )
  41. {
  42. cbNumConnectionNames = 1;
  43. pszConnectionName = TEXT("");
  44. pszConnectionNameArray = &pszConnectionName;
  45. }
  46. else
  47. {
  48. pszConnectionName = *ppConnectionNames;
  49. pszConnectionNameArray = ppConnectionNames;
  50. }
  51. // create a job requesting size for the number of connections passed in.
  52. hr = CreateJobInfo(&m_pFirstJobInfo,cbNumConnectionNames);
  53. if (NOERROR == hr)
  54. {
  55. DWORD dwConnectionIndex;
  56. Assert(cbNumConnectionNames >= 1); // Review assert for debugging to test when have multiple connections for first time.
  57. m_pFirstJobInfo->cbNumConnectionObjs = 0;
  58. // add a connectionObject for each connection
  59. for (dwConnectionIndex = 0; dwConnectionIndex < cbNumConnectionNames; ++dwConnectionIndex)
  60. {
  61. hr = ConnectObj_FindConnectionObj(pszConnectionNameArray[dwConnectionIndex],
  62. TRUE,&(m_pFirstJobInfo->pConnectionObj[dwConnectionIndex]));
  63. if (NOERROR != hr)
  64. {
  65. break;
  66. }
  67. else
  68. {
  69. ++m_pFirstJobInfo->cbNumConnectionObjs;
  70. }
  71. }
  72. if (NOERROR == hr)
  73. {
  74. m_pFirstJobInfo->dwSyncFlags = dwSyncFlags;
  75. if ((SYNCMGRFLAG_SCHEDULED == (dwSyncFlags & SYNCMGRFLAG_EVENTMASK)))
  76. {
  77. lstrcpy(m_pFirstJobInfo->szScheduleName,pszScheduleName);
  78. m_pFirstJobInfo->fCanMakeConnection = fCanMakeConnection;
  79. m_pFirstJobInfo->fTriedConnection = FALSE;
  80. }
  81. }
  82. else
  83. {
  84. // couldn't create the connectionObj so release our jobID
  85. m_pFirstJobInfo = NULL;
  86. }
  87. }
  88. *pJobInfo = m_pFirstJobInfo;
  89. clockqueue.Leave();
  90. return hr;
  91. }
  92. //+---------------------------------------------------------------------------
  93. //
  94. // Member: CHndlrQueue::CHndlrQueue, public
  95. //
  96. // Synopsis: Constructor used to create a progress queue
  97. //
  98. // Arguments: [QueueType] - Type of Queue that should be created.
  99. // [hwndDlg] - Hwnd who owns this queue.
  100. //
  101. // Returns:
  102. //
  103. // Modifies:
  104. //
  105. // History: 17-Nov-97 rogerg Created.
  106. //
  107. //----------------------------------------------------------------------------
  108. CHndlrQueue::CHndlrQueue(QUEUETYPE QueueType,CBaseDlg *pDlg)
  109. {
  110. Assert(QueueType == QUEUETYPE_PROGRESS
  111. || QueueType == QUEUETYPE_CHOICE );
  112. m_pFirstHandler = NULL;
  113. m_wHandlerCount = 0;
  114. m_dwShowErrororOutCallCount = 0;
  115. m_cRefs = 1;
  116. m_QueueType = QueueType;
  117. m_fItemsMissing = FALSE;
  118. m_dwQueueThreadId = GetCurrentThreadId();
  119. m_iNormalizedMax = 0;
  120. m_fNumItemsCompleteNeedsARecalc = TRUE;
  121. m_pDlg = pDlg;
  122. if (m_pDlg)
  123. {
  124. m_hwndDlg = m_pDlg->GetHwnd();
  125. Assert(m_hwndDlg);
  126. }
  127. m_fInCancelCall = FALSE;
  128. m_pFirstJobInfo = NULL;
  129. }
  130. //+---------------------------------------------------------------------------
  131. //
  132. // Member: CHndlrQueue::~CHndlrQueue, public
  133. //
  134. // Synopsis: Destructor
  135. //
  136. // Arguments:
  137. //
  138. // Returns:
  139. //
  140. // Modifies:
  141. //
  142. // History: 17-Nov-97 rogerg Created.
  143. //
  144. //----------------------------------------------------------------------------
  145. CHndlrQueue::~CHndlrQueue()
  146. {
  147. CLock clockqueue(this);
  148. // for a progress queue all the jobInfos should be released
  149. // for the choice queue there should be one JobInfo that has to
  150. // be released that was addref'd in the constructor.
  151. Assert(0 == m_cRefs);
  152. Assert(NULL == m_pFirstJobInfo); // review - this should never fire anymore.
  153. Assert(NULL == m_pFirstJobInfo
  154. || m_QueueType == QUEUETYPE_CHOICE); // there shouldn't be any unreleased JobInfo
  155. Assert(m_pFirstHandler == NULL); // All Handlers should have been released by now.
  156. }
  157. //+---------------------------------------------------------------------------
  158. //
  159. // Member: CHndlrQueue::AddRef, public
  160. //
  161. // Synopsis:
  162. //
  163. // Arguments:
  164. //
  165. // Returns:
  166. //
  167. // Modifies:
  168. //
  169. // History: 01-June-98 rogerg Created.
  170. //
  171. //----------------------------------------------------------------------------
  172. STDMETHODIMP_(ULONG) CHndlrQueue::AddRef()
  173. {
  174. DWORD cRefs;
  175. Assert(m_cRefs >= 1); // should never zero bounce.
  176. cRefs = InterlockedIncrement((LONG *)& m_cRefs);
  177. return cRefs;
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // Member: CHndlrQueue::Release, public
  182. //
  183. // Synopsis:
  184. //
  185. // Arguments:
  186. //
  187. // Returns:
  188. //
  189. // Modifies:
  190. //
  191. // History: 01-June-98 rogerg Created.
  192. //
  193. //----------------------------------------------------------------------------
  194. STDMETHODIMP_(ULONG) CHndlrQueue::Release()
  195. {
  196. DWORD cRefs;
  197. cRefs = InterlockedDecrement( (LONG *) &m_cRefs);
  198. Assert( ((LONG) cRefs) >= 0); // should never go negative.
  199. if (0 == cRefs)
  200. {
  201. delete this;
  202. }
  203. return cRefs;
  204. }
  205. //+---------------------------------------------------------------------------
  206. //
  207. // Member: CHndlrQueue::AddHandler, public
  208. //
  209. // Synopsis: Adds a new empty handler to the queue and returns it ID
  210. //
  211. // Arguments: [pwHandlerID] - on success contains the assigned Handler ID
  212. // [pJobInfo] - Job this item is associated with
  213. // [dwRegistrationFlags] - Flags the Handler has registered for.
  214. //
  215. // Returns: Appropriate return codes
  216. //
  217. // Modifies:
  218. //
  219. // History: 17-Nov-97 rogerg Created.
  220. //
  221. //----------------------------------------------------------------------------
  222. STDMETHODIMP CHndlrQueue::AddHandler(HANDLERINFO **ppHandlerId,JOBINFO *pJobInfo,DWORD dwRegistrationFlags)
  223. {
  224. HRESULT hr = E_OUTOFMEMORY;
  225. LPHANDLERINFO pnewHandlerInfo;
  226. CLock clockqueue(this);
  227. *ppHandlerId = 0;
  228. pnewHandlerInfo = (LPHANDLERINFO) ALLOC(sizeof(HANDLERINFO));
  229. if (pnewHandlerInfo)
  230. {
  231. clockqueue.Enter();
  232. m_fNumItemsCompleteNeedsARecalc = TRUE; // need to recalc next GetProgress.
  233. // initialize the new Handler Entry
  234. memset(pnewHandlerInfo,0,sizeof(HANDLERINFO));
  235. pnewHandlerInfo->HandlerState = HANDLERSTATE_CREATE;
  236. pnewHandlerInfo->pHandlerId = pnewHandlerInfo;
  237. pnewHandlerInfo->dwRegistrationFlags = dwRegistrationFlags;
  238. // queue should be a choice queue and
  239. // there should already be a jobinfo.
  240. Assert(m_QueueType == QUEUETYPE_CHOICE);
  241. Assert(m_pFirstJobInfo);
  242. Assert(pJobInfo == m_pFirstJobInfo); // for now job info should always be the first one.
  243. if (m_QueueType == QUEUETYPE_CHOICE && pJobInfo)
  244. {
  245. AddRefJobInfo(pJobInfo);
  246. pnewHandlerInfo->pJobInfo = pJobInfo;
  247. }
  248. // add to end of list and set pHandlerId. End of list since in choice dialog want
  249. // first writer wins so don't have to continue searches when setting item state.
  250. if (NULL == m_pFirstHandler)
  251. {
  252. m_pFirstHandler = pnewHandlerInfo;
  253. }
  254. else
  255. {
  256. LPHANDLERINFO pCurHandlerInfo;
  257. pCurHandlerInfo = m_pFirstHandler;
  258. while (pCurHandlerInfo->pNextHandler)
  259. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  260. pCurHandlerInfo->pNextHandler = pnewHandlerInfo;
  261. }
  262. *ppHandlerId = pnewHandlerInfo->pHandlerId;
  263. clockqueue.Leave();
  264. hr = NOERROR;
  265. }
  266. return hr;
  267. }
  268. //+---------------------------------------------------------------------------
  269. //
  270. // Member: CHndlrQueue::ForceKillHandlers, public
  271. //
  272. // Synopsis: Kills unresponsive handlers after timeout
  273. //
  274. // Returns: Appropriate return codes
  275. //
  276. // History: 20-Nov-98 rogerg Created.
  277. //
  278. //----------------------------------------------------------------------------
  279. STDMETHODIMP CHndlrQueue::ForceCompleteOutCalls(LPHANDLERINFO pCurHandler)
  280. {
  281. // need to have lock for argument to be valid.
  282. ASSERT_LOCKHELD(this);
  283. //prepare for sync out call
  284. if (pCurHandler->dwOutCallMessages & ThreadMsg_PrepareForSync)
  285. {
  286. CallCompletionRoutine(pCurHandler,ThreadMsg_PrepareForSync,
  287. HRESULT_FROM_WIN32(ERROR_CANCELLED),0,NULL);
  288. }
  289. //Synchronize out call
  290. if (pCurHandler->dwOutCallMessages & ThreadMsg_Synchronize)
  291. {
  292. CallCompletionRoutine(pCurHandler,ThreadMsg_Synchronize,
  293. HRESULT_FROM_WIN32(ERROR_CANCELLED),0,NULL);
  294. }
  295. //ShowProperties out call
  296. if (pCurHandler->dwOutCallMessages & ThreadMsg_ShowProperties)
  297. {
  298. CallCompletionRoutine(pCurHandler,ThreadMsg_ShowProperties,
  299. HRESULT_FROM_WIN32(ERROR_CANCELLED),0,NULL);
  300. }
  301. //Show Errors out call
  302. if (pCurHandler->dwOutCallMessages & ThreadMsg_ShowError)
  303. {
  304. CallCompletionRoutine(pCurHandler,ThreadMsg_ShowError,
  305. HRESULT_FROM_WIN32(ERROR_CANCELLED),0,NULL);
  306. }
  307. // force handler state to release.
  308. pCurHandler->HandlerState = HANDLERSTATE_RELEASE;
  309. return NOERROR;
  310. }
  311. //+---------------------------------------------------------------------------
  312. //
  313. // Member: CHndlrQueue::ForceKillHandlers, public
  314. //
  315. // Synopsis: Kills unresponsive handlers after timeout
  316. //
  317. // Returns: Appropriate return codes
  318. //
  319. // History: 30-Oct-98 susia Created.
  320. // 19-Nov-98 rogerg Change to only kill first unresponsive handler
  321. //
  322. //----------------------------------------------------------------------------
  323. #define BAD_HANDLERSTATE(pHandlerId) \
  324. ( (HANDLERSTATE_INSYNCHRONIZE >= pHandlerId->HandlerState) \
  325. || (pHandlerId->dwOutCallMessages & ThreadMsg_SetItemStatus) \
  326. )
  327. STDMETHODIMP CHndlrQueue::ForceKillHandlers(BOOL *pfItemToKill)
  328. {
  329. HRESULT hr = NOERROR;
  330. LPHANDLERINFO pCurHandler;
  331. CLock clockqueue(this);
  332. *pfItemToKill = TRUE; // if something strange happens make sure timer gets reset.
  333. clockqueue.Enter();
  334. pCurHandler = m_pFirstHandler;
  335. while (pCurHandler)
  336. {
  337. // if handler is cancelled but still in a noncancelled state or
  338. // is cancelled but stuck in the outcall then terminate.
  339. // need to check both because some handlers may call the callback
  340. // to set the state done but still be stuck in an out call.
  341. if ( (TRUE == pCurHandler->fCancelled) && BAD_HANDLERSTATE(pCurHandler) )
  342. {
  343. TCHAR pszHandlerName[MAX_SYNCMGRHANDLERNAME + 1];
  344. ConvertString(pszHandlerName,
  345. (pCurHandler->SyncMgrHandlerInfo).wszHandlerName,
  346. MAX_SYNCMGRHANDLERNAME);
  347. // yield because of message box in Terminate Handler call.
  348. Assert(!pCurHandler->fInTerminateCall);
  349. pCurHandler->fInTerminateCall = TRUE;
  350. clockqueue.Leave();
  351. hr = pCurHandler->pThreadProxy->TerminateHandlerThread(pszHandlerName,TRUE);
  352. clockqueue.Enter();
  353. pCurHandler->fInTerminateCall = FALSE;
  354. if (hr == S_OK)
  355. {
  356. LPHANDLERINFO pKilledHandler = pCurHandler;
  357. ForceCompleteOutCalls(pCurHandler);
  358. // now need to loop through remaining instances handlers off the same clsid
  359. // we just killed
  360. while(pCurHandler = pCurHandler->pNextHandler)
  361. {
  362. if (pCurHandler->clsidHandler == pKilledHandler->clsidHandler)
  363. {
  364. // must meet original kil criteria
  365. if ( (TRUE == pCurHandler->fCancelled) && BAD_HANDLERSTATE(pCurHandler) )
  366. {
  367. HRESULT hrProxyTerminate;
  368. pCurHandler->fInTerminateCall = TRUE;
  369. clockqueue.Leave();
  370. hrProxyTerminate = pCurHandler->pThreadProxy->TerminateHandlerThread(pszHandlerName,FALSE);
  371. clockqueue.Enter();
  372. Assert(S_OK == hrProxyTerminate);// this should never fail.
  373. ForceCompleteOutCalls(pCurHandler);
  374. pCurHandler->fInTerminateCall = FALSE;
  375. }
  376. }
  377. }
  378. }
  379. // if handled one , break out and reqiure to be called again.
  380. break;
  381. }
  382. pCurHandler = pCurHandler->pNextHandler;
  383. }
  384. // finally loop through the queue and see if there are any more items to kill
  385. *pfItemToKill = FALSE;
  386. pCurHandler = m_pFirstHandler;
  387. while (pCurHandler)
  388. {
  389. // if handler is cancelled but still in a noncancelled state or
  390. // is cancelled but stuck in the outcall then terminate.
  391. // need to check both because some handlers may call the callback
  392. // to set the state done but still be stuck in an out call.
  393. if ( (TRUE == pCurHandler->fCancelled) && BAD_HANDLERSTATE(pCurHandler) )
  394. {
  395. *pfItemToKill = TRUE;
  396. break;
  397. }
  398. pCurHandler = pCurHandler->pNextHandler;
  399. }
  400. clockqueue.Leave();
  401. return hr;
  402. }
  403. //+---------------------------------------------------------------------------
  404. //
  405. // Member: CHndlrQueue::Cancel, public
  406. //
  407. // Synopsis: Set the current Handler Items in the queue
  408. // into cancel mode.
  409. //
  410. // The Different States Are.
  411. // If the item is waiting for <= PrepareForSync place in Release
  412. // If InPrepareForSync Skip Items and then Synchrnoize
  413. // will check the complete value before calling through
  414. // and if set will just release the Handler.
  415. // If Waiting to Synchronize Skip Items then let Synchronize
  416. // Check for complete value and just set release
  417. // If Item is currently In the Synchronize Skip all items
  418. // and then just let synchronize return
  419. //
  420. // Algorithm. If <= PrepareForSync then place in Release, Else if <= InSynchronize
  421. // then SkipTheItems
  422. //
  423. // Note: Relies on Synchronize setting handler state before calling
  424. // through to Handlers Synchronize Method. PrepareForSync should
  425. // also check this in case new PrepareforSync request comes
  426. // in during an out call in this routine.
  427. //
  428. // Arguments:
  429. //
  430. // Returns: Appropriate return codes
  431. //
  432. // Modifies:
  433. //
  434. // History: 17-Nov-97 rogerg Created.
  435. //
  436. //----------------------------------------------------------------------------
  437. STDMETHODIMP CHndlrQueue::Cancel(void)
  438. {
  439. HRESULT hr = E_UNEXPECTED;
  440. LPHANDLERINFO pCurHandler;
  441. CLock clockqueue(this);
  442. clockqueue.Enter();
  443. // don't do anything is still processing the last cancel request
  444. if (!m_fInCancelCall)
  445. {
  446. m_fInCancelCall = TRUE;
  447. // first thing set cancel to true on all handler items
  448. // so if sync,PrepareForSyncRequest comes in during SetItemStatus
  449. // out call it will be cancelled immediately.
  450. pCurHandler = m_pFirstHandler;
  451. while (pCurHandler)
  452. {
  453. pCurHandler->fCancelled = TRUE;
  454. pCurHandler = pCurHandler->pNextHandler;
  455. }
  456. // now loop through looking for any items that need to have
  457. // their item status set.
  458. // !!!remember new requests can come in so only make out call
  459. // if fCancelled is set.
  460. // !!! items can be removed from queue in between our cancel call
  461. // and when we return.
  462. pCurHandler = m_pFirstHandler;
  463. while (pCurHandler)
  464. {
  465. CThreadMsgProxy *pThreadProxy = pCurHandler->pThreadProxy;
  466. if (pCurHandler->fCancelled && pThreadProxy
  467. && (pCurHandler->HandlerState >= HANDLERSTATE_INPREPAREFORSYNC)
  468. && (pCurHandler->HandlerState <= HANDLERSTATE_INSYNCHRONIZE) )
  469. {
  470. // could be in a setitemstatus call, if so then don't do another.
  471. // review - dup of SkipCode. should have a general purpose function
  472. // to call after setting what items should be cancelled.
  473. if (!(pCurHandler->dwOutCallMessages & ThreadMsg_SetItemStatus))
  474. {
  475. pCurHandler->dwOutCallMessages |= ThreadMsg_SetItemStatus;
  476. clockqueue.Leave();
  477. // send a reset to the hwnd we belong to if there is one
  478. if (m_hwndDlg)
  479. {
  480. SendMessage(m_hwndDlg,WM_PROGRESS_RESETKILLHANDLERSTIMER,0,0);
  481. }
  482. hr = pThreadProxy->SetItemStatus(GUID_NULL,SYNCMGRSTATUS_STOPPED);
  483. clockqueue.Enter();
  484. pCurHandler->dwOutCallMessages &= ~ThreadMsg_SetItemStatus;
  485. }
  486. }
  487. else if (pCurHandler->HandlerState < HANDLERSTATE_INPREPAREFORSYNC)
  488. {
  489. LPITEMLIST pCurItem;
  490. pCurHandler->HandlerState = HANDLERSTATE_RELEASE;
  491. // need to setup HwndCallback so progres gets updated.
  492. // review, after ship why can't setup HwndCallback on transferqueueu
  493. pCurHandler->hWndCallback = m_hwndDlg;
  494. // if handler hansn't been kicked off yet, just reset the items ourselves
  495. pCurItem = pCurHandler->pFirstItem;
  496. while (pCurItem)
  497. {
  498. if (pCurItem->fIncludeInProgressBar)
  499. {
  500. SYNCMGRPROGRESSITEM SyncProgressItem;
  501. SyncProgressItem.cbSize = sizeof(SYNCMGRPROGRESSITEM);
  502. SyncProgressItem.mask = SYNCMGRPROGRESSITEM_PROGVALUE | SYNCMGRPROGRESSITEM_MAXVALUE | SYNCMGRPROGRESSITEM_STATUSTYPE;
  503. SyncProgressItem.iProgValue = HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE;
  504. SyncProgressItem.iMaxValue = HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE;
  505. SyncProgressItem.dwStatusType = SYNCMGRSTATUS_STOPPED;
  506. // set progress faking we are in an out call so any releasecompleted
  507. // handler that comes through doesn't release us.
  508. // if already in outCall then progress just won't get updated
  509. // until next time.
  510. if (!(pCurHandler->dwOutCallMessages & ThreadMsg_SetItemStatus))
  511. {
  512. pCurHandler->dwOutCallMessages |= ThreadMsg_SetItemStatus;
  513. clockqueue.Leave();
  514. Progress(pCurHandler->pHandlerId,
  515. pCurItem->offlineItem.ItemID,&SyncProgressItem);
  516. clockqueue.Enter();
  517. pCurHandler->dwOutCallMessages &= ~ThreadMsg_SetItemStatus;
  518. }
  519. }
  520. pCurItem = pCurItem->pnextItem;
  521. }
  522. }
  523. pCurHandler = pCurHandler->pNextHandler;
  524. }
  525. m_fInCancelCall = FALSE;
  526. }
  527. clockqueue.Leave();
  528. return hr;
  529. }
  530. //+---------------------------------------------------------------------------
  531. //
  532. // Member: CHndlrQueue::MoveHandler, public
  533. //
  534. // Synopsis: Moves the Handler from a queue into this queue.
  535. //
  536. // Arguments: [pQueueMoveFrom] - Queue the handler is being moved from.
  537. // [pHandlerInfoMoveFrom] - Handler that is being moved
  538. // [ppHandlerId] - On Success contains the new HandlerID
  539. //
  540. // Returns: Appropriate return codes
  541. //
  542. // Modifies:
  543. //
  544. // History: 17-Nov-97 rogerg Created.
  545. //
  546. //----------------------------------------------------------------------------
  547. STDMETHODIMP CHndlrQueue::MoveHandler(CHndlrQueue *pQueueMoveFrom,
  548. LPHANDLERINFO pHandlerInfoMoveFrom,
  549. HANDLERINFO **ppHandlerId,
  550. CLock *pclockQueue)
  551. {
  552. LPITEMLIST pCurItem = NULL;
  553. JOBINFO *pJobInfo = NULL;
  554. BOOL fHasItemsToSync = FALSE;
  555. ASSERT_LOCKHELD(this); // items should already be locked when this function is called.
  556. ASSERT_LOCKHELD(pQueueMoveFrom);
  557. if (QUEUETYPE_PROGRESS != m_QueueType
  558. && QUEUETYPE_CHOICE != m_QueueType)
  559. {
  560. Assert(QUEUETYPE_CHOICE == m_QueueType);
  561. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  562. return E_UNEXPECTED; // review error code.
  563. }
  564. *ppHandlerId = 0;
  565. ++m_wHandlerCount;
  566. // pHandlerInfoMoveFrom->pHandlerId = m_wHandlerCount;
  567. pHandlerInfoMoveFrom->pNextHandler = NULL;
  568. *ppHandlerId = pHandlerInfoMoveFrom->pHandlerId;
  569. // now fix up the items duplicate flag information.
  570. pCurItem = pHandlerInfoMoveFrom->pFirstItem;
  571. while (pCurItem)
  572. {
  573. LPHANDLERINFO pHandlerMatched;
  574. LPITEMLIST pItemListMatch;
  575. // setup the information for the UI depending on if this item is check and
  576. // the state it is in.
  577. // if item is now within a valid range then uncheck it.
  578. if (SYNCMGRITEMSTATE_CHECKED == pCurItem->offlineItem.dwItemState
  579. && ( (pHandlerInfoMoveFrom->HandlerState < HANDLERSTATE_PREPAREFORSYNC)
  580. || (pHandlerInfoMoveFrom->HandlerState >= HANDLERSTATE_RELEASE) ) )
  581. {
  582. Assert(pHandlerInfoMoveFrom->HandlerState >= HANDLERSTATE_PREPAREFORSYNC); // this should never happen.
  583. pCurItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_UNCHECKED;
  584. }
  585. // setup the UI information based on if the item is checked.
  586. // or if its a hidden item.
  587. if (SYNCMGRITEMSTATE_UNCHECKED == pCurItem->offlineItem.dwItemState
  588. || pCurItem->fHiddenItem)
  589. {
  590. SetItemProgressValues(pCurItem,HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE,HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  591. pCurItem->fIncludeInProgressBar = FALSE;
  592. }
  593. else
  594. {
  595. fHasItemsToSync = TRUE;
  596. SetItemProgressValues(pCurItem,0,HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  597. pCurItem->fIncludeInProgressBar = TRUE;
  598. }
  599. if (IsItemAlreadyInList(pHandlerInfoMoveFrom->clsidHandler,
  600. (pCurItem->offlineItem.ItemID),
  601. pHandlerInfoMoveFrom->pHandlerId,
  602. &pHandlerMatched,&pItemListMatch) )
  603. {
  604. pCurItem->fDuplicateItem = TRUE;
  605. }
  606. else
  607. {
  608. Assert(FALSE == pCurItem->fDuplicateItem); // catch case of duplicate getting lost
  609. pCurItem->fDuplicateItem = FALSE;
  610. }
  611. pCurItem = pCurItem->pnextItem;
  612. }
  613. // if the item we are moving has a Proxy then update the proxy to the new queue.
  614. // We update this when the item is not attached to either queue.
  615. if (pHandlerInfoMoveFrom->pThreadProxy)
  616. {
  617. HANDLERINFO *pHandlerInfoArg = pHandlerInfoMoveFrom->pHandlerId;
  618. // set the proxy to point to the new information
  619. pHandlerInfoMoveFrom->pThreadProxy->SetProxyParams(m_hwndDlg
  620. ,m_dwQueueThreadId
  621. ,this
  622. ,pHandlerInfoArg);
  623. }
  624. // Add the handler to this list.
  625. if (NULL == m_pFirstHandler)
  626. {
  627. m_pFirstHandler = pHandlerInfoMoveFrom;
  628. // Assert(1 == m_wHandlerCount); // Review = HandlerCount doesn't have to be 1 if ReleaseCompltedHandlers has been called.
  629. }
  630. else
  631. {
  632. LPHANDLERINFO pCurHandlerInfo;
  633. pCurHandlerInfo = m_pFirstHandler;
  634. while (pCurHandlerInfo->pNextHandler)
  635. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  636. pCurHandlerInfo->pNextHandler = pHandlerInfoMoveFrom;
  637. }
  638. // if this is a progress queue and there are not items to sync for the
  639. // handler or the HandlerState isn't in PrepareForSync then set
  640. // the state to TransferRelease since it can be freed.
  641. if ((QUEUETYPE_PROGRESS == m_QueueType && !fHasItemsToSync )
  642. || (pHandlerInfoMoveFrom->HandlerState != HANDLERSTATE_PREPAREFORSYNC))
  643. {
  644. pHandlerInfoMoveFrom->HandlerState = HANDLERSTATE_TRANSFERRELEASE;
  645. }
  646. return NOERROR;
  647. }
  648. //+---------------------------------------------------------------------------
  649. //
  650. // Member: CHndlrQueue::TransferQueueData, public
  651. //
  652. // Synopsis: Moves the Items from one queue to another. Currently we only
  653. // support transferrring items from a choice queueu to a choice or
  654. // progress queue. Only handlers in the PREPAREFORSYNC state are moved
  655. // when transferring to a Progress queue. When transferring to a choice
  656. // queue only items in the ADDHANDLERITEMS state are moved.
  657. //
  658. // !!Warning - Cannot release lock during this process
  659. //
  660. // Arguments: [pQueueMoveFrom] - Queue to move items from.
  661. // [dwSyncFlags] - flags that started the sync
  662. // [pszConnectionName] - Connection the sync should be performed on, can be NULL
  663. // [szSchedulName] - Name of Schedule that started this Job. Can be NULL.
  664. // [hRasPendingEvent] - Event to signal when job is complete. Can be NULL.
  665. //
  666. // Returns: Appropriate return codes
  667. //
  668. // Modifies:
  669. //
  670. // History: 17-Nov-97 rogerg Created.
  671. //
  672. //----------------------------------------------------------------------------
  673. STDMETHODIMP CHndlrQueue::TransferQueueData(CHndlrQueue *pQueueMoveFrom
  674. /* ,DWORD dwSyncFlags,TCHAR *pzConnectionName,TCHAR *szScheduleName */)
  675. {
  676. HRESULT hr = E_UNEXPECTED;
  677. HANDLERINFO HandlerInfoMoveFrom;
  678. LPHANDLERINFO pHandlerInfoMoveFrom = &HandlerInfoMoveFrom;
  679. CLock clockqueue(this);
  680. CLock clockqueueMoveFrom(pQueueMoveFrom);
  681. clockqueue.Enter();
  682. clockqueueMoveFrom.Enter();
  683. m_fNumItemsCompleteNeedsARecalc = TRUE; // need to recalc NumItems next time
  684. if ((QUEUETYPE_PROGRESS != m_QueueType
  685. && QUEUETYPE_CHOICE != m_QueueType)|| QUEUETYPE_CHOICE != pQueueMoveFrom->m_QueueType)
  686. {
  687. Assert(QUEUETYPE_PROGRESS == m_QueueType || QUEUETYPE_CHOICE == m_QueueType);
  688. Assert(QUEUETYPE_CHOICE == pQueueMoveFrom->m_QueueType);
  689. }
  690. else if (NULL == pQueueMoveFrom->m_pFirstHandler) // if no job info then there aren't any items to move.
  691. {
  692. }
  693. else
  694. {
  695. JOBINFO *pMoveFromJobInfo = NULL;
  696. // transfer everything over and then release after done call freecompletedhandlers
  697. // to clean anything up.
  698. // transfer over all jobs
  699. Assert(pQueueMoveFrom->m_pFirstJobInfo);
  700. Assert(pQueueMoveFrom->m_pFirstJobInfo->pConnectionObj);
  701. pMoveFromJobInfo = pQueueMoveFrom->m_pFirstJobInfo;
  702. pQueueMoveFrom->m_pFirstJobInfo = NULL;
  703. if (NULL == m_pFirstJobInfo)
  704. {
  705. m_pFirstJobInfo = pMoveFromJobInfo;
  706. }
  707. else
  708. {
  709. JOBINFO *pCurLastJob = NULL;
  710. pCurLastJob = m_pFirstJobInfo;
  711. while (pCurLastJob->pNextJobInfo)
  712. {
  713. pCurLastJob = pCurLastJob->pNextJobInfo;
  714. }
  715. pCurLastJob->pNextJobInfo = pMoveFromJobInfo;
  716. }
  717. // loop through moving items, have to reassign the Handler ID and
  718. // !!Warning - This function does nothing with ListViewData it is up to the
  719. // caller to make sure this is set up properly
  720. // review - should just loop through fixing up necessary items and then
  721. // add entire list onto end. inneficient to do one at a time.
  722. pHandlerInfoMoveFrom->pNextHandler = pQueueMoveFrom->m_pFirstHandler;
  723. while (pHandlerInfoMoveFrom->pNextHandler)
  724. {
  725. LPHANDLERINFO pHandlerToMove;
  726. HANDLERINFO *pNewHandlerId;
  727. // Asserts for making sure the UI has been cleared from the queue
  728. Assert(FALSE == pHandlerInfoMoveFrom->pNextHandler->fHasErrorJumps);
  729. Assert(pHandlerInfoMoveFrom->pNextHandler->pJobInfo);
  730. // !!! Warning get next handler before transfer or next ptr will be invalid.
  731. pHandlerToMove = pHandlerInfoMoveFrom->pNextHandler;
  732. pHandlerInfoMoveFrom->pNextHandler = pHandlerToMove->pNextHandler;
  733. MoveHandler(pQueueMoveFrom,pHandlerToMove,&pNewHandlerId,&clockqueue);
  734. // now set the original queues head
  735. pQueueMoveFrom->m_pFirstHandler = HandlerInfoMoveFrom.pNextHandler;
  736. hr = NOERROR;
  737. }
  738. }
  739. clockqueue.Leave();
  740. clockqueueMoveFrom.Leave();
  741. // now free any handlers that came into the queue that we
  742. // don't want to do anything with .
  743. ReleaseHandlers(HANDLERSTATE_TRANSFERRELEASE);
  744. return hr;
  745. }
  746. //+---------------------------------------------------------------------------
  747. //
  748. // Member: CHndlrQueue::SetQueueHwnd, public
  749. //
  750. // Synopsis: informs the queue os the new dialog owner if any
  751. // queue must also loop through existing proxies
  752. // and reset their hwnd.
  753. //
  754. // Arguments:
  755. //
  756. // Returns: Appropriate return codes
  757. //
  758. // Modifies:
  759. //
  760. // History: 17-Nov-97 rogerg Created.
  761. //
  762. //----------------------------------------------------------------------------
  763. STDMETHODIMP CHndlrQueue::SetQueueHwnd(CBaseDlg *pDlg)
  764. {
  765. LPHANDLERINFO pCurHandlerInfo;
  766. CLock clockqueue(this);
  767. clockqueue.Enter();
  768. m_pDlg = pDlg;
  769. if (m_pDlg)
  770. {
  771. m_hwndDlg = m_pDlg->GetHwnd();
  772. }
  773. else
  774. {
  775. m_hwndDlg = NULL;
  776. }
  777. m_dwQueueThreadId = GetCurrentThreadId(); // make sure queu threadId is updated.
  778. pCurHandlerInfo = m_pFirstHandler;
  779. while (pCurHandlerInfo)
  780. {
  781. if (pCurHandlerInfo->pThreadProxy)
  782. {
  783. pCurHandlerInfo->pThreadProxy->SetProxyParams(m_hwndDlg
  784. ,m_dwQueueThreadId
  785. ,this
  786. ,pCurHandlerInfo->pHandlerId);
  787. }
  788. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  789. }
  790. clockqueue.Leave();
  791. return NOERROR;
  792. }
  793. //+---------------------------------------------------------------------------
  794. //
  795. // Member: CHndlrQueue::ReleaseCompletedHandlers, public
  796. //
  797. // Synopsis: Releases any Handlers that are in the Release or free
  798. // dead state from the queue.
  799. //
  800. // Arguments:
  801. //
  802. // Returns: Appropriate return codes
  803. //
  804. // Modifies:
  805. //
  806. // History: 17-Nov-97 rogerg Created.
  807. //
  808. //----------------------------------------------------------------------------
  809. STDMETHODIMP CHndlrQueue::ReleaseCompletedHandlers()
  810. {
  811. return ReleaseHandlers(HANDLERSTATE_RELEASE);
  812. }
  813. //+---------------------------------------------------------------------------
  814. //
  815. // Member: CHndlrQueue::FreeAllHandlers, public
  816. //
  817. // Synopsis: Releases all handlers from the queue.
  818. //
  819. // Arguments:
  820. //
  821. // Returns: Appropriate return codes
  822. //
  823. // Modifies:
  824. //
  825. // History: 17-Nov-97 rogerg Created.
  826. //
  827. //----------------------------------------------------------------------------
  828. STDMETHODIMP CHndlrQueue::FreeAllHandlers(void)
  829. {
  830. return ReleaseHandlers(HANDLERSTATE_NEW); // release handlers in all states.
  831. }
  832. //+---------------------------------------------------------------------------
  833. //
  834. // Member: CHndlrQueue::ReleaseHandlers, public
  835. //
  836. // Synopsis: Releases any Handlers are in a state >= the requested state
  837. //
  838. // Arguments: HandlerState - Frees all handlers that have a state >= the requested state.
  839. //
  840. // !!Warning: This should be the only place the proxy if freed and
  841. // the handler is removed from the list.
  842. //
  843. // Returns: Appropriate return codes
  844. //
  845. // Modifies:
  846. //
  847. // History: 17-Nov-97 rogerg Created.
  848. //
  849. //----------------------------------------------------------------------------
  850. STDMETHODIMP CHndlrQueue::ReleaseHandlers(HANDLERSTATE HandlerState)
  851. {
  852. HANDLERINFO HandlerInfoStart;
  853. LPHANDLERINFO pPrevHandlerInfo = &HandlerInfoStart;
  854. LPHANDLERINFO pCurHandlerInfo = NULL;
  855. LPHANDLERINFO pHandlerFreeList = NULL;
  856. LPITEMLIST pCurItem = NULL;
  857. LPITEMLIST pNextItem = NULL;
  858. CLock clockqueue(this);
  859. ASSERT_LOCKNOTHELD(this); // shouldn't be any out calls in progress when this is called.
  860. clockqueue.Enter();
  861. m_fNumItemsCompleteNeedsARecalc = TRUE; // need to recalc next GetProgress.
  862. // loop through the handlers finding the one that match the criteria
  863. // removing them from list and adding them to the free list
  864. // we do this so don't have to worry about someone else accessing
  865. // handlers we are freeing during an out call.
  866. if (HANDLERSTATE_NEW == HandlerState)
  867. {
  868. // Release should only be called on this state if caller is sure no out
  869. // calls are in progress or else handler may not exist when
  870. // they come back
  871. pHandlerFreeList = m_pFirstHandler;
  872. m_pFirstHandler = NULL;
  873. }
  874. else
  875. {
  876. Assert(HandlerState >= HANDLERSTATE_RELEASE); // if in release no out calls are in progress.
  877. pPrevHandlerInfo->pNextHandler = m_pFirstHandler;
  878. while (pPrevHandlerInfo->pNextHandler)
  879. {
  880. pCurHandlerInfo = pPrevHandlerInfo->pNextHandler;
  881. // if meet handler state criteria and not in any out calls then can
  882. // remove from list.
  883. // if request for HANDLERSTATE_NEW then assert than there shouldn't be
  884. // any out calls in progress or terminating.
  885. Assert(!(HandlerState == HANDLERSTATE_NEW) ||
  886. (0 == pCurHandlerInfo->dwOutCallMessages && !pCurHandlerInfo->fInTerminateCall));
  887. if ( (HandlerState <= pCurHandlerInfo->HandlerState)
  888. && (0 == pCurHandlerInfo->dwOutCallMessages)
  889. && !(pCurHandlerInfo->fInTerminateCall))
  890. {
  891. Assert (HANDLERSTATE_RELEASE == pCurHandlerInfo->HandlerState ||
  892. HANDLERSTATE_TRANSFERRELEASE == pCurHandlerInfo->HandlerState ||
  893. HANDLERSTATE_HASERRORJUMPS == pCurHandlerInfo->HandlerState ||
  894. HANDLERSTATE_DEAD == pCurHandlerInfo->HandlerState);
  895. // remove from queue list and add to free.
  896. pPrevHandlerInfo->pNextHandler = pCurHandlerInfo->pNextHandler;
  897. pCurHandlerInfo->pNextHandler = pHandlerFreeList;
  898. pHandlerFreeList = pCurHandlerInfo;
  899. }
  900. else
  901. {
  902. // if no match then just continue.
  903. pPrevHandlerInfo = pCurHandlerInfo;
  904. }
  905. }
  906. // update the queue head.
  907. m_pFirstHandler = HandlerInfoStart.pNextHandler;
  908. }
  909. // now loop through the free list freeing the items.
  910. while (pHandlerFreeList)
  911. {
  912. pCurHandlerInfo = pHandlerFreeList;
  913. pHandlerFreeList = pHandlerFreeList->pNextHandler;
  914. // if the item has a job info release the reference on it.
  915. if (pCurHandlerInfo->pJobInfo)
  916. {
  917. ReleaseJobInfo(pCurHandlerInfo->pJobInfo);
  918. pCurHandlerInfo->pJobInfo = NULL;
  919. }
  920. if (pCurHandlerInfo->pThreadProxy)
  921. {
  922. CThreadMsgProxy *pThreadProxy = pCurHandlerInfo->pThreadProxy;
  923. HWND hwndCallback;
  924. Assert(HANDLERSTATE_DEAD != pCurHandlerInfo->HandlerState);
  925. pCurHandlerInfo->HandlerState = HANDLERSTATE_DEAD;
  926. pThreadProxy = pCurHandlerInfo->pThreadProxy;
  927. pCurHandlerInfo->pThreadProxy = NULL;
  928. hwndCallback = pCurHandlerInfo->hWndCallback;
  929. pCurHandlerInfo->hWndCallback = NULL;
  930. clockqueue.Leave(); // release lock when making the OutCall.
  931. pThreadProxy->Release(); // review, don't release proxy to try to catch race condition.
  932. clockqueue.Enter();
  933. }
  934. pCurItem = pCurHandlerInfo->pFirstItem;
  935. while (pCurItem)
  936. {
  937. pNextItem = pCurItem->pnextItem;
  938. FREE(pCurItem);
  939. pCurItem = pNextItem;
  940. }
  941. FREE(pCurHandlerInfo);
  942. }
  943. clockqueue.Leave();
  944. return NOERROR;
  945. }
  946. //+---------------------------------------------------------------------------
  947. //
  948. // Member: CHndlrQueue::GetHandlerInfo, public
  949. //
  950. // Synopsis: Gets Data associated with the HandlerID and ItemID
  951. //
  952. // Arguments: [clsidHandler] - ClsiId Of Handler the Item belongs too
  953. //
  954. // Returns: Appropriate return codes
  955. //
  956. // Modifies:
  957. //
  958. // History: 17-Nov-97 rogerg Created.
  959. //
  960. //----------------------------------------------------------------------------
  961. STDMETHODIMP CHndlrQueue::GetHandlerInfo(REFCLSID clsidHandler,
  962. LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo)
  963. {
  964. HRESULT hr = S_FALSE;
  965. LPHANDLERINFO pCurHandlerInfo = NULL;
  966. CLock clockqueue(this);
  967. clockqueue.Enter();
  968. // find first handler that matches the request CLSID
  969. pCurHandlerInfo = m_pFirstHandler;
  970. while (pCurHandlerInfo )
  971. {
  972. if (clsidHandler == pCurHandlerInfo->clsidHandler)
  973. {
  974. *pSyncMgrHandlerInfo = pCurHandlerInfo->SyncMgrHandlerInfo;
  975. hr = NOERROR;
  976. break;
  977. }
  978. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  979. }
  980. clockqueue.Leave();
  981. return hr;
  982. }
  983. //+---------------------------------------------------------------------------
  984. //
  985. // Member: CHndlrQueue::GetHandlerInfo, public
  986. //
  987. // Synopsis: Gets Data associated with the HandlerID and ItemID
  988. //
  989. // Arguments: [wHandlerId] - Id Of Handler the Item belongs too
  990. //
  991. // Returns: Appropriate return codes
  992. //
  993. // Modifies:
  994. //
  995. // History: 17-Nov-97 rogerg Created.
  996. //
  997. //----------------------------------------------------------------------------
  998. STDMETHODIMP CHndlrQueue::GetHandlerInfo(HANDLERINFO *pHandlerId,
  999. LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo)
  1000. {
  1001. HRESULT hr = S_FALSE;
  1002. LPHANDLERINFO pHandlerInfo = NULL;
  1003. CLock clockqueue(this);
  1004. clockqueue.Enter();
  1005. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  1006. {
  1007. *pSyncMgrHandlerInfo = pHandlerInfo->SyncMgrHandlerInfo;
  1008. hr = NOERROR;
  1009. }
  1010. clockqueue.Leave();
  1011. return hr;
  1012. }
  1013. //+---------------------------------------------------------------------------
  1014. //
  1015. // Member: CHndlrQueue::GetItemDataAtIndex, public
  1016. //
  1017. // Synopsis: Gets Data associated with the HandlerID and ItemID
  1018. //
  1019. // Arguments: [wHandlerId] - Id Of Handler the Item belongs too
  1020. // [wItemID] - Identifies the Item in the Handler
  1021. // [pclsidHandler] - on return contains a pointer to the clsid of the Handler
  1022. // [offlineItem] - on returns contains a pointer to the OfflineItem for the item.
  1023. // [pfHiddenItem] - On return is a bool indicating if this item is hidden.
  1024. //
  1025. // Returns: Appropriate return codes
  1026. //
  1027. // Modifies:
  1028. //
  1029. // History: 17-Nov-97 rogerg Created.
  1030. //
  1031. //----------------------------------------------------------------------------
  1032. STDMETHODIMP CHndlrQueue::GetItemDataAtIndex(HANDLERINFO *pHandlerId,WORD wItemID,
  1033. CLSID *pclsidHandler,SYNCMGRITEM *offlineItem,BOOL *pfHiddenItem)
  1034. {
  1035. BOOL fFoundMatch = FALSE;
  1036. LPHANDLERINFO pCurHandlerInfo = NULL;
  1037. LPITEMLIST pCurItem = NULL;
  1038. CLock clockqueue(this);
  1039. clockqueue.Enter();
  1040. pCurHandlerInfo = m_pFirstHandler;
  1041. while (pCurHandlerInfo && !fFoundMatch)
  1042. {
  1043. // only valid if Hanlder is in the PrepareForSync state.
  1044. if (pHandlerId == pCurHandlerInfo->pHandlerId) // see if CLSID matches
  1045. {
  1046. // see if handler info has a matching item
  1047. pCurItem = pCurHandlerInfo->pFirstItem;
  1048. while (pCurItem)
  1049. {
  1050. if (wItemID == pCurItem->wItemId)
  1051. {
  1052. fFoundMatch = TRUE;
  1053. break;
  1054. }
  1055. pCurItem = pCurItem->pnextItem;
  1056. }
  1057. }
  1058. if (!fFoundMatch)
  1059. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1060. }
  1061. if (fFoundMatch)
  1062. {
  1063. if (pclsidHandler)
  1064. {
  1065. *pclsidHandler = pCurHandlerInfo->clsidHandler;
  1066. }
  1067. if (offlineItem)
  1068. {
  1069. *offlineItem = pCurItem->offlineItem;
  1070. }
  1071. if (pfHiddenItem)
  1072. {
  1073. *pfHiddenItem = pCurItem->fHiddenItem;
  1074. }
  1075. }
  1076. clockqueue.Leave();
  1077. return fFoundMatch ? NOERROR : S_FALSE;
  1078. }
  1079. //+---------------------------------------------------------------------------
  1080. //
  1081. // Member: CHndlrQueue::GetItemDataAtIndex, public
  1082. //
  1083. // Synopsis: Gets Data associated with the HandlerID and OfflineItemID
  1084. //
  1085. // Arguments: [wHandlerId] - Id Of Handler the Item belongs too
  1086. // [ItemID] - identifies the Item by its OfflineItemID
  1087. // [pclsidHandler] - on return contains a pointer to the clsid of the Handler
  1088. // [offlineItem] - on returns contains a pointer to the OfflineItem for the item.
  1089. // [pfHiddenItem] - On return is a bool indicating if this item is a hidden item.
  1090. //
  1091. // Returns: Appropriate return codes
  1092. //
  1093. // Modifies:
  1094. //
  1095. // History: 17-Nov-97 rogerg Created.
  1096. //
  1097. //----------------------------------------------------------------------------
  1098. STDMETHODIMP CHndlrQueue::GetItemDataAtIndex(HANDLERINFO *pHandlerId,REFSYNCMGRITEMID ItemID,CLSID *pclsidHandler,
  1099. SYNCMGRITEM *offlineItem,BOOL *pfHiddenItem)
  1100. {
  1101. BOOL fFoundMatch = FALSE;
  1102. LPHANDLERINFO pCurHandlerInfo = NULL;
  1103. LPITEMLIST pCurItem = NULL;
  1104. CLock clockqueue(this);
  1105. clockqueue.Enter();
  1106. pCurHandlerInfo = m_pFirstHandler;
  1107. while (pCurHandlerInfo && !fFoundMatch)
  1108. {
  1109. // only valid if handler is in the PrepareForSync state.
  1110. if (pHandlerId == pCurHandlerInfo->pHandlerId) // see if CLSID matches
  1111. {
  1112. // see if handler info has a matching item
  1113. pCurItem = pCurHandlerInfo->pFirstItem;
  1114. while (pCurItem)
  1115. {
  1116. if (ItemID == pCurItem->offlineItem.ItemID)
  1117. {
  1118. fFoundMatch = TRUE;
  1119. break;
  1120. }
  1121. pCurItem = pCurItem->pnextItem;
  1122. }
  1123. }
  1124. if (!fFoundMatch)
  1125. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1126. }
  1127. if (fFoundMatch)
  1128. {
  1129. *pclsidHandler = pCurHandlerInfo->clsidHandler;
  1130. *offlineItem = pCurItem->offlineItem;
  1131. *pfHiddenItem = pCurItem->fHiddenItem;
  1132. }
  1133. clockqueue.Leave();
  1134. return fFoundMatch ? NOERROR : S_FALSE;
  1135. }
  1136. //+---------------------------------------------------------------------------
  1137. //
  1138. // Member: CHndlrQueue::FindFirstItemInState, public
  1139. //
  1140. // Synopsis: Finds the first Item in the queue that matches the given state.
  1141. //
  1142. // Arguments:
  1143. // [hndlrState] - specifies matching state we are looking for.
  1144. // [pwHandlerId] - on return contains the HandlerID of the Item
  1145. // [pwItemID] - on returns contains the ItemID of the item in the queue.
  1146. //
  1147. // Returns: NOERROR if an Item was found with an unassigned ListView.
  1148. // S_FALSE - if no Item was found.
  1149. // Appropriate error return codes
  1150. //
  1151. // Modifies:
  1152. //
  1153. // History: 30-Jul-98 rogerg Created.
  1154. //
  1155. //----------------------------------------------------------------------------
  1156. STDMETHODIMP CHndlrQueue::FindFirstItemInState(HANDLERSTATE hndlrState,
  1157. HANDLERINFO **ppHandlerId,WORD *pwItemID)
  1158. {
  1159. return FindNextItemInState(hndlrState,0,0,ppHandlerId,pwItemID);
  1160. }
  1161. //+---------------------------------------------------------------------------
  1162. //
  1163. // Member: CHndlrQueue::FindNextItemInState, public
  1164. //
  1165. // Synopsis: Finds the first Item in the queue that matches the given state.
  1166. // after the specified item.
  1167. //
  1168. // Arguments:
  1169. // [hndlrState] - specifies matching state we are looking for.
  1170. // [pOfflineItemID] - on returns contains a pointer to the OfflineItem for the item.
  1171. // [pwHandlerId] - on return contains the HandlerID of the Item
  1172. // [pwItemID] - on returns contains the ItemID of the item in the queue.
  1173. //
  1174. // Returns: NOERROR if an Item was found with an unassigned ListView.
  1175. // S_FALSE - if no Item was found.
  1176. // Appropriate error return codes
  1177. //
  1178. // Modifies:
  1179. //
  1180. // History: 30-Jul-98 rogerg Created.
  1181. //
  1182. //----------------------------------------------------------------------------
  1183. STDMETHODIMP CHndlrQueue::FindNextItemInState(HANDLERSTATE hndlrState,
  1184. HANDLERINFO *pLastHandlerId,WORD wLastItemID,
  1185. HANDLERINFO **ppHandlerId,WORD *pwItemID)
  1186. {
  1187. BOOL fFoundMatch = FALSE;
  1188. LPHANDLERINFO pCurHandlerInfo = NULL;
  1189. LPITEMLIST pCurItem = NULL;
  1190. CLock clockqueue(this);
  1191. clockqueue.Enter();
  1192. pCurHandlerInfo = m_pFirstHandler;
  1193. if (0 != pLastHandlerId)
  1194. {
  1195. // loop until find the specified handler or hit end of list.
  1196. while(pCurHandlerInfo && pLastHandlerId != pCurHandlerInfo->pHandlerId)
  1197. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1198. if (NULL == pCurHandlerInfo) // reached end of list without finding the Handler
  1199. {
  1200. Assert(0); // user must have passed an invalid start HandlerID.
  1201. clockqueue.Leave();
  1202. return S_FALSE;
  1203. }
  1204. // loop until find item or end of item list
  1205. pCurItem = pCurHandlerInfo->pFirstItem;
  1206. while (pCurItem && pCurItem->wItemId != wLastItemID)
  1207. pCurItem = pCurItem->pnextItem;
  1208. if (NULL == pCurItem) // reached end of item list without finding the specified item
  1209. {
  1210. Assert(0); // user must have passed an invalid start ItemID.
  1211. clockqueue.Leave();
  1212. return S_FALSE;
  1213. }
  1214. // now we found the Handler and item. loop through remaining items for this handler
  1215. // if it still has another item then just return that.
  1216. pCurItem = pCurItem->pnextItem;
  1217. if (pCurItem)
  1218. {
  1219. Assert(hndlrState == pCurHandlerInfo->HandlerState); // should only be called in PrepareForSyncState
  1220. fFoundMatch = TRUE;
  1221. }
  1222. if (!fFoundMatch)
  1223. pCurHandlerInfo = pCurHandlerInfo->pNextHandler; // increment to next handler if no match
  1224. }
  1225. if (FALSE == fFoundMatch)
  1226. {
  1227. // in didn't find a match in the
  1228. while (pCurHandlerInfo)
  1229. {
  1230. if ((hndlrState == pCurHandlerInfo->HandlerState)
  1231. && (pCurHandlerInfo->pFirstItem) )
  1232. {
  1233. pCurItem = pCurHandlerInfo->pFirstItem;
  1234. fFoundMatch = TRUE;
  1235. break;
  1236. }
  1237. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1238. }
  1239. }
  1240. if (fFoundMatch)
  1241. {
  1242. *ppHandlerId = pCurHandlerInfo->pHandlerId;
  1243. *pwItemID = pCurItem->wItemId;
  1244. }
  1245. clockqueue.Leave();
  1246. return fFoundMatch ? NOERROR : S_FALSE;
  1247. }
  1248. //+---------------------------------------------------------------------------
  1249. //
  1250. // Member: CHndlrQueue::SetItemState, public
  1251. //
  1252. // Synopsis: Set the Item state for the first item finds that it
  1253. // matches in the Queue. Sets all other matches to unchecked.
  1254. //
  1255. // Arguments:
  1256. //
  1257. // Returns: Appropriate error return codes
  1258. //
  1259. // Modifies:
  1260. //
  1261. // History: 30-Jul-98 rogerg Created.
  1262. //
  1263. //----------------------------------------------------------------------------
  1264. STDMETHODIMP CHndlrQueue::SetItemState(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID,DWORD dwState)
  1265. {
  1266. LPHANDLERINFO pCurHandlerInfo = NULL;
  1267. LPITEMLIST pCurItem = NULL;
  1268. BOOL fFoundMatch = FALSE;
  1269. CLock clockqueue(this);
  1270. if (QUEUETYPE_CHOICE != m_QueueType)
  1271. {
  1272. Assert(QUEUETYPE_CHOICE == m_QueueType);
  1273. return E_UNEXPECTED;
  1274. }
  1275. clockqueue.Enter();
  1276. pCurHandlerInfo = m_pFirstHandler;
  1277. while (pCurHandlerInfo)
  1278. {
  1279. if (clsidHandler == pCurHandlerInfo->clsidHandler)
  1280. {
  1281. pCurItem = pCurHandlerInfo->pFirstItem;
  1282. while (pCurItem)
  1283. {
  1284. if (ItemID == pCurItem->offlineItem.ItemID)
  1285. {
  1286. // if the handlerstate is not prepareforsync or not first match then uncheck
  1287. if ((HANDLERSTATE_PREPAREFORSYNC != pCurHandlerInfo->HandlerState)
  1288. || fFoundMatch)
  1289. {
  1290. pCurItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_UNCHECKED;
  1291. }
  1292. else
  1293. {
  1294. pCurItem->offlineItem.dwItemState = dwState;
  1295. fFoundMatch = TRUE;
  1296. }
  1297. }
  1298. pCurItem = pCurItem->pnextItem;
  1299. }
  1300. }
  1301. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1302. }
  1303. clockqueue.Leave();
  1304. Assert(fFoundMatch); // we should have found at least one match.
  1305. return NOERROR;
  1306. }
  1307. //+---------------------------------------------------------------------------
  1308. //
  1309. // Member: CHndlrQueue::SkipItem, public
  1310. //
  1311. // Synopsis: loop through handler and mark the items appropriately that match..
  1312. //
  1313. // Arguments: [iItem] - List View Item to skip.
  1314. //
  1315. // Returns: Appropriate return codes.
  1316. //
  1317. // Modifies:
  1318. //
  1319. // History: 17-Nov-97 rogerg Created.
  1320. //
  1321. //----------------------------------------------------------------------------
  1322. STDMETHODIMP CHndlrQueue::SkipItem(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID)
  1323. {
  1324. LPHANDLERINFO pCurHandlerInfo = NULL;
  1325. LPITEMLIST pCurItem = NULL;
  1326. CLock clockqueue(this);
  1327. HRESULT hr = NOERROR;
  1328. if (QUEUETYPE_PROGRESS != m_QueueType)
  1329. {
  1330. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  1331. return E_UNEXPECTED;
  1332. }
  1333. clockqueue.Enter();
  1334. pCurHandlerInfo = m_pFirstHandler;
  1335. while (pCurHandlerInfo )
  1336. {
  1337. if (clsidHandler == pCurHandlerInfo->clsidHandler)
  1338. {
  1339. pCurItem = pCurHandlerInfo->pFirstItem;
  1340. while (pCurItem)
  1341. {
  1342. // if item is cancelled then also treat as a match to
  1343. // handle case cancel came in while in an out call.
  1344. if ( ItemID == pCurItem->offlineItem.ItemID)
  1345. {
  1346. // found an item, now if it hasn't started the sync or
  1347. // is not already complete set the value.
  1348. if ((pCurHandlerInfo->HandlerState < HANDLERSTATE_RELEASE) )
  1349. {
  1350. pCurItem->fItemCancelled = TRUE;
  1351. // If haven't called PrepareforSync yet then
  1352. // set uncheck the item so it isn't passed to PrepareForSync
  1353. // If PrepareForSync has already been called, call the items
  1354. // SkipMethod. if already in a setItemstatus call for this handler don't
  1355. // do anything.
  1356. // if not in another setitemstatus call loop through freeing all
  1357. // the items that have the cancel set.
  1358. // essentially a dup of cance and also handle case cancel
  1359. // comes win while this handler is in an out call.
  1360. if (!(pCurHandlerInfo->dwOutCallMessages & ThreadMsg_SetItemStatus))
  1361. {
  1362. pCurHandlerInfo->dwOutCallMessages |= ThreadMsg_SetItemStatus;
  1363. if (pCurHandlerInfo->HandlerState >= HANDLERSTATE_INPREPAREFORSYNC
  1364. && pCurItem->fSynchronizingItem )
  1365. {
  1366. CThreadMsgProxy *pThreadProxy;
  1367. SYNCMGRITEMID ItemId;
  1368. pThreadProxy = pCurHandlerInfo->pThreadProxy;
  1369. ItemId = pCurItem->offlineItem.ItemID;
  1370. clockqueue.Leave();
  1371. if (pThreadProxy)
  1372. {
  1373. hr = pThreadProxy->SetItemStatus(ItemId,
  1374. SYNCMGRSTATUS_SKIPPED);
  1375. }
  1376. clockqueue.Enter();
  1377. }
  1378. else
  1379. {
  1380. // once done skipping handler if state is <= preparefor sync we set the state accordingly.
  1381. // if were syncing up to handler.
  1382. if ( (pCurHandlerInfo->HandlerState <= HANDLERSTATE_PREPAREFORSYNC)
  1383. && (pCurItem->fIncludeInProgressBar) )
  1384. {
  1385. SYNCMGRPROGRESSITEM SyncProgressItem;
  1386. // unheck the state so PrepareForsync doesn't include
  1387. // this item.
  1388. pCurItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_UNCHECKED;
  1389. SyncProgressItem.cbSize = sizeof(SYNCMGRPROGRESSITEM);
  1390. SyncProgressItem.mask = SYNCMGRPROGRESSITEM_PROGVALUE | SYNCMGRPROGRESSITEM_MAXVALUE | SYNCMGRPROGRESSITEM_STATUSTYPE;
  1391. SyncProgressItem.iProgValue = HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE;
  1392. SyncProgressItem.iMaxValue = HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE;
  1393. SyncProgressItem.dwStatusType = SYNCMGRSTATUS_SKIPPED;
  1394. // need to setup HwndCallback so progres gets updated.
  1395. // review, after ship why can't setup HwndCallback on transferqueueu
  1396. pCurHandlerInfo->hWndCallback = m_hwndDlg;
  1397. clockqueue.Leave();
  1398. Progress(pCurHandlerInfo->pHandlerId,
  1399. pCurItem->offlineItem.ItemID,&SyncProgressItem);
  1400. clockqueue.Enter();
  1401. }
  1402. }
  1403. pCurHandlerInfo->dwOutCallMessages &= ~ThreadMsg_SetItemStatus;
  1404. }
  1405. }
  1406. }
  1407. pCurItem = pCurItem->pnextItem;
  1408. }
  1409. }
  1410. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1411. }
  1412. clockqueue.Leave();
  1413. return hr;
  1414. }
  1415. //+---------------------------------------------------------------------------
  1416. //
  1417. // Member: CHndlrQueue::ItemHasProperties, public
  1418. //
  1419. // Synopsis: determines if the item in the queue has properties.
  1420. // Uses the first item match it finds.
  1421. //
  1422. // Arguments:
  1423. //
  1424. // Returns: Appropriate error return codes
  1425. //
  1426. // Modifies:
  1427. //
  1428. // History: 30-Jul-98 rogerg Created.
  1429. //
  1430. //----------------------------------------------------------------------------
  1431. STDMETHODIMP CHndlrQueue::ItemHasProperties(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID)
  1432. {
  1433. LPHANDLERINFO pHandlerInfo;
  1434. LPITEMLIST pItem;
  1435. HRESULT hr = S_FALSE;
  1436. CLock clockqueue(this);
  1437. Assert(QUEUETYPE_CHOICE == m_QueueType);
  1438. ASSERT_LOCKNOTHELD(this);
  1439. clockqueue.Enter();
  1440. // item is guidNULL this is toplevel so use the getHandlerInfo, else see
  1441. // if the item supports showProperties.
  1442. if (NOERROR == FindItemData(clsidHandler,ItemID,
  1443. HANDLERSTATE_PREPAREFORSYNC,HANDLERSTATE_PREPAREFORSYNC,&pHandlerInfo,&pItem))
  1444. {
  1445. if (GUID_NULL == ItemID)
  1446. {
  1447. Assert(NULL == pItem);
  1448. hr = (pHandlerInfo->SyncMgrHandlerInfo).SyncMgrHandlerFlags
  1449. & SYNCMGRHANDLER_HASPROPERTIES ? S_OK : S_FALSE;
  1450. }
  1451. else
  1452. {
  1453. Assert(pItem);
  1454. if (pItem)
  1455. {
  1456. hr = (pItem->offlineItem).dwFlags & SYNCMGRITEM_HASPROPERTIES ? S_OK : S_FALSE;
  1457. }
  1458. else
  1459. {
  1460. hr = S_FALSE;
  1461. }
  1462. }
  1463. }
  1464. clockqueue.Leave();
  1465. return hr;
  1466. }
  1467. //+---------------------------------------------------------------------------
  1468. //
  1469. // Member: CHndlrQueue::ShowProperties, public
  1470. //
  1471. // Synopsis: Calls the ShowProperties Method on the first items it finds.
  1472. // Uses the first item match it finds.
  1473. //
  1474. // Arguments:
  1475. //
  1476. // Returns: Appropriate error return codes
  1477. //
  1478. // Modifies:
  1479. //
  1480. // History: 30-Jul-98 rogerg Created.
  1481. //
  1482. //----------------------------------------------------------------------------
  1483. STDMETHODIMP CHndlrQueue::ShowProperties(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID,HWND hwndParent)
  1484. {
  1485. LPHANDLERINFO pHandlerInfo;
  1486. LPHANDLERINFO pHandlerId = NULL;
  1487. LPITEMLIST pItem;
  1488. HRESULT hr = E_UNEXPECTED;
  1489. BOOL fHandlerCalled = FALSE;
  1490. BOOL fHasProperties = FALSE;
  1491. CThreadMsgProxy *pThreadProxy;
  1492. CLock clockqueue(this);
  1493. Assert(QUEUETYPE_CHOICE == m_QueueType);
  1494. ASSERT_LOCKNOTHELD(this);
  1495. clockqueue.Enter();
  1496. if (NOERROR == FindItemData(clsidHandler,ItemID,
  1497. HANDLERSTATE_PREPAREFORSYNC,HANDLERSTATE_PREPAREFORSYNC,&pHandlerInfo,&pItem))
  1498. {
  1499. Assert(HANDLERSTATE_PREPAREFORSYNC == pHandlerInfo->HandlerState);
  1500. pThreadProxy = pHandlerInfo->pThreadProxy;
  1501. pHandlerId = pHandlerInfo->pHandlerId;
  1502. Assert(!(ThreadMsg_ShowProperties & pHandlerInfo->dwOutCallMessages));
  1503. pHandlerInfo->dwOutCallMessages |= ThreadMsg_ShowProperties;
  1504. if (GUID_NULL == ItemID && pHandlerInfo)
  1505. {
  1506. Assert(NULL == pItem);
  1507. fHasProperties = (pHandlerInfo->SyncMgrHandlerInfo).SyncMgrHandlerFlags
  1508. & SYNCMGRHANDLER_HASPROPERTIES ? TRUE : FALSE;
  1509. }
  1510. else if (pItem)
  1511. {
  1512. Assert(SYNCMGRITEM_HASPROPERTIES & pItem->offlineItem.dwFlags);
  1513. fHasProperties = (pItem->offlineItem).dwFlags
  1514. & SYNCMGRITEM_HASPROPERTIES ? TRUE : FALSE;
  1515. }
  1516. else
  1517. {
  1518. fHasProperties = FALSE;
  1519. }
  1520. clockqueue.Leave();
  1521. // make sure properties flag isn't set.
  1522. if (fHasProperties && pThreadProxy )
  1523. {
  1524. fHandlerCalled = TRUE;
  1525. hr = pThreadProxy->ShowProperties(hwndParent,ItemID);
  1526. }
  1527. else
  1528. {
  1529. AssertSz(0,"ShowProperties called on an Item without properties");
  1530. hr = S_FALSE;
  1531. }
  1532. Assert(pHandlerId);
  1533. if ( (fHandlerCalled && (FAILED(hr))) || (!fHandlerCalled) )
  1534. {
  1535. GUID guidCompletion = ItemID;
  1536. CallCompletionRoutine(pHandlerId,ThreadMsg_ShowProperties,hr,1,&guidCompletion);
  1537. // since called completion routine map anything but S_OK to S_FALSE;
  1538. // so caller doesn't wait for the callback.
  1539. if (S_OK != hr)
  1540. {
  1541. hr = S_FALSE;
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. Assert(FAILED(hr)); // should return some failure so caller knows callback isn't coming.
  1548. clockqueue.Leave();
  1549. }
  1550. return hr;
  1551. }
  1552. //+---------------------------------------------------------------------------
  1553. //
  1554. // Member: CHndlrQueue::ReEnumHandlerItems, public
  1555. //
  1556. // Synopsis: Deletes any Items associated with any handlers that
  1557. // match the clsid of the handler and then
  1558. // call the first handlers in the list enumeration method
  1559. // again.
  1560. //
  1561. // Arguments:
  1562. //
  1563. // Returns: Appropriate error return codes
  1564. //
  1565. // Modifies:
  1566. //
  1567. // History: 30-Jul-98 rogerg Created.
  1568. //
  1569. //----------------------------------------------------------------------------
  1570. STDMETHODIMP CHndlrQueue::ReEnumHandlerItems(REFCLSID clsidHandler,REFSYNCMGRITEMID ItemID)
  1571. {
  1572. LPHANDLERINFO pCurHandlerInfo = NULL;
  1573. HANDLERINFO *pHandlerId = NULL;
  1574. LPITEMLIST pCurItem = NULL;
  1575. CLock clockqueue(this);
  1576. if (QUEUETYPE_CHOICE != m_QueueType)
  1577. {
  1578. Assert(QUEUETYPE_CHOICE == m_QueueType);
  1579. return E_UNEXPECTED;
  1580. }
  1581. clockqueue.Enter();
  1582. pCurHandlerInfo = m_pFirstHandler;
  1583. while (pCurHandlerInfo)
  1584. {
  1585. if (clsidHandler == pCurHandlerInfo->clsidHandler)
  1586. {
  1587. LPITEMLIST pNextItem;
  1588. // if first handler we found update the handlerID
  1589. if (NULL == pHandlerId)
  1590. {
  1591. pHandlerId = pCurHandlerInfo->pHandlerId;
  1592. pCurHandlerInfo->HandlerState = HANDLERSTATE_ADDHANDLERTEMS; // put back to addhandlerItems statest
  1593. }
  1594. pCurHandlerInfo->wItemCount = 0;
  1595. pCurItem = pCurHandlerInfo->pFirstItem;
  1596. while (pCurItem)
  1597. {
  1598. pNextItem = pCurItem->pnextItem;
  1599. FREE(pCurItem);
  1600. pCurItem = pNextItem;
  1601. }
  1602. pCurHandlerInfo->pFirstItem = NULL;
  1603. }
  1604. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1605. }
  1606. clockqueue.Leave();
  1607. // if have a handler id add them back to the queue
  1608. if (pHandlerId)
  1609. {
  1610. DWORD cbNumItemsAdded;
  1611. AddHandlerItemsToQueue(pHandlerId,&cbNumItemsAdded);
  1612. }
  1613. return NOERROR;
  1614. }
  1615. //+---------------------------------------------------------------------------
  1616. //
  1617. // Member: CHndlrQueue::IsItemCompleted, private
  1618. //
  1619. // Synopsis: Given an handler item determines if its
  1620. // synchronization is completed
  1621. //
  1622. // !!!This is not efficient. n! solution. If get
  1623. // a lot of items may need to have to rewrite
  1624. // and cache some information concerning dup
  1625. // items.
  1626. //
  1627. // Arguments: [wHandlerId] - Handler the item belongs too.
  1628. // [wItemID] - Identifies the Item
  1629. //
  1630. // Returns:
  1631. //
  1632. // Modifies:
  1633. //
  1634. // History: 17-Nov-97 rogerg Created.
  1635. //
  1636. //----------------------------------------------------------------------------
  1637. BOOL CHndlrQueue::IsItemCompleted(LPHANDLERINFO pHandler,LPITEMLIST pItem)
  1638. {
  1639. CLSID clsidHandler;
  1640. SYNCMGRITEMID ItemId;
  1641. int iItemNotComplete = 0;
  1642. Assert(pHandler);
  1643. Assert(pItem);
  1644. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  1645. clsidHandler = pHandler->clsidHandler;
  1646. ItemId = pItem->offlineItem.ItemID;
  1647. // back up to beginning of handler to simplify logic
  1648. // items must be pCurItem->fIncludeInProgressBar && !pCurItem->fProgressBarHandled
  1649. // to count toward not being a completion;
  1650. while (pHandler)
  1651. {
  1652. if (pHandler->clsidHandler == clsidHandler)
  1653. {
  1654. // see if handler info has a matching item
  1655. pItem = pHandler->pFirstItem;
  1656. while (pItem)
  1657. {
  1658. if (pItem->offlineItem.ItemID
  1659. == ItemId)
  1660. {
  1661. if (pItem->fIncludeInProgressBar
  1662. && !pItem->fProgressBarHandled)
  1663. {
  1664. if (pItem->iProgValue < pItem->iProgMaxValue)
  1665. {
  1666. ++iItemNotComplete;
  1667. }
  1668. pItem->fProgressBarHandled = TRUE;
  1669. }
  1670. }
  1671. pItem = pItem->pnextItem;
  1672. }
  1673. }
  1674. pHandler = pHandler->pNextHandler;
  1675. }
  1676. return iItemNotComplete ? FALSE : TRUE;
  1677. }
  1678. //+---------------------------------------------------------------------------
  1679. //
  1680. // Member: CHndlrQueue::SetItemProgressInfo, public
  1681. //
  1682. // Synopsis: Updates the stored progress information for the
  1683. // Associated Items
  1684. //
  1685. // Arguments: [wHandlerId] - Handler the item belongs too.
  1686. // [wItemID] - Identifies the Item
  1687. // [pSyncProgressItem] - Pointer to Progress Information.
  1688. // [pfProgressChanged] - returns true if any progress values were changed
  1689. // for the item
  1690. //
  1691. // Returns: NOERROR - at least one item with the iItem assigned was found
  1692. // S_FALSE - Item does not have properties.
  1693. // Appropriate error return codes
  1694. //
  1695. // Modifies:
  1696. //
  1697. // History: 17-Nov-97 rogerg Created.
  1698. //
  1699. //----------------------------------------------------------------------------
  1700. STDMETHODIMP CHndlrQueue::SetItemProgressInfo(HANDLERINFO *pHandlerId,WORD wItemID,
  1701. LPSYNCMGRPROGRESSITEM pSyncProgressItem,
  1702. BOOL *pfProgressChanged)
  1703. {
  1704. HRESULT hr = E_UNEXPECTED;
  1705. LPHANDLERINFO pHandlerInfo = NULL;
  1706. BOOL fFoundMatch = FALSE;
  1707. LPITEMLIST pCurItem = NULL;
  1708. CLock clockqueue(this);
  1709. Assert(pfProgressChanged);
  1710. *pfProgressChanged = FALSE;
  1711. if (QUEUETYPE_PROGRESS != m_QueueType)
  1712. {
  1713. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  1714. return E_UNEXPECTED; // review error code.
  1715. }
  1716. clockqueue.Enter();
  1717. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  1718. {
  1719. // try to find the matching item.
  1720. pCurItem = pHandlerInfo->pFirstItem;
  1721. while (pCurItem)
  1722. {
  1723. if (wItemID == pCurItem->wItemId)
  1724. {
  1725. fFoundMatch = TRUE;
  1726. break;
  1727. }
  1728. pCurItem = pCurItem->pnextItem;
  1729. }
  1730. }
  1731. if (fFoundMatch)
  1732. {
  1733. SetItemProgressInfo(pCurItem,pSyncProgressItem,pfProgressChanged);
  1734. }
  1735. clockqueue.Leave();
  1736. return fFoundMatch ? S_OK : S_FALSE;
  1737. }
  1738. //+---------------------------------------------------------------------------
  1739. //
  1740. // Member: CHndlrQueue::SetItemProgressInfo, private
  1741. //
  1742. // Synopsis: Updates the stored progress information for the
  1743. // Associated iTEM
  1744. //
  1745. // Arguments: [pItem] - Identifies the Item
  1746. // [pSyncProgressItem] - Pointer to Progress Information.
  1747. // [pfProgressChanged] - returns true if any progress values were changed
  1748. // for the item
  1749. //
  1750. // Returns: NOERROR - at least one item with the iItem assigned was found
  1751. // Appropriate error return codes
  1752. //
  1753. // !!Caller must have already taken a lock.
  1754. //
  1755. // Modifies:
  1756. //
  1757. // History: 17-Nov-97 rogerg Created.
  1758. //
  1759. //----------------------------------------------------------------------------
  1760. STDMETHODIMP CHndlrQueue::SetItemProgressInfo(LPITEMLIST pItem,LPSYNCMGRPROGRESSITEM pSyncProgressItem,
  1761. BOOL *pfProgressChanged)
  1762. {
  1763. BOOL fProgressAlreadyCompleted;
  1764. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  1765. // progress is considered complete if Values is >= Maxa
  1766. fProgressAlreadyCompleted = (pItem->iProgMaxValue <= pItem->iProgValue);
  1767. if (SYNCMGRPROGRESSITEM_MAXVALUE & pSyncProgressItem->mask)
  1768. {
  1769. // if Progress Max Value is negative then don't set.
  1770. if (pSyncProgressItem->iMaxValue >= 0)
  1771. {
  1772. if (pItem->iProgMaxValue != pSyncProgressItem->iMaxValue)
  1773. {
  1774. *pfProgressChanged = TRUE;
  1775. pItem->fProgValueDirty = TRUE;
  1776. pItem->iProgMaxValue = pSyncProgressItem->iMaxValue;
  1777. }
  1778. }
  1779. }
  1780. if (SYNCMGRPROGRESSITEM_PROGVALUE & pSyncProgressItem->mask)
  1781. {
  1782. // if progress value is negative, don't change it
  1783. if (pSyncProgressItem->iProgValue > 0)
  1784. {
  1785. if (pItem->iProgValue != pSyncProgressItem->iProgValue)
  1786. {
  1787. *pfProgressChanged = TRUE;
  1788. pItem->fProgValueDirty = TRUE;
  1789. pItem->iProgValue = pSyncProgressItem->iProgValue;
  1790. }
  1791. }
  1792. }
  1793. if (SYNCMGRPROGRESSITEM_STATUSTYPE & pSyncProgressItem->mask)
  1794. {
  1795. if (pItem->dwStatusType != pSyncProgressItem->dwStatusType)
  1796. {
  1797. *pfProgressChanged = TRUE;
  1798. pItem->dwStatusType = pSyncProgressItem->dwStatusType;
  1799. // if status is complete set the progvalue == to the max
  1800. // on behalf of the handler so the Items completed and progress bar
  1801. // gets updated.
  1802. if (pItem->dwStatusType == SYNCMGRSTATUS_SKIPPED
  1803. || pItem->dwStatusType == SYNCMGRSTATUS_SUCCEEDED
  1804. || pItem->dwStatusType == SYNCMGRSTATUS_FAILED )
  1805. {
  1806. pItem->fProgValueDirty = TRUE;
  1807. pItem->iProgValue = pItem->iProgMaxValue;
  1808. }
  1809. }
  1810. }
  1811. // if progressValue is > max then set it to max
  1812. if (pItem->iProgValue > pItem->iProgMaxValue)
  1813. {
  1814. // AssertSz(0,"Progress Value is > Max");
  1815. pItem->iProgValue = pItem->iProgMaxValue;
  1816. }
  1817. // see if need to recalc numItems completed next time
  1818. // GetProgressInfo is Called.
  1819. BOOL fProgressCompletedNow = (pItem->iProgMaxValue <= pItem->iProgValue);
  1820. if (fProgressAlreadyCompleted != fProgressCompletedNow)
  1821. {
  1822. m_fNumItemsCompleteNeedsARecalc = TRUE;
  1823. }
  1824. return NOERROR;
  1825. }
  1826. //+---------------------------------------------------------------------------
  1827. //
  1828. // Member: CHndlrQueue::SetItemProgressValues, private
  1829. //
  1830. // Synopsis: Private helper function for updating/initializing
  1831. // an items progress bar values.
  1832. //
  1833. // Arguments: [pItem] - Identifies the Item
  1834. // [pSyncProgressItem] - Pointer to Progress Information.
  1835. // [pfProgressChanged] - returns true if any progress values were changed
  1836. // for the item
  1837. //
  1838. // Returns: NOERROR - at least one item with the iItem assigned was found
  1839. // Appropriate error return codes
  1840. //
  1841. // !!Caller must have already taken a lock.
  1842. //
  1843. // Modifies:
  1844. //
  1845. // History: 17-Nov-97 rogerg Created.
  1846. //
  1847. //----------------------------------------------------------------------------
  1848. STDMETHODIMP CHndlrQueue::SetItemProgressValues(LPITEMLIST pItem,INT iProgValue,INT iProgMaxValue)
  1849. {
  1850. SYNCMGRPROGRESSITEM SyncProgressItem;
  1851. BOOL fProgressChanged;
  1852. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  1853. SyncProgressItem.cbSize = sizeof(SYNCMGRPROGRESSITEM);
  1854. SyncProgressItem.mask = SYNCMGRPROGRESSITEM_PROGVALUE | SYNCMGRPROGRESSITEM_MAXVALUE;
  1855. SyncProgressItem.iProgValue = iProgValue;
  1856. SyncProgressItem.iMaxValue = iProgMaxValue;
  1857. return SetItemProgressInfo(pItem,&SyncProgressItem,&fProgressChanged);
  1858. }
  1859. //+---------------------------------------------------------------------------
  1860. //
  1861. // Member: CHndlrQueue::GetProgressInfo, public
  1862. //
  1863. // Synopsis: calculates current progress bar values and number of items complete.
  1864. //
  1865. // Arguments: [piProgValue] - on return contains the new Progress Bar Value.
  1866. // [piMaxValue] - on return contains the Progress Bar Max Value
  1867. // [piNumItemsComplete] - on returns contains number of items complete.
  1868. // [iNumItemsTotal] - on returns contains number of total items.
  1869. //
  1870. // Returns: Appropriate error codes
  1871. //
  1872. // Modifies:
  1873. //
  1874. // History: 17-Nov-97 rogerg Created.
  1875. //
  1876. //----------------------------------------------------------------------------
  1877. STDMETHODIMP CHndlrQueue::GetProgressInfo(INT *piProgValue,INT *piMaxValue,INT *piNumItemsComplete,
  1878. INT *piNumItemsTotal)
  1879. {
  1880. LPHANDLERINFO pCurHandlerInfo = NULL;
  1881. LPITEMLIST pCurItem = NULL;
  1882. INT iCurValue;
  1883. BOOL fNormalizedValueChanged = FALSE;
  1884. CLock clockqueue(this);
  1885. if (QUEUETYPE_PROGRESS != m_QueueType)
  1886. {
  1887. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  1888. return E_UNEXPECTED; // review error code.
  1889. }
  1890. clockqueue.Enter();
  1891. // if m_fNumItemsCompleteNeedsARecalc is set need
  1892. // to recalc normalized and numItems Comlete and Total Items.
  1893. if (m_fNumItemsCompleteNeedsARecalc)
  1894. {
  1895. INT iNormalizedMax;
  1896. m_ulProgressItemCount = 0;
  1897. // get the number of selected items in the queue.
  1898. pCurHandlerInfo = m_pFirstHandler;
  1899. while (pCurHandlerInfo)
  1900. {
  1901. // see if handler info has a matching item
  1902. pCurItem = pCurHandlerInfo->pFirstItem;
  1903. while (pCurItem)
  1904. {
  1905. if (pCurItem->fIncludeInProgressBar)
  1906. {
  1907. //if this item should be included in the progress, increment the progress bar count.
  1908. ++m_ulProgressItemCount;
  1909. pCurItem->fProgressBarHandled = FALSE; // reset handled
  1910. }
  1911. pCurItem = pCurItem->pnextItem;
  1912. }
  1913. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1914. }
  1915. if (0 == m_ulProgressItemCount)
  1916. {
  1917. iNormalizedMax = 0;
  1918. }
  1919. else
  1920. {
  1921. iNormalizedMax = MAXPROGRESSVALUE/m_ulProgressItemCount;
  1922. if (0 == iNormalizedMax)
  1923. {
  1924. iNormalizedMax = 1;
  1925. }
  1926. }
  1927. if (m_iNormalizedMax != iNormalizedMax)
  1928. {
  1929. fNormalizedValueChanged = TRUE;
  1930. m_iNormalizedMax = iNormalizedMax;
  1931. }
  1932. }
  1933. // now loop thruogh again getting total CurValue and finished items
  1934. // we say an item is finished if it is out of the synchronize method or the min==max.
  1935. pCurHandlerInfo = m_pFirstHandler;
  1936. iCurValue = 0;
  1937. // if numitemcount needs updated reset the member vars
  1938. if (m_fNumItemsCompleteNeedsARecalc)
  1939. {
  1940. m_iCompletedItems = 0;
  1941. m_iItemCount = 0;
  1942. }
  1943. while (pCurHandlerInfo)
  1944. {
  1945. // see if handler info has a matching item
  1946. pCurItem = pCurHandlerInfo->pFirstItem;
  1947. while (pCurItem)
  1948. {
  1949. if (pCurItem->fIncludeInProgressBar)
  1950. {
  1951. // if Progress is dirty or normalized value changed
  1952. // need to recalc this items progress value
  1953. if (pCurItem->fProgValueDirty || fNormalizedValueChanged)
  1954. {
  1955. int iProgValue = pCurItem->iProgValue;
  1956. int iProgMaxValue = pCurItem->iProgMaxValue;
  1957. if (iProgValue && iProgMaxValue)
  1958. {
  1959. pCurItem->iProgValueNormalized = (int) ((1.0*iProgValue*m_iNormalizedMax)/iProgMaxValue);
  1960. }
  1961. else
  1962. {
  1963. pCurItem->iProgValueNormalized = 0;
  1964. }
  1965. pCurItem->fProgValueDirty = FALSE;
  1966. }
  1967. iCurValue += pCurItem->iProgValueNormalized;
  1968. // Handle NumItems needing to be recalc'd
  1969. if (m_fNumItemsCompleteNeedsARecalc && !pCurItem->fProgressBarHandled)
  1970. {
  1971. ++m_iItemCount;
  1972. // now loop through this item and remaining items and if any match
  1973. // mark as handled and if complete then incrment the compleated count;
  1974. if (IsItemCompleted(pCurHandlerInfo,pCurItem))
  1975. {
  1976. ++m_iCompletedItems;
  1977. }
  1978. }
  1979. }
  1980. pCurItem = pCurItem->pnextItem;
  1981. }
  1982. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1983. }
  1984. m_fNumItemsCompleteNeedsARecalc = FALSE;
  1985. *piProgValue = iCurValue;
  1986. *piMaxValue = m_iNormalizedMax*m_ulProgressItemCount;
  1987. *piNumItemsComplete = m_iCompletedItems;
  1988. *piNumItemsTotal = m_iItemCount;
  1989. Assert(*piProgValue <= *piMaxValue);
  1990. clockqueue.Leave();
  1991. return NOERROR;
  1992. }
  1993. //+---------------------------------------------------------------------------
  1994. //
  1995. // Member: CHndlrQueue::RemoveFinishedProgressItems, public
  1996. //
  1997. // Synopsis: Loops through handler setting any finished items
  1998. // fIncludeInProgressBar value to false
  1999. //
  2000. // Arguments:
  2001. //
  2002. // Returns: Appropriate return codes.
  2003. //
  2004. // Modifies:
  2005. //
  2006. // History: 17-Nov-97 rogerg Created.
  2007. //
  2008. //----------------------------------------------------------------------------
  2009. STDMETHODIMP CHndlrQueue::RemoveFinishedProgressItems()
  2010. {
  2011. LPHANDLERINFO pCurHandlerInfo = NULL;
  2012. LPITEMLIST pCurItem = NULL;
  2013. CLock clockqueue(this);
  2014. clockqueue.Enter();
  2015. m_fNumItemsCompleteNeedsARecalc = TRUE;
  2016. pCurHandlerInfo = m_pFirstHandler;
  2017. while (pCurHandlerInfo)
  2018. {
  2019. // mark any items that have completed their synchronization.
  2020. if (HANDLERSTATE_INSYNCHRONIZE < pCurHandlerInfo->HandlerState)
  2021. {
  2022. // see if handler info has a matching item
  2023. pCurItem = pCurHandlerInfo->pFirstItem;
  2024. while (pCurItem)
  2025. {
  2026. pCurItem->fIncludeInProgressBar = FALSE;
  2027. pCurItem = pCurItem->pnextItem;
  2028. }
  2029. }
  2030. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  2031. }
  2032. clockqueue.Leave();
  2033. return NOERROR;
  2034. }
  2035. //+---------------------------------------------------------------------------
  2036. //
  2037. // Member: CHndlrQueue::AreAnyItemsSelectedInQueue, public
  2038. //
  2039. // Synopsis: Determines if there are any items selected in the queue.
  2040. // can be called by choice dialog for example before creating
  2041. // progress and doing a transfer since there is no need to
  2042. // if nothing to sync anyways.
  2043. //
  2044. // Arguments:
  2045. //
  2046. // Returns: TRUE - At least one item is selected inthe queue
  2047. // FALSE - No Items are slected in the queue.
  2048. //
  2049. // Modifies:
  2050. //
  2051. // History: 17-Nov-97 rogerg Created.
  2052. //
  2053. //----------------------------------------------------------------------------
  2054. BOOL CHndlrQueue::AreAnyItemsSelectedInQueue()
  2055. {
  2056. LPHANDLERINFO pCurHandlerInfo = NULL;
  2057. LPITEMLIST pCurItem = NULL;
  2058. BOOL fFoundSelectedItem = FALSE;
  2059. CLock clockqueue(this);
  2060. clockqueue.Enter();
  2061. // invalidate UI that applies to entire queue
  2062. pCurHandlerInfo = m_pFirstHandler;
  2063. while (pCurHandlerInfo && !fFoundSelectedItem)
  2064. {
  2065. // if handler state is less than a completion go ahead and
  2066. // check the items.
  2067. if (HANDLERSTATE_HASERRORJUMPS > pCurHandlerInfo->HandlerState)
  2068. {
  2069. pCurItem = pCurHandlerInfo->pFirstItem;
  2070. while (pCurItem)
  2071. {
  2072. // clear Item UI information
  2073. if (pCurItem->offlineItem.dwItemState == SYNCMGRITEMSTATE_CHECKED)
  2074. {
  2075. fFoundSelectedItem = TRUE;
  2076. break;
  2077. }
  2078. pCurItem = pCurItem->pnextItem;
  2079. }
  2080. }
  2081. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  2082. }
  2083. clockqueue.Leave();
  2084. return fFoundSelectedItem;
  2085. }
  2086. //+---------------------------------------------------------------------------
  2087. //
  2088. // Member: CHndlrQueue::PersistChoices, public
  2089. //
  2090. // Synopsis: Saves Selected Users choices for the next time
  2091. // the choice dialog is brought up. Only should
  2092. // be called from a choice queue.
  2093. //
  2094. // Arguments:
  2095. //
  2096. // Returns: Appropriate return codes.
  2097. //
  2098. // Modifies:
  2099. //
  2100. // History: 17-Nov-97 rogerg Created.
  2101. //
  2102. //----------------------------------------------------------------------------
  2103. STDMETHODIMP CHndlrQueue::PersistChoices(void)
  2104. {
  2105. LPHANDLERINFO pCurHandlerInfo = NULL;
  2106. LPITEMLIST pCurItem = NULL;
  2107. CLock clockqueue(this);
  2108. if (QUEUETYPE_CHOICE != m_QueueType)
  2109. {
  2110. Assert(QUEUETYPE_CHOICE == m_QueueType);
  2111. return S_FALSE;
  2112. }
  2113. ASSERT_LOCKNOTHELD(this);
  2114. clockqueue.Enter();
  2115. // currently only persist on a manual invoke since user
  2116. // has to go to settings to change other invoke types and
  2117. // that is persisted
  2118. // since this is the choice queue we know all handlers have the
  2119. // same JobID. if this ever changes, have to set on a case by
  2120. // case basis.
  2121. if (m_pFirstJobInfo && m_pFirstJobInfo->pConnectionObj &&
  2122. (SYNCMGRFLAG_MANUAL == (m_pFirstJobInfo->dwSyncFlags & SYNCMGRFLAG_EVENTMASK)) )
  2123. {
  2124. TCHAR *pszConnectionName = m_pFirstJobInfo->pConnectionObj[0]->pwszConnectionName;
  2125. DWORD dwSyncFlags = m_pFirstJobInfo->dwSyncFlags;
  2126. Assert(1 == m_pFirstJobInfo->cbNumConnectionObjs); // assert manual only ever has one connectionObj
  2127. // delete all previously stored preferences.
  2128. // this is valid because only called from choice queue that all ConnectionNames are the same.
  2129. if (!m_fItemsMissing)
  2130. {
  2131. RegRemoveManualSyncSettings(pszConnectionName);
  2132. }
  2133. pCurHandlerInfo = m_pFirstHandler;
  2134. while (pCurHandlerInfo)
  2135. {
  2136. // only save if Handler is in the PrepareForSync state.
  2137. // bug, need to make sure return code from enum wasn't missing items
  2138. if (HANDLERSTATE_PREPAREFORSYNC == pCurHandlerInfo->HandlerState )
  2139. {
  2140. // save out these items.
  2141. pCurItem = pCurHandlerInfo->pFirstItem;
  2142. while (pCurItem)
  2143. {
  2144. if (!pCurItem->fDuplicateItem)
  2145. {
  2146. switch(dwSyncFlags & SYNCMGRFLAG_EVENTMASK)
  2147. {
  2148. case SYNCMGRFLAG_MANUAL:
  2149. RegSetSyncItemSettings(SYNCTYPE_MANUAL,
  2150. pCurHandlerInfo->clsidHandler,
  2151. pCurItem->offlineItem.ItemID,
  2152. pszConnectionName,
  2153. pCurItem->offlineItem.dwItemState,
  2154. NULL);
  2155. break;
  2156. default:
  2157. AssertSz(0,"UnknownSyncFlag Event");
  2158. break;
  2159. };
  2160. }
  2161. pCurItem = pCurItem->pnextItem;
  2162. }
  2163. }
  2164. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  2165. }
  2166. }
  2167. clockqueue.Leave();
  2168. return NOERROR;
  2169. }
  2170. //+---------------------------------------------------------------------------
  2171. //
  2172. // Member: CHndlrQueue::FindFirstHandlerInState, public
  2173. //
  2174. // Synopsis: Finds the first Handler that matches the specified
  2175. // state in the queue.
  2176. //
  2177. // Arguments: [hndlrState] - Requested handler state.
  2178. // [pwHandlerID] - on success filled with HandlerID that was found
  2179. //
  2180. // Returns: Appropriate return codes.
  2181. //
  2182. // Modifies:
  2183. //
  2184. // History: 17-Nov-97 rogerg Created.
  2185. //
  2186. //----------------------------------------------------------------------------
  2187. STDMETHODIMP CHndlrQueue::FindFirstHandlerInState(HANDLERSTATE hndlrState, REFCLSID clsidHandler,
  2188. HANDLERINFO **ppHandlerId,CLSID *pMatchHandlerClsid)
  2189. {
  2190. return FindNextHandlerInState(0,clsidHandler,hndlrState,ppHandlerId,pMatchHandlerClsid);
  2191. }
  2192. //+---------------------------------------------------------------------------
  2193. //
  2194. // Member: CHndlrQueue::FindNextHandlerInState, public
  2195. //
  2196. // Synopsis: Finds next handler after LastHandlerID in the queue that matches
  2197. // the requested state. Passing in 0 for the LastHandlerID is the same
  2198. // as calling FindFirstHandlerInState
  2199. //
  2200. // if GUID_NULL is passed in for the clsidHandler the first handler that
  2201. // matches the specified state is returned.
  2202. //
  2203. // Arguments: [wLastHandlerID] - Id of last handler found.
  2204. // [clsidHandler] - specific handler classid is requested, only find matches with this clsid
  2205. // [hndlrState] - Requested handler state.
  2206. // [pwHandlerID] - on success filled with HandlerID that was found
  2207. // [pMatchHandlerClsid] - on sucdess clsid of handler found.
  2208. //
  2209. // Returns: Appropriate return codes.
  2210. //
  2211. // Modifies:
  2212. //
  2213. // History: 17-Nov-97 rogerg Created.
  2214. //
  2215. //----------------------------------------------------------------------------
  2216. STDMETHODIMP CHndlrQueue::FindNextHandlerInState(HANDLERINFO *pLastHandlerID,REFCLSID clsidHandler,
  2217. HANDLERSTATE hndlrState,HANDLERINFO **ppHandlerID,CLSID *pMatchHandlerClsid)
  2218. {
  2219. HRESULT hr = S_FALSE;
  2220. LPHANDLERINFO pCurHandler;
  2221. CLock clockqueue(this);
  2222. *ppHandlerID = 0;
  2223. clockqueue.Enter();
  2224. pCurHandler = m_pFirstHandler;
  2225. if (0 != pLastHandlerID)
  2226. {
  2227. // loop foward until find the last handlerID we checked or hit the end
  2228. while (pCurHandler)
  2229. {
  2230. if (pLastHandlerID == pCurHandler->pHandlerId)
  2231. {
  2232. break;
  2233. }
  2234. pCurHandler = pCurHandler->pNextHandler;
  2235. }
  2236. if (NULL != pCurHandler)
  2237. {
  2238. pCurHandler = pCurHandler->pNextHandler; // increment to next handler.
  2239. }
  2240. }
  2241. while (pCurHandler)
  2242. {
  2243. if (hndlrState == pCurHandler->HandlerState
  2244. && ((GUID_NULL == clsidHandler) || (clsidHandler == pCurHandler->clsidHandler)) )
  2245. {
  2246. *ppHandlerID = pCurHandler->pHandlerId;
  2247. *pMatchHandlerClsid = pCurHandler->clsidHandler;
  2248. hr = NOERROR;
  2249. break;
  2250. }
  2251. pCurHandler = pCurHandler->pNextHandler;
  2252. }
  2253. clockqueue.Leave();
  2254. return hr;
  2255. }
  2256. //+---------------------------------------------------------------------------
  2257. //
  2258. // Member: CHndlrQueue::CreateServer, public
  2259. //
  2260. // Synopsis: Creates a new proxy then calls proxy to create and instance of the
  2261. // specified handler.
  2262. //
  2263. // Arguments: [wHandlerId] - Id of handler to call.
  2264. // [pCLSIDServer] - CLSID of Handler to Create.
  2265. //
  2266. // Returns: Appropriate return codes.
  2267. //
  2268. // Modifies:
  2269. //
  2270. // History: 17-Nov-97 rogerg Created.
  2271. //
  2272. //----------------------------------------------------------------------------
  2273. STDMETHODIMP CHndlrQueue::CreateServer(HANDLERINFO *pHandlerId, const CLSID *pCLSIDServer)
  2274. {
  2275. HRESULT hr = E_UNEXPECTED;
  2276. LPHANDLERINFO pHandlerInfo = NULL;
  2277. CLock clockqueue(this);
  2278. ASSERT_LOCKNOTHELD(this);
  2279. clockqueue.Enter();
  2280. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2281. {
  2282. Assert(HANDLERSTATE_CREATE == pHandlerInfo->HandlerState);
  2283. Assert(0 == pHandlerInfo->dwCallNestCount);
  2284. pHandlerInfo->dwCallNestCount++;
  2285. if (HANDLERSTATE_CREATE == pHandlerInfo->HandlerState)
  2286. {
  2287. pHandlerInfo->HandlerState = HANDLERSTATE_INCREATE;
  2288. Assert(NULL == pHandlerInfo->pThreadProxy);
  2289. // see if there is already a thread for this handler's
  2290. // CLSID.
  2291. hr = CreateHandlerThread(&(pHandlerInfo->pThreadProxy),m_hwndDlg,
  2292. *pCLSIDServer);
  2293. if (NOERROR == hr)
  2294. {
  2295. HANDLERINFO *pHandlerIdArg;
  2296. CThreadMsgProxy *pThreadProxy;
  2297. pHandlerIdArg = pHandlerInfo->pHandlerId;
  2298. pThreadProxy = pHandlerInfo->pThreadProxy;
  2299. clockqueue.Leave();
  2300. hr = pThreadProxy->CreateServer(pCLSIDServer,this,pHandlerIdArg);
  2301. clockqueue.Enter();
  2302. pHandlerInfo->pThreadProxy = pThreadProxy;
  2303. }
  2304. if (NOERROR == hr)
  2305. {
  2306. pHandlerInfo->clsidHandler = *pCLSIDServer;
  2307. pHandlerInfo->HandlerState = HANDLERSTATE_INITIALIZE;
  2308. }
  2309. else
  2310. {
  2311. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2312. }
  2313. }
  2314. pHandlerInfo->dwCallNestCount--;
  2315. }
  2316. clockqueue.Leave();
  2317. return hr;
  2318. }
  2319. //+---------------------------------------------------------------------------
  2320. //
  2321. // Member: CHndlrQueue::Initialize, public
  2322. //
  2323. // Synopsis: Calls Hanlder's Initialize method
  2324. //
  2325. // Arguments: [wHandlerId] - Id of handler to call.
  2326. // [dwReserved] - Initialize reserved parameter
  2327. // [dwSyncFlags] - Sync flags
  2328. // [cbCookie] - size of cookie data
  2329. // [lpCookie] - ptr to cookie data
  2330. //
  2331. // Returns: Appropriate return codes.
  2332. //
  2333. // Modifies:
  2334. //
  2335. // History: 17-Nov-97 rogerg Created.
  2336. //
  2337. //----------------------------------------------------------------------------
  2338. STDMETHODIMP CHndlrQueue::Initialize(HANDLERINFO *pHandlerId,DWORD dwReserved,DWORD dwSyncFlags,
  2339. DWORD cbCookie,const BYTE *lpCooke)
  2340. {
  2341. HRESULT hr = E_UNEXPECTED;
  2342. LPHANDLERINFO pHandlerInfo = NULL;
  2343. CLock clockqueue(this);
  2344. ASSERT_LOCKNOTHELD(this);
  2345. clockqueue.Enter();
  2346. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2347. {
  2348. Assert(HANDLERSTATE_INITIALIZE == pHandlerInfo->HandlerState);
  2349. Assert(NULL != pHandlerInfo->pThreadProxy);
  2350. Assert(0 == pHandlerInfo->dwCallNestCount);
  2351. pHandlerInfo->dwCallNestCount++;
  2352. if (HANDLERSTATE_INITIALIZE == pHandlerInfo->HandlerState
  2353. && (NULL != pHandlerInfo->pThreadProxy) )
  2354. {
  2355. CThreadMsgProxy *pThreadProxy;
  2356. Assert(dwSyncFlags & SYNCMGRFLAG_EVENTMASK); // an event should be set
  2357. pHandlerInfo->HandlerState = HANDLERSTATE_ININITIALIZE;
  2358. pThreadProxy = pHandlerInfo->pThreadProxy;
  2359. clockqueue.Leave();
  2360. hr = pThreadProxy->Initialize(dwReserved,dwSyncFlags,cbCookie,lpCooke);
  2361. clockqueue.Enter();
  2362. if (NOERROR == hr)
  2363. {
  2364. pHandlerInfo->HandlerState = HANDLERSTATE_ADDHANDLERTEMS;
  2365. }
  2366. else
  2367. {
  2368. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2369. }
  2370. }
  2371. pHandlerInfo->dwCallNestCount--;
  2372. }
  2373. clockqueue.Leave();
  2374. return hr;
  2375. }
  2376. //+---------------------------------------------------------------------------
  2377. //
  2378. // Member: CHndlrQueue::AddHandlerItemsToQueue, public
  2379. //
  2380. // Synopsis: Calls through to proxy to add items to the queue
  2381. //
  2382. // Arguments: [wHandlerId] - Id of handler to call.
  2383. //
  2384. // Returns: Appropriate return codes.
  2385. //
  2386. // Modifies:
  2387. //
  2388. // History: 17-Nov-97 rogerg Created.
  2389. //
  2390. //----------------------------------------------------------------------------
  2391. STDMETHODIMP CHndlrQueue::AddHandlerItemsToQueue(HANDLERINFO *pHandlerId,DWORD *pcbNumItems)
  2392. {
  2393. HRESULT hr = E_UNEXPECTED;
  2394. LPHANDLERINFO pHandlerInfo = NULL;
  2395. CLock clockqueue(this);
  2396. ASSERT_LOCKNOTHELD(this);
  2397. clockqueue.Enter();
  2398. Assert(pcbNumItems);
  2399. Assert(QUEUETYPE_CHOICE == m_QueueType); // items should only be added in a choice queue.
  2400. *pcbNumItems = 0;
  2401. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2402. {
  2403. Assert(0 == pHandlerInfo->dwCallNestCount);
  2404. pHandlerInfo->dwCallNestCount++;
  2405. Assert(HANDLERSTATE_ADDHANDLERTEMS == pHandlerInfo->HandlerState);
  2406. Assert(NULL != pHandlerInfo->pThreadProxy);
  2407. if (HANDLERSTATE_ADDHANDLERTEMS == pHandlerInfo->HandlerState
  2408. && (NULL != pHandlerInfo->pThreadProxy) )
  2409. {
  2410. CThreadMsgProxy *pThreadProxy;
  2411. pHandlerInfo->HandlerState = HANDLERSTATE_INADDHANDLERITEMS;
  2412. pThreadProxy = pHandlerInfo->pThreadProxy;
  2413. clockqueue.Leave();
  2414. // on return all items should be filled in.
  2415. hr = pThreadProxy->AddHandlerItems(NULL /* HWND */,pcbNumItems);
  2416. clockqueue.Enter();
  2417. if (NOERROR == hr || S_SYNCMGR_MISSINGITEMS == hr)
  2418. {
  2419. m_fItemsMissing |= (S_SYNCMGR_MISSINGITEMS == hr);
  2420. hr = NOERROR; // review, need to handler missing items in registry.
  2421. pHandlerInfo->HandlerState = HANDLERSTATE_PREPAREFORSYNC;
  2422. }
  2423. else
  2424. {
  2425. // on an error, go ahead and release the proxy if server can't enum
  2426. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2427. *pcbNumItems = 0;
  2428. }
  2429. }
  2430. pHandlerInfo->dwCallNestCount--;
  2431. }
  2432. clockqueue.Leave();
  2433. return hr;
  2434. }
  2435. //+---------------------------------------------------------------------------
  2436. //
  2437. // Member: CHndlrQueue::GetItemObject, public
  2438. //
  2439. // Synopsis: Calls through to proxy to get an items object pointer
  2440. //
  2441. // Arguments: [wHandlerId] - Id of handler to call.
  2442. // [wItemID] - ID of item to get the object of.
  2443. // [riid] - interface requested of the object
  2444. // [ppv] - on success is a pointer to the newly created object
  2445. //
  2446. // Returns: Currently all handlers should return E_NOTIMPL.
  2447. //
  2448. // Modifies:
  2449. //
  2450. // History: 17-Nov-97 rogerg Created.
  2451. //
  2452. //----------------------------------------------------------------------------
  2453. STDMETHODIMP CHndlrQueue::GetItemObject(HANDLERINFO *pHandlerId,WORD wItemID,REFIID riid,void** ppv)
  2454. {
  2455. HRESULT hr = E_UNEXPECTED;
  2456. LPHANDLERINFO pHandlerInfo = NULL;
  2457. CLock clockqueue(this);
  2458. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  2459. ASSERT_LOCKNOTHELD(this);
  2460. clockqueue.Enter();
  2461. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2462. {
  2463. LPITEMLIST pCurItem;
  2464. Assert(HANDLERSTATE_PREPAREFORSYNC == pHandlerInfo->HandlerState);
  2465. Assert(NULL != pHandlerInfo->pThreadProxy);
  2466. Assert(0 == pHandlerInfo->dwCallNestCount);
  2467. pHandlerInfo->dwCallNestCount++;
  2468. if (HANDLERSTATE_PREPAREFORSYNC == pHandlerInfo->HandlerState
  2469. && (NULL != pHandlerInfo->pThreadProxy))
  2470. {
  2471. // now try to find the item.
  2472. pCurItem = pHandlerInfo->pFirstItem;
  2473. while (pCurItem)
  2474. {
  2475. if (wItemID == pCurItem->wItemId)
  2476. {
  2477. CThreadMsgProxy *pThreadProxy;
  2478. SYNCMGRITEMID ItemID;
  2479. pThreadProxy = pHandlerInfo->pThreadProxy;
  2480. ItemID = pCurItem->offlineItem.ItemID;
  2481. clockqueue.Leave();
  2482. hr = pThreadProxy->GetItemObject(ItemID,riid,ppv);
  2483. return hr;
  2484. }
  2485. pCurItem = pCurItem->pnextItem;
  2486. }
  2487. }
  2488. pHandlerInfo->dwCallNestCount--;
  2489. }
  2490. clockqueue.Leave();
  2491. AssertSz(0,"Specified object wasn't found");
  2492. return hr;
  2493. }
  2494. //+---------------------------------------------------------------------------
  2495. //
  2496. // Member: CHndlrQueue::SetUpProgressCallback, public
  2497. //
  2498. // Synopsis: Calls through to proxy to set up the progress callback
  2499. //
  2500. // Arguments: [wHandlerId] - Id of handler to call.
  2501. // [fSet] - TRUE == create, FALSE == destroy.
  2502. // [hwnd] - Callback info should be sent to specified window.
  2503. //
  2504. // Returns: Appropriate Error code
  2505. //
  2506. // Modifies:
  2507. //
  2508. // History: 17-Nov-97 rogerg Created.
  2509. //
  2510. //----------------------------------------------------------------------------
  2511. STDMETHODIMP CHndlrQueue::SetUpProgressCallback(HANDLERINFO *pHandlerId,BOOL fSet,HWND hwnd)
  2512. {
  2513. HRESULT hr = E_UNEXPECTED;
  2514. LPHANDLERINFO pHandlerInfo = NULL;
  2515. CLock clockqueue(this);
  2516. AssertSz(0,"this function no longer used");
  2517. return E_NOTIMPL;
  2518. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  2519. ASSERT_LOCKNOTHELD(this);
  2520. clockqueue.Enter();
  2521. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2522. {
  2523. Assert(HANDLERSTATE_PREPAREFORSYNC == pHandlerInfo->HandlerState || FALSE == fSet);
  2524. Assert(NULL != pHandlerInfo->pThreadProxy);
  2525. Assert(1 == pHandlerInfo->dwCallNestCount); // should be called from PrepareForSync
  2526. pHandlerInfo->dwCallNestCount++;
  2527. if ( ((FALSE == fSet) || (HANDLERSTATE_PREPAREFORSYNC == pHandlerInfo->HandlerState))
  2528. && (NULL != pHandlerInfo->pThreadProxy))
  2529. {
  2530. CThreadMsgProxy *pThreadProxy;
  2531. pHandlerInfo->hWndCallback = hwnd;
  2532. pHandlerInfo->HandlerState = HANDLERSTATE_INSETCALLBACK;
  2533. pThreadProxy = pHandlerInfo->pThreadProxy;
  2534. clockqueue.Leave();
  2535. hr = pThreadProxy->SetupCallback(fSet);
  2536. clockqueue.Enter();
  2537. pHandlerInfo->HandlerState = HANDLERSTATE_PREPAREFORSYNC;
  2538. if (hr != NOERROR) // make sure on error the hwnd gets set back to NULL.
  2539. pHandlerInfo->hWndCallback = NULL;
  2540. }
  2541. pHandlerInfo->dwCallNestCount--;
  2542. }
  2543. clockqueue.Leave();
  2544. return hr;
  2545. }
  2546. //+---------------------------------------------------------------------------
  2547. //
  2548. // Member: CHndlrQueue::PrepareForSync, public
  2549. //
  2550. // Synopsis: Calls through to Handlers PrepareForSync method.
  2551. //
  2552. // Arguments: [wHandlerId] - Id of handler to call.
  2553. // [hWndParent] - Hwnd to use for any displayed dialogs.
  2554. //
  2555. // Returns: Appropriate Error code
  2556. //
  2557. // Modifies:
  2558. //
  2559. // History: 17-Nov-97 rogerg Created.
  2560. //
  2561. //----------------------------------------------------------------------------
  2562. STDMETHODIMP CHndlrQueue::PrepareForSync(HANDLERINFO *pHandlerId,HWND hWndParent)
  2563. {
  2564. HRESULT hr = E_UNEXPECTED;
  2565. LPHANDLERINFO pHandlerInfo = NULL;
  2566. ULONG cbNumItems;
  2567. SYNCMGRITEMID *pItemIDs;
  2568. BOOL fHandlerCalled = FALSE;
  2569. CLock clockqueue(this);
  2570. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  2571. ASSERT_LOCKNOTHELD(this);
  2572. clockqueue.Enter();
  2573. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2574. {
  2575. Assert(HANDLERSTATE_PREPAREFORSYNC == pHandlerInfo->HandlerState);
  2576. Assert(NULL != pHandlerInfo->pThreadProxy);
  2577. Assert(0 == pHandlerInfo->dwCallNestCount);
  2578. pHandlerInfo->dwCallNestCount++;
  2579. Assert(!(ThreadMsg_PrepareForSync & pHandlerInfo->dwOutCallMessages));
  2580. pHandlerInfo->dwOutCallMessages |= ThreadMsg_PrepareForSync;
  2581. if (HANDLERSTATE_PREPAREFORSYNC == pHandlerInfo->HandlerState)
  2582. {
  2583. // if item doesn't have a ThreadProxy or it has been cancelled,
  2584. // put in the Release State
  2585. if ( (NULL == pHandlerInfo->pThreadProxy) || (pHandlerInfo->fCancelled) )
  2586. {
  2587. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2588. }
  2589. else
  2590. {
  2591. // create a list of the selected items and pass to PrepareForSync
  2592. cbNumItems = GetSelectedItemsInHandler(pHandlerInfo,0,NULL);
  2593. if (0 == cbNumItems)
  2594. {
  2595. // if no items selected don't call prepareforsync
  2596. // and set the HandlerState so it can be released
  2597. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2598. hr = S_FALSE;
  2599. }
  2600. else
  2601. {
  2602. pItemIDs = (SYNCMGRITEMID *) ALLOC(sizeof(SYNCMGRITEMID)*cbNumItems);
  2603. if (NULL != pItemIDs)
  2604. {
  2605. // loop through items filling in the proper data
  2606. GetSelectedItemsInHandler(pHandlerInfo,&cbNumItems,pItemIDs);
  2607. if (0 == cbNumItems)
  2608. {
  2609. hr = S_FALSE; // There are no selected items.
  2610. }
  2611. else
  2612. {
  2613. CThreadMsgProxy *pThreadProxy;
  2614. JOBINFO *pJobInfo = NULL;
  2615. pHandlerInfo->HandlerState = HANDLERSTATE_INPREPAREFORSYNC;
  2616. pThreadProxy = pHandlerInfo->pThreadProxy;
  2617. pHandlerInfo->hWndCallback = hWndParent;
  2618. pJobInfo = pHandlerInfo->pJobInfo;
  2619. // if we need to dial to make the connection do
  2620. // so now.
  2621. clockqueue.Leave();
  2622. DWORD dwSyncFlags = pJobInfo->dwSyncFlags & SYNCMGRFLAG_EVENTMASK;
  2623. BOOL fAutoDialDisable = TRUE;
  2624. if ( dwSyncFlags == SYNCMGRFLAG_MANUAL || dwSyncFlags == SYNCMGRFLAG_INVOKE )
  2625. fAutoDialDisable = FALSE;
  2626. //
  2627. // Ignore failure return from ApplySyncItemDialState
  2628. //
  2629. ApplySyncItemDialState( fAutoDialDisable );
  2630. hr = OpenConnection(pJobInfo);
  2631. if (NOERROR == hr)
  2632. {
  2633. // if this is on an idle write out the last
  2634. // handler id
  2635. // review - if don't wait to call PrepareForSync
  2636. // on idle the setlastIdlehandler should be called on sync.
  2637. if (pJobInfo && (SYNCMGRFLAG_IDLE ==
  2638. (pJobInfo->dwSyncFlags & SYNCMGRFLAG_EVENTMASK)) )
  2639. {
  2640. SetLastIdleHandler(pHandlerInfo->clsidHandler);
  2641. }
  2642. fHandlerCalled = TRUE;
  2643. hr = pThreadProxy->PrepareForSync(cbNumItems,pItemIDs,
  2644. hWndParent,0 /* dwReserved */ );
  2645. }
  2646. else
  2647. {
  2648. clockqueue.Enter();
  2649. pHandlerInfo->hWndCallback = NULL;
  2650. clockqueue.Leave();
  2651. }
  2652. }
  2653. // on return from PrepareFroSync or error need to free items
  2654. clockqueue.Enter();
  2655. FREE(pItemIDs);
  2656. }
  2657. else
  2658. {
  2659. hr = E_OUTOFMEMORY;
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. clockqueue.Leave();
  2666. // if the handler returns an errorfrom PrepareForSync we need
  2667. // to call the completion routine ourselves and/or we never got to the point
  2668. // of making the outcall.
  2669. if ( (fHandlerCalled && (NOERROR != hr)) || (!fHandlerCalled))
  2670. {
  2671. CallCompletionRoutine(pHandlerId,ThreadMsg_PrepareForSync,hr,0,NULL);
  2672. }
  2673. return hr;
  2674. }
  2675. //+---------------------------------------------------------------------------
  2676. //
  2677. // Member: CHndlrQueue::PrepareForSyncCompleted, public
  2678. //
  2679. // Synopsis: Called by completion routine on a PrepareForSyncCompleted
  2680. //
  2681. // Warning: Assume queue is locked and pHandlerInfo has
  2682. // already been verified.
  2683. //
  2684. // Returns: Appropriate Error code
  2685. //
  2686. // Modifies:
  2687. //
  2688. // History: 02-Jun-98 rogerg Created.
  2689. //
  2690. //----------------------------------------------------------------------------
  2691. STDMETHODIMP CHndlrQueue::PrepareForSyncCompleted(LPHANDLERINFO pHandlerInfo,HRESULT hCallResult)
  2692. {
  2693. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  2694. if (NOERROR == hCallResult)
  2695. {
  2696. pHandlerInfo->HandlerState = HANDLERSTATE_SYNCHRONIZE;
  2697. }
  2698. else
  2699. {
  2700. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2701. }
  2702. if ( (pHandlerInfo->HandlerState != HANDLERSTATE_SYNCHRONIZE))
  2703. {
  2704. // if handler didn't make it to the synchronize state then fix up the items
  2705. LPITEMLIST pCurItem = NULL;
  2706. // prepare for sync either doesn't want to handle the
  2707. // items or an error occured,
  2708. // need to go ahead and mark the items as completed.
  2709. // same routine that is after synchronize.
  2710. pCurItem = pHandlerInfo->pFirstItem;
  2711. while (pCurItem)
  2712. {
  2713. SetItemProgressValues(pCurItem,
  2714. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE,
  2715. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  2716. pCurItem->fSynchronizingItem = FALSE;
  2717. pCurItem = pCurItem->pnextItem;
  2718. }
  2719. }
  2720. pHandlerInfo->dwCallNestCount--; // decrement nestcount put on by PrepareForSync call.
  2721. // if the handler state has been released but it has some jumptext, which it can if
  2722. // the PrepareForsync was caused by a retry then set the results to HANDLERSTATE_HASERRORJUMPS
  2723. if ((HANDLERSTATE_RELEASE == pHandlerInfo->HandlerState) && (pHandlerInfo->fHasErrorJumps))
  2724. {
  2725. pHandlerInfo->HandlerState = HANDLERSTATE_HASERRORJUMPS;
  2726. }
  2727. return NOERROR;
  2728. }
  2729. //+---------------------------------------------------------------------------
  2730. //
  2731. // Member: CHndlrQueue::Synchronize, public
  2732. //
  2733. // Synopsis: Calls through to Handlers Synchronize method.
  2734. //
  2735. // Arguments: [wHandlerId] - Id of handler to call.
  2736. // [hWndParent] - Hwnd to use for any displayed dialogs.
  2737. //
  2738. // Returns: Appropriate Error code
  2739. //
  2740. // Modifies:
  2741. //
  2742. // History: 17-Nov-97 rogerg Created.
  2743. //
  2744. //----------------------------------------------------------------------------
  2745. STDMETHODIMP CHndlrQueue::Synchronize(HANDLERINFO *pHandlerId,HWND hWndParent)
  2746. {
  2747. HRESULT hr = E_UNEXPECTED;
  2748. LPHANDLERINFO pHandlerInfo = NULL;
  2749. BOOL fHandlerCalled = FALSE;
  2750. CLock clockqueue(this);
  2751. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  2752. ASSERT_LOCKNOTHELD(this);
  2753. clockqueue.Enter();
  2754. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2755. {
  2756. Assert(HANDLERSTATE_SYNCHRONIZE == pHandlerInfo->HandlerState);
  2757. Assert(NULL != pHandlerInfo->pThreadProxy);
  2758. Assert(0 == pHandlerInfo->dwCallNestCount);
  2759. pHandlerInfo->dwCallNestCount++;
  2760. Assert(!(ThreadMsg_Synchronize & pHandlerInfo->dwOutCallMessages));
  2761. pHandlerInfo->dwOutCallMessages |= ThreadMsg_Synchronize;
  2762. if (HANDLERSTATE_SYNCHRONIZE == pHandlerInfo->HandlerState
  2763. && (NULL != pHandlerInfo->pThreadProxy) )
  2764. {
  2765. // make sure the handler has a proxy and the item
  2766. // wasn't cancelled.
  2767. if ( (NULL == pHandlerInfo->pThreadProxy) || (pHandlerInfo->fCancelled))
  2768. {
  2769. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2770. }
  2771. else
  2772. {
  2773. CThreadMsgProxy *pThreadProxy;
  2774. pHandlerInfo->HandlerState = HANDLERSTATE_INSYNCHRONIZE;
  2775. pThreadProxy= pHandlerInfo->pThreadProxy;
  2776. clockqueue.Leave();
  2777. fHandlerCalled = TRUE;
  2778. hr = pThreadProxy->Synchronize(hWndParent);
  2779. clockqueue.Enter();
  2780. }
  2781. }
  2782. }
  2783. clockqueue.Leave();
  2784. // if the handler returns an error from Synchronize we need
  2785. // to call the completion routine ourselves and/or we never got to the point
  2786. // of making the outcall.
  2787. if ( (fHandlerCalled && (NOERROR != hr)) || (!fHandlerCalled) )
  2788. {
  2789. CallCompletionRoutine(pHandlerId,ThreadMsg_Synchronize,hr,0,NULL);
  2790. }
  2791. return hr;
  2792. }
  2793. //+---------------------------------------------------------------------------
  2794. //
  2795. // Member: CHndlrQueue::SynchronizeCompleted, public
  2796. //
  2797. // Synopsis: Called by completion routine on a SynchronizeCompleted
  2798. //
  2799. // Warning: Assume queue is locked and pHandlerInfo has
  2800. // already been verified.
  2801. //
  2802. // Returns: Appropriate Error code
  2803. //
  2804. // Modifies:
  2805. //
  2806. // History: 02-Jun-98 rogerg Created.
  2807. //
  2808. //----------------------------------------------------------------------------
  2809. STDMETHODIMP CHndlrQueue::SynchronizeCompleted(LPHANDLERINFO pHandlerInfo,HRESULT hCallResult)
  2810. {
  2811. LPITEMLIST pCurItem = NULL;
  2812. BOOL fRetrySync = FALSE;
  2813. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  2814. if (pHandlerInfo->fRetrySync)
  2815. {
  2816. // if a retry request came in during the sync, retry it.
  2817. pHandlerInfo->HandlerState = HANDLERSTATE_PREPAREFORSYNC;
  2818. pHandlerInfo->fRetrySync = FALSE; // reset the retry sync flag.
  2819. fRetrySync = TRUE;
  2820. }
  2821. else if (pHandlerInfo->fHasErrorJumps)
  2822. {
  2823. pHandlerInfo->HandlerState = HANDLERSTATE_HASERRORJUMPS;
  2824. }
  2825. else
  2826. {
  2827. pHandlerInfo->HandlerState = HANDLERSTATE_RELEASE;
  2828. }
  2829. // when come out of synchronize we set the items values for them.
  2830. // in case they were negligent.
  2831. pCurItem = pHandlerInfo->pFirstItem;
  2832. while (pCurItem)
  2833. {
  2834. SetItemProgressValues(pCurItem,
  2835. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE,
  2836. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  2837. pCurItem->fSynchronizingItem = FALSE;
  2838. pCurItem = pCurItem->pnextItem;
  2839. }
  2840. pHandlerInfo->dwCallNestCount--; // remove nest count
  2841. // if the handler state has been released but it has some jumptext, which it can if
  2842. // the sycnrhonize was caused by a retry then set the results to HANDLERSTATE_HASERRORJUMPS
  2843. if ((HANDLERSTATE_RELEASE == pHandlerInfo->HandlerState) && (pHandlerInfo->fHasErrorJumps))
  2844. {
  2845. pHandlerInfo->HandlerState = HANDLERSTATE_HASERRORJUMPS;
  2846. }
  2847. return NOERROR;
  2848. }
  2849. //+---------------------------------------------------------------------------
  2850. //
  2851. // Member: CHndlrQueue::ShowError, public
  2852. //
  2853. // Synopsis: Calls through to Handlers ShowError method.
  2854. //
  2855. // Arguments: [wHandlerId] - Id of handler to call.
  2856. // [hWndParent] - Hwnd to use for any displayed dialogs.
  2857. // [dwErrorID] - Identifies the error to show
  2858. //
  2859. // Returns: Appropriate Error code
  2860. //
  2861. // Modifies:
  2862. //
  2863. // History: 17-Nov-97 rogerg Created.
  2864. //
  2865. //----------------------------------------------------------------------------
  2866. STDMETHODIMP CHndlrQueue::ShowError(HANDLERINFO *pHandlerId,HWND hWndParent,REFSYNCMGRERRORID ErrorID)
  2867. {
  2868. HRESULT hr = E_UNEXPECTED;
  2869. LPHANDLERINFO pHandlerInfo = NULL;
  2870. BOOL fHandlerCalled = FALSE;
  2871. BOOL fAlreadyInShowErrors = TRUE;
  2872. CLock clockqueue(this);
  2873. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  2874. clockqueue.Enter();
  2875. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  2876. {
  2877. Assert(TRUE == pHandlerInfo->fHasErrorJumps);
  2878. Assert(NULL != pHandlerInfo->pThreadProxy);
  2879. // if we are already handling a ShowError for this handler then don't
  2880. // start another one
  2881. if (!(pHandlerInfo->fInShowErrorCall))
  2882. {
  2883. fAlreadyInShowErrors = FALSE;
  2884. m_dwShowErrororOutCallCount++; // increment handlers ShowError OutCall Count.
  2885. Assert(!(ThreadMsg_ShowError & pHandlerInfo->dwOutCallMessages));
  2886. pHandlerInfo->dwOutCallMessages |= ThreadMsg_ShowError;
  2887. if (NULL != pHandlerInfo->pThreadProxy )
  2888. {
  2889. CThreadMsgProxy *pThreadProxy;
  2890. ULONG cbNumItems = 0; // review, these are not longer necessary.
  2891. SYNCMGRITEMID *pItemIDs = NULL;
  2892. pThreadProxy = pHandlerInfo->pThreadProxy;
  2893. fHandlerCalled = TRUE;
  2894. pHandlerInfo->fInShowErrorCall = TRUE;
  2895. clockqueue.Leave();
  2896. hr = pThreadProxy->ShowError(hWndParent,ErrorID,&cbNumItems,&pItemIDs);
  2897. clockqueue.Enter();
  2898. }
  2899. }
  2900. }
  2901. clockqueue.Leave();
  2902. // if the handler returns an error from ShowError we need
  2903. // to call the completion routine ourselves and/or we never got to the point
  2904. // of making the outcall and there wasn't already an outcall in progress.
  2905. if ( (fHandlerCalled && (NOERROR != hr)) ||
  2906. (!fHandlerCalled && !fAlreadyInShowErrors) )
  2907. {
  2908. CallCompletionRoutine(pHandlerId,ThreadMsg_ShowError,hr,0,NULL);
  2909. }
  2910. return hr;
  2911. }
  2912. //+---------------------------------------------------------------------------
  2913. //
  2914. // Member: CHndlrQueue::ShowErrorCompleted, public
  2915. //
  2916. // Synopsis: Called by completion routine on a ShowErrorCompleted
  2917. //
  2918. // Warning: Assume queue is locked and pHandlerInfo has
  2919. // already been verified.
  2920. //
  2921. // Returns:
  2922. //
  2923. // Modifies:
  2924. //
  2925. // History: 02-Jun-98 rogerg Created.
  2926. //
  2927. //----------------------------------------------------------------------------
  2928. STDMETHODIMP CHndlrQueue::ShowErrorCompleted(LPHANDLERINFO pHandlerInfo,HRESULT hCallResult,
  2929. ULONG cbNumItems,SYNCMGRITEMID *pItemIDs)
  2930. {
  2931. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  2932. if (S_SYNCMGR_RETRYSYNC == hCallResult)
  2933. {
  2934. // validate we got something back for cbNumItems and pItemIDs or
  2935. // don't do anything
  2936. if ( (0 == cbNumItems) || (NULL == pItemIDs))
  2937. {
  2938. Assert(0 != cbNumItems); // assert in debug so can catch handlers.
  2939. Assert(NULL != pItemIDs);
  2940. }
  2941. else
  2942. {
  2943. SYNCMGRITEMID *pCurItemItemId;
  2944. ULONG cbNumItemsIndex;
  2945. // if the handler is in the release state then change to prepareForSync
  2946. // if it is still in a synchronize just set the fRetrySync flag in the
  2947. // handler for it to check when done.
  2948. // Cases
  2949. // Handlers PrepareForSync Method hasn't been called. Just add items to request
  2950. // Handlers is between InPrepareForSync and InSynchronize. Set RetrySyncFlag
  2951. // Handler has is done with it synchronize. reset state to PrepareForSync
  2952. // when prepareforsync is called on an item it state gets set back to unchecked
  2953. // so just need to worry about setting appropriate items to checked.
  2954. pCurItemItemId = pItemIDs;
  2955. for (cbNumItemsIndex = 0 ; cbNumItemsIndex < cbNumItems; cbNumItemsIndex++)
  2956. {
  2957. BOOL fFoundMatch = FALSE;
  2958. LPITEMLIST pHandlerItem;
  2959. pHandlerItem = pHandlerInfo->pFirstItem;
  2960. while (pHandlerItem)
  2961. {
  2962. if (*pCurItemItemId == pHandlerItem->offlineItem.ItemID)
  2963. {
  2964. pHandlerItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_CHECKED;
  2965. SetItemProgressValues(pHandlerItem,0,
  2966. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  2967. pHandlerItem->fIncludeInProgressBar = TRUE;
  2968. fFoundMatch = TRUE;
  2969. break;
  2970. }
  2971. pHandlerItem = pHandlerItem->pnextItem;
  2972. }
  2973. if (!fFoundMatch)
  2974. {
  2975. LPITEMLIST pNewItem;
  2976. SYNCMGRITEM syncItem;
  2977. // if didn't find a match this must be a new item, add it to the list
  2978. // and set up the appropriate states.
  2979. // Note: items added like this should not be included in the progress bar.
  2980. // first time progress is called on an item it will get included
  2981. // in the progress bar.
  2982. syncItem.cbSize = sizeof(SYNCMGRITEM);
  2983. syncItem.dwFlags = SYNCMGRITEM_TEMPORARY;
  2984. syncItem.ItemID = *pCurItemItemId;
  2985. syncItem.dwItemState = SYNCMGRITEMSTATE_CHECKED;
  2986. syncItem.hIcon = NULL;
  2987. *syncItem.wszItemName = L'\0';
  2988. pNewItem = AllocNewHandlerItem(pHandlerInfo,&syncItem);
  2989. if (pNewItem)
  2990. {
  2991. pNewItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_CHECKED;
  2992. SetItemProgressValues(pNewItem,
  2993. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE,
  2994. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  2995. pNewItem->fHiddenItem = TRUE; // set to indicate not part of UI.
  2996. pNewItem->fIncludeInProgressBar = FALSE;
  2997. }
  2998. }
  2999. ++pCurItemItemId;
  3000. }
  3001. if (pHandlerInfo->HandlerState < HANDLERSTATE_INPREPAREFORSYNC)
  3002. {
  3003. // don't reset anything. just make sure requested items are added
  3004. // to the request.
  3005. }
  3006. else if (pHandlerInfo->HandlerState > HANDLERSTATE_INSYNCHRONIZE)
  3007. {
  3008. // if synchronize is complete reset the state to PrepareForSync.
  3009. pHandlerInfo->HandlerState = HANDLERSTATE_PREPAREFORSYNC;
  3010. }
  3011. else
  3012. {
  3013. // retry request came in between the PrepareForSync call and Synchronize
  3014. // being complete.
  3015. Assert(pHandlerInfo->HandlerState >= HANDLERSTATE_INPREPAREFORSYNC);
  3016. Assert(pHandlerInfo->HandlerState < HANDLERSTATE_DEAD);
  3017. pHandlerInfo->fRetrySync = TRUE;
  3018. }
  3019. //
  3020. // If the handler has been canceled, uncancel it to enable the retry
  3021. //
  3022. pHandlerInfo->fCancelled = FALSE;
  3023. }
  3024. }
  3025. --m_dwShowErrororOutCallCount; // decrement handlers ShowError OutCall Count.
  3026. // should never happen but in case out call goes negative fixup to zero.
  3027. Assert( ((LONG) m_dwShowErrororOutCallCount) >= 0);
  3028. if ( ((LONG) m_dwShowErrororOutCallCount) < 0)
  3029. {
  3030. m_dwShowErrororOutCallCount = 0;
  3031. }
  3032. pHandlerInfo->fInShowErrorCall = FALSE; // handler is no longer in a ShowError Call
  3033. return NOERROR;
  3034. }
  3035. //+---------------------------------------------------------------------------
  3036. //
  3037. // Member: CHndlrQueue::FindItemData, private
  3038. //
  3039. // Synopsis: finds associated handler and item info. caller must be
  3040. // holding the lock and access the returned info before
  3041. // releasing the lock
  3042. //
  3043. // !! Only matches items that have a state between or equal
  3044. // to the handler state ranges.
  3045. //
  3046. // !!! If ItemID of GUID_NULL is passed it it returns a match
  3047. // of the first handler found and sets pItem out param to NULL
  3048. //
  3049. // Arguments:
  3050. //
  3051. // Returns: Appropriate return codes
  3052. //
  3053. // Modifies:
  3054. //
  3055. // History: 17-Nov-97 rogerg Created.
  3056. //
  3057. //----------------------------------------------------------------------------
  3058. STDMETHODIMP CHndlrQueue::FindItemData(CLSID clsidHandler,REFSYNCMGRITEMID OfflineItemID,
  3059. HANDLERSTATE hndlrStateFirst,HANDLERSTATE hndlrStateLast,
  3060. LPHANDLERINFO *ppHandlerInfo,LPITEMLIST *ppItem)
  3061. {
  3062. LPHANDLERINFO pCurHandlerInfo = NULL;
  3063. LPITEMLIST pCurItem = NULL;
  3064. BOOL fNoMatchFound = TRUE;
  3065. HRESULT hr = S_FALSE;
  3066. ASSERT_LOCKHELD(this);
  3067. Assert(ppHandlerInfo);
  3068. Assert(ppItem);
  3069. *ppHandlerInfo = NULL;
  3070. *ppItem = NULL;
  3071. pCurHandlerInfo = m_pFirstHandler;
  3072. while (pCurHandlerInfo && fNoMatchFound)
  3073. {
  3074. if ( (clsidHandler == pCurHandlerInfo->clsidHandler)
  3075. && (hndlrStateLast >= pCurHandlerInfo->HandlerState)
  3076. && (hndlrStateFirst <= pCurHandlerInfo->HandlerState) )
  3077. {
  3078. *ppHandlerInfo = pCurHandlerInfo;
  3079. // if top level item tem ppItem to NULL and return okay
  3080. if (GUID_NULL == OfflineItemID)
  3081. {
  3082. *ppItem = NULL;
  3083. hr = S_OK;
  3084. fNoMatchFound = FALSE;
  3085. }
  3086. else
  3087. {
  3088. pCurItem = pCurHandlerInfo->pFirstItem;
  3089. while (pCurItem)
  3090. {
  3091. if (OfflineItemID == pCurItem->offlineItem.ItemID)
  3092. {
  3093. *ppItem = pCurItem;
  3094. hr = S_OK;
  3095. fNoMatchFound = FALSE;
  3096. break;
  3097. }
  3098. pCurItem = pCurItem->pnextItem;
  3099. }
  3100. }
  3101. }
  3102. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  3103. }
  3104. return hr;
  3105. }
  3106. //+---------------------------------------------------------------------------
  3107. //
  3108. // Member: CHndlrQueue::LookupHandlerFromId, private
  3109. //
  3110. // Synopsis: Finds associate handler info from the given Id
  3111. //
  3112. // Arguments: [wHandlerId] - Id of handler to call.
  3113. // [pHandlerInfo] - on NOERROR pointer to handler info
  3114. //
  3115. // Returns: Appropriate Error code
  3116. //
  3117. // Modifies:
  3118. //
  3119. // History: 17-Nov-97 rogerg Created.
  3120. //
  3121. //----------------------------------------------------------------------------
  3122. STDMETHODIMP CHndlrQueue::LookupHandlerFromId(HANDLERINFO *pHandlerId,LPHANDLERINFO *pHandlerInfo)
  3123. {
  3124. HRESULT hr = E_UNEXPECTED;
  3125. LPHANDLERINFO pCurItem;
  3126. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  3127. *pHandlerInfo = NULL;
  3128. pCurItem = m_pFirstHandler;
  3129. while (pCurItem)
  3130. {
  3131. if (pHandlerId == pCurItem->pHandlerId )
  3132. {
  3133. *pHandlerInfo = pCurItem;
  3134. Assert(pCurItem == pHandlerId);
  3135. hr = NOERROR;
  3136. break;
  3137. }
  3138. pCurItem = pCurItem->pNextHandler;
  3139. }
  3140. Assert(NOERROR == hr); // test assert to see if everv fires.
  3141. return hr;
  3142. }
  3143. //+---------------------------------------------------------------------------
  3144. //
  3145. // Member: CHndlrQueue::AllocNewHandlerItem, public
  3146. //
  3147. // Synopsis: Adds new item to the specified handler.
  3148. //
  3149. // Arguments: [wHandlerId] - Id of handler.
  3150. // [pOfflineItem] - Points to Items information to add.
  3151. //
  3152. // Returns: Appropriate Error code
  3153. //
  3154. // Modifies:
  3155. //
  3156. // History: 13-May-98 rogerg Created.
  3157. //
  3158. //----------------------------------------------------------------------------
  3159. LPITEMLIST CHndlrQueue::AllocNewHandlerItem(LPHANDLERINFO pHandlerInfo,SYNCMGRITEM *pOfflineItem)
  3160. {
  3161. LPITEMLIST pNewItem = NULL;
  3162. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  3163. Assert(pHandlerInfo);
  3164. Assert(pOfflineItem);
  3165. // Allocate the item.
  3166. pNewItem = (LPITEMLIST) ALLOC(sizeof(ITEMLIST));
  3167. if (pNewItem)
  3168. {
  3169. // set up defaults.
  3170. memset(pNewItem,0,sizeof(ITEMLIST));
  3171. pNewItem->wItemId = ++pHandlerInfo->wItemCount;
  3172. pNewItem->pHandlerInfo = pHandlerInfo;
  3173. pNewItem->fDuplicateItem = FALSE;
  3174. pNewItem->fIncludeInProgressBar = FALSE;
  3175. SetItemProgressValues(pNewItem,0,
  3176. HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  3177. pNewItem->dwStatusType = SYNCMGRSTATUS_PENDING;
  3178. pNewItem->fHiddenItem = FALSE;
  3179. pNewItem->fSynchronizingItem = FALSE;
  3180. pNewItem->offlineItem = *pOfflineItem;
  3181. // stick the item on the end of the list
  3182. if (NULL == pHandlerInfo->pFirstItem)
  3183. {
  3184. pHandlerInfo->pFirstItem = pNewItem;
  3185. Assert(1 == pHandlerInfo->wItemCount);
  3186. }
  3187. else
  3188. {
  3189. LPITEMLIST pCurItem;
  3190. pCurItem = pHandlerInfo->pFirstItem;
  3191. while (pCurItem->pnextItem)
  3192. pCurItem = pCurItem->pnextItem;
  3193. pCurItem->pnextItem = pNewItem;
  3194. Assert ((pCurItem->wItemId + 1) == pNewItem->wItemId);
  3195. }
  3196. }
  3197. return pNewItem;
  3198. }
  3199. //+---------------------------------------------------------------------------
  3200. //
  3201. // Member: CHndlrQueue::SetHandlerInfo, public
  3202. //
  3203. // Synopsis: Adds item to the specified handler.
  3204. // Called in context of the handlers thread.
  3205. //
  3206. // Arguments: [pHandlerId] - Id of handler.
  3207. // [pSyncMgrHandlerInfo] - Points to SyncMgrHandlerInfo to be filled in.
  3208. //
  3209. // Returns: Appropriate Error code
  3210. //
  3211. // Modifies:
  3212. //
  3213. // History: 28-Jul-98 rogerg Created.
  3214. //
  3215. //----------------------------------------------------------------------------
  3216. STDMETHODIMP CHndlrQueue::SetHandlerInfo(HANDLERINFO *pHandlerId,LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo)
  3217. {
  3218. HRESULT hr = E_UNEXPECTED;
  3219. LPHANDLERINFO pHandlerInfo = NULL;
  3220. CLock clockqueue(this);
  3221. if (!pSyncMgrHandlerInfo)
  3222. {
  3223. return E_INVALIDARG;
  3224. Assert(pSyncMgrHandlerInfo);
  3225. }
  3226. clockqueue.Enter();
  3227. Assert(m_QueueType == QUEUETYPE_CHOICE);
  3228. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  3229. {
  3230. if (HANDLERSTATE_INADDHANDLERITEMS != pHandlerInfo->HandlerState)
  3231. {
  3232. Assert(HANDLERSTATE_INADDHANDLERITEMS == pHandlerInfo->HandlerState);
  3233. hr = E_UNEXPECTED;
  3234. }
  3235. else
  3236. {
  3237. // Quick Check of Size here. other paramters should already
  3238. // be validated by hndlrmsg
  3239. if (pSyncMgrHandlerInfo->cbSize != sizeof(SYNCMGRHANDLERINFO) )
  3240. {
  3241. Assert(pSyncMgrHandlerInfo->cbSize == sizeof(SYNCMGRHANDLERINFO));
  3242. hr = E_INVALIDARG;
  3243. }
  3244. else
  3245. {
  3246. pHandlerInfo->SyncMgrHandlerInfo = *pSyncMgrHandlerInfo;
  3247. hr = NOERROR;
  3248. }
  3249. }
  3250. }
  3251. clockqueue.Leave();
  3252. return hr;
  3253. }
  3254. //+---------------------------------------------------------------------------
  3255. //
  3256. // Member: CHndlrQueue::IsAllHandlerInstancesCancelCompleted, private
  3257. //
  3258. // Synopsis: Asks queue if all interintances of a Handler CLSID
  3259. // are completed, Called in proxy terminate to see
  3260. // if after requesting user input there are still items to
  3261. // kill.
  3262. //
  3263. // Note: Only checks instances for this queue.
  3264. //
  3265. // Arguments:
  3266. //
  3267. // Returns: S_OK; if all handler instances are done.
  3268. // S_FALSE - if still items going that should be killed.
  3269. //
  3270. // Modifies:
  3271. //
  3272. // History: 17-Nov-97 rogerg Created.
  3273. //
  3274. //----------------------------------------------------------------------------
  3275. STDMETHODIMP CHndlrQueue::IsAllHandlerInstancesCancelCompleted(REFCLSID clsidHandler)
  3276. {
  3277. HRESULT hr = S_OK;
  3278. LPHANDLERINFO pCurHandlerInfo;
  3279. CLock clockqueue(this);
  3280. // just loop through handlers matching clsid and if any are <= SynchronizeCompleted
  3281. // and the cancelled flag set then an instance of the Handler is still
  3282. // stuck in a Cancel.
  3283. Assert(m_QueueType == QUEUETYPE_PROGRESS);
  3284. clockqueue.Enter();
  3285. pCurHandlerInfo = m_pFirstHandler;
  3286. while (pCurHandlerInfo)
  3287. {
  3288. if ( (clsidHandler == pCurHandlerInfo->clsidHandler)
  3289. && (BAD_HANDLERSTATE(pCurHandlerInfo) )
  3290. && (pCurHandlerInfo->fCancelled) )
  3291. {
  3292. hr = S_FALSE;
  3293. break;
  3294. }
  3295. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  3296. }
  3297. clockqueue.Leave();
  3298. return hr;
  3299. }
  3300. //+---------------------------------------------------------------------------
  3301. //
  3302. // Member: CHndlrQueue::AddItemToHandler, public
  3303. //
  3304. // Synopsis: Adds item to the specified handler.
  3305. // Called in context of the handlers thread.
  3306. //
  3307. // Arguments: [wHandlerId] - Id of handler.
  3308. // [pOfflineItem] - Points to Items information to add.
  3309. //
  3310. // Returns: Appropriate Error code
  3311. //
  3312. // Modifies:
  3313. //
  3314. // History: 17-Nov-97 rogerg Created.
  3315. //
  3316. //----------------------------------------------------------------------------
  3317. STDMETHODIMP CHndlrQueue::AddItemToHandler(HANDLERINFO *pHandlerId,SYNCMGRITEM *pOfflineItem)
  3318. {
  3319. HRESULT hr = E_UNEXPECTED; // review for Lookup failures
  3320. LPHANDLERINFO pHandlerInfo = NULL;
  3321. LPITEMLIST pNewItem = NULL;
  3322. LPHANDLERINFO pHandlerMatched;
  3323. LPITEMLIST pItemListMatch;
  3324. CLock clockqueue(this);
  3325. clockqueue.Enter();
  3326. Assert(m_QueueType == QUEUETYPE_CHOICE);
  3327. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  3328. {
  3329. if (HANDLERSTATE_INADDHANDLERITEMS != pHandlerInfo->HandlerState)
  3330. {
  3331. Assert(HANDLERSTATE_INADDHANDLERITEMS == pHandlerInfo->HandlerState);
  3332. hr = E_UNEXPECTED;
  3333. }
  3334. else
  3335. {
  3336. // make sure the handler has a jobID and ConnectionObj
  3337. // associated with it.
  3338. Assert(pHandlerInfo->pJobInfo);
  3339. Assert(pHandlerInfo->pJobInfo->pConnectionObj);
  3340. if (pHandlerInfo->pJobInfo
  3341. && pHandlerInfo->pJobInfo->pConnectionObj)
  3342. {
  3343. DWORD dwSyncFlags = pHandlerInfo->pJobInfo->dwSyncFlags;
  3344. // Allocate the item.
  3345. pNewItem = AllocNewHandlerItem(pHandlerInfo,pOfflineItem);
  3346. if (NULL == pNewItem)
  3347. {
  3348. hr = E_OUTOFMEMORY;
  3349. }
  3350. else
  3351. {
  3352. DWORD dwCheckState;
  3353. DWORD dwDefaultCheck; // what default for the item should be.
  3354. DWORD ConnectionIndex;
  3355. DWORD dwSyncEvent = dwSyncFlags & SYNCMGRFLAG_EVENTMASK;
  3356. // if SyncType is SYNCMGRFLAG_CONNECT, SYNCMGRFLAG_PENDINGDISCONNECT
  3357. // or Idle, set the defaults based on registration flags
  3358. // If change this logic need to also change logic in dll hndlrq.
  3359. dwDefaultCheck = pOfflineItem->dwItemState;
  3360. if (
  3361. ( (dwSyncEvent == SYNCMGRFLAG_IDLE) && !(pHandlerInfo->dwRegistrationFlags & SYNCMGRREGISTERFLAG_IDLE) )
  3362. || ( (dwSyncEvent == SYNCMGRFLAG_CONNECT) && !(pHandlerInfo->dwRegistrationFlags & SYNCMGRREGISTERFLAG_CONNECT) )
  3363. || ( (dwSyncEvent == SYNCMGRFLAG_PENDINGDISCONNECT) && !(pHandlerInfo->dwRegistrationFlags & SYNCMGRREGISTERFLAG_PENDINGDISCONNECT) )
  3364. )
  3365. {
  3366. dwDefaultCheck = SYNCMGRITEMSTATE_UNCHECKED;
  3367. }
  3368. // get appropriate stored setting based on the sync flags
  3369. // invoke we just use whatever the handler tells us it should be.
  3370. if (SYNCMGRFLAG_INVOKE != dwSyncEvent)
  3371. {
  3372. for (ConnectionIndex = 0; ConnectionIndex <
  3373. pHandlerInfo->pJobInfo->cbNumConnectionObjs;
  3374. ++ConnectionIndex)
  3375. {
  3376. TCHAR *pszConnectionName =
  3377. pHandlerInfo->pJobInfo->pConnectionObj[ConnectionIndex]->pwszConnectionName;
  3378. switch(dwSyncEvent)
  3379. {
  3380. case SYNCMGRFLAG_MANUAL:
  3381. // only support one connection for manual
  3382. Assert(pHandlerInfo->pJobInfo->cbNumConnectionObjs == 1);
  3383. if (RegGetSyncItemSettings(SYNCTYPE_MANUAL,
  3384. pHandlerInfo->clsidHandler,
  3385. pOfflineItem->ItemID,
  3386. pszConnectionName,&dwCheckState,
  3387. dwDefaultCheck,
  3388. NULL))
  3389. {
  3390. pNewItem->offlineItem.dwItemState = dwCheckState;
  3391. }
  3392. break;
  3393. case SYNCMGRFLAG_CONNECT:
  3394. case SYNCMGRFLAG_PENDINGDISCONNECT:
  3395. if (RegGetSyncItemSettings(SYNCTYPE_AUTOSYNC,
  3396. pHandlerInfo->clsidHandler,
  3397. pOfflineItem->ItemID,
  3398. pszConnectionName,&dwCheckState,
  3399. dwDefaultCheck,
  3400. NULL))
  3401. {
  3402. // for logon/logoff a checkstate of set wins and
  3403. // as soon as it is set break out of the loop
  3404. if (0 == ConnectionIndex ||
  3405. (SYNCMGRITEMSTATE_CHECKED == dwCheckState))
  3406. {
  3407. pNewItem->offlineItem.dwItemState = dwCheckState;
  3408. }
  3409. if (SYNCMGRITEMSTATE_CHECKED ==pNewItem->offlineItem.dwItemState)
  3410. {
  3411. break;
  3412. }
  3413. }
  3414. break;
  3415. case SYNCMGRFLAG_IDLE:
  3416. if (RegGetSyncItemSettings(SYNCTYPE_IDLE,
  3417. pHandlerInfo->clsidHandler,
  3418. pOfflineItem->ItemID,
  3419. pszConnectionName,&dwCheckState,
  3420. dwDefaultCheck,
  3421. NULL))
  3422. {
  3423. // for Idle a checkstate of set wins and
  3424. // as soon as it is set break out of the loop
  3425. if (0 == ConnectionIndex ||
  3426. (SYNCMGRITEMSTATE_CHECKED == dwCheckState))
  3427. {
  3428. pNewItem->offlineItem.dwItemState = dwCheckState;
  3429. }
  3430. if (SYNCMGRITEMSTATE_CHECKED ==pNewItem->offlineItem.dwItemState)
  3431. {
  3432. break;
  3433. }
  3434. }
  3435. break;
  3436. case SYNCMGRFLAG_SCHEDULED: // if caused by an invoke, use whatever handler tells us.
  3437. // only support one connection for schedule
  3438. Assert(pHandlerInfo->pJobInfo->cbNumConnectionObjs == 1);
  3439. if (pHandlerInfo->pJobInfo)
  3440. {
  3441. if (RegGetSyncItemSettings(SYNCTYPE_SCHEDULED,
  3442. pHandlerInfo->clsidHandler,
  3443. pOfflineItem->ItemID,
  3444. pszConnectionName,
  3445. &dwCheckState,
  3446. SYNCMGRITEMSTATE_UNCHECKED, // if don't find item, don't check
  3447. pHandlerInfo->pJobInfo->szScheduleName))
  3448. {
  3449. pNewItem->offlineItem.dwItemState = dwCheckState;
  3450. }
  3451. else
  3452. {
  3453. // If don't find then default is to be unchecked.
  3454. pNewItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_UNCHECKED;
  3455. }
  3456. }
  3457. break;
  3458. case SYNCMGRFLAG_INVOKE: // if caused by an invoke, use whatever handler tells us.
  3459. break;
  3460. default:
  3461. AssertSz(0,"UnknownSyncFlag Event");
  3462. break;
  3463. };
  3464. }
  3465. }
  3466. // Search and mark duplicate entries.
  3467. if (IsItemAlreadyInList(pHandlerInfo->clsidHandler,
  3468. (pOfflineItem->ItemID),pHandlerInfo->pHandlerId,
  3469. &pHandlerMatched,&pItemListMatch) )
  3470. {
  3471. Assert(QUEUETYPE_CHOICE == m_QueueType || QUEUETYPE_PROGRESS == m_QueueType);
  3472. pNewItem->fDuplicateItem = TRUE;
  3473. // duplicate handling
  3474. // if a manual sync then first writer to the queue wins,
  3475. if (QUEUETYPE_CHOICE == m_QueueType)
  3476. {
  3477. pNewItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_UNCHECKED;
  3478. }
  3479. }
  3480. hr = NOERROR;
  3481. }
  3482. }
  3483. }
  3484. }
  3485. clockqueue.Leave();
  3486. return hr;
  3487. }
  3488. //+---------------------------------------------------------------------------
  3489. //
  3490. // Member: CHndlrQueue::Progress, public
  3491. //
  3492. // Synopsis: Updates items progress information
  3493. // Called in the context of the Handlers thread
  3494. //
  3495. // Arguments: [wHandlerId] - Id of handler.
  3496. // [ItemID] - OfflineItemID of the specified item.
  3497. // [lpSyncProgressItem] - Pointer to SyncProgressItem.
  3498. //
  3499. // Returns: Appropriate Error code
  3500. //
  3501. // Modifies:
  3502. //
  3503. // History: 17-Nov-97 rogerg Created.
  3504. //
  3505. //----------------------------------------------------------------------------
  3506. STDMETHODIMP CHndlrQueue::Progress(HANDLERINFO *pHandlerId,REFSYNCMGRITEMID ItemID,
  3507. LPSYNCMGRPROGRESSITEM lpSyncProgressItem)
  3508. {
  3509. HRESULT hr = E_UNEXPECTED;
  3510. LPHANDLERINFO pHandlerInfo = NULL;
  3511. LPITEMLIST pCurItem = NULL;
  3512. BOOL fFoundMatch = FALSE;
  3513. PROGRESSUPDATEDATA progressData;
  3514. HWND hwndCallback;
  3515. CLock clockqueue(this);
  3516. progressData.pHandlerID = pHandlerId;
  3517. progressData.ItemID = ItemID;
  3518. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  3519. clockqueue.Enter();
  3520. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  3521. {
  3522. pCurItem = pHandlerInfo->pFirstItem;
  3523. while (pCurItem)
  3524. {
  3525. if (ItemID == pCurItem->offlineItem.ItemID)
  3526. {
  3527. fFoundMatch = TRUE;
  3528. break;
  3529. }
  3530. pCurItem = pCurItem->pnextItem;
  3531. }
  3532. if (pHandlerInfo->fCancelled)
  3533. hr = S_SYNCMGR_CANCELALL;
  3534. else if (!fFoundMatch || pCurItem->fItemCancelled)
  3535. {
  3536. Assert(fFoundMatch);
  3537. hr = S_SYNCMGR_CANCELITEM;
  3538. }
  3539. else
  3540. hr = NOERROR;
  3541. }
  3542. if (fFoundMatch) // store everyting in local vars.
  3543. {
  3544. // if found match but shouldn't include in progress bar
  3545. // fix it up.
  3546. if ( (pCurItem->fHiddenItem) || (FALSE == pCurItem->fIncludeInProgressBar))
  3547. {
  3548. // if found a match it should be included in the progress bar
  3549. // Assert(TRUE == pCurItem->fIncludeInProgressBar); // Review if test app hits this.
  3550. Assert(FALSE == pCurItem->fHiddenItem); // shouldn't get progress on hidden items.
  3551. fFoundMatch = FALSE;
  3552. if (NOERROR == hr)
  3553. {
  3554. hr = S_SYNCMGR_CANCELITEM; // return cancel item just as if item wasn't cancelled.
  3555. }
  3556. }
  3557. else
  3558. {
  3559. progressData.clsidHandler = pHandlerInfo->clsidHandler;
  3560. progressData.wItemId = pCurItem->wItemId;
  3561. hwndCallback = pHandlerInfo->hWndCallback;
  3562. }
  3563. }
  3564. clockqueue.Leave();
  3565. if (fFoundMatch)
  3566. {
  3567. // send off data to the callback window.
  3568. // it is responsible for updating the items progress values.
  3569. if (hwndCallback)
  3570. {
  3571. // validate the ProgressItem structure before passing it on.
  3572. if (IsValidSyncProgressItem(lpSyncProgressItem))
  3573. {
  3574. SendMessage(hwndCallback,WM_PROGRESS_UPDATE,
  3575. (WPARAM) &progressData,(LPARAM) lpSyncProgressItem);
  3576. }
  3577. else
  3578. {
  3579. if (NOERROR == hr) // CANCEL RESULTS OVERRIDE ARG PROBLEMS
  3580. {
  3581. hr = E_INVALIDARG;
  3582. }
  3583. }
  3584. }
  3585. }
  3586. return hr;
  3587. }
  3588. //+---------------------------------------------------------------------------
  3589. //
  3590. // Member: CHndlrQueue::LogError, public
  3591. //
  3592. // Synopsis: Logs and error for the specified item
  3593. // Called in the context of the Handlers thread
  3594. //
  3595. // Arguments: [wHandlerId] - Id of handler.
  3596. // [dwErrorLevel] - ErrorLevel of the Error
  3597. // [lpcErrorText] - Text of the Error.
  3598. // [lpSyncLogError] - Pointer to SyncLogError structure
  3599. //
  3600. // Returns: Appropriate Error code
  3601. //
  3602. // Modifies:
  3603. //
  3604. // History: 17-Nov-97 rogerg Created.
  3605. //
  3606. //----------------------------------------------------------------------------
  3607. STDMETHODIMP CHndlrQueue::LogError(HANDLERINFO *pHandlerId,DWORD dwErrorLevel,
  3608. const WCHAR *lpcErrorText, LPSYNCMGRLOGERRORINFO lpSyncLogError)
  3609. {
  3610. HRESULT hr = E_UNEXPECTED;
  3611. LPHANDLERINFO pHandlerInfo = NULL;
  3612. LPITEMLIST pCurItem = NULL;
  3613. BOOL fFoundMatch = FALSE;
  3614. MSGLogErrors msgLogErrors;
  3615. HWND hWndCallback = NULL;
  3616. CLock clockqueue(this);
  3617. msgLogErrors.dwErrorLevel = dwErrorLevel;
  3618. msgLogErrors.lpcErrorText = lpcErrorText;
  3619. msgLogErrors.ErrorID = GUID_NULL;
  3620. msgLogErrors.fHasErrorJumps = FALSE;
  3621. msgLogErrors.mask = 0;
  3622. Assert(QUEUETYPE_PROGRESS == m_QueueType);
  3623. clockqueue.Enter();
  3624. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  3625. {
  3626. hWndCallback = pHandlerInfo->hWndCallback;
  3627. // validate the paramaters.
  3628. if (NULL == hWndCallback)
  3629. {
  3630. hr = E_UNEXPECTED;
  3631. }
  3632. else if (!IsValidSyncLogErrorInfo(dwErrorLevel,lpcErrorText,lpSyncLogError))
  3633. {
  3634. hr = E_INVALIDARG;
  3635. }
  3636. else
  3637. {
  3638. if (lpSyncLogError && (lpSyncLogError->mask & SYNCMGRLOGERROR_ERRORID))
  3639. {
  3640. pHandlerInfo->fHasErrorJumps = TRUE;
  3641. msgLogErrors.mask |= SYNCMGRLOGERROR_ERRORID;
  3642. msgLogErrors.ErrorID = lpSyncLogError->ErrorID;
  3643. }
  3644. if (lpSyncLogError && (lpSyncLogError->mask & SYNCMGRLOGERROR_ERRORFLAGS))
  3645. {
  3646. if (SYNCMGRERRORFLAG_ENABLEJUMPTEXT & lpSyncLogError->dwSyncMgrErrorFlags)
  3647. {
  3648. pHandlerInfo->fHasErrorJumps = TRUE;
  3649. msgLogErrors.fHasErrorJumps = TRUE;
  3650. }
  3651. }
  3652. if (lpSyncLogError && (lpSyncLogError->mask & SYNCMGRLOGERROR_ITEMID))
  3653. {
  3654. msgLogErrors.mask |= SYNCMGRLOGERROR_ITEMID;
  3655. msgLogErrors.ItemID = lpSyncLogError->ItemID;
  3656. }
  3657. hr = NOERROR;
  3658. }
  3659. }
  3660. clockqueue.Leave();
  3661. if (NOERROR == hr)
  3662. {
  3663. Assert(sizeof(WPARAM) >= sizeof(HANDLERINFO *));
  3664. SendMessage(hWndCallback,WM_PROGRESS_LOGERROR,(WPARAM) pHandlerId, (LPARAM) &msgLogErrors);
  3665. }
  3666. return hr;
  3667. }
  3668. //+---------------------------------------------------------------------------
  3669. //
  3670. // Member: CHndlrQueue::DeleteLogError, public
  3671. //
  3672. // Synopsis: Deletes an Error from the Results pane that was previously logged.
  3673. //
  3674. // Arguments:
  3675. //
  3676. // Returns: Appropriate Error code
  3677. //
  3678. // Modifies:
  3679. //
  3680. // History: 17-Nov-97 rogerg Created.
  3681. //
  3682. //----------------------------------------------------------------------------
  3683. STDMETHODIMP CHndlrQueue::DeleteLogError(HANDLERINFO *pHandlerId,REFSYNCMGRERRORID ErrorID,DWORD dwReserved)
  3684. {
  3685. MSGDeleteLogErrors msgDeleteLogError;
  3686. HWND hWndCallback = NULL;
  3687. HANDLERINFO *pHandlerInfo;
  3688. CLock clockqueue(this);
  3689. clockqueue.Enter();
  3690. msgDeleteLogError.pHandlerId = pHandlerId;
  3691. msgDeleteLogError.ErrorID = ErrorID;
  3692. if (NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  3693. {
  3694. hWndCallback = pHandlerInfo->hWndCallback;
  3695. }
  3696. // review, if handler doesn't have any more error jumps after the deletelogError we can now
  3697. // release it (pHandlerInfo->fHasErrorJumps)
  3698. clockqueue.Leave();
  3699. if (hWndCallback)
  3700. {
  3701. SendMessage(hWndCallback,WM_PROGRESS_DELETELOGERROR,(WPARAM) 0, (LPARAM) &msgDeleteLogError);
  3702. }
  3703. return NOERROR;
  3704. }
  3705. //+---------------------------------------------------------------------------
  3706. //
  3707. // Member: CHndlrQueue::CallCompletionRoutine, public
  3708. //
  3709. // Synopsis: Called by callback on handler thread
  3710. // to indicate a call with a completion callback
  3711. // has completed.
  3712. //
  3713. // Returns: Appropriate Error code
  3714. //
  3715. // Modifies:
  3716. //
  3717. // History: 02-Jun-98 rogerg Created.
  3718. //
  3719. //----------------------------------------------------------------------------
  3720. void CHndlrQueue::CallCompletionRoutine(HANDLERINFO *pHandlerId,DWORD dwThreadMsg,HRESULT hCallResult,
  3721. ULONG cbNumItems,SYNCMGRITEMID *pItemIDs)
  3722. {
  3723. HWND hWndDlg = NULL;
  3724. HRESULT hrHandlerCall = NOERROR;
  3725. BOOL fCallbackAlreadyCalled = FALSE;
  3726. HANDLERINFO *pHandlerInfo;
  3727. CLock clockqueue(this);
  3728. if (!pHandlerId)
  3729. {
  3730. Assert(pHandlerId);
  3731. return;
  3732. }
  3733. // Note: cbNumItems and pItemIDs is only valid for ShowErrors
  3734. // make sure the handlid is valid and then if there
  3735. // is a pdlg call its completion routine via the postmessage
  3736. // method.
  3737. clockqueue.Enter();
  3738. hWndDlg = m_hwndDlg;
  3739. Assert(hWndDlg);
  3740. if (pHandlerId && NOERROR == LookupHandlerFromId(pHandlerId,&pHandlerInfo))
  3741. {
  3742. // if flag isn't set for the message
  3743. // then it was already handled i.e. handler called
  3744. // us even though it returned an error.
  3745. if (dwThreadMsg & pHandlerInfo->dwOutCallMessages)
  3746. {
  3747. pHandlerInfo->dwOutCallMessages &= ~dwThreadMsg;
  3748. }
  3749. else
  3750. {
  3751. AssertSz(0,"Callback called twice"); // test apps currently do this.
  3752. fCallbackAlreadyCalled = TRUE;
  3753. }
  3754. // if already handled don't call these again.
  3755. if (!fCallbackAlreadyCalled)
  3756. {
  3757. // fix up internal states before informing caller
  3758. // the call is complete.
  3759. switch(dwThreadMsg)
  3760. {
  3761. case ThreadMsg_ShowProperties: // don't need to do anything on show properties.
  3762. break;
  3763. case ThreadMsg_PrepareForSync:
  3764. hrHandlerCall = PrepareForSyncCompleted(pHandlerInfo,hCallResult);
  3765. break;
  3766. case ThreadMsg_Synchronize:
  3767. hrHandlerCall = SynchronizeCompleted(pHandlerInfo,hCallResult);
  3768. break;
  3769. case ThreadMsg_ShowError:
  3770. hrHandlerCall = ShowErrorCompleted(pHandlerInfo,hCallResult,cbNumItems,pItemIDs);
  3771. break;
  3772. default:
  3773. AssertSz(0,"Unknown Queue Completion Callback");
  3774. break;
  3775. }
  3776. }
  3777. // possible completion routine comes in before handler has actually
  3778. // returned from the original call. Wait until proxy is no longer in an
  3779. // out call.
  3780. // If switch to COM for messaging need to find a better way of doing this.
  3781. if (pHandlerInfo->pThreadProxy &&
  3782. pHandlerInfo->pThreadProxy->IsProxyInOutCall()
  3783. && hWndDlg)
  3784. {
  3785. // tell proxy to post the message whenver it gets done.
  3786. if ( 0 /* NOERROR ==
  3787. pHandlerInfo->pThreadProxy->SetProxyCompletion(hWndDlg,WM_BASEDLG_COMPLETIONROUTINE,dwThreadMsg,hCallResult)*/)
  3788. {
  3789. hWndDlg = NULL;
  3790. }
  3791. }
  3792. }
  3793. else
  3794. {
  3795. // on handler lookup assert but still post the message to the hwnd
  3796. // so it won't get stuck waiting for the completion routine
  3797. // this is only valid for setproperties in the
  3798. // case the user clicked on a non-existant item but
  3799. // this shouldn't really happen either
  3800. AssertSz(dwThreadMsg == ThreadMsg_ShowProperties,"LookupHandler failed in CompletionRoutine");
  3801. }
  3802. LPCALLCOMPLETIONMSGLPARAM lpCallCompletelParam = (LPCALLCOMPLETIONMSGLPARAM) ALLOC(sizeof(CALLCOMPLETIONMSGLPARAM));
  3803. if (lpCallCompletelParam)
  3804. {
  3805. lpCallCompletelParam->hCallResult = hCallResult;
  3806. lpCallCompletelParam->clsidHandler = pHandlerId->clsidHandler;
  3807. // itemID is GUID_NULL unless its a ShowProperties completed.
  3808. if ((ThreadMsg_ShowProperties == dwThreadMsg) && (1 == cbNumItems))
  3809. {
  3810. lpCallCompletelParam->itemID = *pItemIDs;
  3811. }
  3812. else
  3813. {
  3814. lpCallCompletelParam->itemID = GUID_NULL;
  3815. }
  3816. }
  3817. clockqueue.Leave();
  3818. if (hWndDlg && !fCallbackAlreadyCalled) // if already out of out call or proxy failed post the messge ourselves.
  3819. {
  3820. // if alloc of completion lparam fails send message anyways so callback count
  3821. // remains accurate.
  3822. PostMessage(hWndDlg,WM_BASEDLG_COMPLETIONROUTINE,dwThreadMsg,(LPARAM) lpCallCompletelParam);
  3823. }
  3824. else
  3825. {
  3826. // if don't post message up to us to free the lpCallCopmlete.
  3827. if (lpCallCompletelParam)
  3828. {
  3829. FREE(lpCallCompletelParam);
  3830. }
  3831. }
  3832. }
  3833. //+---------------------------------------------------------------------------
  3834. //
  3835. // Member: CHndlrQueue::IsItemAlreadyInList, private
  3836. //
  3837. // Synopsis: Given a clsid and ItemID determines if a matchin
  3838. // item is already in the list
  3839. // Called in the context of the Handlers thread
  3840. //
  3841. // Arguments: [clsidHandler] - clsid of the handler
  3842. // [ItemID] - ItemID of the item
  3843. // [wHandlerId] - HandlerID of the item.
  3844. // [ppHandlerMatched] - on out the handler that matched
  3845. // [ppItemIdMatch] - on out Item that matched.
  3846. //
  3847. // Returns: Appropriate Error code
  3848. //
  3849. // Modifies:
  3850. //
  3851. // History: 17-Nov-97 rogerg Created.
  3852. //
  3853. //----------------------------------------------------------------------------
  3854. BOOL CHndlrQueue::IsItemAlreadyInList(CLSID clsidHandler,REFSYNCMGRITEMID ItemID,
  3855. HANDLERINFO *pHandlerId,
  3856. LPHANDLERINFO *ppHandlerMatched,
  3857. LPITEMLIST *ppItemListMatch)
  3858. {
  3859. BOOL fFoundMatch = FALSE;
  3860. LPHANDLERINFO pCurHandlerInfo = NULL;
  3861. LPITEMLIST pCurItem = NULL;
  3862. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  3863. pCurHandlerInfo = m_pFirstHandler;
  3864. while (pCurHandlerInfo && !fFoundMatch)
  3865. {
  3866. if (pHandlerId == pCurHandlerInfo->pHandlerId) // when find hander know didn't find any before.
  3867. break;
  3868. if (clsidHandler == pCurHandlerInfo->clsidHandler) // see if CLSID matches
  3869. {
  3870. // see if handler info has a matching item
  3871. pCurItem = pCurHandlerInfo->pFirstItem;
  3872. while (pCurItem)
  3873. {
  3874. if (ItemID == pCurItem->offlineItem.ItemID)
  3875. {
  3876. *ppHandlerMatched = pCurHandlerInfo;
  3877. *ppItemListMatch = pCurItem;
  3878. fFoundMatch = TRUE;
  3879. break;
  3880. }
  3881. pCurItem = pCurItem->pnextItem;
  3882. }
  3883. }
  3884. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  3885. }
  3886. return fFoundMatch;
  3887. }
  3888. //+---------------------------------------------------------------------------
  3889. //
  3890. // Member: CHndlrQueue::GetSelectedItemsInHandler, private
  3891. //
  3892. // Synopsis: Gets the number of selected items for this handler
  3893. //
  3894. // for our implementation if a cbCount is passed and it doesn't match
  3895. // the number of actually selected then assert since we call this routine
  3896. // internally.
  3897. //
  3898. //
  3899. // Arguments: [pHandlerInfo] - Pointer to the HandlerInfo to look at.
  3900. // [cbcount] - [in] cbCount == number of pItems allocated,
  3901. // [out] cbCpimt == number of items actually written.
  3902. // if the buffer is too small items written will be zero.
  3903. // [pItems] - Pointer to array of SYNCMGRITEMs to be filled in.
  3904. //
  3905. // Returns: Returns the number of selectd items.
  3906. //
  3907. // Modifies:
  3908. //
  3909. // History: 17-Nov-97 rogerg Created.
  3910. //
  3911. //----------------------------------------------------------------------------
  3912. DWORD CHndlrQueue::GetSelectedItemsInHandler(LPHANDLERINFO pHandlerInfo,ULONG *cbCount,
  3913. SYNCMGRITEMID* pItems)
  3914. {
  3915. LPITEMLIST pCurItem;
  3916. DWORD dwSelectCount = 0;
  3917. DWORD dwArraySizeIndex;
  3918. DWORD dwArraySize;
  3919. ASSERT_LOCKHELD(this); // caller of this function should have already locked the queue.
  3920. if (cbCount)
  3921. {
  3922. dwArraySizeIndex = *cbCount;
  3923. dwArraySize = *cbCount;
  3924. *cbCount = 0; // initialize to zero.
  3925. }
  3926. else
  3927. {
  3928. dwArraySizeIndex = 0;
  3929. dwArraySize = 0;
  3930. }
  3931. if (0 != dwArraySize && NULL == pItems)
  3932. {
  3933. Assert(0 == dwArraySize || NULL != pItems);
  3934. return 0;
  3935. }
  3936. if (NULL == pHandlerInfo)
  3937. {
  3938. Assert(pHandlerInfo);
  3939. return 0;
  3940. }
  3941. pCurItem = pHandlerInfo->pFirstItem;
  3942. while (pCurItem)
  3943. {
  3944. // dwItemState
  3945. if (SYNCMGRITEMSTATE_CHECKED == pCurItem->offlineItem.dwItemState)
  3946. {
  3947. ++dwSelectCount;
  3948. if (dwArraySizeIndex)
  3949. {
  3950. *pItems = pCurItem->offlineItem.ItemID;
  3951. *cbCount += 1;
  3952. ++pItems;
  3953. --dwArraySizeIndex;
  3954. if (!pCurItem->fHiddenItem) // if not a hidden item
  3955. {
  3956. Assert(TRUE == pCurItem->fIncludeInProgressBar);
  3957. Assert(HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE == pCurItem->iProgMaxValue);
  3958. // reset iProgValue back to zero since may not be zero if retry came in while still synchronizing.
  3959. SetItemProgressValues(pCurItem,0,HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE);
  3960. }
  3961. else
  3962. {
  3963. // if item is hidden,a assert it doesn't have UI
  3964. Assert(FALSE == pCurItem->fIncludeInProgressBar);
  3965. Assert(HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE == pCurItem->iProgValue);
  3966. Assert(HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE == pCurItem->iProgMaxValue);
  3967. }
  3968. pCurItem->fSynchronizingItem = TRUE; // item is now synchronizing
  3969. // once added to the array uncheck the item so on a retry we can just
  3970. // always reset items to checked
  3971. pCurItem->offlineItem.dwItemState = SYNCMGRITEMSTATE_UNCHECKED;
  3972. }
  3973. }
  3974. else
  3975. {
  3976. Assert(FALSE == pCurItem->fSynchronizingItem);
  3977. // Assert(FALSE == pCurItem->fIncludeInProgressBar); Can be included in progress bar if retry comes in before RemoveFinished is called.
  3978. Assert(HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE == pCurItem->iProgValue);
  3979. Assert(HNDRLQUEUE_DEFAULT_PROGRESS_MAXVALUE == pCurItem->iProgMaxValue);
  3980. }
  3981. pCurItem = pCurItem->pnextItem;
  3982. }
  3983. // internal call should always request a proper array size.
  3984. Assert(dwSelectCount == dwArraySize || 0 == dwArraySize);
  3985. return dwSelectCount;
  3986. }
  3987. #ifdef _OLD
  3988. //+---------------------------------------------------------------------------
  3989. //
  3990. // Member: CHndlrQueue::SetPendingDisconnectEvent, private
  3991. //
  3992. // Synopsis: Sets the Pending Disconnect Event, If on already
  3993. // exists, S_FALSE is returned.
  3994. //
  3995. //
  3996. // Arguments:
  3997. //
  3998. // Returns:
  3999. //
  4000. // Modifies:
  4001. //
  4002. // History: 17-Nov-97 rogerg Created.
  4003. //
  4004. //----------------------------------------------------------------------------
  4005. STDMETHODIMP CHndlrQueue::SetPendingDisconnectEvent(HANDLE hRasPendingEvent)
  4006. {
  4007. HRESULT hr = S_FALSE;
  4008. CLock clockqueue(this);
  4009. Assert(hRasPendingEvent);
  4010. clockqueue.Enter();
  4011. /*
  4012. if (NULL == m_hRasPendingEvent)
  4013. {
  4014. m_hRasPendingEvent = hRasPendingEvent;
  4015. hr = NOERROR;
  4016. }
  4017. */
  4018. clockqueue.Leave();
  4019. return hr;
  4020. }
  4021. // signals and resets any disconnect event objects.
  4022. STDMETHODIMP CHndlrQueue::SetDisconnectEvent()
  4023. {
  4024. CLock clockqueue(this);
  4025. HANDLE hRasPendingEvent = NULL;
  4026. clockqueue.Enter();
  4027. /*
  4028. if (NULL != m_hRasPendingEvent)
  4029. {
  4030. hRasPendingEvent = m_hRasPendingEvent;
  4031. m_hRasPendingEvent = NULL;
  4032. }
  4033. */
  4034. clockqueue.Leave();
  4035. if (NULL != hRasPendingEvent)
  4036. {
  4037. SetEvent(hRasPendingEvent);
  4038. }
  4039. return NOERROR;
  4040. }
  4041. #endif // _OLD
  4042. // job info methods
  4043. STDMETHODIMP CHndlrQueue::CreateJobInfo(JOBINFO **ppJobInfo,DWORD cbNumConnectionNames)
  4044. {
  4045. HRESULT hr = S_FALSE;
  4046. JOBINFO *pNewJobInfo = NULL;
  4047. ASSERT_LOCKHELD(this);
  4048. // create a new job and add it to the the JobInfo list.
  4049. // allocate space for JobInfo + number of connection objects that
  4050. // will be associated with this job.
  4051. Assert(cbNumConnectionNames);
  4052. if (cbNumConnectionNames < 1)
  4053. return S_FALSE;
  4054. pNewJobInfo = (JOBINFO *) ALLOC(sizeof(JOBINFO) +
  4055. sizeof(CONNECTIONOBJ)*(cbNumConnectionNames - 1));
  4056. if (pNewJobInfo)
  4057. {
  4058. memset(pNewJobInfo,0,sizeof(JOBINFO));
  4059. pNewJobInfo->cRefs = 1;
  4060. pNewJobInfo->pNextJobInfo = m_pFirstJobInfo;
  4061. m_pFirstJobInfo = pNewJobInfo;
  4062. *ppJobInfo = pNewJobInfo;
  4063. hr = NOERROR;
  4064. }
  4065. else
  4066. {
  4067. hr = E_OUTOFMEMORY;
  4068. }
  4069. return hr;
  4070. }
  4071. DWORD CHndlrQueue::ReleaseJobInfoExt(JOBINFO *pJobInfo)
  4072. {
  4073. DWORD dwRet;
  4074. CLock clockqueue(this);
  4075. clockqueue.Enter();
  4076. dwRet = ReleaseJobInfo(pJobInfo);
  4077. clockqueue.Leave();
  4078. return dwRet;
  4079. }
  4080. DWORD CHndlrQueue::ReleaseJobInfo(JOBINFO *pJobInfo)
  4081. {
  4082. DWORD cRefs;
  4083. ASSERT_LOCKHELD(this);
  4084. --(pJobInfo->cRefs);
  4085. cRefs = pJobInfo->cRefs;
  4086. Assert( ((LONG) cRefs) >= 0);
  4087. if (0 == cRefs)
  4088. {
  4089. JOBINFO *pCurJobInfo = NULL;
  4090. DWORD dwConnObjIndex;
  4091. // loop through release all connection objs on this job
  4092. for (dwConnObjIndex = 0 ; dwConnObjIndex < pJobInfo->cbNumConnectionObjs;
  4093. dwConnObjIndex++)
  4094. {
  4095. Assert(pJobInfo->pConnectionObj[dwConnObjIndex]);
  4096. if (pJobInfo->pConnectionObj[dwConnObjIndex])
  4097. {
  4098. ConnectObj_ReleaseConnectionObj(pJobInfo->pConnectionObj[dwConnObjIndex]);
  4099. pJobInfo->pConnectionObj[dwConnObjIndex] = NULL;
  4100. }
  4101. }
  4102. // remove this JobInfo from the list.
  4103. if (pJobInfo == m_pFirstJobInfo)
  4104. {
  4105. m_pFirstJobInfo = pJobInfo->pNextJobInfo;
  4106. }
  4107. else
  4108. {
  4109. pCurJobInfo = m_pFirstJobInfo;
  4110. while (pCurJobInfo->pNextJobInfo)
  4111. {
  4112. if (pJobInfo == pCurJobInfo->pNextJobInfo)
  4113. {
  4114. pCurJobInfo->pNextJobInfo = pJobInfo->pNextJobInfo;
  4115. break;
  4116. }
  4117. pCurJobInfo = pCurJobInfo->pNextJobInfo;
  4118. }
  4119. }
  4120. FREE(pJobInfo);
  4121. }
  4122. return cRefs;
  4123. }
  4124. DWORD CHndlrQueue::AddRefJobInfo(JOBINFO *pJobInfo)
  4125. {
  4126. DWORD cRefs;
  4127. ASSERT_LOCKHELD(this);
  4128. ++(pJobInfo->cRefs);
  4129. cRefs = pJobInfo->cRefs;
  4130. return cRefs;
  4131. }
  4132. // determines ifthe specified JobInfo's connection can be openned.
  4133. // review should really call into connection Object help api.
  4134. STDMETHODIMP CHndlrQueue::OpenConnection(JOBINFO *pJobInfo)
  4135. {
  4136. CONNECTIONOBJ *pConnectionObj;
  4137. HRESULT hr;
  4138. Assert(pJobInfo);
  4139. if (NULL == pJobInfo) // if no job info go ahead and say the connection is open.
  4140. return NOERROR;
  4141. // turn off workOffline during the sync CloseConnection will turn
  4142. // it back on if the user had it off.
  4143. ConnectObj_SetWorkOffline(FALSE);
  4144. // if this is anything but a schedule go ahead and say NOERROR;
  4145. if (!(SYNCMGRFLAG_SCHEDULED ==
  4146. (pJobInfo->dwSyncFlags & SYNCMGRFLAG_EVENTMASK)) )
  4147. {
  4148. return NOERROR;
  4149. }
  4150. // for schedule sink we only support one connection Object.
  4151. Assert(1 == pJobInfo->cbNumConnectionObjs);
  4152. if (1 != pJobInfo->cbNumConnectionObjs)
  4153. {
  4154. return E_UNEXPECTED;
  4155. }
  4156. pConnectionObj = pJobInfo->pConnectionObj[0];
  4157. if (NULL == pConnectionObj)
  4158. return NOERROR;
  4159. // if we aren't suppose to make a connection of there is already
  4160. // a hRasConn as part of the connection object then just
  4161. // return NOERROR;
  4162. // if connection is already open and we are on a job that
  4163. // has already tried to open it then return NOERROR;
  4164. if (pJobInfo->pConnectionObj[0]->fConnectionOpen
  4165. && pJobInfo->fTriedConnection)
  4166. return NOERROR;
  4167. // if we haven't already tried to make the connection
  4168. // on this job then call OpenConnection to make sure the
  4169. // connection is still really open.
  4170. if (!pJobInfo->fTriedConnection)
  4171. {
  4172. pJobInfo->fTriedConnection = TRUE;
  4173. hr = ConnectObj_OpenConnection(pConnectionObj,pJobInfo->fCanMakeConnection,m_pDlg);
  4174. }
  4175. else
  4176. {
  4177. hr = S_FALSE;
  4178. }
  4179. // if get down to the bottom and still no hRasConn then return S_FALSE
  4180. return hr;
  4181. }
  4182. //+---------------------------------------------------------------------------
  4183. //
  4184. // Member: CHndlrQueue::ScrambleIdleHandlers, private
  4185. //
  4186. // Synopsis: Called on an Idle Choice queue just before transfer
  4187. // so the lastHandler is placed at the back of the list.
  4188. //
  4189. // Arguments:
  4190. //
  4191. // Returns:
  4192. //
  4193. // Modifies:
  4194. //
  4195. // History: 17-Nov-97 rogerg Created.
  4196. //
  4197. //----------------------------------------------------------------------------
  4198. STDMETHODIMP CHndlrQueue::ScrambleIdleHandlers(REFCLSID clsidLastHandler)
  4199. {
  4200. LPHANDLERINFO pMatchHandler;
  4201. LPHANDLERINFO pLastHandler;
  4202. CLock clockqueue(this);
  4203. Assert(m_QueueType == QUEUETYPE_CHOICE);
  4204. clockqueue.Enter();
  4205. // find the first occurance of specified handler and then place that handler
  4206. // at the end of the list and everything after at the beginning of the list
  4207. // no an error to not find the Handler since may have been deleted or
  4208. // no longer has items.
  4209. pMatchHandler = m_pFirstHandler;
  4210. while (pMatchHandler)
  4211. {
  4212. if (pMatchHandler->clsidHandler == clsidLastHandler)
  4213. {
  4214. // if there are no items after the match then just break;
  4215. if (NULL == pMatchHandler->pNextHandler)
  4216. {
  4217. break;
  4218. }
  4219. // loop until find the last handler.
  4220. pLastHandler = pMatchHandler->pNextHandler;
  4221. while (pLastHandler->pNextHandler)
  4222. {
  4223. pLastHandler = pLastHandler->pNextHandler;
  4224. }
  4225. // now set the handler after the matchHandler to be the
  4226. // head and set the next pointer of the LastHandler in
  4227. // the list to point to the MatchHandler.
  4228. pLastHandler->pNextHandler = m_pFirstHandler;
  4229. m_pFirstHandler = pMatchHandler->pNextHandler;
  4230. pMatchHandler->pNextHandler = NULL;
  4231. break;
  4232. }
  4233. pMatchHandler = pMatchHandler->pNextHandler;
  4234. }
  4235. clockqueue.Leave();
  4236. return NOERROR;
  4237. }
  4238. //+---------------------------------------------------------------------------
  4239. //
  4240. // Member: CHndlrQueue::BeginSyncSession
  4241. //
  4242. // Synopsis: Called to signal the beginning of the core synchronization session
  4243. // to setup up dial support.
  4244. //
  4245. // History: 28-Jul-98 SitaramR Created
  4246. //
  4247. //----------------------------------------------------------------------------
  4248. STDMETHODIMP CHndlrQueue::BeginSyncSession()
  4249. {
  4250. HRESULT hr = ::BeginSyncSession();
  4251. return hr;
  4252. }
  4253. //+---------------------------------------------------------------------------
  4254. //
  4255. // Member: CHndlrQueue::EndSyncSession
  4256. //
  4257. // Synopsis: Called to signal the end of the core synchronization session
  4258. // to teardown dial support.
  4259. //
  4260. // History: 28-Jul-98 SitaramR Created
  4261. //
  4262. //----------------------------------------------------------------------------
  4263. STDMETHODIMP CHndlrQueue::EndSyncSession()
  4264. {
  4265. HRESULT hr = ::EndSyncSession();
  4266. return hr;
  4267. }
  4268. //+---------------------------------------------------------------------------
  4269. //
  4270. // Member: CHndlrQueue::SortHandlersByConnection
  4271. //
  4272. // Synopsis: Moves hanlders that won't establish connection to the end,
  4273. // ie after handlers that can establish connectoin.
  4274. //
  4275. // History: 28-Jul-98 SitaramR Created
  4276. //
  4277. //----------------------------------------------------------------------------
  4278. STDMETHODIMP CHndlrQueue::SortHandlersByConnection()
  4279. {
  4280. CLock clockqueue(this);
  4281. clockqueue.Enter();
  4282. Assert(m_QueueType == QUEUETYPE_CHOICE);
  4283. LPHANDLERINFO pFirstCannotDialHandler = NULL;
  4284. LPHANDLERINFO pLastCannotDialHandler = NULL;
  4285. LPHANDLERINFO pPrevHandler = NULL;
  4286. LPHANDLERINFO pCurHandler = m_pFirstHandler;
  4287. while ( pCurHandler )
  4288. {
  4289. if ( pCurHandler->SyncMgrHandlerInfo.SyncMgrHandlerFlags & SYNCMGRHANDLER_MAYESTABLISHCONNECTION )
  4290. {
  4291. //
  4292. // Move to next handler
  4293. //
  4294. pPrevHandler = pCurHandler;
  4295. pCurHandler = pCurHandler->pNextHandler;
  4296. }
  4297. else
  4298. {
  4299. //
  4300. // Move handler to cannot dial list
  4301. //
  4302. if ( pPrevHandler == NULL )
  4303. {
  4304. //
  4305. // This is the first handler in list
  4306. //
  4307. m_pFirstHandler = pCurHandler->pNextHandler;
  4308. pCurHandler->pNextHandler = NULL;
  4309. if ( pLastCannotDialHandler == NULL )
  4310. {
  4311. Assert( pFirstCannotDialHandler == NULL );
  4312. pFirstCannotDialHandler = pLastCannotDialHandler = pCurHandler;
  4313. }
  4314. else
  4315. {
  4316. pLastCannotDialHandler->pNextHandler = pCurHandler;
  4317. pLastCannotDialHandler = pCurHandler;
  4318. }
  4319. pCurHandler = m_pFirstHandler;
  4320. }
  4321. else
  4322. {
  4323. pPrevHandler->pNextHandler = pCurHandler->pNextHandler;
  4324. pCurHandler->pNextHandler = NULL;
  4325. if ( pLastCannotDialHandler == NULL )
  4326. {
  4327. Assert( pFirstCannotDialHandler == NULL );
  4328. pFirstCannotDialHandler = pLastCannotDialHandler = pCurHandler;
  4329. }
  4330. else
  4331. {
  4332. pLastCannotDialHandler->pNextHandler = pCurHandler;
  4333. pLastCannotDialHandler = pCurHandler;
  4334. }
  4335. pCurHandler = pPrevHandler->pNextHandler;
  4336. }
  4337. }
  4338. }
  4339. //
  4340. // Attach cannot dial list at end of m_pFirstHandler list
  4341. //
  4342. if ( pPrevHandler )
  4343. {
  4344. Assert( pPrevHandler->pNextHandler == NULL );
  4345. pPrevHandler->pNextHandler = pFirstCannotDialHandler;
  4346. }
  4347. else
  4348. {
  4349. //
  4350. // Case where the original list became empty
  4351. //
  4352. Assert( m_pFirstHandler == NULL );
  4353. m_pFirstHandler = pFirstCannotDialHandler;
  4354. }
  4355. clockqueue.Leave();
  4356. return NOERROR;
  4357. }
  4358. //+---------------------------------------------------------------------------
  4359. //
  4360. // Member: CHndlrQueue::EstablishConnection
  4361. //
  4362. // Synopsis: Called by handler to establish a connection.
  4363. //
  4364. // Arguments: [pHandlerID] -- Ptr to handler
  4365. // [lpwszConnection] -- Connection to establish
  4366. // [dwReserved] -- Must be zero for now
  4367. //
  4368. // History: 28-Jul-98 SitaramR Created
  4369. //
  4370. //----------------------------------------------------------------------------
  4371. STDMETHODIMP CHndlrQueue::EstablishConnection( LPHANDLERINFO pHandlerID,
  4372. WCHAR const * lpwszConnection,
  4373. DWORD dwReserved )
  4374. {
  4375. HRESULT hr = NOERROR;
  4376. CLock clockqueue(this);
  4377. clockqueue.Enter();
  4378. CONNECTIONOBJ *pConnObj = NULL;
  4379. BOOL fAutoDial = FALSE;
  4380. LPHANDLERINFO pHandlerInfo = NULL;
  4381. hr = LookupHandlerFromId( pHandlerID, &pHandlerInfo );
  4382. if ( NOERROR == hr )
  4383. {
  4384. JOBINFO *pJobInfo = pHandlerInfo->pJobInfo;
  4385. DWORD dwSyncFlags = pJobInfo->dwSyncFlags & SYNCMGRFLAG_EVENTMASK;
  4386. if ( ( dwSyncFlags == SYNCMGRFLAG_MANUAL
  4387. || dwSyncFlags == SYNCMGRFLAG_INVOKE )
  4388. && pHandlerInfo->SyncMgrHandlerInfo.SyncMgrHandlerFlags & SYNCMGRHANDLER_MAYESTABLISHCONNECTION )
  4389. {
  4390. if ( lpwszConnection == NULL )
  4391. {
  4392. //
  4393. // Null connection means use the default autodial connection
  4394. //
  4395. fAutoDial = TRUE;
  4396. }
  4397. else
  4398. {
  4399. hr = ConnectObj_FindConnectionObj(lpwszConnection,TRUE,&pConnObj);
  4400. }
  4401. }
  4402. else
  4403. {
  4404. //
  4405. // Either the handler invoke type does not permit establishing connection,
  4406. // or GetHandlerInfo flags did not specify the EstablishConnection flag.
  4407. //
  4408. hr = E_UNEXPECTED;
  4409. }
  4410. }
  4411. clockqueue.Leave();
  4412. if (NOERROR == hr)
  4413. {
  4414. if (fAutoDial)
  4415. {
  4416. hr = ConnectObj_AutoDial(INTERNET_AUTODIAL_FORCE_ONLINE,m_pDlg);
  4417. }
  4418. else
  4419. {
  4420. Assert( pConnObj );
  4421. if ( !pConnObj->fConnectionOpen )
  4422. {
  4423. hr = ConnectObj_OpenConnection(pConnObj, TRUE, m_pDlg );
  4424. ConnectObj_ReleaseConnectionObj(pConnObj);
  4425. }
  4426. }
  4427. }
  4428. return hr;
  4429. }