notfmgr.cxx
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 77k
Category:

Windows Develop

Development Platform:

Visual C++

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. //  File:       NotfMgr.cxx
  7. //
  8. //  Contents:
  9. //
  10. //  Classes:
  11. //
  12. //  Functions:
  13. //
  14. //  History:    12-21-1996   JohannP (Johann Posch)   Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <notiftn.h>
  18. //
  19. //
  20. // dll shared data
  21. //
  22. #pragma data_seg("SharedData")
  23. ULONG       g_dwCurrentCookie = 0;
  24. ULONG       g_dwCurrentPackage = 0;
  25. ULONG       g_dwCurrentUserIdle = 0;
  26. ULONG       g_dwGlobalState = 0;
  27. CFileTime   g_dateLastSchedListChange = 0;
  28. ULONG       g_cSchedListCount = 0;
  29. ULONG       g_cThrottleItemCount = 0;
  30. ULONG       g_cRefPorts = 0;
  31. ULONG       g_cRefProcesses = 0;
  32. ULONG       g_urgCDestPortMax = DESTINATIONPORT_MAX;
  33. ULONG       g_urgScheduleListItemtMax = SCHEDULELISITEM_MAX;
  34. ULONG       g_urgThrottleItemtMax = THROTTLEITEM_MAX;
  35. DestinationPort  g_DefaultDestPort = {0, 0, 0};
  36. DestinationPort  g_rgCDestPorts[DESTINATIONPORT_MAX] = {{0,0},{0,0},{0,0}};
  37. SCHEDLISTITEMKEY g_rgSortListItem[SCHEDULELISITEM_MAX]=  {{0, 0, 0, 0}};
  38. THROTTLE_ITEM    g_rgThrottleItem[THROTTLEITEM_MAX] = {{0,-1,0,0,0},{0,-1,0,0,0} };
  39. #pragma data_seg()
  40. CFileTime   g_DateLastSync;
  41. //
  42. // the ProcessPacket is called for global notifications
  43. //
  44. ULONG GetGlobalCounter()
  45. {
  46.     return GetGlobalNotfMgr()->GetPackageCount(TRUE);
  47. }
  48. ULONG GetUserIdleCounter()
  49. {
  50.     NotfAssert(( GetGlobalNotfMgr() ));
  51.     return GetGlobalNotfMgr()->GetUserIdleCount(TRUE);
  52. }
  53. DWORD GetGlobalState()
  54. {
  55.     return GetGlobalNotfMgr()->GetGlobalState();
  56. }
  57. DWORD SetGlobalStateOn(DWORD dwFlags)
  58. {
  59.     return GetGlobalNotfMgr()->SetGlobalStateOn(dwFlags);
  60. }
  61. DWORD SetGlobalStateOff(DWORD dwFlags)
  62. {
  63.     return GetGlobalNotfMgr()->SetGlobalStateOff(dwFlags);
  64. }
  65. //+---------------------------------------------------------------------------
  66. //
  67. //  Method:     CGlobalNotfMgr::CGlobalNotfMgr
  68. //
  69. //  Synopsis:
  70. //
  71. //  Arguments:  (none)
  72. //
  73. //  Returns:
  74. //
  75. //  History:    2-13-1997   JohannP (Johann Posch)   Created
  76. //
  77. //  Notes:
  78. //
  79. //----------------------------------------------------------------------------
  80. CGlobalNotfMgr::CGlobalNotfMgr() : CCourierAgent()
  81. {
  82.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::CGlobalNotfMgrn", NULL));
  83.     //
  84.     // create the mutex and get the lock
  85.     _Smxs.Init("NotificationMgrSharedData", TRUE);
  86.     if (_Smxs.Created())
  87.     {
  88.         NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::CGlobalNotfMgr INIT TABLES!!n", NULL));
  89.         // ok, the first intance init the shared data
  90.         memset(g_rgSortListItem, 0, sizeof(SCHEDLISTITEMKEY) * g_urgScheduleListItemtMax);
  91.         memset(g_rgThrottleItem, 0, sizeof(THROTTLE_ITEM) * g_urgThrottleItemtMax);
  92.         memset(g_rgCDestPorts, 0, sizeof(DestinationPort) * g_urgCDestPortMax);
  93.         g_cRefPorts = 0;
  94.         g_cRefProcesses = 0;
  95.         g_cSchedListCount = 0;
  96.         g_cThrottleItemCount = 0;
  97.         g_dateLastSchedListChange = GetCurrentDtTime();
  98.         SetGlobalStateOff(GL_STATE_USERIDLE);
  99.         DeletRegSetting(c_pszRegKeyPackageDelete, NULL);
  100.         DeletRegSetting(c_pszRegKeyRunningDestDelete, NULL);
  101.     }
  102.     _uProcessCount = ++g_cRefProcesses;
  103.     // release the lock
  104.     _Smxs.Release();
  105.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::CGlobalNotfMgr (g_cRefProcesses:%lx)n", this,g_cRefProcesses));
  106. }
  107. //
  108. //  Helper which will use the default process window for timers or
  109. //  fallback to the old behavior with a callback proc.
  110. //
  111. UINT CGlobalNotfMgr::SetScheduleTimer(UINT idTimer, UINT uTimeout, TIMERPROC tmprc)
  112. {
  113.     UINT timer;
  114.     CDestinationPort cDefDest;
  115.     DWORD dwDefProcessId;
  116.     
  117.     if (GetDefaultDestinationPort(&cDefDest) == S_OK && 
  118.         GetWindowThreadProcessId(cDefDest.GetPort(), &dwDefProcessId) &&
  119.         (dwDefProcessId == ::GetCurrentProcessId()))
  120.     {
  121.         timer = ::SetTimer(cDefDest.GetPort(), idTimer, uTimeout, NULL);
  122.     }
  123.     else
  124.     {
  125.         TNotfDebugOut((DEB_TSCHEDULE, "WARNING - no default process in SetScheduleTimern"));
  126.         timer = ::SetTimer(NULL, idTimer, uTimeout, tmprc);
  127.     }
  128.     return timer;
  129. }
  130. HRESULT CGlobalNotfMgr::SetLastUpdateDate(CPackage *pCPackage)
  131. {
  132.     HRESULT hr = E_FAIL;
  133.     if (pCPackage)
  134.     {
  135.         CLockSmMutex lck(_Smxs);
  136.         for (ULONG i = 0; i < g_urgScheduleListItemtMax; i ++)
  137.         {
  138.             if (g_rgSortListItem[i].notfCookie == pCPackage->GetNotificationCookie())
  139.             {
  140.                 SYSTEMTIME st;
  141.                 CFileTime ft;
  142.                 
  143.                 GetLocalTime(&st);
  144.                 SystemTimeToFileTime(&st, &ft);
  145.                 g_rgSortListItem[i].lastUpdateDate = FileTimeToInt64(ft);
  146.                 hr = S_OK;
  147.                 break;
  148.             }
  149.         }
  150.     }
  151.     return hr;
  152. }
  153. //+---------------------------------------------------------------------------
  154. //
  155. //  Method:     CGlobalNotfMgr::SetDefaultDestinationPort
  156. //
  157. //  Synopsis:
  158. //
  159. //  Arguments:  [rCDestPort] --
  160. //              [pCDestPortPrev] --
  161. //
  162. //  Returns:
  163. //
  164. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  165. //
  166. //  Notes:
  167. //
  168. //----------------------------------------------------------------------------
  169. HRESULT CGlobalNotfMgr::SetDefaultDestinationPort(CDestinationPort &rCDestPort, CDestinationPort *pCDestPortPrev)
  170. {
  171.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::SetDefaultDestinationPortn", this));
  172.     HRESULT hr = NOERROR;
  173.     do
  174.     {   // BEGIN LOCK BLOCK
  175.         CLockSmMutex lck(_Smxs);
  176.         if (pCDestPortPrev)
  177.         {
  178.             *pCDestPortPrev = g_DefaultDestPort;
  179.         }
  180.         g_DefaultDestPort = rCDestPort;
  181.         break;
  182.     } while (TRUE); // END LOCK BLOCK
  183.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::SetDefaultDestinationPort (hr:%lx, hwnd:%lx)n",this, hr, rCDestPort.GetPort()));
  184.     return hr;
  185. }
  186. //+---------------------------------------------------------------------------
  187. //
  188. //  Method:     CGlobalNotfMgr::GetDefaultDestinationPort
  189. //
  190. //  Synopsis:
  191. //
  192. //  Arguments:  [pCDestPort] --
  193. //
  194. //  Returns:
  195. //
  196. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  197. //
  198. //  Notes:
  199. //
  200. //----------------------------------------------------------------------------
  201. HRESULT CGlobalNotfMgr::GetDefaultDestinationPort(CDestinationPort *pCDestPort)
  202. {
  203.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::GetDefaultDestinationPortn", this));
  204.     HRESULT hr = NOERROR;
  205.     do
  206.     {   // BEGIN LOCK BLOCK
  207.         CLockSmMutex lck(_Smxs);
  208.         if (!pCDestPort)
  209.         {
  210.             hr = E_INVALIDARG;
  211.             break;
  212.         }
  213.         if (!IsWindow(g_DefaultDestPort._hWndPort))
  214.         {
  215.             // not default prot registered
  216.             hr = S_FALSE;
  217.         }
  218.         else
  219.         {
  220.             *pCDestPort = g_DefaultDestPort;
  221.         }
  222.         break;
  223.     } while (TRUE); // END LOCK BLOCK
  224.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::GetDefaultDestinationPort (hr:%lx)n",this, hr));
  225.     return hr;
  226. }
  227. //+---------------------------------------------------------------------------
  228. //
  229. //  Method:     CGlobalNotfMgr::GetAllDestinationPorts
  230. //
  231. //  Synopsis:
  232. //
  233. //  Arguments:  [ppCDestPort] --
  234. //              [pCount] --
  235. //
  236. //  Returns:
  237. //
  238. //  History:    2-13-1997   JohannP (Johann Posch)   Created
  239. //
  240. //  Notes:
  241. //
  242. //----------------------------------------------------------------------------
  243. HRESULT CGlobalNotfMgr::GetAllDestinationPorts(CDestinationPort **ppCDestPort, ULONG *pCount)
  244. {
  245.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::GetAllDestinationPortsn", this));
  246.     HRESULT hr = NOERROR;
  247.     NotfAssert((ppCDestPort && pCount));
  248.     ULONG uElements = 0;
  249.     ULONG pos = 0;
  250.     do
  251.     {   // BEGIN LOCK BLOCK
  252.         CLockSmMutex lck(_Smxs);
  253.         if (g_cRefPorts == 0)
  254.         {
  255.             // nothing to do
  256.             break;
  257.         }
  258.         CDestinationPort *phWnd = new CDestinationPort [g_cRefPorts];
  259.         if (phWnd == 0)
  260.         {
  261.             *pCount = 0;
  262.             *ppCDestPort = 0;
  263.             hr = E_OUTOFMEMORY;
  264.             break;
  265.         }
  266.         CDestinationPort *pDestPort = (CDestinationPort *)g_rgCDestPorts;
  267.         for (ULONG i = 0;
  268.              (   (i < g_urgCDestPortMax)
  269.               && (pos < g_cRefPorts))
  270.              ;i++)
  271.         {
  272.             if ( pDestPort[i].GetPort() != 0)
  273.             {
  274.                 if ( IsWindow(pDestPort[i].GetPort()) )
  275.                 {
  276.                     phWnd[pos] = g_rgCDestPorts[i];
  277.                     pos++;
  278.                 }
  279.                 else
  280.                 {
  281.                     pDestPort[i].SetPort(0);
  282.                     g_cRefPorts--;
  283.                 }
  284.             }
  285.         }
  286.         *ppCDestPort  = phWnd;
  287.         *pCount = pos;
  288.         uElements = g_cRefPorts;
  289.         hr = (pos) ? S_OK : E_FAIL;
  290.         break;
  291.     } while (TRUE); // END LOCK BLOCK
  292.     NotfAssert((uElements == pos));
  293.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::GetAllDestinationPorts (hr:%lx, pCount:%lx)n",this, hr, *pCount));
  294.     return hr;
  295. }
  296. //+---------------------------------------------------------------------------
  297. //
  298. //  Method:     CGlobalNotfMgr::AddDestinationPort
  299. //
  300. //  Synopsis:
  301. //
  302. //  Arguments:  [rCDestPort] --
  303. //              [pCDestination] --
  304. //
  305. //  Returns:
  306. //
  307. //  History:    2-13-1997   JohannP (Johann Posch)   Created
  308. //
  309. //  Notes:
  310. //
  311. //----------------------------------------------------------------------------
  312. HRESULT CGlobalNotfMgr::AddDestinationPort(CDestinationPort &rCDestPort, CDestination *pCDestination)
  313. {
  314.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::AddDestinationPortn", this));
  315.     HRESULT hr = E_FAIL;
  316.     NotfAssert((pCDestination));
  317.     // save the destination in the running dest key
  318.     hr = pCDestination->SaveToPersist(c_pszRegKeyRunningDest);
  319.     if (hr == NOERROR)
  320.     {
  321.         CLockSmMutex lck(_Smxs);
  322.         hr = E_FAIL;
  323.         CDestinationPort *pDestPort = (CDestinationPort *)g_rgCDestPorts;
  324.         //
  325.         // check if the port is already registered
  326.         //
  327.         for (ULONG i = 0; i < g_urgCDestPortMax; i ++)
  328.         {
  329.             if ( pDestPort[i].GetPort() == rCDestPort.GetPort())
  330.             {
  331.                 // ok, found port; just addref it
  332.                 pDestPort[i].AddRef();
  333.                 i = g_urgCDestPortMax;
  334.                 hr = NOERROR;
  335.             }
  336.         }
  337.         //
  338.         // not found; find an empty slot and add it
  339.         //
  340.         pDestPort = (CDestinationPort *)g_rgCDestPorts;
  341.         if (hr != NOERROR)
  342.         {
  343.             for (ULONG i = 0; i < g_urgCDestPortMax; i ++)
  344.             {
  345.                 if (pDestPort[i].GetPort() == 0)
  346.                 {
  347.                     pDestPort[i] = rCDestPort;
  348.                     g_cRefPorts++;
  349.                     i = g_urgCDestPortMax;
  350.                     hr = NOERROR;
  351.                 }
  352.             }
  353.         }
  354.     }
  355.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::AddDestinationPort (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  356.     return hr;
  357. }
  358. //+---------------------------------------------------------------------------
  359. //
  360. //  Method:     CGlobalNotfMgr::RemoveDestinationPort
  361. //
  362. //  Synopsis:
  363. //
  364. //  Arguments:  [hWnd] --
  365. //              [pCDestination] --
  366. //
  367. //  Returns:
  368. //
  369. //  History:    2-13-1997   JohannP (Johann Posch)   Created
  370. //
  371. //  Notes:
  372. //
  373. //----------------------------------------------------------------------------
  374. HRESULT CGlobalNotfMgr::RemoveDestinationPort(CDestinationPort &rCDestPort, CDestination *pCDestination)
  375. {
  376.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::RemoveDestinationPortn", this));
  377.     HRESULT hr = E_FAIL;
  378.     NotfAssert((pCDestination));
  379.     // save the destination in the running dest key
  380.     hr = pCDestination->RemovePersist(c_pszRegKeyRunningDest);
  381.     if (rCDestPort.GetPort())
  382.     {
  383.         CLockSmMutex lck(_Smxs);
  384.         CDestinationPort *pDestPort = (CDestinationPort *)g_rgCDestPorts;
  385.         //
  386.         // find the slot with this port
  387.         //
  388.         for (ULONG i = 0; i < g_urgCDestPortMax; i ++)
  389.         {
  390.             if (pDestPort[i].GetPort() == rCDestPort.GetPort())
  391.             {
  392.                 if ((pDestPort+i)->Release() == 0)
  393.                 {
  394.                     // if last release clean the slot
  395.                     pDestPort[i].SetPort(0);
  396.                     g_cRefPorts--;
  397.                 }
  398.                 i = g_urgCDestPortMax;
  399.                 hr = NOERROR;
  400.             }
  401.         }
  402.     }
  403.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::RemoveDestinationPort (cPorts:%lx, hr:%lx)n",this,g_cRefPorts, hr));
  404.     return hr;
  405. }
  406. //+---------------------------------------------------------------------------
  407. //
  408. //  Method:     CGlobalNotfMgr::LookupDestinationPort
  409. //
  410. //  Synopsis:
  411. //
  412. //  Arguments:  [rCDestPort] --
  413. //              [pCDest] --
  414. //
  415. //  Returns:
  416. //
  417. //  History:    2-13-1997   JohannP (Johann Posch)   Created
  418. //
  419. //  Notes:
  420. //
  421. //----------------------------------------------------------------------------
  422. HRESULT CGlobalNotfMgr::LookupDestinationPort(CDestinationPort &rCDestPort, CDestination *pCDest)
  423. {
  424.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::LookupDestinationPortn", this));
  425.     HRESULT hr = E_FAIL;
  426.     ULONG cPorts = 0;
  427.     {
  428.         CLockSmMutex lck(_Smxs);
  429.         CDestinationPort *pDestPort = (CDestinationPort *)g_rgCDestPorts;
  430.         cPorts = g_cRefPorts;
  431.         for (ULONG i = 0; i < g_urgCDestPortMax; i ++)
  432.         {
  433.             if (pDestPort[i].GetPort() == rCDestPort.GetPort())
  434.             {
  435.                 // got exchanged
  436.                 i = g_urgCDestPortMax;
  437.                 hr = NOERROR;
  438.             }
  439.         }
  440.     }
  441.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::LookupDestinationPort (cPorts:%lx, hr:%lx)n",this, cPorts, hr));
  442.     return hr;
  443. }
  444. //+---------------------------------------------------------------------------
  445. //
  446. //  Method:     CGlobalNotfMgr::AddScheduleItem
  447. //
  448. //  Synopsis:   add a package to the global table
  449. //
  450. //  Arguments:  [pCPackage] --
  451. //
  452. //  Returns:
  453. //
  454. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  455. //
  456. //  Notes:
  457. //
  458. //----------------------------------------------------------------------------
  459. HRESULT CGlobalNotfMgr::AddScheduleItem(CPackage *pCPackage, BOOL fCheck)
  460. {
  461.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::AddScheduleItemn", this));
  462.     HRESULT hr = E_FAIL;
  463.     NotfAssert((pCPackage));
  464.     do
  465.     {
  466.         if (!pCPackage)
  467.         {
  468.             hr = E_INVALIDARG;
  469.             break;
  470.         }
  471.         NotfAssert(( pCPackage->GetNextRunDate() != 0 ));
  472.         if ( pCPackage->GetNextRunDate() == 0 )
  473.         {
  474.             hr = E_INVALIDARG;
  475.             break;
  476.         }
  477.         CLockSmMutex lck(_Smxs);
  478.         ULONG iPos = g_urgScheduleListItemtMax;
  479.         if (g_cSchedListCount >= g_urgScheduleListItemtMax)
  480.         {
  481.             break;
  482.         }
  483.         if (fCheck)
  484.         {
  485.             if (pCPackage)
  486.             {
  487.                 iPos = pCPackage->GetIndex();
  488.             }
  489.             if (iPos < g_urgScheduleListItemtMax)
  490.             {
  491.                 if (g_rgSortListItem[iPos].notfCookie != pCPackage->GetNotificationCookie())
  492.                 {
  493.                     iPos = g_urgScheduleListItemtMax;
  494.                 }
  495.             }
  496.             if (iPos >= g_urgScheduleListItemtMax)
  497.             {
  498.                 //
  499.                 // BUGBUG: need better algorithm here
  500.                 //
  501.                 NOTIFICATIONCOOKIE notfCookie = pCPackage->GetNotificationCookie();
  502.                 for (ULONG i = 0; i < g_urgScheduleListItemtMax; i++)
  503.                 {
  504.                     if (g_rgSortListItem[i].notfCookie == notfCookie)
  505.                     {
  506.                         hr = NOERROR;
  507.                         iPos = i;
  508.                         i = g_urgScheduleListItemtMax;
  509.                     }
  510.                 }
  511.             }
  512.         }
  513.         hr = pCPackage->SaveToPersist(c_pszRegKey);
  514.         BREAK_ONERROR(hr);
  515.         //g_dateLastSchedListChange = GetCurrentDtTime();
  516.         if (iPos >= g_urgScheduleListItemtMax)
  517.         {
  518.             //
  519.             // did not find entry - find empty slot and add item
  520.             //
  521.             g_cSchedListCount++;
  522.             for (ULONG i = 0; i < g_urgScheduleListItemtMax; i ++)
  523.             {
  524.                 if (g_rgSortListItem[i].date == 0)
  525.                 {
  526.                     //NotfAssert(( pCPackage->GetNextRunDate() ));
  527.                     g_rgSortListItem[i].date = FileTimeToInt64(pCPackage->GetNextRunDate());
  528.                     g_rgSortListItem[i].notfCookie = pCPackage->GetNotificationCookie();
  529.                     pCPackage->SetIndex(i);
  530.                     i = g_urgScheduleListItemtMax;
  531.                 }
  532.             }
  533.         }
  534.         else
  535.         {
  536.             // use the found position
  537.             g_rgSortListItem[iPos].date = FileTimeToInt64(pCPackage->GetNextRunDate());
  538.             NotfAssert(( g_rgSortListItem[iPos].notfCookie == pCPackage->GetNotificationCookie() ));
  539.             g_rgSortListItem[iPos].notfCookie = pCPackage->GetNotificationCookie();
  540.             pCPackage->SetIndex(iPos);
  541.         }
  542.         g_dateLastSchedListChange = GetCurrentDtTime();
  543.         break;
  544.     } while (TRUE);
  545.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::AddScheduleItem (hr:%lx)n",this, hr));
  546.     return hr;
  547. }
  548. //+---------------------------------------------------------------------------
  549. //
  550. //  Method:     CGlobalNotfMgr::RemoveScheduleItem
  551. //
  552. //  Synopsis:   remove a package from the global table
  553. //
  554. //  Arguments:  [CPackage] --
  555. //              [pCPackage] --
  556. //
  557. //  Returns:
  558. //
  559. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  560. //
  561. //  Notes:
  562. //
  563. //----------------------------------------------------------------------------
  564. HRESULT CGlobalNotfMgr::RemoveScheduleItem(SCHEDLISTITEMKEY &rSchItem,CPackage *pCPackage)
  565. {
  566.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::RemoveScheduleItemn", this));
  567.     HRESULT hr = E_FAIL;
  568.     NotfAssert((pCPackage));
  569.     do
  570.     {
  571.         if (!pCPackage)
  572.         {
  573.             hr = E_INVALIDARG;
  574.             break;
  575.         }
  576.         { //BEGIN LOCK BLOCK
  577.             CLockSmMutex lck(_Smxs);
  578.             if (g_cSchedListCount == 0)
  579.             {
  580.                 break;
  581.             }
  582.             ULONG index = 0xffffffff;
  583.             index = pCPackage->GetIndex();
  584.             if (index < g_urgScheduleListItemtMax)
  585.             {
  586.                 if (g_rgSortListItem[index].notfCookie == rSchItem.notfCookie)
  587.                 {
  588.                     hr = NOERROR;
  589.                 }
  590.                 else
  591.                 {
  592.                     NotfDebugOut((DEB_TRACE, "CGlobalNotfMgr::LookupScheduleItem: List not in sync!"));
  593.                     NotfAssert((FALSE && "CGlobalNotfMgr::RemoveScheduleItem not in sync!"));
  594.                 }
  595.             }
  596.             if (hr != NOERROR)
  597.             {
  598.                 //
  599.                 // BUGBUG: need better algorithm here
  600.                 //
  601.                 for (ULONG i = 0; i < g_urgScheduleListItemtMax; i ++)
  602.                 {
  603.                     if (g_rgSortListItem[i].notfCookie == rSchItem.notfCookie)
  604.                     {
  605.                         index = i;
  606.                         hr = NOERROR;
  607.                         i = g_urgScheduleListItemtMax;
  608.                     }
  609.                 }
  610.             }
  611.             BREAK_ONERROR(hr);
  612.             if ((index < g_urgScheduleListItemtMax) &&
  613.                 (g_rgSortListItem[index].date != 0))
  614.             {
  615.                 g_rgSortListItem[index].date = 0;
  616.                 g_rgSortListItem[index].notfCookie = COOKIE_NULL;
  617.                 g_cSchedListCount--;
  618.                 g_dateLastSchedListChange = GetCurrentDtTime();
  619.             }
  620.         } // END LOCK BLOCK
  621.         if (pCPackage)
  622.         {
  623.             // don't care if this fails
  624.             pCPackage->SetIndex(0XFFFFFFFF);
  625.             HRESULT hr1 = pCPackage->RemovePersist(c_pszRegKey);
  626.             //NotfAssert((hr1 == NOERROR));
  627.         }
  628.         break;
  629.     } while (TRUE);
  630.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::RemoveScheduleItem (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  631.     return hr;
  632. }
  633. //+---------------------------------------------------------------------------
  634. //
  635. //  Method:     CGlobalNotfMgr::LookupScheduleItem
  636. //
  637. //  Synopsis:   find all package item currently in the global table
  638. //
  639. //  Arguments:  [CPackage] --
  640. //              [pCPackage] --
  641. //
  642. //  Returns:
  643. //
  644. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  645. //
  646. //  Notes:
  647. //
  648. //----------------------------------------------------------------------------
  649. HRESULT CGlobalNotfMgr::LookupScheduleItem(SCHEDLISTITEMKEY &rSchItem, CPackage *pCPackage)
  650. {
  651.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::LookupScheduleItemn", this));
  652.     HRESULT hr = E_FAIL;
  653.     NotfAssert((pCPackage));
  654.     do
  655.     {
  656.         if (!pCPackage)
  657.         {
  658.             hr = E_INVALIDARG;
  659.             break;
  660.         }
  661.         CLockSmMutex lck(_Smxs);
  662.         ULONG index = 0xffffffff;
  663.         if (g_cSchedListCount == 0)
  664.         {
  665.             break;
  666.         }
  667.         if (pCPackage)
  668.         {
  669.             index = pCPackage->GetIndex();
  670.         }
  671.         if (index < g_urgScheduleListItemtMax)
  672.         {
  673.             if (g_rgSortListItem[index].notfCookie == pCPackage->GetNotificationCookie())
  674.             {
  675.                 hr = NOERROR;
  676.             }
  677.             else
  678.             {
  679.                 NotfDebugOut((DEB_TRACE, "CGlobalNotfMgr::LookupScheduleItem: List not in sync!"));
  680.                 NotfAssert((FALSE && "CGlobalNotfMgr::LookupScheduleItem: List not in sync!"));
  681.             }
  682.         }
  683.         if (hr != NOERROR)
  684.         {
  685.             //
  686.             // BUGBUG: need better algorithm here
  687.             //
  688.             for (ULONG i = 0; i < g_urgScheduleListItemtMax; i ++)
  689.             {
  690.                 if (g_rgSortListItem[i].notfCookie == rSchItem.notfCookie)
  691.                 {
  692.                     rSchItem = g_rgSortListItem[i];
  693.                     hr = NOERROR;
  694.                     i = g_urgScheduleListItemtMax;
  695.                 }
  696.             }
  697.         }
  698.         break;
  699.     } while (TRUE);
  700.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::LookupScheduleItem (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  701.     return hr;
  702. }
  703. //+---------------------------------------------------------------------------
  704. //
  705. //  Method:     CGlobalNotfMgr::SetScheduleItemState
  706. //
  707. //  Synopsis:   find all package item currently in the global table
  708. //
  709. //  Arguments:  [CPackage] --
  710. //              [pCPackage] --
  711. //
  712. //  Returns:
  713. //
  714. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  715. //
  716. //  Notes:
  717. //
  718. //----------------------------------------------------------------------------
  719. HRESULT CGlobalNotfMgr::SetScheduleItemState(PNOTIFICATIONCOOKIE pNotfCookie, DWORD dwStateNew, SCHEDLISTITEMKEY *pSchItem)
  720. {
  721.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::SetScheduleItemStaten", this));
  722.     HRESULT hr = E_FAIL;
  723.     do
  724.     {
  725.         if (!pNotfCookie)
  726.         {
  727.             hr = E_INVALIDARG;
  728.             break;
  729.         }
  730.         CLockSmMutex lck(_Smxs);
  731.         if (g_cSchedListCount == 0)
  732.         {
  733.             break;
  734.         }
  735.         if (hr != NOERROR)
  736.         {
  737.             //
  738.             // BUGBUG: need better algorithm here
  739.             //
  740.             for (ULONG i = 0; i < g_urgScheduleListItemtMax; i ++)
  741.             {
  742.                 if (g_rgSortListItem[i].notfCookie == *pNotfCookie)
  743.                 {
  744.                     if (pSchItem)
  745.                     {
  746.                         *pSchItem = g_rgSortListItem[i];
  747.                     }
  748.                     g_rgSortListItem[i].dwState |= dwStateNew;
  749.                     hr = NOERROR;
  750.                     i = g_urgScheduleListItemtMax;
  751.                 }
  752.             }
  753.         }
  754.         break;
  755.     } while (TRUE);
  756.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::SetScheduleItemState (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  757.     return hr;
  758. }
  759. //+---------------------------------------------------------------------------
  760. //
  761. //  Method:     CGlobalNotfMgr::SetScheduleItemState
  762. //
  763. //  Synopsis:   find all package item currently in the global table
  764. //
  765. //  Arguments:  [CPackage] --
  766. //              [pCPackage] --
  767. //
  768. //  Returns:
  769. //
  770. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  771. //
  772. //  Notes:
  773. //
  774. //----------------------------------------------------------------------------
  775. HRESULT CGlobalNotfMgr::SetScheduleItemState(DWORD dwIndex, DWORD dwStateNew, SCHEDLISTITEMKEY *pSchItem)
  776. {
  777.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::SetScheduleItemStaten", this));
  778.     HRESULT hr = E_FAIL;
  779.     do
  780.     {
  781.         CLockSmMutex lck(_Smxs);
  782.         if (g_cSchedListCount == 0)
  783.         {
  784.             break;
  785.         }
  786.         if (dwIndex >= g_urgScheduleListItemtMax)
  787.         {
  788.             break;
  789.         }
  790.         ULONG i = dwIndex;
  791.         if (g_rgSortListItem[i].date != 0)
  792.         {
  793.             if (pSchItem)
  794.             {
  795.                 *pSchItem = g_rgSortListItem[i];
  796.             }
  797.             g_rgSortListItem[i].dwState |= dwStateNew;
  798.             hr = NOERROR;
  799.             i = g_urgScheduleListItemtMax;
  800.         }
  801.         break;
  802.     } while (TRUE);
  803.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::SetScheduleItemState (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  804.     return hr;
  805. }
  806. //+---------------------------------------------------------------------------
  807. //
  808. //  Method:     CGlobalNotfMgr::LoadScheduleItemPackage
  809. //
  810. //  Synopsis:   load a CPackage based on the SchItem key information
  811. //
  812. //  Arguments:  [rSchItem] --
  813. //              [ppCPackage] --
  814. //
  815. //  Returns:
  816. //
  817. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  818. //
  819. //  Notes:
  820. //
  821. //----------------------------------------------------------------------------
  822. HRESULT CGlobalNotfMgr::LoadScheduleItemPackage(
  823.                             SCHEDLISTITEMKEY &rSchItem,
  824.                             CPackage **ppCPackage)
  825. {
  826.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::LoadScheduleItemPackagen", this));
  827.     HRESULT hr = E_FAIL;
  828.     NotfAssert((ppCPackage));
  829.     hr = CPackage::LoadPersistedPackage(
  830.                        c_pszRegKey
  831.                        ,&rSchItem.notfCookie
  832.                        ,0
  833.                        ,ppCPackage);
  834.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::LoadScheduleItemPackage (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  835.     return hr;
  836. }
  837. //+---------------------------------------------------------------------------
  838. //
  839. //  Method:     CGlobalNotfMgr::GetScheduleItemCount
  840. //
  841. //  Synopsis:   get number of elements currently in the global table
  842. //
  843. //  Arguments:  [pulCount] --
  844. //
  845. //  Returns:
  846. //
  847. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  848. //
  849. //  Notes:
  850. //
  851. //----------------------------------------------------------------------------
  852. HRESULT CGlobalNotfMgr::GetScheduleItemCount(ULONG *pulCount)
  853. {
  854.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::GetScheduleItemCountn", this));
  855.     HRESULT hr = E_FAIL;
  856.     NotfAssert((pulCount));
  857.     CLockSmMutex lck(_Smxs);
  858.     *pulCount = g_cSchedListCount;
  859.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::GetScheduleItemCount (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  860.     return hr;
  861. }
  862. //+---------------------------------------------------------------------------
  863. //
  864. //  Method:     CGlobalNotfMgr::IsScheduleItemSyncd
  865. //
  866. //  Synopsis:   checks if the date and count match with the global table
  867. //              date and count
  868. //
  869. //  Arguments:  [rdate] --
  870. //              [uCount] --
  871. //
  872. //  Returns:
  873. //
  874. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  875. //
  876. //  Notes:
  877. //
  878. //----------------------------------------------------------------------------
  879. HRESULT CGlobalNotfMgr::IsScheduleItemSyncd(CFileTime &rdate, ULONG uCount)
  880. {
  881.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::IsScheduleItemSyncedn", this));
  882.     HRESULT hr = E_FAIL;
  883.     {   // BEGIN LOCK BLOCK
  884.         CLockSmMutex lck(_Smxs);
  885.         hr = (   (g_dateLastSchedListChange == rdate)
  886.               && (uCount == g_cSchedListCount))
  887.              ? S_OK : S_FALSE;
  888.     }  // END LOCK BLOCK
  889.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::IsScheduleItemSyncd (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  890.     return hr;
  891. }
  892. //+---------------------------------------------------------------------------
  893. //
  894. //  Method:     CGlobalNotfMgr::GetAllScheduleItems
  895. //
  896. //  Synopsis:   retrieves all item keys from the global table
  897. //
  898. //  Arguments:  [ppSchItems] --
  899. //              [pCount] --
  900. //              [rdate] --
  901. //
  902. //  Returns:
  903. //
  904. //  History:    2-20-1997   JohannP (Johann Posch)   Created
  905. //
  906. //  Notes:
  907. //
  908. //----------------------------------------------------------------------------
  909. HRESULT CGlobalNotfMgr::GetAllScheduleItems(SCHEDLISTITEMKEY **ppSchItems, ULONG *pCount, CFileTime &rdate)
  910. {
  911.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::GetAllScheduleItemsn", this));
  912.     HRESULT hr = NOERROR;
  913.     NotfAssert((ppSchItems && pCount));
  914.     ULONG uElements = 0;
  915.     ULONG pos = 0;
  916.     do
  917.     {   // BEGIN LOCK BLOCK
  918.         CLockSmMutex lck(_Smxs);
  919.         if (g_cSchedListCount == 0)
  920.         {
  921.             *pCount = 0;
  922.             *ppSchItems = 0;
  923.             break;
  924.         }
  925.         SCHEDLISTITEMKEY *pSchItems = new SCHEDLISTITEMKEY [g_cSchedListCount];
  926.         if (pSchItems == 0)
  927.         {
  928.             *pCount = 0;
  929.             *ppSchItems = 0;
  930.             hr = E_OUTOFMEMORY;
  931.             break;
  932.         }
  933.         ULONG cBogus = 0;
  934.         ULONG   i;
  935.         for (i = 0, pos = 0
  936.              ;(   (i < g_urgScheduleListItemtMax)
  937.                && (pos < g_cSchedListCount))
  938.              ; i ++)
  939.         {
  940.             if (g_rgSortListItem[i].date != 0)
  941.             {
  942.                 if (CPackage::IsPersisted(c_pszRegKey,&g_rgSortListItem[i].notfCookie) == NOERROR)
  943.                 {
  944.                     pSchItems[pos] = g_rgSortListItem[i];
  945.                     pos++;
  946.                 }
  947.                 else
  948.                 {
  949.                     g_rgSortListItem[i].date = 0;
  950.                     g_rgSortListItem[i].notfCookie = CLSID_NULL;
  951.                 }
  952.             }
  953.         }
  954.         if (g_cSchedListCount != pos)
  955.         {
  956.             g_dateLastSchedListChange = GetCurrentDtTime();
  957.             g_cSchedListCount = pos;
  958.         }
  959.         *ppSchItems  = pSchItems;
  960.         *pCount = pos;
  961.         rdate = g_dateLastSchedListChange;
  962.         uElements = (ULONG)g_cSchedListCount;
  963.         hr = (pos) ? S_OK : E_FAIL;
  964.         break;
  965.     } while (TRUE); // END LOCK BLOCK
  966.     NotfAssert((uElements >= pos));
  967.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::GetAllScheduleItems (hr:%lx, pCount:%lx)n",this, hr, *pCount));
  968.     return hr;
  969. }
  970. //+---------------------------------------------------------------------------
  971. //
  972. //  Method:     CGlobalNotfMgr::HandlePackage
  973. //
  974. //  Synopsis:
  975. //
  976. //  Arguments:  [pCPackage] --
  977. //
  978. //  Returns:
  979. //
  980. //  History:    2-13-1997   JohannP (Johann Posch)   Created
  981. //
  982. //  Notes:
  983. //
  984. //----------------------------------------------------------------------------
  985. HRESULT CGlobalNotfMgr::HandlePackage(CPackage *pCPackage)
  986. {
  987.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::HandlePackagen", this));
  988.     HRESULT hr = E_FAIL;
  989.     NotfAssert((pCPackage));
  990.     BOOL fBroadcast = pCPackage->IsBroadcast();
  991.     BOOL fReport    = pCPackage->IsReport();
  992.     ULONG uXProcess = 0;
  993.     BOOL  fSaved = FALSE;
  994.     DWORD dwMode = 0;
  995.     CHAR szPackageSubKey[SZREGVALUE_MAX] = {0};
  996.     do
  997.     {
  998.         // save the package first
  999.         ULONG uPkgCount = GetPackageCount();
  1000.         wsprintf(szPackageSubKey,"%lx",uPkgCount);
  1001.         if (fBroadcast)
  1002.         {
  1003.             //
  1004.             // find all destination ports
  1005.             //
  1006.             ULONG uHWndCount = 0;
  1007.             CDestinationPort *pDestPort= 0;
  1008.             hr = GetAllDestinationPorts(&pDestPort, &uHWndCount);
  1009.             if (hr == NOERROR)
  1010.             {
  1011.                 for (ULONG i = 0; i < uHWndCount; i++)
  1012.                 {
  1013.                     HWND hWnd = (pDestPort+i)->GetPort();
  1014.                     NotfAssert((hWnd));
  1015.                     DWORD dwProcessId = 0;
  1016.                     DWORD dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
  1017.                     if (GetCurrentProcessId() == dwProcessId)
  1018.                     {
  1019.                         dwMode = 0;
  1020.                     }
  1021.                     else
  1022.                     {
  1023.                         dwMode = uPkgCount;
  1024.                         uXProcess++;
  1025.                         if (!fSaved)
  1026.                         {
  1027.                             pCPackage->SetDestPort(GetThreadNotificationWnd(), 
  1028.                                                     GetCurrentThreadId());
  1029.                             hr = pCPackage->SaveToPersist(c_pszRegKeyPackage,szPackageSubKey);
  1030.                             BREAK_ONERROR(hr);
  1031.                             pCPackage->SetNotificationState(pCPackage->GetNotificationState() | PF_CROSSPROCESS);
  1032.                             fSaved = TRUE;
  1033.                         }
  1034.                     }
  1035.                     //  BUGBUGBUG
  1036.                     HRESULT hr1 = pCPackage->Deliver(hWnd, dwMode);
  1037.                     //  Doesn't make sense to reset the port.
  1038.                     //  pCPackage->SetDestPort(hWnd, dwThreadId);
  1039.                 }
  1040.             }
  1041.             if (pDestPort)
  1042.             {
  1043.                 delete [] pDestPort;
  1044.             }
  1045.             
  1046.             break;
  1047.         }
  1048.         else if (fReport && (pCPackage->GetCDestPort().GetPort()) )
  1049.         {
  1050.             CDestinationPort &rCDest = pCPackage->GetCDestPort();
  1051.             HWND hWnd = rCDest.GetPort();
  1052.             if (!hWnd)
  1053.             {
  1054.                 hr = E_FAIL;
  1055.                 break;
  1056.             }
  1057.             DWORD dwProcessId = 0;
  1058.             DWORD dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
  1059.             if (GetCurrentProcessId() == dwProcessId)
  1060.             {
  1061.                 dwMode = 0;
  1062.             }
  1063.             else
  1064.             {
  1065.                 dwMode = uPkgCount;
  1066.                 uXProcess++;
  1067.                 if (!fSaved)
  1068.                 {
  1069.                     pCPackage->SetDestPort(GetThreadNotificationWnd(), 
  1070.                                             GetCurrentThreadId());
  1071.                     hr = pCPackage->SaveToPersist(c_pszRegKeyPackage,szPackageSubKey);
  1072.                     pCPackage->SetNotificationState(pCPackage->GetNotificationState() | PF_CROSSPROCESS);
  1073.                     BREAK_ONERROR(hr);
  1074.                     fSaved = TRUE;
  1075.                 }
  1076.             }
  1077.             hr = pCPackage->Deliver(hWnd, dwMode);
  1078.             //  Reset it back.
  1079.             pCPackage->SetDestPort(hWnd, dwThreadId);
  1080.             break;
  1081.         }
  1082.         else if (pCPackage->IsForDefaultProcess())
  1083.         {
  1084.             CDestinationPort cDefDest;
  1085.             hr = GetDefaultDestinationPort(&cDefDest);
  1086.             if (hr == NOERROR)
  1087.             {
  1088.                 HWND hWnd = cDefDest.GetPort();
  1089.                 NotfAssert((hWnd));
  1090.                 DWORD dwProcessId = 0;
  1091.                 DWORD dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
  1092.                 if (GetCurrentProcessId() == dwProcessId)
  1093.                 {
  1094.                     dwMode = 0;
  1095.                 }
  1096.                 else
  1097.                 {
  1098.                     dwMode = uPkgCount;
  1099.                     uXProcess++;
  1100.                     if (!fSaved)
  1101.                     {
  1102.                         pCPackage->SetDestPort(GetThreadNotificationWnd(), 
  1103.                                                 GetCurrentThreadId());
  1104.                         hr = pCPackage->SaveToPersist(c_pszRegKeyPackage,szPackageSubKey);
  1105.                         pCPackage->SetNotificationState(pCPackage->GetNotificationState() | PF_CROSSPROCESS);
  1106.                         BREAK_ONERROR(hr);
  1107.                         fSaved = TRUE;
  1108.                     }
  1109.                 }
  1110.                 hr = pCPackage->Deliver(hWnd, dwMode);
  1111.                 //  Reset it back.
  1112.                 pCPackage->SetDestPort(hWnd, dwThreadId);
  1113.                 break;
  1114.             }
  1115.         }
  1116.         // default case
  1117.         {
  1118.             CDestination *pCDestination = 0;
  1119.             hr = LookupDestination(pCPackage, &pCDestination,0);
  1120.             if (hr == NOERROR)
  1121.             {
  1122.                 NotfAssert((pCDestination));
  1123.                 HWND hWnd = pCDestination->GetPort();
  1124.                 NotfAssert((hWnd));
  1125.                 DWORD dwProcessId = 0;
  1126.                 DWORD dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
  1127.                 if (GetCurrentProcessId() == dwProcessId)
  1128.                 {
  1129.                     dwMode = 0;
  1130.                 }
  1131.                 else
  1132.                 {
  1133.                     dwMode = uPkgCount;
  1134.                     uXProcess++;
  1135.                     if (!fSaved)
  1136.                     {
  1137.                         pCPackage->SetDestPort(GetThreadNotificationWnd(), 
  1138.                                                 GetCurrentThreadId());
  1139.                         hr = pCPackage->SaveToPersist(c_pszRegKeyPackage,szPackageSubKey);
  1140.                         BREAK_ONERROR(hr);
  1141.                         fSaved = TRUE;
  1142.                     }
  1143.                 }
  1144.                 hr = pCPackage->Deliver(hWnd, dwMode);
  1145.                 //  Reset it back.
  1146.                 pCPackage->SetDestPort(hWnd, dwThreadId);
  1147.             }
  1148.         }
  1149.         break;
  1150.     } while (TRUE);
  1151.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::HandlePackage (hr:%lx)n",this, hr));
  1152.     return hr;
  1153. }
  1154. //+---------------------------------------------------------------------------
  1155. //
  1156. //  Method:     CGlobalNotfMgr::LookupDestination
  1157. //
  1158. //  Synopsis:
  1159. //
  1160. //  Arguments:  [pCPackage] --
  1161. //              [ppCDestination] --
  1162. //              [dwFlags] --
  1163. //
  1164. //  Returns:
  1165. //
  1166. //  History:    2-13-1997   JohannP (Johann Posch)   Created
  1167. //
  1168. //  Notes:
  1169. //
  1170. //----------------------------------------------------------------------------
  1171. HRESULT CGlobalNotfMgr::LookupDestination(
  1172.                         CPackage              *pCPackage,
  1173.                         CDestination         **ppCDestination,
  1174.                         DWORD                 dwFlags
  1175.                         )
  1176. {
  1177.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::LookupDestinationn", this));
  1178.     HRESULT hr = E_FAIL;
  1179.     NotfAssert((pCPackage));
  1180.     NotfAssert((ppCDestination));
  1181.     *ppCDestination = 0;
  1182.     BOOL fSynchronous = pCPackage->IsSynchronous();
  1183.     BOOL fBroadcast   = pCPackage->IsBroadcast();
  1184.     BOOL fReport      = pCPackage->IsReport();
  1185.     NOTIFICATIONTYPE nofType = pCPackage->GetNotificationID();
  1186.     CLSID clsDest = pCPackage->GetDestID();
  1187.     DELIVERMODE delMode = pCPackage->GetDeliverMode();
  1188.     CDestination *pCDestination = 0;
  1189.     {
  1190.     LPSTR pszWhere = 0;
  1191.     LPSTR pszSubKeyIn = 0;
  1192.     LPCSTR    pszStr = c_pszRegKey; // the global registry key
  1193.     CDestination *pCDest = 0;
  1194.     HKEY      hKey = 0;
  1195.     const int cbStrKeyLen = 1024;
  1196.     DWORD dwValueLen = SZREGVALUE_MAX;
  1197.     char szValue[SZREGVALUE_MAX];
  1198.     do
  1199.     {
  1200.         long   lRes;
  1201.         DWORD  dwDisposition, dwIndex = 0;
  1202.         CHAR   szLocation[SZREGSETTING_MAX];
  1203.         // construct the new location
  1204.         strcpy(szLocation,c_pszRegKeyRunningDest);
  1205.         lRes = RegCreateKeyEx(HKEY_CURRENT_USER, szLocation, 0, NULL, 0,
  1206.                               HKEY_READ_WRITE_ACCESS, NULL, &hKey, &dwDisposition);
  1207.         // loop over all elements and schedule the elements
  1208.         while ((lRes == ERROR_SUCCESS) && (ERROR_NO_MORE_ITEMS != lRes))
  1209.         {
  1210.             DWORD dwType;
  1211.             DWORD dwNameLen;
  1212.             dwNameLen = SZREGVALUE_MAX;
  1213.             lRes = RegEnumValue(hKey, dwIndex, szValue, &dwNameLen,
  1214.                                 NULL, &dwType, NULL, NULL);
  1215.             dwIndex++;
  1216.             if ((lRes == ERROR_SUCCESS) && (ERROR_NO_MORE_ITEMS != lRes))
  1217.             {
  1218.                 NotfAssert((pCDest == 0));
  1219.                 HRESULT hr1 = CDestination::LoadFromPersist(szLocation,szValue, 0, &pCDest);
  1220.                 if (hr1 == NOERROR)
  1221.                 {
  1222.                     NotfAssert((pCDest));
  1223.                     DESTINATIONDATA destData;
  1224.                     pCDest->GetDestinationData(&destData);
  1225.                     NotfAssert(( pCDest->GetNotfTypes() ));
  1226.                     if (clsDest == *pCDest->GetDestId())
  1227.                     {
  1228.                         // the class IDs match
  1229.                         if (!IsWindow(pCDest->GetPort()))
  1230.                         {
  1231.                             // dete the entry
  1232.                             pCDest->RemovePersist(szLocation);
  1233.                         }
  1234.                         else if (   pCDest->IsDestMode(NM_ACCEPT_DIRECTED_NOTIFICATION)
  1235.                                  || (pCDest->LookupNotificationType(nofType) == NOERROR)
  1236.                                 )
  1237.                         {
  1238.                             // addref gets transfered
  1239.                             *ppCDestination = pCDest;
  1240.                             pCDest = 0;
  1241.                             hr = NOERROR;
  1242.                             lRes = ERROR_NO_MORE_ITEMS;
  1243.                         }
  1244.                     }
  1245.                 }
  1246.             }
  1247.             if (pCDest)
  1248.             {
  1249.                 pCDest->Release();
  1250.                 pCDest = 0;
  1251.             }
  1252.         } // end while keys
  1253.         break;
  1254.     } while (TRUE);
  1255.     if (pCDest)
  1256.     {
  1257.         pCDest->Release();
  1258.     }
  1259.     if (hKey)
  1260.     {
  1261.         RegCloseKey(hKey);
  1262.     }
  1263.     } // end reg lookup
  1264.     // Note: ppCDestination is addref if it contains a valid destination
  1265.     //
  1266.     NotfAssert((   ((hr == NOERROR) && (*ppCDestination))
  1267.                  || ((hr != NOERROR) && (!*ppCDestination)) ));
  1268.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::LookupDestination (hr:%lx)n",this, hr));
  1269.     return hr;
  1270. }
  1271. //+---------------------------------------------------------------------------
  1272. //
  1273. //  Function:   NotfMgrWndProc
  1274. //
  1275. //  Synopsis:   the transaction callback function
  1276. //
  1277. //  Arguments:  [hWnd] --
  1278. //              [WPARAM] --
  1279. //              [wParam] --
  1280. //              [lParam] --
  1281. //
  1282. //  Returns:
  1283. //
  1284. //  History:    12-02-95   JohannP (Johann Posch)   Created
  1285. //
  1286. //  Notes:
  1287. //
  1288. //----------------------------------------------------------------------------
  1289. LRESULT CALLBACK NotfMgrWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1290. {
  1291.     if (   (msg >= WM_TRANS_FIRST && msg <= WM_TRANS_LAST)
  1292.         || (msg == WM_TIMECHANGE) 
  1293.         || ((msg == WM_TIMER) && ((wParam == NOTF_SCHED_TIMER) || (wParam == NOTF_DELAY_TIMER))))
  1294.     {
  1295.         switch (msg)
  1296.         {
  1297. #ifdef WITH_EXEPTION
  1298.                 _try
  1299. #endif //WITH_EXEPTIO
  1300.                 {
  1301.                 }
  1302. #ifdef WITH_EXEPTION
  1303.                 _except(UrlMonInvokeExceptionFilter(GetExceptionCode(), GetExceptionInformation()))
  1304.                 {
  1305.                     dwFault = GetExceptionCode();
  1306.                     #if DBG == 1
  1307.                     //
  1308.                     // UrlMon catches exceptions when the server generates them. This is so we can
  1309.                     // cleanup properly, and allow the client to continue.
  1310.                     //
  1311.                     if (   dwFault == STATUS_ACCESS_VIOLATION
  1312.                         || dwFault == 0xC0000194 /*STATUS_POSSIBLE_DEADLOCK*/
  1313.                         || dwFault == 0xC00000AA /*STATUS_INSTRUCTION_MISALIGNMENT*/
  1314.                         || dwFault == 0x80000002 /*STATUS_DATATYPE_MISALIGNMENT*/ )
  1315.                     {
  1316.                         WCHAR iidName[256];
  1317.                         iidName[0] = 0;
  1318.                         char achProgname[256];
  1319.                         achProgname[0] = 0;
  1320.                         GetModuleFileNameA(NULL,achProgname,sizeof(achProgname));
  1321.                         NotfDebugOut((DEB_FORCE,
  1322.                                        "UrlMon has caught a fault 0x%08x on behalf of application %sn",
  1323.                                        dwFault, achProgname));
  1324.                         NotfAssert((!"The application has faulted processing. Check the kernel debugger for useful output.URLMon can continue but you probably want to stop and debug the application."));
  1325.                     }
  1326.                     #endif
  1327.                 }
  1328. #endif //WITH_EXEPTIO
  1329.         case WM_THREADPACKET_POST:
  1330.         case WM_THREADPACKET_SEND:
  1331.             {
  1332.                 CThreadPacket  *pCThreadPacket = (CThreadPacket *) lParam;
  1333.                 NotfAssert((pCThreadPacket != NULL));
  1334.                 NotfDebugOut((DEB_MGR, "%p _IN CThreadPacket::NotfMgrWndProc (Msg:%x)n", pCThreadPacket, wParam));
  1335.                 pCThreadPacket->OnPacket(msg,(DWORD)wParam);
  1336.                 NotfDebugOut((DEB_MGR, "%p OUT CThreadPacket::NotfMgrWndProc (Msg:%x) WM_TRANS_PACKET n", pCThreadPacket, wParam));
  1337.             }
  1338.             break;
  1339.         case WM_PROCESSPACKET_POST :
  1340.         case WM_PROCESSPACKET_SEND :
  1341.         {
  1342.             DWORD dwParam = lParam;
  1343.             NotfAssert((dwParam));
  1344.             CPackage *pCPkg = 0;
  1345.             HRESULT hr = NOERROR;
  1346.             CHAR szPackageSubKey[SZREGVALUE_MAX] = {0};
  1347.             wsprintf(szPackageSubKey,"%lx",dwParam);
  1348.             CHAR szTemp[512];
  1349.             strcpy(szTemp, c_pszRegKeyPackage);
  1350.             strcat(szTemp, szPackageSubKey);
  1351.             hr = RegIsPersistedKey(HKEY_CURRENT_USER, szTemp, szPackageSubKey);
  1352.             if (hr == NOERROR)
  1353.             {
  1354.                 //unpersist the package
  1355.                 hr = CPackage::LoadFromPersist(c_pszRegKeyPackage,szPackageSubKey, 0, &pCPkg);
  1356.                 // the new package is addref'd
  1357.                 // release is called inside OnPackage
  1358.                 if ((hr == NOERROR) && pCPkg)
  1359.                 {
  1360.                     pCPkg->SetCrossProcessId(dwParam);
  1361.                     pCPkg->SetNotificationState(pCPkg->GetNotificationState() | PF_CROSSPROCESS);
  1362.                     pCPkg->OnPacket(msg, 0);
  1363.                 }
  1364.             }
  1365.         }
  1366.         break;
  1367.         case WM_PROCESSWAKEUP :
  1368.         {
  1369.             CThrottleListAgent *pCThrottleAgent = GetThrottleListAgent();
  1370.             NotfAssert(( pCThrottleAgent ));
  1371.             pCThrottleAgent->OnWakeup(WT_NEXTITEM, 0);
  1372.         }
  1373.         break;
  1374.         case WM_TIMER:
  1375.         {
  1376.             CScheduleAgent *pthis = GetScheduleAgent();
  1377.             NotfAssert((pthis));
  1378.             switch (wParam)
  1379.             {
  1380.                 case NOTF_SCHED_TIMER:
  1381.                     pthis->OnWakeup(WT_SCHED);
  1382.                     break;
  1383.                 case NOTF_DELAY_TIMER:
  1384.                     pthis->OnWakeup(WT_DELAY);
  1385.                     break;
  1386.             }
  1387.         }
  1388.         break;
  1389.         
  1390.         case WM_TIMECHANGE :
  1391.         {
  1392.             CSchedListAgent *pListAgent = GetScheduleListAgent();
  1393.             if (pListAgent)
  1394.             {
  1395.                 pListAgent->OnWakeup(WT_TIMECHANGE);
  1396.             }
  1397.         }
  1398.         break;
  1399.         case WM_SYNC_DEF_PROC_NOTIFICATIONS:
  1400.         {
  1401.             CSchedListAgent *pSchedListAgent = GetScheduleListAgent();
  1402.             if (pSchedListAgent)
  1403.             {
  1404.                 pSchedListAgent->Resync();
  1405.             }
  1406.         }
  1407.         break;
  1408.         case WM_ENDSESSION:
  1409.         {
  1410.             if (wParam == TRUE)
  1411.             {
  1412.                 //  Clean up running items by delivering NOTIFICATIONTYPE_TASKS_ABORT 
  1413.                 //  to all notifications on this thread.                
  1414.             }
  1415.         }
  1416.         break;
  1417.         }
  1418.     }
  1419.     return 0;
  1420. }
  1421. //+---------------------------------------------------------------------------
  1422. //
  1423. //  Method:     CGlobalNotfMgr::AddItemToRunningList
  1424. //
  1425. //  Synopsis:
  1426. //
  1427. //  Arguments:  [pCPackage] --
  1428. //              [dwMode] --
  1429. //
  1430. //  Returns:
  1431. //
  1432. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  1433. //
  1434. //  Notes:
  1435. //
  1436. //----------------------------------------------------------------------------
  1437. HRESULT CGlobalNotfMgr::AddItemToRunningList(CPackage *pCPackage, DWORD dwMode)
  1438. {
  1439.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::AddItemToRunningListn", this));
  1440.     HRESULT hr = S_FALSE;
  1441.     NotfAssert((pCPackage));
  1442.     PNOTIFICATIONTYPE pNotificationType = 0;;
  1443.     do
  1444.     {
  1445.         if (!pCPackage)
  1446.         {
  1447.             hr = E_INVALIDARG;
  1448.             break;
  1449.         }
  1450.         CLockSmMutex lck(_Smxs);
  1451.         ULONG index = 0xffffffff;
  1452.         if (g_cThrottleItemCount == 0)
  1453.         {
  1454.             hr = S_OK;
  1455.             break;
  1456.         }
  1457.         hr = S_OK;  // assume the item can be dispatched
  1458.         LONG posItem = -1;
  1459.         for (ULONG i = 0; i < g_cThrottleItemCount; i++)
  1460.         {
  1461.             if (g_rgThrottleItem[i].NotificationType == *pCPackage->GetNotificationType())
  1462.             {
  1463.                 posItem =  i;
  1464.                 i = g_cThrottleItemCount;
  1465.             }
  1466.         }
  1467.         if ((posItem < 0)  || (posItem >= THROTTLE_WAITING_MAX))
  1468.         {
  1469.             hr = S_OK;
  1470.             break;
  1471.         }
  1472.         //
  1473.         // do not deliver scheduled notifications if disabled
  1474.         //
  1475.         #define TF_RESTRICTIONS     (TF_DONT_DELIVER_SCHEDULED_ITEMS | 
  1476.                                      TF_APPLY_UPDATEINTERVAL | 
  1477.                                      TF_APPLY_EXCLUDE_RANGE)
  1478.                                      
  1479.         if ((pCPackage->GetNotificationState() & PF_SCHEDULED) &&
  1480.             (g_rgThrottleItem[posItem].dwFlags & TF_RESTRICTIONS))
  1481.         {
  1482.             if (g_rgThrottleItem[posItem].dwFlags & TF_DONT_DELIVER_SCHEDULED_ITEMS)
  1483.             {
  1484.                 hr = S_FALSE;
  1485.             }
  1486.             if ((hr == S_OK) && (g_rgThrottleItem[posItem].dwFlags & TF_APPLY_UPDATEINTERVAL))
  1487.             {
  1488.                 __int64 intervalMin,
  1489.                         intervalNow;
  1490.                 SYSTEMTIME st;
  1491.                 CFileTime ftNow;
  1492.                 
  1493.                 GetLocalTime(&st);
  1494.                 SystemTimeToFileTime(&st, &ftNow);
  1495. #ifndef unix                
  1496.                 intervalMin = __int64(g_rgThrottleItem[posItem].dwIntervalMin) *
  1497. #else
  1498.                 // Looks like the Solaris C++ compiler cant handle new
  1499.                 // style casts.
  1500.                 intervalMin = (__int64)(g_rgThrottleItem[posItem].dwIntervalMin) * 
  1501. #endif /* unix */ 
  1502.                               ONE_MINUTE_IN_FILETIME;
  1503.                 intervalNow = FileTimeToInt64(ftNow - pCPackage->GetPrevRunDate());
  1504.                 if (intervalNow < intervalMin)
  1505.                 {
  1506.                     pCPackage->SetNextRunInterval(intervalMin);
  1507.                     hr = S_FALSE;
  1508.                 }                
  1509.             }
  1510.             if ((hr == S_OK) && (g_rgThrottleItem[posItem].dwFlags & TF_APPLY_EXCLUDE_RANGE))
  1511.             {
  1512.                 SYSTEMTIME st;
  1513.                 CFileTime ftNow,
  1514.                           ftBegin,
  1515.                           ftEnd;
  1516.                 
  1517.                 GetLocalTime(&st);
  1518.                 SystemTimeToFileTime(&st, &ftNow);
  1519.                 
  1520.                 st.wSecond = 0;
  1521.                 st.wMilliseconds = 0;
  1522.                 
  1523.                 st.wHour   = g_rgThrottleItem[posItem].dateExcludeBegin.wHour;
  1524.                 st.wMinute = g_rgThrottleItem[posItem].dateExcludeBegin.wMinute;
  1525.                 SystemTimeToFileTime(&st, &ftBegin);
  1526.                 
  1527.                 st.wHour   = g_rgThrottleItem[posItem].dateExcludeEnd.wHour;
  1528.                 st.wMinute = g_rgThrottleItem[posItem].dateExcludeEnd.wMinute;
  1529.                 SystemTimeToFileTime(&st, &ftEnd);
  1530.                 //  if these values are normalized (ie. begin comes before end)
  1531.                 if (ftBegin <= ftEnd)
  1532.                 {
  1533.                     //  Then just check to see if time now is between begin 
  1534.                     //  and end.  (ie.  ftEnd >= ftNow >= ftBegin)
  1535.                     if ((ftNow >= ftBegin) && (ftNow <= ftEnd))
  1536.                     {
  1537.                         hr = S_FALSE;
  1538.                     }
  1539.                 }
  1540.                 else
  1541.                 {
  1542.                     //  Begin and end are not normalized.  So we check to see if
  1543.                     //  now is before end or now is after begin.
  1544.                     //  For example:
  1545.                     //  Assuming begin is 6pm and end is 6am.  If now is 5 pm, the
  1546.                     //  notification should run.  If now is 10pm or 4am, the 
  1547.                     //  notification should not run.
  1548.                     if ((ftNow <= ftEnd) || (ftNow >= ftBegin))
  1549.                     {
  1550.                         hr = S_FALSE;
  1551.                     }
  1552.                 }
  1553.             }
  1554.             if (hr == S_FALSE)
  1555.             {
  1556.                 CSchedListAgent *pCSchLst = GetScheduleListAgent();
  1557.                 if (pCSchLst)
  1558.                 {
  1559.                     GetThrottleListAgent()->RevokePackage(&pCPackage->GetNotificationCookie(),
  1560.                                                           NULL, 
  1561.                                                           0);
  1562.                     //  Reschedule this package
  1563.                     pCPackage->SetNotificationState(pCPackage->GetNotificationState() 
  1564.                                                     & ~PF_DELIVERED);
  1565.                     pCSchLst->HandlePackage(pCPackage);
  1566.                 }
  1567.                 break;
  1568.             }
  1569.         }
  1570.         if (g_rgThrottleItem[posItem].nParallel == -1)
  1571.         {
  1572.             // do not throttle at all
  1573.             hr = S_OK;
  1574.             break;
  1575.         }
  1576.         //
  1577.         // found the notification type
  1578.         //
  1579.         BOOL fFound = FALSE;
  1580.         hr = S_FALSE;
  1581.         NotfAssert(( g_rgThrottleItem[posItem].nParallel ));
  1582.         if ((g_rgThrottleItem[posItem].nRunning < g_rgThrottleItem[posItem].nParallel) 
  1583.             && (!(dwMode & TL_ADD_TO_WAIT)))
  1584.         {
  1585.             //
  1586.             // item can run - add it to the running list
  1587.             //
  1588.             LONG    posVacant = -1;
  1589.             BOOL    fRunning = FALSE;
  1590.             for (LONG j = 0; (j < THROTTLEITEM_MAX) && (j < g_rgThrottleItem[posItem].nRunning + 1); j++)
  1591.             {
  1592.                 if (g_rgThrottleItem[posItem].nRunningCookie[j] == pCPackage->GetNotificationCookie() )
  1593.                 {
  1594.                     // already added
  1595.                     j = g_urgThrottleItemtMax + 1;
  1596.                     fRunning = TRUE;
  1597.                     TNotfDebugOut((DEB_TFLOW, "%p Already on throttle list in CGlobalNotfMgr::AddItemToRunningListn", pCPackage));
  1598.                 }
  1599.                 else if (g_rgThrottleItem[posItem].nRunningCookie[j] == COOKIE_NULL)
  1600.                 {
  1601.                 //  We still need to loop through all items in case we will
  1602.                 //  find a running instance.
  1603. //                    g_rgThrottleItem[posItem].nRunningCookie[j] = pCPackage->GetNotificationCookie();
  1604. //                    j = g_urgThrottleItemtMax;
  1605.                     if (!fFound)    {
  1606.                         posVacant = j;
  1607.                         fFound = TRUE;
  1608.                     }
  1609.                     TNotfDebugOut((DEB_TFLOW, "%p Added to throttle list in CGlobalNotfMgr::AddItemToRunningListn", pCPackage));
  1610.                 }
  1611.             }
  1612.             if (fRunning)   {
  1613.                 //  We are going to return S_FALSE. So we'd better add the
  1614.                 //  waiting counter.
  1615.                 g_rgThrottleItem[posItem].nWaiting++;
  1616.             } else if (fFound == TRUE)  {
  1617.                 // found a slot and item can run
  1618.                 NotfAssert((posVacant != -1));
  1619.                 g_rgThrottleItem[posItem].nRunningCookie[posVacant] = pCPackage->GetNotificationCookie();
  1620.                 g_rgThrottleItem[posItem].nRunning++;
  1621.                 hr = S_OK;
  1622.             }
  1623.         }
  1624.         else
  1625.         {
  1626.             //
  1627.             // item can not run - add it to the waiting list
  1628.             //
  1629.             DWORD dwFoundInvalid = 0;
  1630.             BOOL  fCheckInvalid = TRUE;
  1631.             do
  1632.             {
  1633.                 dwFoundInvalid = 0;
  1634.                 NotfAssert(( g_rgThrottleItem[posItem].nRunning == g_rgThrottleItem[posItem].nParallel ));
  1635.                 DWORD dwPriorityMinWaiting = 0;
  1636.                 LONG pos = -1;
  1637.                 LONG posEmpty = -1;
  1638.                 BOOL fAlreadyWaiting = FALSE;
  1639.                 for (LONG j = 0; j < THROTTLE_WAITING_MAX; j++)
  1640.                 {
  1641.                     if (g_rgThrottleItem[posItem].nWaitItem[j].NotificationCookie == pCPackage->GetNotificationCookie())
  1642.                     {
  1643.                         // stop the loop - nothing to do
  1644.                         pos = -1;
  1645.                         j = THROTTLE_WAITING_MAX;
  1646.                         fAlreadyWaiting = TRUE;
  1647.                         TNotfDebugOut((DEB_TFLOW, "%p Already on waiting list in CGlobalNotfMgr::AddItemToRunningListn", pCPackage));
  1648.                     }
  1649.                     else if (g_rgThrottleItem[posItem].nWaitItem[j].NotificationCookie != COOKIE_NULL)
  1650.                     {
  1651.                         // remember the position and the item with the lowest priority
  1652.                         if (g_rgThrottleItem[posItem].nWaitItem[j].dwCurrentPriority < dwPriorityMinWaiting)
  1653.                         {
  1654.                             dwPriorityMinWaiting = g_rgThrottleItem[posItem].nWaitItem[j].dwCurrentPriority;
  1655.                             pos =  j;
  1656.                         }
  1657.                     }
  1658.                     else
  1659.                     {
  1660.                         // found and empty slot - keep looping; our cookie might be in the list
  1661.                         dwPriorityMinWaiting = 0;
  1662.                         posEmpty = j;
  1663.                     }
  1664.                 }
  1665.                 //  We still want to increase this count, so we can wake up the
  1666.                 //  process later.
  1667.                 g_rgThrottleItem[posItem].nWaiting++;
  1668.                 if (fAlreadyWaiting)
  1669.                 {
  1670.                     // stop nothing to do
  1671.                     break;
  1672.                 }
  1673.                 if ( (posEmpty > -1) && (posEmpty < THROTTLE_WAITING_MAX) )
  1674.                 {
  1675.                     pos = posEmpty;
  1676.                 }
  1677.                 if ( (pos > -1) && (pos < THROTTLE_WAITING_MAX) )
  1678.                 {
  1679.                     //
  1680.                     // add item to waiting list
  1681.                     if (g_rgThrottleItem[posItem].dwPriorityMaxWaiting < pCPackage->GetPriority())
  1682.                     {
  1683.                         g_rgThrottleItem[posItem].dwPriorityMaxWaiting =  pCPackage->GetPriority();
  1684.                     }
  1685.                     TNotfDebugOut((DEB_TFLOW, "%p Added to waiting list in CGlobalNotfMgr::AddItemToRunningListn", pCPackage));
  1686.                     g_rgThrottleItem[posItem].nWaitItem[pos].NotificationCookie = pCPackage->GetNotificationCookie();
  1687.                     g_rgThrottleItem[posItem].nWaitItem[pos].hWnd = GetThreadNotificationWnd();
  1688.                     g_rgThrottleItem[posItem].nWaitItem[pos].dwCurrentPriority = pCPackage->GetPriority();
  1689.                 }
  1690.                 else if (fCheckInvalid)
  1691.                 {
  1692.                     // validate the entries
  1693.                     for (j = 0; j < THROTTLE_WAITING_MAX; j++)
  1694.                     {
  1695.                         if (!IsWindow(g_rgThrottleItem[posItem].nWaitItem[j].hWnd) )
  1696.                         {
  1697.                             //BUGBUG should we be looking elsewhere to clean up also
  1698.                             
  1699.                             // invalid port (hwnd) remove it!
  1700.                             g_rgThrottleItem[posItem].nWaitItem[pos].NotificationCookie = COOKIE_NULL;
  1701.                             g_rgThrottleItem[posItem].nWaitItem[pos].hWnd = 0;
  1702.                             g_rgThrottleItem[posItem].nWaitItem[pos].dwCurrentPriority = 0;
  1703.                             g_rgThrottleItem[posItem].nWaiting--;
  1704.                             dwFoundInvalid++;
  1705.                         }
  1706.                     }
  1707.                     fCheckInvalid = FALSE;
  1708.                 }
  1709.                 
  1710.             } while (dwFoundInvalid);
  1711.         }
  1712.         break;
  1713.     } while (TRUE);
  1714.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::AddItemToRunningList (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  1715.     return hr;
  1716. }
  1717. //+---------------------------------------------------------------------------
  1718. //
  1719. //  Method:     CGlobalNotfMgr::RemoveItemFromRunningList
  1720. //
  1721. //  Synopsis:
  1722. //
  1723. //  Arguments:  [pCPackage] --
  1724. //              [dwMode] --
  1725. //
  1726. //  Returns:
  1727. //
  1728. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  1729. //
  1730. //  Notes:
  1731. //
  1732. //----------------------------------------------------------------------------
  1733. HRESULT CGlobalNotfMgr::RemoveItemFromRunningList(CPackage *pCPackage, DWORD dwMode)
  1734. {
  1735.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::RemoveItemFromRunningListn", this));
  1736.     HRESULT hr = S_FALSE;
  1737.     NotfAssert((pCPackage));
  1738.     BOOL fWakeup = FALSE;
  1739.     PNOTIFICATIONTYPE pNotificationType = 0;
  1740.     PNOTIFICATIONCOOKIE pNotificationCookie = 0;
  1741.     do
  1742.     {
  1743.         if (!pCPackage)
  1744.         {
  1745.             hr = E_INVALIDARG;
  1746.             break;
  1747.         }
  1748.         pNotificationType = pCPackage->GetNotificationType();
  1749.         pNotificationCookie = &pCPackage->GetNotificationCookie();
  1750.         CLockSmMutex lck(_Smxs);
  1751.         ULONG index = 0xffffffff;
  1752.         if (g_cThrottleItemCount == 0)
  1753.         {
  1754.             hr = S_OK;
  1755.             break;
  1756.         }
  1757.         hr = S_FALSE;
  1758.         LONG posItem = -1;
  1759.         for (ULONG i = 0; i < g_cThrottleItemCount; i++)
  1760.         {
  1761.             if (g_rgThrottleItem[i].NotificationType == *pCPackage->GetNotificationType())
  1762.             {
  1763.                 posItem =  i;
  1764.                 i = g_cThrottleItemCount;
  1765.             }
  1766.         }
  1767.         if ((posItem < 0)  || (posItem >= THROTTLE_WAITING_MAX))
  1768.         {
  1769.             hr = S_FALSE;
  1770.             break;
  1771.         }
  1772.         NotfAssert((g_rgThrottleItem[posItem].NotificationType == *pNotificationType));
  1773.         if (g_rgThrottleItem[posItem].nParallel == -1)
  1774.         {
  1775.             // ok
  1776.             hr = S_OK;
  1777.         }
  1778.         if (g_rgThrottleItem[posItem].nRunning == 0)
  1779.         {
  1780.             hr = S_OK;
  1781.             break;
  1782.         }
  1783.         
  1784.         // need to find the slot of the cookie
  1785.         //
  1786.         // This for loop used to exit at nRunning, but that doesn't
  1787.         // work since the notifications aren't necessarily the first nRunning
  1788.         // in the array
  1789.         for (ULONG j = 0; j < g_urgThrottleItemtMax; j++)
  1790.         {
  1791.             if (g_rgThrottleItem[posItem].nRunningCookie[j] == *pNotificationCookie)
  1792.             {
  1793.                 g_rgThrottleItem[posItem].nRunningCookie[j] = COOKIE_NULL;
  1794.                 g_rgThrottleItem[posItem].nRunning--;
  1795.                 j = g_urgThrottleItemtMax;
  1796.                 hr = S_OK;
  1797.             }
  1798.         }
  1799.         // done if none is waiting
  1800.         if (g_rgThrottleItem[posItem].nWaiting == 0)
  1801.         {
  1802.             break;
  1803.         }
  1804.         //
  1805.         // find the item with highest priority
  1806.         //
  1807.         ULONG PriorityMax = 0;
  1808.         LONG pos = -1;
  1809.         for (j = 0; j < THROTTLE_WAITING_MAX; j++)
  1810.         {
  1811.             //
  1812.             // find the item with the highest priority
  1813.             //
  1814.             if (   (g_rgThrottleItem[posItem].nWaitItem[j].NotificationCookie != COOKIE_NULL )
  1815.                 && (g_rgThrottleItem[posItem].nWaitItem[j].dwCurrentPriority > PriorityMax))
  1816.             {
  1817.                 if (IsWindow(g_rgThrottleItem[posItem].nWaitItem[j].hWnd) )
  1818.                 {
  1819.                     PriorityMax = g_rgThrottleItem[posItem].nWaitItem[j].dwCurrentPriority;
  1820.                     pos = j;
  1821.                 }
  1822.                 else
  1823.                 {
  1824.                     // invalid port (hwnd) remove it!
  1825.                     g_rgThrottleItem[posItem].nWaitItem[pos].NotificationCookie = COOKIE_NULL;
  1826.                     g_rgThrottleItem[posItem].nWaitItem[pos].hWnd = 0;
  1827.                     g_rgThrottleItem[posItem].nWaitItem[pos].dwCurrentPriority = 0;
  1828.                     g_rgThrottleItem[posItem].nWaiting--;
  1829.                 }
  1830.             }
  1831.         }
  1832.         //NotfAssert((    ((pos != -1) && (pos < THROTTLE_WAITING_MAX))
  1833.         //            ||  (g_rgThrottleItem[posItem].nWaiting == 0)           ));
  1834.         if (pos >= 0  && pos < THROTTLE_WAITING_MAX)
  1835.         {
  1836.             if ( IsWindow(g_rgThrottleItem[posItem].nWaitItem[pos].hWnd) )
  1837.             {
  1838.                 NotfDebugOut((DEB_MGR, "%p CPackage:%p === SendNotifyMessage (hwnd:%lx) WM_THREADPACKET_SENDn", this,this, g_rgThrottleItem[posItem].nWaitItem[pos].hWnd ));
  1839.                 fWakeup = !PostMessage(g_rgThrottleItem[posItem].nWaitItem[pos].hWnd, WM_PROCESSWAKEUP, 0, 0);
  1840.                 NotfDebugOut((DEB_MGR, "%p Out CGlobalNotfMgr:%p === SendNotifyMessage (hwnd:%lx, fSend:%lx) WM_THREADPACKET_POSTn", this,this, g_rgThrottleItem[posItem].nWaitItem[pos].hWnd, fWakeup));
  1841.             }
  1842.             g_rgThrottleItem[posItem].nWaitItem[pos].NotificationCookie = COOKIE_NULL;
  1843.             g_rgThrottleItem[posItem].nWaitItem[pos].hWnd = 0;
  1844.             g_rgThrottleItem[posItem].nWaitItem[pos].dwCurrentPriority = 0;
  1845.             g_rgThrottleItem[posItem].nWaiting--;
  1846.         }
  1847.         else if (g_rgThrottleItem[posItem].nWaiting)
  1848.         {
  1849.             //  We want to nuke the count so we can get a fresh count by calling
  1850.             //  up all waiting process.
  1851.             g_rgThrottleItem[posItem].nWaiting = 0;
  1852.             fWakeup = TRUE;
  1853.         }
  1854.         break;
  1855.     } while (TRUE);
  1856.     if (fWakeup)
  1857.     {
  1858.         // broadcast the wakeup all threats who wait to run
  1859.         // a throttle notification
  1860.         WakeupAll();
  1861.     }
  1862.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::RemoveItemFromRunningList (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  1863.     return hr;
  1864. }
  1865. //+---------------------------------------------------------------------------
  1866. //
  1867. //  Method:     CGlobalNotfMgr::RemoveItemFromWaitingList
  1868. //
  1869. //  Synopsis:
  1870. //
  1871. //  Arguments:  [pCPackage] --
  1872. //              [dwMode] --
  1873. //
  1874. //  Returns:
  1875. //
  1876. //  History:    8-1-1997   DZhang(Dachuan Zhang)   Created
  1877. //
  1878. //  Notes:
  1879. //
  1880. //----------------------------------------------------------------------------
  1881. HRESULT CGlobalNotfMgr::RemoveItemFromWaitingList(CPackage *pCPackage, DWORD dwMode)
  1882. {
  1883.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::RemoveItemFromWaitingListn", this));
  1884.     NotfAssert((pCPackage));
  1885.     PNOTIFICATIONTYPE pNotificationType = 0;
  1886.     if (!pCPackage)
  1887.         return E_INVALIDARG;
  1888.     pNotificationType = pCPackage->GetNotificationType();
  1889.     NOTIFICATIONCOOKIE &NotificationCookie = pCPackage->GetNotificationCookie();
  1890.     CLockSmMutex lck(_Smxs);
  1891.     ULONG index = 0xffffffff;
  1892.     if (g_cThrottleItemCount == 0)
  1893.         return S_OK;
  1894.     LONG posItem = -1;
  1895.     for (ULONG i = 0; i < g_cThrottleItemCount; i++)
  1896.     {
  1897.         if (g_rgThrottleItem[i].NotificationType == *pCPackage->GetNotificationType())
  1898.         {
  1899.             posItem =  i;
  1900.             i = g_cThrottleItemCount;
  1901.         }
  1902.     }
  1903.     if ((posItem < 0)  || (posItem >= THROTTLE_WAITING_MAX))
  1904.         return S_FALSE;
  1905.     if (g_rgThrottleItem[posItem].nParallel == -1)
  1906.         return S_OK;
  1907.  
  1908.     THROTTLE_ITEM * pThrottleItem = &(g_rgThrottleItem[posItem]);
  1909.     //
  1910.     // find the item
  1911.     //
  1912.     LONG pos = -1;
  1913.     for (ULONG j = 0; j < THROTTLE_WAITING_MAX; j++)
  1914.     {
  1915.         if (pThrottleItem->nWaitItem[j].NotificationCookie ==NotificationCookie)
  1916.         {
  1917.             pThrottleItem->nWaitItem[j].NotificationCookie = COOKIE_NULL;
  1918.             pThrottleItem->nWaitItem[j].hWnd = 0;
  1919.             pThrottleItem->nWaitItem[j].dwCurrentPriority = 0;
  1920.             if (IsWindow(pThrottleItem->nWaitItem[j].hWnd) )
  1921.             {
  1922.                 g_rgThrottleItem[posItem].nWaiting--;
  1923.             }
  1924.         }
  1925.     }
  1926.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::RemoveItemFromWaitingListn",this));
  1927.     return S_OK;
  1928. }
  1929. //+---------------------------------------------------------------------------
  1930. //
  1931. //  Method:     CGlobalNotfMgr::RegisterThrottleNotificationType
  1932. //
  1933. //  Synopsis:
  1934. //
  1935. //  Arguments:  [cItems] --
  1936. //              [pThrottleItems] --
  1937. //              [pcItemsOut] --
  1938. //              [ppThrottleItemsOut] --
  1939. //              [dwMode] --
  1940. //              [dwReserved] --
  1941. //
  1942. //  Returns:
  1943. //
  1944. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  1945. //
  1946. //  Notes:
  1947. //
  1948. //----------------------------------------------------------------------------
  1949. HRESULT CGlobalNotfMgr::RegisterThrottleNotificationType(ULONG cItems, PTHROTTLEITEM  pThrottleItems,
  1950.                                                          ULONG *pcItemsOut, PTHROTTLEITEM  *ppThrottleItemsOut,
  1951.                                                          DWORD dwMode, DWORD dwReserved)
  1952. {
  1953.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::RegisterThrottleNotificationTypen", this));
  1954.     HRESULT hr = NOERROR;
  1955.     BOOL fBroadcast = FALSE;
  1956.     do
  1957.     {
  1958.         if (   !cItems
  1959.             || !pThrottleItems
  1960.             || dwMode
  1961.             || dwReserved
  1962.             //|| pcItemsOut
  1963.             //|| ppThrottleItemsOut
  1964.             )
  1965.         {
  1966.             hr = E_INVALIDARG;
  1967.             break;
  1968.         }
  1969.         for (ULONG i = 0; i < cItems; i++)
  1970.         {
  1971.             if (!IsThrottleableNotificationType(pThrottleItems[i].NotificationType))
  1972.             {
  1973.                 // can not throttle this notification
  1974.                 hr = E_FAIL;
  1975.                 i = cItems;
  1976.             }
  1977.             else if (pThrottleItems[i].nParallel < -1)
  1978.             {
  1979.                 //  Invalid throttling count.
  1980.                 hr = E_INVALIDARG;
  1981.                 i = cItems;
  1982.             }
  1983.             else if (pThrottleItems[i].nParallel > THROTTLEITEM_MAX)
  1984.             {
  1985.                 //  Invalid throttling count.
  1986.                 hr = E_INVALIDARG;
  1987.                 i = cItems;
  1988.             }
  1989.             //  REVIEW
  1990.             //  Looks like nParallel( = 0) is valid. It effectively
  1991.             //  UnRegistered the type!
  1992.             
  1993.             //  REVIEW
  1994.             //  What about invalid NotificationType?
  1995.         }
  1996.         BREAK_ONERROR(hr);
  1997.         CLockSmMutex lck(_Smxs);
  1998.         //
  1999.         // set the new settings
  2000.         //
  2001.         //  How could this used to work with multiple item case? No way!
  2002.         hr = NOERROR;
  2003.         for (ULONG n = 0; n < cItems; n ++)
  2004.         {
  2005.             LONG    posFound = -1, posVacant = -1;
  2006.             for (i = 0; i < g_urgThrottleItemtMax; i++)
  2007.             {
  2008.                 if (g_rgThrottleItem[i].NotificationType
  2009.                                 == pThrottleItems[n].NotificationType)
  2010.                 {
  2011.                     posFound = i;
  2012.                     break;
  2013.                 }
  2014.                 else if (g_rgThrottleItem[i].nParallel == 0)
  2015.                 {
  2016.                     if (posVacant == -1)
  2017.                         posVacant = i;
  2018.                 }
  2019.             }
  2020.             if (posFound != -1)
  2021.             {
  2022.                 i = posFound;
  2023.                 if (pThrottleItems[n].nParallel != g_rgThrottleItem[posFound].nParallel)
  2024.                 {
  2025.                     if ((pThrottleItems[n].nParallel == -1) || (g_rgThrottleItem[i].nRunning < pThrottleItems[n].nParallel))
  2026.                         fBroadcast = TRUE;
  2027.                     //  REVIEW. We are not suspending anything!
  2028. //                    else
  2029. //                        suspend those extra items?
  2030.                 }
  2031.                 g_rgThrottleItem[i].nParallel = pThrottleItems[n].nParallel;
  2032.                 //  We should not nuke the count 'coz we could be in something
  2033.                 //  and the count holds a valid non-zero value. We don't want
  2034.                 //  to decrease it to something like -1 :) in RemoveFromThrList.
  2035. //              g_rgThrottleItem[i].nRunning = 0;
  2036.                 g_rgThrottleItem[i].dwPriority = 0;
  2037.                 g_rgThrottleItem[i].dwIntervalMin = pThrottleItems[n].dwMinItemUpdateInterval;
  2038.                 g_rgThrottleItem[i].dateExcludeBegin = pThrottleItems[n].stBegin;
  2039.                 g_rgThrottleItem[i].dateExcludeEnd = pThrottleItems[n].stEnd;
  2040.                 g_rgThrottleItem[i].dwFlags = pThrottleItems[n].dwFlags;
  2041.             }
  2042.             else if (posVacant != -1)
  2043.             {
  2044.                 i = posVacant;
  2045.                 g_rgThrottleItem[i].NotificationType = pThrottleItems[n].NotificationType;
  2046.                 g_rgThrottleItem[i].nParallel = pThrottleItems[n].nParallel;
  2047.                 g_rgThrottleItem[i].dwFlags = pThrottleItems[n].dwFlags;
  2048.                 g_rgThrottleItem[i].dwIntervalMin = pThrottleItems[n].dwMinItemUpdateInterval;
  2049.                 g_rgThrottleItem[i].dateExcludeBegin = pThrottleItems[n].stBegin;
  2050.                 g_rgThrottleItem[i].dateExcludeEnd = pThrottleItems[n].stEnd;
  2051.                 g_rgThrottleItem[i].nRunning = 0;
  2052.                 g_rgThrottleItem[i].dwPriority = 0;
  2053.             }
  2054.             else
  2055.             {
  2056.                 //  no more vacancy?
  2057.                 hr = S_FALSE;
  2058.                 break;
  2059.             }
  2060.         }
  2061.         //  At this point, we can be only half way through.
  2062. //        NotfAssert((n == cItems));
  2063.         g_cThrottleItemCount = 0;
  2064.         for (i = 0; i < g_urgThrottleItemtMax; i++)
  2065.         {
  2066.             if (g_rgThrottleItem[i].nParallel)
  2067.                 g_cThrottleItemCount ++;
  2068.         }
  2069.         break;
  2070.     } while (TRUE);
  2071.     if (fBroadcast)
  2072.     {
  2073.         // global broadcast
  2074.         WakeupAll();
  2075.     }
  2076.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::RegisterThrottleNotificationType (cPorts:%lx, hr:%lx)n",this, g_cRefPorts, hr));
  2077.     return hr;
  2078. }
  2079. //+---------------------------------------------------------------------------
  2080. //
  2081. //  Method:     CGlobalNotfMgr::WakeupAll
  2082. //
  2083. //  Synopsis:
  2084. //
  2085. //  Arguments:  (none)
  2086. //
  2087. //  Returns:
  2088. //
  2089. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  2090. //
  2091. //  Notes:
  2092. //
  2093. //----------------------------------------------------------------------------
  2094. HRESULT CGlobalNotfMgr::WakeupAll()
  2095. {
  2096.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::WakeupAlln", this));
  2097.     HRESULT hr = NOERROR;
  2098.     ULONG uHWndCount = 0;
  2099.     CDestinationPort *pDestPort= 0;
  2100.     hr = GetAllDestinationPorts(&pDestPort, &uHWndCount);
  2101.     if (hr == NOERROR)
  2102.     {
  2103.         for (ULONG i = 0; i < uHWndCount; i++)
  2104.         {
  2105.             HWND hWnd = (pDestPort+i)->GetPort();
  2106.             NotfAssert((hWnd));
  2107.             PostMessage(hWnd, WM_PROCESSWAKEUP, 0, 0);
  2108.         }
  2109.     }
  2110.     if (pDestPort)
  2111.     {
  2112.         delete [] pDestPort;
  2113.     }
  2114.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::WakeupAll (hr:%lx)n",this, hr));
  2115.     return hr;
  2116. }
  2117. //+---------------------------------------------------------------------------
  2118. //
  2119. //  Method:     CGlobalNotfMgr::IsConnectedToInternet
  2120. //
  2121. //  Synopsis:
  2122. //
  2123. //  Arguments:  (none)
  2124. //
  2125. //  Returns:
  2126. //
  2127. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  2128. //
  2129. //  Notes:
  2130. //
  2131. //----------------------------------------------------------------------------
  2132. HRESULT CGlobalNotfMgr::IsConnectedToInternet()
  2133. {
  2134.     NotfDebugOut((DEB_MGRGLOBAL, "%p _IN CGlobalNotfMgr::IsConnectedToInternetn", this));
  2135.     HRESULT hr = S_FALSE;
  2136.     
  2137.     DWORD dwState = INTERNET_CONNECTION_MODEM | INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY;
  2138.     if (InternetGetConnectedState(&dwState ,0) )
  2139.     {
  2140.         if (dwState & (INTERNET_CONNECTION_MODEM | INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY))
  2141.         {
  2142.             hr = S_OK;
  2143.         }
  2144.     }
  2145.     NotfDebugOut((DEB_MGRGLOBAL, "%p OUT CGlobalNotfMgr::IsConnectedToInternet (hr:%lx)n",this, hr));
  2146.     return hr;
  2147. }
  2148. //+---------------------------------------------------------------------------
  2149. //
  2150. //  Function:   IsThrottleableNotificationType
  2151. //
  2152. //  Synopsis:
  2153. //
  2154. //  Arguments:  [riid] --
  2155. //
  2156. //  Returns:
  2157. //
  2158. //  History:    1-24-1997   JohannP (Johann Posch)   Created
  2159. //
  2160. //  Notes:
  2161. //
  2162. //----------------------------------------------------------------------------
  2163. BOOL IsThrottleableNotificationType(REFIID riid)
  2164. {
  2165.     return  (   (riid == NOTIFICATIONTYPE_AGENT_START)
  2166.              || (riid == NOTIFICATIONTYPE_START_1)
  2167.              || (riid == NOTIFICATIONTYPE_START_2)
  2168.              || (riid == NOTIFICATIONTYPE_START_3)
  2169.              || (riid == NOTIFICATIONTYPE_START_4)
  2170.              || (riid == NOTIFICATIONTYPE_START_5)
  2171.              || (riid == NOTIFICATIONTYPE_START_6)
  2172.              || (riid == NOTIFICATIONTYPE_START_7)
  2173.              || (riid == NOTIFICATIONTYPE_START_8)
  2174.              || (riid == NOTIFICATIONTYPE_START_9)
  2175.              || (riid == NOTIFICATIONTYPE_START_A)
  2176.              || (riid == NOTIFICATIONTYPE_START_B)
  2177.              || (riid == NOTIFICATIONTYPE_START_C)
  2178.              || (riid == NOTIFICATIONTYPE_START_D)
  2179.              || (riid == NOTIFICATIONTYPE_START_E)
  2180.              || (riid == NOTIFICATIONTYPE_START_F));
  2181. }