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

293 lines
9.5 KiB

  1. /*****************************************************************************
  2. * (C) COPYRIGHT MICROSOFT CORPORATION, 2002
  3. *
  4. * AUTHOR: ByronC
  5. *
  6. * DATE: 3/24/2002
  7. *
  8. * @doc INTERNAL
  9. *
  10. * @module EventRegistrationInfo.cpp - Implementation for <c EventRegistrationInfo> |
  11. *
  12. * This file contains the implementation for the <c EventRegistrationInfo> class.
  13. *
  14. *****************************************************************************/
  15. #include "cplusinc.h"
  16. #include "coredbg.h"
  17. /*****************************************************************************
  18. * @doc INTERNAL
  19. *
  20. * @mfunc | EventRegistrationInfo | EventRegistrationInfo |
  21. *
  22. * We initialize all member variables. In general, this sets the values to 0,
  23. * except:
  24. * <nl><md EventRegistrationInfo::m_cRef> is set to be 1.
  25. *
  26. *****************************************************************************/
  27. EventRegistrationInfo::EventRegistrationInfo(
  28. DWORD dwFlags,
  29. GUID guidEvent,
  30. WCHAR *wszDeviceID,
  31. ULONG_PTR Callback) :
  32. m_cRef(1),
  33. m_dwFlags(dwFlags),
  34. m_guidEvent(guidEvent),
  35. m_bstrDeviceID(NULL),
  36. m_Callback(Callback)
  37. {
  38. DBG_FN(EventRegistrationInfo);
  39. if (wszDeviceID)
  40. {
  41. m_bstrDeviceID = SysAllocString(wszDeviceID);
  42. }
  43. else
  44. {
  45. m_bstrDeviceID = SysAllocString(WILDCARD_DEVICEID_STR);
  46. }
  47. }
  48. /*****************************************************************************
  49. * @doc INTERNAL
  50. *
  51. * @mfunc | EventRegistrationInfo | ~EventRegistrationInfo |
  52. *
  53. * Do any cleanup that is not already done.
  54. *
  55. *****************************************************************************/
  56. EventRegistrationInfo::~EventRegistrationInfo()
  57. {
  58. DBG_FN(~EventRegistrationInfo);
  59. m_cRef = 0;
  60. if (m_bstrDeviceID)
  61. {
  62. SysFreeString(m_bstrDeviceID);
  63. m_bstrDeviceID = NULL;
  64. }
  65. m_Callback = 0;
  66. }
  67. /*****************************************************************************
  68. * @doc INTERNAL
  69. *
  70. * @mfunc ULONG | EventRegistrationInfo | AddRef |
  71. *
  72. * Increments this object's ref count. We should always AddRef when handing
  73. * out a pointer to this object.
  74. *
  75. * @rvalue Count |
  76. * The reference count after the count has been incremented.
  77. *****************************************************************************/
  78. ULONG __stdcall EventRegistrationInfo::AddRef()
  79. {
  80. InterlockedIncrement((long*) &m_cRef);
  81. return m_cRef;
  82. }
  83. /*****************************************************************************
  84. * @doc INTERNAL
  85. *
  86. * @mfunc ULONG | EventRegistrationInfo | Release |
  87. *
  88. * Decrement this object's ref count. We should always Release when finished
  89. * with a pointer to this object.
  90. *
  91. * @rvalue Count |
  92. * The reference count after the count has been decremented.
  93. *****************************************************************************/
  94. ULONG __stdcall EventRegistrationInfo::Release()
  95. {
  96. ULONG ulRefCount = m_cRef - 1;
  97. if (InterlockedDecrement((long*) &m_cRef) == 0) {
  98. delete this;
  99. return 0;
  100. }
  101. return ulRefCount;
  102. }
  103. /*****************************************************************************
  104. * @doc INTERNAL
  105. *
  106. * @mfunc BOOL | EventRegistrationInfo | MatchesDeviceEvent |
  107. *
  108. * This method returns true if the device event matches our registration. It
  109. * is a match only if both Event and DeviceId match.
  110. *
  111. * Note that the STI Proxy event is considered wild, as is a DeviceID of "*".
  112. *
  113. * @parm BSTR | bstrDevice |
  114. * The WIA DeviceID identifying which device the event <p guidEvent> originated from.
  115. * @parm GUID | guidEvent |
  116. * The event guid.
  117. *
  118. * @rvalue TRUE |
  119. * This registration matches the device event.
  120. * @rvalue FALSE |
  121. * This registration does not match the device event.
  122. *****************************************************************************/
  123. BOOL EventRegistrationInfo::MatchesDeviceEvent(
  124. BSTR bstrDeviceID,
  125. GUID guidEvent)
  126. {
  127. BOOL bDeviceMatch = FALSE;
  128. BOOL bEventMatch = FALSE;
  129. if (bstrDeviceID && m_bstrDeviceID)
  130. {
  131. //
  132. // First check whether we have a match on event.
  133. // We also need to check whether this is a
  134. // STIProxyEvent registration, in which case we match
  135. // all events.
  136. //
  137. if ((m_guidEvent == guidEvent) || (m_guidEvent == WIA_EVENT_STI_PROXY))
  138. {
  139. bEventMatch = TRUE;
  140. }
  141. //
  142. // If we match on event guid, let's check whether we also match on
  143. // DeviceID. We also need to check whether our device ID is the wildcard'*',
  144. // in which case we match all devices.
  145. //
  146. if (bEventMatch)
  147. {
  148. if ((lstrcmpiW(m_bstrDeviceID, WILDCARD_DEVICEID_STR) == 0) ||
  149. (lstrcmpiW(m_bstrDeviceID, bstrDeviceID) == 0))
  150. {
  151. bDeviceMatch = TRUE;
  152. }
  153. }
  154. }
  155. return (bDeviceMatch && bEventMatch);
  156. }
  157. /*****************************************************************************
  158. * @doc INTERNAL
  159. *
  160. * @mfunc BOOL | EventRegistrationInfo | Equals |
  161. *
  162. * Checks whether this <c EventRegistrationInfo> is semantically equivalent
  163. * to <p pEventRegistrationInfo>. This is different to <mf EventRegistrationInfo::MatchesDeviceEvent>.
  164. *
  165. * For example: Suppose <c EventRegistrationInfo> A has Device ID == L"*", and
  166. * and event guid == Guid1.
  167. * <nl>Suppose also that <c EventRegistrationInfo> B has Device ID == L"DeviceFoo", and
  168. * and event guid == Guid1.
  169. * <nl> Now A would "match" B, but A and B are not equal.
  170. *
  171. * Equality is checked against:
  172. * <nl> <md EventRegistrationInfo::m_guidEvent>
  173. * <nl> <md EventRegistrationInfo::m_Callback>
  174. * <nl> <md EventRegistrationInfo::m_bstrDeviceID>
  175. *
  176. * @parm EventRegistrationInfo* | pEventRegistrationInfo |
  177. * Specifies the <c EventRegistrationInfo> to compare against.
  178. *
  179. * @rvalue TRUE |
  180. * The registration are equal.
  181. * @rvalue FALSE |
  182. * The registrations are not equal.
  183. *****************************************************************************/
  184. BOOL EventRegistrationInfo::Equals(
  185. EventRegistrationInfo *pEventRegistrationInfo)
  186. {
  187. BOOL bEqual = FALSE;
  188. if (pEventRegistrationInfo)
  189. {
  190. if ((m_guidEvent == pEventRegistrationInfo->m_guidEvent) &&
  191. (m_Callback == pEventRegistrationInfo->m_Callback) &&
  192. (lstrcmpiW(m_bstrDeviceID, pEventRegistrationInfo->m_bstrDeviceID) == 0))
  193. {
  194. bEqual = TRUE;
  195. }
  196. }
  197. return bEqual;
  198. }
  199. /*****************************************************************************
  200. * @doc INTERNAL
  201. *
  202. * @mfunc DWORD | EventRegistrationInfo | getFlags |
  203. *
  204. * Accessor method for the flags used for this registration.
  205. *
  206. * @rvalue DWORD |
  207. * The value of <md EventRegistrationInfo::m_dwFlags>.
  208. *****************************************************************************/
  209. DWORD EventRegistrationInfo::getFlags()
  210. {
  211. return m_dwFlags;
  212. }
  213. /*****************************************************************************
  214. * @doc INTERNAL
  215. *
  216. * @mfunc GUID | EventRegistrationInfo | getEventGuid |
  217. *
  218. * Accessor method for the event guid used for this registration.
  219. *
  220. * @rvalue GUID |
  221. * The value of <md EventRegistrationInfo::m_guidEvent>.
  222. *****************************************************************************/
  223. GUID EventRegistrationInfo::getEventGuid()
  224. {
  225. return m_guidEvent;
  226. }
  227. /*****************************************************************************
  228. * @doc INTERNAL
  229. *
  230. * @mfunc BSTR | EventRegistrationInfo | getDeviceID |
  231. *
  232. * Accessor method for the device id used for this registration.
  233. *
  234. * @rvalue BSTR |
  235. * The value of <md EventRegistrationInfo::m_bstrDeviceID>.
  236. *****************************************************************************/
  237. BSTR EventRegistrationInfo::getDeviceID()
  238. {
  239. return m_bstrDeviceID;
  240. }
  241. /*****************************************************************************
  242. * @doc INTERNAL
  243. *
  244. * @mfunc ULONG_PTR | EventRegistrationInfo | getCallback |
  245. *
  246. * Accessor method for the callback used for this registration.
  247. *
  248. * @rvalue ULONG_PTR |
  249. * The value of <md EventRegistrationInfo::m_Callback>.
  250. *****************************************************************************/
  251. ULONG_PTR EventRegistrationInfo::getCallback()
  252. {
  253. return m_Callback;
  254. }
  255. /*****************************************************************************
  256. * @doc INTERNAL
  257. *
  258. * @mfunc VOID | EventRegistrationInfo | Dump |
  259. *
  260. * Dumps the fields of this class.
  261. *
  262. *****************************************************************************/
  263. VOID EventRegistrationInfo::Dump()
  264. {
  265. WCHAR wszEventGuid[40];
  266. StringFromGUID2(m_guidEvent, wszEventGuid, sizeof(wszEventGuid)/sizeof(wszEventGuid[0]));
  267. wszEventGuid[sizeof(wszEventGuid)/sizeof(wszEventGuid[0])-1]=L'\0';
  268. DBG_TRC((" dwFlags: 0x%08X", m_dwFlags));
  269. DBG_TRC((" guidEvent: %ws", wszEventGuid));
  270. DBG_TRC((" bstrDeviceID: %ws", m_bstrDeviceID));
  271. DBG_TRC((" Callback: 0x%p", m_Callback));
  272. }