Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.4 KiB

  1. #ifndef _IUCTLCP_H_
  2. #define _IUCTLCP_H_
  3. #include <assert.h>
  4. #define QuitIfNull(ptr) if (NULL == ptr) return // TO DO: add logging if quit
  5. template <class T>
  6. class CProxyIUpdateEvents : public IConnectionPointImpl<T, &DIID_IUpdateEvents, CComDynamicUnkArray>
  7. {
  8. //Warning this class may be recreated by the wizard.
  9. public:
  10. /////////////////////////////////////////////////////////////////////////////
  11. // Fire_OnItemStart()
  12. //
  13. // fire event to notify that this item is about to be downloaded.
  14. // and (in VB) plCommandRequest can be set to pause or cancel the
  15. // whole download/install operation
  16. //
  17. // Input:
  18. // bstrUuidOperation - the operation identification guid
  19. // bstrXmlItem - item XML node in BSTR
  20. // Output:
  21. // plCommandRequest - a command to pass from the listener to the owner of the event,
  22. // e.g. UPDATE_COMMAND_CANCEL, zero if nothing is requested.
  23. /////////////////////////////////////////////////////////////////////////////
  24. void Fire_OnItemStart(BSTR bstrUuidOperation,
  25. BSTR bstrXmlItem,
  26. LONG* plCommandRequest)
  27. {
  28. VARIANTARG* pvars = new VARIANTARG[3];
  29. QuitIfNull(pvars);
  30. for (int i = 0; i < 3; i++)
  31. {
  32. VariantInit(&pvars[i]);
  33. }
  34. T* pT = (T*)this;
  35. pT->Lock();
  36. IUnknown** pp = m_vec.begin();
  37. while (pp && pp < m_vec.end())
  38. {
  39. if (*pp != NULL)
  40. {
  41. pvars[2].vt = VT_BSTR;
  42. pvars[2].bstrVal = bstrUuidOperation;
  43. pvars[1].vt = VT_BSTR;
  44. pvars[1].bstrVal = bstrXmlItem;
  45. pvars[0].vt = VT_I4 | VT_BYREF;
  46. pvars[0].byref = plCommandRequest;
  47. DISPPARAMS disp = { pvars, NULL, 3, 0 };
  48. IDispatch* pDispatch = reinterpret_cast<IDispatch*>(*pp);
  49. HRESULT hr = pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  50. _ASSERT(S_OK == hr);
  51. }
  52. pp++;
  53. }
  54. pT->Unlock();
  55. delete[] pvars;
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // Fire_OnProgress()
  59. //
  60. // Notify the listener that a portion of the files has finished operation
  61. // (e.g downloaded or installed). Enables monitoring of progress.
  62. // Input:
  63. // bstrUuidOperation - the operation identification guid
  64. // fItemCompleted - TRUE if the current item has completed the operation
  65. // nPercentComplete - total percentage of operation completed
  66. // Output:
  67. // plCommandRequest - a command to pass from the listener to the owner of the event,
  68. // e.g. UPDATE_COMMAND_CANCEL, zero if nothing is requested.
  69. /////////////////////////////////////////////////////////////////////////////
  70. void Fire_OnProgress(BSTR bstrUuidOperation,
  71. VARIANT_BOOL fItemCompleted,
  72. BSTR bstrProgress,
  73. LONG* plCommandRequest)
  74. {
  75. VARIANTARG* pvars = new VARIANTARG[4];
  76. QuitIfNull(pvars);
  77. for (int i = 0; i < 4; i++)
  78. VariantInit(&pvars[i]);
  79. T* pT = (T*)this;
  80. pT->Lock();
  81. IUnknown** pp = m_vec.begin();
  82. while (pp && pp < m_vec.end())
  83. {
  84. if (*pp != NULL)
  85. {
  86. pvars[3].vt = VT_BSTR;
  87. pvars[3].bstrVal = bstrUuidOperation;
  88. pvars[2].vt = VT_BOOL;
  89. pvars[2].boolVal = fItemCompleted;
  90. pvars[1].vt = VT_BSTR;
  91. pvars[1].bstrVal = bstrProgress;
  92. pvars[0].vt = VT_I4 | VT_BYREF;
  93. pvars[0].byref = plCommandRequest;
  94. DISPPARAMS disp = { pvars, NULL, 4, 0 };
  95. IDispatch* pDispatch = reinterpret_cast<IDispatch*>(*pp);
  96. HRESULT hr = pDispatch->Invoke(0x2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  97. _ASSERT(S_OK == hr);
  98. }
  99. pp++;
  100. }
  101. pT->Unlock();
  102. delete[] pvars;
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. // Fire_OnOperationComplete()
  106. //
  107. // Notify the listener when the operation is complete.
  108. // Input:
  109. // bstrUuidOperation - the operation identification guid
  110. /////////////////////////////////////////////////////////////////////////////
  111. void Fire_OnOperationComplete(BSTR bstrUuidOperation, BSTR bstrXmlItems)
  112. {
  113. VARIANTARG* pvars = new VARIANTARG[2];
  114. QuitIfNull(pvars);
  115. VariantInit(&pvars[0]);
  116. VariantInit(&pvars[1]);
  117. T* pT = (T*)this;
  118. pT->Lock();
  119. IUnknown** pp = m_vec.begin();
  120. while (pp && pp < m_vec.end())
  121. {
  122. if (*pp != NULL)
  123. {
  124. pvars[1].vt = VT_BSTR;
  125. pvars[1].bstrVal = bstrUuidOperation;
  126. pvars[0].vt = VT_BSTR;
  127. pvars[0].bstrVal = bstrXmlItems;
  128. DISPPARAMS disp = { pvars, NULL, 2, 0 };
  129. IDispatch* pDispatch = reinterpret_cast<IDispatch*>(*pp);
  130. HRESULT hr = pDispatch->Invoke(0x3, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  131. _ASSERT(S_OK == hr);
  132. }
  133. pp++;
  134. }
  135. pT->Unlock();
  136. delete[] pvars;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // Fire_OnSelfUpdateComplete()
  140. //
  141. // Notify the listener when the operation is complete.
  142. // Input:
  143. // bstrUuidOperation - the operation identification guid
  144. /////////////////////////////////////////////////////////////////////////////
  145. void Fire_OnSelfUpdateComplete(LONG lErrorCode)
  146. {
  147. VARIANTARG var;
  148. VariantInit(&var);
  149. T* pT = (T*)this;
  150. pT->Lock();
  151. IUnknown** pp = m_vec.begin();
  152. while (pp && pp < m_vec.end())
  153. {
  154. if (*pp != NULL)
  155. {
  156. var.vt = VT_I4;
  157. var.lVal = lErrorCode;
  158. DISPPARAMS disp = { &var, NULL, 1, 0 };
  159. IDispatch* pDispatch = reinterpret_cast<IDispatch*>(*pp);
  160. HRESULT hr = pDispatch->Invoke(0x4, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  161. _ASSERT(S_OK == hr);
  162. }
  163. pp++;
  164. }
  165. pT->Unlock();
  166. }
  167. };
  168. #endif