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

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