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.

1548 lines
45 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. event.cxx
  5. Abstract:
  6. SENS code related to firing Events using LCE mechanism.
  7. Author:
  8. Gopal Parupudi <GopalP>
  9. [Notes:]
  10. optional-notes
  11. Revision History:
  12. GopalP 10/31/1997 Start.
  13. --*/
  14. #include <precomp.hxx>
  15. #define STRSAFE_NO_DEPRECATE
  16. #include <strsafe.h>
  17. //
  18. // Some useful Macros
  19. //
  20. /*++
  21. Macro Description:
  22. Helper Macro for firing Winlogon events.
  23. Arguments:
  24. See signature.
  25. --*/
  26. #define FIRE_WINLOGON_EVENT(_EVENT_NAME_, _EVENT_TYPE_) \
  27. { \
  28. PSENSEVENT_WINLOGON pData = (PSENSEVENT_WINLOGON)EventData; \
  29. WCHAR buffer[256*2+1+1]; \
  30. \
  31. wcscpy(buffer, SENS_BSTR("")); \
  32. \
  33. SensPrint(SENS_INFO, (SENS_STRING("\t| WINLOGON Event\n"))); \
  34. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Type - %s\n"), _EVENT_NAME_)); \
  35. SensPrint(SENS_INFO, (SENS_STRING("\t| Size - %d\n"), pData->Info.Size)); \
  36. SensPrint(SENS_INFO, (SENS_STRING("\t| Flags - 0x%x\n"), pData->Info.Flags)); \
  37. SensPrintW(SENS_INFO, (SENS_BSTR("\t| UserName - %s\n"), \
  38. pData->Info.UserName ? pData->Info.UserName : SENS_BSTR(""))); \
  39. SensPrintW(SENS_INFO, (SENS_BSTR("\t| Domain - %s\n"), \
  40. pData->Info.Domain ? pData->Info.Domain : SENS_BSTR(""))); \
  41. SensPrintW(SENS_INFO, (SENS_BSTR("\t| WinStation - %s\n"), \
  42. pData->Info.WindowStation ? pData->Info.WindowStation : SENS_BSTR(""))); \
  43. SensPrint(SENS_INFO, (SENS_STRING("\t| hToken - 0x%x\n"), pData->Info.hToken)); \
  44. SensPrint(SENS_INFO, (SENS_STRING("\t| hDesktop - 0x%x\n"), pData->Info.hDesktop)); \
  45. SensPrint(SENS_INFO, (SENS_STRING("\t| dwSessionId - 0x%x\n"), pData->Info.dwSessionId)); \
  46. \
  47. if (pData->Info.Domain != NULL) \
  48. { \
  49. StringCbCopy(buffer, sizeof(buffer), pData->Info.Domain); \
  50. StringCbCat(buffer, sizeof(buffer), SENS_BSTR("\\")); \
  51. } \
  52. if (pData->Info.UserName != NULL) \
  53. { \
  54. StringCbCat(buffer, sizeof(buffer), pData->Info.UserName); \
  55. } \
  56. SensPrintW(SENS_INFO, (SENS_BSTR("\t| UserName passed is - %s\n"), buffer)); \
  57. hr = SensFireWinlogonEventHelper(buffer, pData->Info.dwSessionId, _EVENT_TYPE_); \
  58. \
  59. break; \
  60. }
  61. /*++
  62. Macro Description:
  63. Helper Macro for firing PnP events.
  64. Arguments:
  65. See signature.
  66. Notes:
  67. a. This is not an actual event exposed by SENS.
  68. --*/
  69. #define FIRE_PNP_EVENT(_EVENT_NAME_) \
  70. { \
  71. PSENSEVENT_PNP pData = (PSENSEVENT_PNP)EventData; \
  72. \
  73. SensPrint(SENS_INFO, (SENS_STRING("\t| PNP Event\n"))); \
  74. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Type - DEVICE %s\n"), _EVENT_NAME_)); \
  75. SensPrint(SENS_INFO, (SENS_STRING("\t| Size - %d\n"), pData->Size)); \
  76. SensPrint(SENS_INFO, (SENS_STRING("\t| DevType - %d\n"), pData->DevType)); \
  77. SensPrint(SENS_INFO, (SENS_STRING("\t| Resource - 0x%x\n"), pData->Resource)); \
  78. SensPrint(SENS_INFO, (SENS_STRING("\t| Flags - 0x%x\n"), pData->Flags)); \
  79. \
  80. break; \
  81. }
  82. /*++
  83. Macro Description:
  84. Helper Macro for firing Power events.
  85. Arguments:
  86. See signature.
  87. --*/
  88. #define FIRE_POWER_EVENT(_EVENT_NAME_, _EVENT_TYPE_) \
  89. { \
  90. PSENSEVENT_POWER pData = (PSENSEVENT_POWER)EventData; \
  91. \
  92. SensPrint(SENS_INFO, (SENS_STRING("\t| POWER MANAGEMENT Event\n"))); \
  93. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Type - %s\n"), _EVENT_NAME_)); \
  94. SensPrint(SENS_INFO, (SENS_STRING("\t| ACLineStatus - %d\n"), \
  95. pData->PowerStatus.ACLineStatus)); \
  96. SensPrint(SENS_INFO, (SENS_STRING("\t| BatteryFlag - %d\n"), \
  97. pData->PowerStatus.BatteryFlag)); \
  98. SensPrint(SENS_INFO, (SENS_STRING("\t| BatteryLifePercent - %d\n"), \
  99. pData->PowerStatus.BatteryLifePercent)); \
  100. SensPrint(SENS_INFO, (SENS_STRING("\t| BatteryLifeTime - 0x%x secs\n"), \
  101. pData->PowerStatus.BatteryLifeTime)); \
  102. SensPrint(SENS_INFO, (SENS_STRING("\t| BatteryFullLifeTime - 0x%x secs\n"), \
  103. pData->PowerStatus.BatteryFullLifeTime)); \
  104. hr = SensFirePowerEventHelper(pData->PowerStatus, _EVENT_TYPE_); \
  105. break; \
  106. }
  107. /*++
  108. Macro Description:
  109. Helper Macro for firing RAS events.
  110. Arguments:
  111. See signature.
  112. Notes:
  113. a. This is not an actual event exposed by SENS. It may, however, generate
  114. a WAN Connectivity event.
  115. --*/
  116. #define FIRE_RAS_EVENT(_EVENT_NAME_) \
  117. { \
  118. \
  119. PSENSEVENT_RAS pData = (PSENSEVENT_RAS)EventData; \
  120. \
  121. SensPrint(SENS_INFO, (SENS_STRING("\t| RAS Event\n"))); \
  122. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Type - %s\n"), _EVENT_NAME_)); \
  123. SensPrint(SENS_INFO, (SENS_STRING("\t| Connection Handle - 0x%x\n"), pData->hConnection)); \
  124. break; \
  125. }
  126. /*++
  127. Macro Description:
  128. Helper Macro for firing LAN events.
  129. Arguments:
  130. See signature.
  131. Notes:
  132. a. This is not an actual event exposed by SENS. It may, however, generate
  133. a LAN Connectivity event.
  134. --*/
  135. #define FIRE_LAN_EVENT(_EVENT_NAME_) \
  136. \
  137. { \
  138. PSENSEVENT_LAN pData = (PSENSEVENT_LAN)EventData; \
  139. \
  140. SensPrint(SENS_INFO, (SENS_STRING("\t| LAN Event\n"))); \
  141. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Type - %s\n"), _EVENT_NAME_)); \
  142. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Connection Name - %s\n"), pData->Name)); \
  143. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Status - 0x%x\n"), pData->Status)); \
  144. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Type - 0x%x\n"), pData->Type)); \
  145. break; \
  146. }
  147. /*++
  148. Macro Description:
  149. This macro is called when we allocate the EventData so that it can be
  150. queued to a worker thread. ALLOCATE_END() should be called to signal the
  151. end of the allocation.
  152. Arguments:
  153. See signature.
  154. Notes:
  155. a. pData, pTempData and pReturnData are fixed names for the variable.
  156. They should not be changed without updating the code that uses
  157. this macro.
  158. --*/
  159. #define ALLOCATE_BEGIN(_EVENT_STRUCT_) \
  160. \
  161. _EVENT_STRUCT_ *pData, *pTempData; \
  162. \
  163. /* Allocate the Data structure */ \
  164. pTempData = (_EVENT_STRUCT_ *) EventData; \
  165. pData = (_EVENT_STRUCT_ *) new char[sizeof(_EVENT_STRUCT_)]; \
  166. if (NULL == pData) \
  167. { \
  168. goto Cleanup; \
  169. } \
  170. \
  171. memcpy(pData, EventData, sizeof(_EVENT_STRUCT_));
  172. /*++
  173. Macro Description:
  174. This macro is called when we allocate the strings in the EventData before
  175. queueing to a worker thread. FREE_STRING_MEMBER() should be called to free
  176. the string before the EventData itself is freed.
  177. Arguments:
  178. See signature.
  179. Notes:
  180. a. pData, pTempData and pReturnData are fixed names for the variable.
  181. They should not be changed without updating the code that uses
  182. this macro.
  183. --*/
  184. #define ALLOCATE_STRING_MEMBER(_DEST_, _SOURCE_) \
  185. \
  186. if (NULL != _SOURCE_) \
  187. { \
  188. /* Allocate the string */ \
  189. _DEST_ = new WCHAR[(wcslen(_SOURCE_)+1)]; \
  190. if (NULL == _DEST_) \
  191. { \
  192. delete pData; \
  193. goto Cleanup; \
  194. } \
  195. wcscpy(_DEST_, _SOURCE_); \
  196. }
  197. /*++
  198. Macro Description:
  199. This macro is called when we finish allocating the EventData so that
  200. it can be queued to a worker thread. It should be always called after
  201. ALLOCATE_BEGIN() macro.
  202. Arguments:
  203. None.
  204. Notes:
  205. a. pData, pTempData and pReturnData are fixed names for the variable.
  206. They should not be changed without updating the code that uses
  207. this macro.
  208. --*/
  209. #define ALLOCATE_END() \
  210. \
  211. SensPrint(SENS_INFO, (SENS_STRING("******** Allocated a DS (0x%x)\n"), pData)); \
  212. pReturnData = pData; \
  213. break;
  214. /*++
  215. Macro Description:
  216. This macro is called to begin the deallocation of the EventData. This
  217. should always match with a call to ALLOCATE_BEGIN() macro.
  218. Arguments:
  219. None.
  220. Notes:
  221. a. pData, pTempData and pReturnData are fixed names for the variable.
  222. They should not be changed without updating the code that uses
  223. this macro.
  224. --*/
  225. #define FREE_BEGIN(_EVENT_STRUCT_) \
  226. \
  227. _EVENT_STRUCT_ *pData; \
  228. \
  229. pData = (_EVENT_STRUCT_ *) EventData;
  230. /*++
  231. Macro Description:
  232. This macro is called to free the string member of an EventData. This
  233. should always match with a call to ALLOCATE_STRING_MEMBER() macro.
  234. Arguments:
  235. See signature.
  236. Notes:
  237. a. pData, pTempData and pReturnData are fixed names for the variable.
  238. They should not be changed without updating the code that uses
  239. this macro.
  240. --*/
  241. #define FREE_STRING_MEMBER(_STRING_) \
  242. \
  243. if (NULL != _STRING_) \
  244. { \
  245. /* Free the string */ \
  246. delete _STRING_; \
  247. }
  248. /*++
  249. Macro Description:
  250. This macro is called to end the deallocation of EventData. This
  251. should always match with a call to FREE_BEGIN() macro.
  252. Arguments:
  253. See signature.
  254. Notes:
  255. a. pData, pTempData and pReturnData are fixed names for the variable.
  256. They should not be changed without updating the code that uses
  257. this macro.
  258. --*/
  259. #define FREE_END() \
  260. \
  261. SensPrint(SENS_INFO, (SENS_STRING("********** Freed a DS (0x%x)\n"), pData)); \
  262. delete pData; \
  263. break;
  264. void
  265. EvaluateConnectivity(
  266. IN CONNECTIVITY_TYPE Type
  267. )
  268. /*++
  269. Routine Description:
  270. This code queues up a job (for evaluating Network connectivity) to
  271. a worker thread.
  272. Arguments:
  273. Type - Indicates the type of connectivity to be evaluated.
  274. Return Value:
  275. None.
  276. --*/
  277. {
  278. BOOL bRetVal;
  279. LPTHREAD_START_ROUTINE lpfnEvaluate;
  280. switch (Type)
  281. {
  282. case TYPE_WAN:
  283. lpfnEvaluate = (LPTHREAD_START_ROUTINE) EvaluateWanConnectivity;
  284. break;
  285. case TYPE_DELAY_LAN:
  286. lpfnEvaluate = (LPTHREAD_START_ROUTINE) EvaluateLanConnectivityDelayed;
  287. break;
  288. default:
  289. case TYPE_LAN:
  290. lpfnEvaluate = (LPTHREAD_START_ROUTINE) EvaluateLanConnectivity;
  291. break;
  292. }
  293. bRetVal = SensQueueUserWorkItem(
  294. (LPTHREAD_START_ROUTINE) lpfnEvaluate,
  295. NULL,
  296. SENS_LONG_ITEM // Flags
  297. );
  298. if (FALSE == bRetVal)
  299. {
  300. SensPrintA(SENS_ERR, ("EvaluateConnectivity(): SensQueueUserWorkItem() failed with %d.\n",
  301. GetLastError()));
  302. }
  303. }
  304. void
  305. SensFireEvent(
  306. IN PVOID EventData
  307. )
  308. /*++
  309. Routine Description:
  310. This code queues up a job (for firing a SENS event) to a worker thread.
  311. Arguments:
  312. EventData - Data relating to the event.
  313. Return Value:
  314. None.
  315. --*/
  316. {
  317. BOOL bRetVal;
  318. PVOID pAllocatedData;
  319. pAllocatedData = AllocateEventData(EventData);
  320. if (NULL == pAllocatedData)
  321. {
  322. SensPrintA(SENS_ERR, ("SensFireEvent(): Failed to allocate Event Data!\n"));
  323. return;
  324. }
  325. bRetVal = SensQueueUserWorkItem(
  326. (LPTHREAD_START_ROUTINE) SensFireEventHelper,
  327. pAllocatedData, // Event Data
  328. SENS_LONG_ITEM // Flags
  329. );
  330. if (FALSE == bRetVal)
  331. {
  332. SensPrintA(SENS_ERR, ("SensFireEvent(): SensQueueUserWorkItem() failed with %d.\n",
  333. GetLastError()));
  334. }
  335. else
  336. {
  337. SensPrintA(SENS_INFO, ("SensFireEvent(): SensQueueUserWorkItem() succeeded.\n"));
  338. }
  339. }
  340. DWORD WINAPI
  341. SensFireEventHelper(
  342. IN PVOID EventData
  343. )
  344. /*++
  345. Routine Description:
  346. This code sets up the necessary stuff for firing a SENS event.
  347. Arguments:
  348. EventData - Data relating to the event.
  349. Return Value:
  350. S_OK, if successful
  351. hr, otherwise
  352. --*/
  353. {
  354. SENS_EVENT_TYPE eType;
  355. HRESULT hr;
  356. SensPrint(SENS_INFO, (SENS_STRING("\t|-------------------------------------------------------|\n")));
  357. SensPrint(SENS_INFO, (SENS_STRING("\t| E V E N T F I R E D |\n")));
  358. SensPrint(SENS_INFO, (SENS_STRING("\t|-------------------------------------------------------|\n")));
  359. hr = S_OK;
  360. eType = *(SENS_EVENT_TYPE *)EventData;
  361. switch (eType)
  362. {
  363. case SENS_EVENT_NETALIVE:
  364. {
  365. PSENSEVENT_NETALIVE pData = (PSENSEVENT_NETALIVE)EventData;
  366. SensPrint(SENS_INFO, (SENS_STRING("\t| %s%sNetwork Connectivity is %sPRESENT.\n\t|\n"),
  367. (pData->QocInfo.dwFlags & CONNECTION_WAN) ? SENS_STRING("WAN ") : SENS_STRING(""),
  368. (pData->QocInfo.dwFlags & CONNECTION_LAN) ? SENS_STRING("LAN ") : SENS_STRING(""),
  369. pData->bAlive ? SENS_STRING("") : SENS_STRING("NOT "))
  370. );
  371. hr = SensFireNetEventHelper(pData);
  372. break;
  373. }
  374. case SENS_EVENT_REACH:
  375. {
  376. PSENSEVENT_REACH pData = (PSENSEVENT_REACH)EventData;
  377. SensPrint(SENS_INFO, (SENS_STRING("\t| Destination is %sREACHABLE.\n"), pData->bReachable ? "" : "NOT "));
  378. SensPrint(SENS_INFO, (SENS_STRING("\t|\n\t| Name : %s\n"), pData->Destination));
  379. if (pData->bReachable == TRUE)
  380. {
  381. SensPrint(SENS_INFO, (SENS_STRING("\t| dwFlags : 0x%x \n"), pData->QocInfo.dwFlags));
  382. SensPrint(SENS_INFO, (SENS_STRING("\t| InSpeed : %d bits/sec.\n"), pData->QocInfo.dwInSpeed));
  383. SensPrint(SENS_INFO, (SENS_STRING("\t| OutSpeed : %d bits/sec.\n"), pData->QocInfo.dwOutSpeed));
  384. }
  385. hr = SensFireReachabilityEventHelper(pData);
  386. break;
  387. }
  388. case SENS_EVENT_PNP_DEVICE_ARRIVED:
  389. FIRE_PNP_EVENT(SENS_STRING("ARRIVED"));
  390. case SENS_EVENT_PNP_DEVICE_REMOVED:
  391. FIRE_PNP_EVENT(SENS_STRING("REMOVED"));
  392. case SENS_EVENT_POWER_ON_ACPOWER:
  393. FIRE_POWER_EVENT(SENS_STRING("ON AC POWER"), eType);
  394. case SENS_EVENT_POWER_ON_BATTERYPOWER:
  395. FIRE_POWER_EVENT(SENS_STRING("ON BATTERY POWER"), eType);
  396. case SENS_EVENT_POWER_BATTERY_LOW:
  397. FIRE_POWER_EVENT(SENS_STRING("BATTERY IS LOW"), eType);
  398. case SENS_EVENT_POWER_STATUS_CHANGE:
  399. FIRE_POWER_EVENT(SENS_STRING("POWER STATUS CHANGED"), eType);
  400. case SENS_EVENT_LOGON:
  401. FIRE_WINLOGON_EVENT(SENS_STRING("LOGON"), eType);
  402. case SENS_EVENT_LOGOFF:
  403. FIRE_WINLOGON_EVENT(SENS_STRING("LOGOFF"), eType);
  404. case SENS_EVENT_STARTSHELL:
  405. FIRE_WINLOGON_EVENT(SENS_STRING("STARTSHELL"), eType);
  406. case SENS_EVENT_POSTSHELL:
  407. FIRE_WINLOGON_EVENT(SENS_STRING("POSTSHELL"), eType);
  408. case SENS_EVENT_SESSION_DISCONNECT:
  409. FIRE_WINLOGON_EVENT(SENS_STRING("SESSION DISCONNECT"), eType);
  410. case SENS_EVENT_SESSION_RECONNECT:
  411. FIRE_WINLOGON_EVENT(SENS_STRING("SESSION RECONNECT"), eType);
  412. case SENS_EVENT_STARTSCREENSAVER:
  413. FIRE_WINLOGON_EVENT(SENS_STRING("STARTSCREENSAVER"), eType);
  414. case SENS_EVENT_STOPSCREENSAVER:
  415. FIRE_WINLOGON_EVENT(SENS_STRING("STOPSCREENSAVER"), eType);
  416. case SENS_EVENT_LOCK:
  417. FIRE_WINLOGON_EVENT(SENS_STRING("DISPLAY LOCK"), eType);
  418. case SENS_EVENT_UNLOCK:
  419. FIRE_WINLOGON_EVENT(SENS_STRING("DISPLAY UNLOCK"), eType);
  420. case SENS_EVENT_RAS_STARTED:
  421. FIRE_RAS_EVENT(SENS_STRING("RAS STARTED"));
  422. case SENS_EVENT_RAS_STOPPED:
  423. FIRE_RAS_EVENT(SENS_STRING("RAS STOPPED"));
  424. case SENS_EVENT_RAS_CONNECT:
  425. FIRE_RAS_EVENT(SENS_STRING("RAS CONNECT"));
  426. case SENS_EVENT_RAS_DISCONNECT:
  427. FIRE_RAS_EVENT(SENS_STRING("RAS DISCONNECT"));
  428. case SENS_EVENT_RAS_DISCONNECT_PENDING:
  429. FIRE_RAS_EVENT(SENS_STRING("RAS DISCONNECT PENDING"));
  430. case SENS_EVENT_LAN_CONNECT:
  431. FIRE_LAN_EVENT(SENS_STRING("LAN CONNECT"));
  432. case SENS_EVENT_LAN_DISCONNECT:
  433. FIRE_LAN_EVENT(SENS_STRING("LAN DISCONNECT"));
  434. default:
  435. SensPrint(SENS_ERR, (SENS_STRING("\t| A bogus event - %d !\n"), eType));
  436. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  437. }
  438. //
  439. // Free the allocated Event data structure.
  440. //
  441. FreeEventData(EventData);
  442. return ((DWORD) hr);
  443. }
  444. PVOID
  445. AllocateEventData(
  446. PVOID EventData
  447. )
  448. /*++
  449. Routine Description:
  450. Allocated the EventData depending on the type of the event.
  451. Arguments:
  452. EventData - Data relating to the event.
  453. Return Value:
  454. None.
  455. --*/
  456. {
  457. SENS_EVENT_TYPE eType;
  458. PVOID pReturnData;
  459. pReturnData = NULL;
  460. if (NULL == EventData)
  461. {
  462. goto Cleanup;
  463. }
  464. eType = *(SENS_EVENT_TYPE *)EventData;
  465. switch (eType)
  466. {
  467. case SENS_EVENT_NETALIVE:
  468. {
  469. ALLOCATE_BEGIN(SENSEVENT_NETALIVE);
  470. ALLOCATE_STRING_MEMBER(pData->strConnection, pTempData->strConnection);
  471. ALLOCATE_END();
  472. }
  473. case SENS_EVENT_REACH:
  474. {
  475. ALLOCATE_BEGIN(SENSEVENT_REACH);
  476. ALLOCATE_STRING_MEMBER(pData->Destination, pTempData->Destination);
  477. ALLOCATE_STRING_MEMBER(pData->strConnection, pTempData->strConnection);
  478. ALLOCATE_END();
  479. }
  480. case SENS_EVENT_PNP_DEVICE_ARRIVED:
  481. case SENS_EVENT_PNP_DEVICE_REMOVED:
  482. {
  483. ALLOCATE_BEGIN(SENSEVENT_PNP);
  484. ALLOCATE_END();
  485. }
  486. case SENS_EVENT_POWER_ON_ACPOWER:
  487. case SENS_EVENT_POWER_ON_BATTERYPOWER:
  488. case SENS_EVENT_POWER_BATTERY_LOW:
  489. case SENS_EVENT_POWER_STATUS_CHANGE:
  490. {
  491. ALLOCATE_BEGIN(SENSEVENT_POWER);
  492. ALLOCATE_END();
  493. }
  494. case SENS_EVENT_LOGON:
  495. case SENS_EVENT_LOGOFF:
  496. case SENS_EVENT_STARTSHELL:
  497. case SENS_EVENT_POSTSHELL:
  498. case SENS_EVENT_SESSION_DISCONNECT:
  499. case SENS_EVENT_SESSION_RECONNECT:
  500. case SENS_EVENT_STARTSCREENSAVER:
  501. case SENS_EVENT_STOPSCREENSAVER:
  502. case SENS_EVENT_LOCK:
  503. case SENS_EVENT_UNLOCK:
  504. {
  505. ALLOCATE_BEGIN(SENSEVENT_WINLOGON);
  506. ALLOCATE_STRING_MEMBER(pData->Info.UserName, pTempData->Info.UserName);
  507. ALLOCATE_STRING_MEMBER(pData->Info.Domain, pTempData->Info.Domain);
  508. ALLOCATE_STRING_MEMBER(pData->Info.WindowStation, pTempData->Info.WindowStation);
  509. ALLOCATE_END();
  510. }
  511. case SENS_EVENT_RAS_STARTED:
  512. case SENS_EVENT_RAS_STOPPED:
  513. case SENS_EVENT_RAS_CONNECT:
  514. case SENS_EVENT_RAS_DISCONNECT:
  515. case SENS_EVENT_RAS_DISCONNECT_PENDING:
  516. {
  517. ALLOCATE_BEGIN(SENSEVENT_RAS);
  518. ALLOCATE_END();
  519. }
  520. case SENS_EVENT_LAN_CONNECT:
  521. case SENS_EVENT_LAN_DISCONNECT:
  522. {
  523. ALLOCATE_BEGIN(SENSEVENT_LAN);
  524. ALLOCATE_STRING_MEMBER(pData->Name, pTempData->Name);
  525. ALLOCATE_END();
  526. }
  527. default:
  528. SensPrint(SENS_ERR, (SENS_STRING("\t| A bogus event - %d !\n"), eType));
  529. break;
  530. }
  531. Cleanup:
  532. //
  533. // Cleanup
  534. //
  535. return pReturnData;
  536. }
  537. void
  538. FreeEventData(
  539. PVOID EventData
  540. )
  541. /*++
  542. Routine Description:
  543. Frees the EventData depending on the type of the event.
  544. Arguments:
  545. EventData - Data relating to the event.
  546. Return Value:
  547. None.
  548. --*/
  549. {
  550. SENS_EVENT_TYPE eType;
  551. if (NULL == EventData)
  552. {
  553. goto Cleanup;
  554. }
  555. eType = *(SENS_EVENT_TYPE *)EventData;
  556. switch (eType)
  557. {
  558. case SENS_EVENT_NETALIVE:
  559. {
  560. FREE_BEGIN(SENSEVENT_NETALIVE);
  561. FREE_STRING_MEMBER(pData->strConnection);
  562. FREE_END();
  563. }
  564. case SENS_EVENT_REACH:
  565. {
  566. FREE_BEGIN(SENSEVENT_REACH);
  567. FREE_STRING_MEMBER(pData->Destination);
  568. FREE_STRING_MEMBER(pData->strConnection);
  569. FREE_END();
  570. }
  571. case SENS_EVENT_PNP_DEVICE_ARRIVED:
  572. case SENS_EVENT_PNP_DEVICE_REMOVED:
  573. {
  574. FREE_BEGIN(SENSEVENT_PNP);
  575. FREE_END();
  576. }
  577. case SENS_EVENT_POWER_ON_ACPOWER:
  578. case SENS_EVENT_POWER_ON_BATTERYPOWER:
  579. case SENS_EVENT_POWER_BATTERY_LOW:
  580. case SENS_EVENT_POWER_STATUS_CHANGE:
  581. {
  582. FREE_BEGIN(SENSEVENT_POWER);
  583. FREE_END();
  584. }
  585. case SENS_EVENT_LOGON:
  586. case SENS_EVENT_LOGOFF:
  587. case SENS_EVENT_STARTSHELL:
  588. case SENS_EVENT_POSTSHELL:
  589. case SENS_EVENT_SESSION_DISCONNECT:
  590. case SENS_EVENT_SESSION_RECONNECT:
  591. case SENS_EVENT_STARTSCREENSAVER:
  592. case SENS_EVENT_STOPSCREENSAVER:
  593. case SENS_EVENT_LOCK:
  594. case SENS_EVENT_UNLOCK:
  595. {
  596. FREE_BEGIN(SENSEVENT_WINLOGON);
  597. FREE_STRING_MEMBER(pData->Info.UserName);
  598. FREE_STRING_MEMBER(pData->Info.Domain);
  599. FREE_STRING_MEMBER(pData->Info.WindowStation);
  600. FREE_END();
  601. }
  602. case SENS_EVENT_RAS_STARTED:
  603. case SENS_EVENT_RAS_STOPPED:
  604. case SENS_EVENT_RAS_CONNECT:
  605. case SENS_EVENT_RAS_DISCONNECT:
  606. case SENS_EVENT_RAS_DISCONNECT_PENDING:
  607. {
  608. FREE_BEGIN(SENSEVENT_RAS);
  609. FREE_END();
  610. }
  611. case SENS_EVENT_LAN_CONNECT:
  612. case SENS_EVENT_LAN_DISCONNECT:
  613. {
  614. FREE_BEGIN(SENSEVENT_LAN);
  615. FREE_STRING_MEMBER(pData->Name);
  616. FREE_END();
  617. }
  618. default:
  619. SensPrint(SENS_ERR, (SENS_STRING("\t| A bogus structure to free - %d !\n"), eType));
  620. break;
  621. }
  622. Cleanup:
  623. //
  624. // Cleanup
  625. //
  626. return;
  627. }
  628. HRESULT
  629. SensFireNetEventHelper(
  630. PSENSEVENT_NETALIVE pData
  631. )
  632. /*++
  633. Routine Description:
  634. Helps fire the SENS Network Alive event.
  635. Arguments:
  636. pData - Net alive event data.
  637. Return Value:
  638. S_OK, if successful.
  639. Failure hr, otherwise.
  640. --*/
  641. {
  642. HRESULT hr;
  643. BSTR bstrConnectionName;
  644. BSTR bstrMethodName;
  645. ISensNetwork *pISensNetwork;
  646. IEventControl *pIEventControl;
  647. SENS_QOCINFO SensQocInfo;
  648. CImpISensNetworkFilter NetEventsFilter; // Already AddRef'ed
  649. hr = S_OK;
  650. bstrConnectionName = NULL;
  651. bstrMethodName = NULL;
  652. pISensNetwork = NULL;
  653. pIEventControl = NULL;
  654. hr = CoCreateInstance(
  655. SENSGUID_EVENTCLASS_NETWORK,
  656. NULL,
  657. CLSCTX_SERVER,
  658. IID_ISensNetwork,
  659. (LPVOID *) &pISensNetwork
  660. );
  661. if (FAILED(hr))
  662. {
  663. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't get ISensNetwork object - ")
  664. SENS_STRING("hr = 0x%x\n"), hr));
  665. goto Cleanup;
  666. }
  667. SensPrint(SENS_INFO, (SENS_STRING("\t| Successfully created ISensNetwork Object\n")));
  668. //
  669. // Setup Publisher filtering
  670. //
  671. hr = pISensNetwork->QueryInterface(
  672. IID_IEventControl,
  673. (LPVOID *) &pIEventControl
  674. );
  675. if (FAILED(hr))
  676. {
  677. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't get IEventControl object - ")
  678. SENS_STRING("hr = 0x%x\n"), hr));
  679. goto Cleanup;
  680. }
  681. SensPrint(SENS_INFO, (SENS_STRING("\t| Successfully created IEventControl Object\n")));
  682. //
  683. // Disallow inproc activation (we're local system, and we
  684. // don't like foreign components in our security context,
  685. // potentially crashing us).
  686. //
  687. pIEventControl->put_AllowInprocActivation(FALSE);
  688. AllocateBstrFromString(bstrConnectionName, pData->strConnection);
  689. if (pData->bAlive)
  690. {
  691. // Connect events
  692. AllocateBstrFromString(bstrMethodName, CONNECTION_MADE_NOQOC_METHOD);
  693. hr = NetEventsFilter.Initialize(bstrMethodName, pIEventControl);
  694. if (FAILED(hr))
  695. {
  696. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't initialize PublisherFilters for Net Connect Event - ")
  697. SENS_STRING("hr = 0x%x\n"), hr));
  698. goto Cleanup;
  699. }
  700. hr = pIEventControl->SetPublisherFilter(
  701. bstrMethodName,
  702. &NetEventsFilter
  703. );
  704. if (FAILED(hr))
  705. {
  706. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't set PublisherFilters for Net Connect Event - ")
  707. SENS_STRING("hr = 0x%x\n"), hr));
  708. goto Cleanup;
  709. }
  710. //
  711. // Fire the necessary ISensNetwork events
  712. //
  713. //
  714. // ConnectionMadeNoQOCInfo event
  715. //
  716. hr = pISensNetwork->ConnectionMadeNoQOCInfo(
  717. bstrConnectionName,
  718. pData->QocInfo.dwFlags
  719. );
  720. if (FAILED(hr))
  721. {
  722. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire ConnectionMadeQOCInfo - ")
  723. SENS_STRING("hr = 0x%x\n"), hr));
  724. goto Cleanup;
  725. }
  726. SensPrint(SENS_INFO, (SENS_STRING("\t| ConnectionMadeNoQOCInfo() returned 0x%x\n"), hr));
  727. //
  728. // ConnectionMade event
  729. //
  730. FreeBstr(bstrMethodName);
  731. AllocateBstrFromString(bstrMethodName, CONNECTION_MADE_METHOD);
  732. hr = NetEventsFilter.Initialize(bstrMethodName, pIEventControl);
  733. if (FAILED(hr))
  734. {
  735. SensPrint(SENS_ERR, (SENS_STRING("\t| initialize't set PublisherFilters for NetEvent - ")
  736. SENS_STRING("hr = 0x%x\n"), hr));
  737. goto Cleanup;
  738. }
  739. hr = pIEventControl->SetPublisherFilter(
  740. bstrMethodName,
  741. &NetEventsFilter
  742. );
  743. if (FAILED(hr))
  744. {
  745. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't set PublisherFilters for NetEvent - ")
  746. SENS_STRING("hr = 0x%x\n"), hr));
  747. goto Cleanup;
  748. }
  749. memcpy(&SensQocInfo, &pData->QocInfo, sizeof(SENS_QOCINFO));
  750. hr = pISensNetwork->ConnectionMade(
  751. bstrConnectionName,
  752. pData->QocInfo.dwFlags,
  753. &SensQocInfo
  754. );
  755. if (FAILED(hr))
  756. {
  757. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire ConnectionMade - ")
  758. SENS_STRING("hr = 0x%x\n"), hr));
  759. goto Cleanup;
  760. }
  761. SensPrint(SENS_INFO, (SENS_STRING("\t| ConnectionMade() returned 0x%x\n"), hr));
  762. }
  763. else // bAlive == FALSE
  764. {
  765. // Disconnect event
  766. AllocateBstrFromString(bstrMethodName, CONNECTION_LOST_METHOD);
  767. hr = NetEventsFilter.Initialize(bstrMethodName, pIEventControl);
  768. if (FAILED(hr))
  769. {
  770. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't initialize PublisherFilters for Net Disconnect Event - ")
  771. SENS_STRING("hr = 0x%x\n"), hr));
  772. goto Cleanup;
  773. }
  774. hr = pIEventControl->SetPublisherFilter(
  775. bstrMethodName,
  776. &NetEventsFilter
  777. );
  778. if (FAILED(hr))
  779. {
  780. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't set PublisherFilters for Net Disconnect Event - ")
  781. SENS_STRING("hr = 0x%x\n"), hr));
  782. goto Cleanup;
  783. }
  784. //
  785. // Fire the necessary ISensNetwork events
  786. //
  787. //
  788. // ConnectionMadeNoQOCInfo event
  789. //
  790. hr = pISensNetwork->ConnectionLost(
  791. bstrConnectionName,
  792. pData->QocInfo.dwFlags
  793. );
  794. if (FAILED(hr))
  795. {
  796. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire ConnectionLost - ")
  797. SENS_STRING("hr = 0x%x\n"), hr));
  798. goto Cleanup;
  799. }
  800. SensPrint(SENS_INFO, (SENS_STRING("\t| ConnectionLost() returned 0x%x\n"), hr));
  801. }
  802. Cleanup:
  803. //
  804. // Cleanup
  805. //
  806. if (pIEventControl)
  807. {
  808. pIEventControl->Release();
  809. }
  810. if (pISensNetwork)
  811. {
  812. pISensNetwork->Release();
  813. }
  814. FreeBstr(bstrMethodName);
  815. FreeBstr(bstrConnectionName);
  816. return hr;
  817. }
  818. HRESULT
  819. SensFireReachabilityEventHelper(
  820. PSENSEVENT_REACH pData
  821. )
  822. /*++
  823. Routine Description:
  824. Helps fire the SENS Reachability event.
  825. Arguments:
  826. pData - Reachability event Data.
  827. Return Value:
  828. S_OK, if successful.
  829. Failure hr, otherwise.
  830. --*/
  831. {
  832. HRESULT hr;
  833. BSTR bstrConnectionName;
  834. BSTR bstrMethodName;
  835. BSTR bstrDestinationName;
  836. ISensNetwork *pISensNetwork;
  837. IEventControl *pIEventControl;
  838. SENS_QOCINFO SensQocInfo;
  839. CImpISensNetworkFilter NetEventsFilter; // Already AddRef'ed
  840. hr = S_OK;
  841. bstrMethodName = NULL;
  842. bstrConnectionName = NULL;
  843. bstrDestinationName = NULL;
  844. pISensNetwork = NULL;
  845. pIEventControl = NULL;
  846. hr = CoCreateInstance(
  847. SENSGUID_EVENTCLASS_NETWORK,
  848. NULL,
  849. CLSCTX_SERVER,
  850. IID_ISensNetwork,
  851. (LPVOID *) &pISensNetwork
  852. );
  853. if (FAILED(hr))
  854. {
  855. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't get ISensNetwork object - ")
  856. SENS_STRING("hr = 0x%x\n"), hr));
  857. goto Cleanup;
  858. }
  859. SensPrint(SENS_INFO, (SENS_STRING("\t| Successfully created ISensNetwork Object\n")));
  860. //
  861. // Setup Publisher filtering
  862. //
  863. hr = pISensNetwork->QueryInterface(
  864. IID_IEventControl,
  865. (LPVOID *) &pIEventControl
  866. );
  867. if (FAILED(hr))
  868. {
  869. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't get IEventControl object - ")
  870. SENS_STRING("hr = 0x%x\n"), hr));
  871. goto Cleanup;
  872. }
  873. SensPrint(SENS_INFO, (SENS_STRING("\t| Successfully created IEventControl Object\n")));
  874. //
  875. // Disallow inproc activation (we're local system, and we
  876. // don't like foreign components in our security context,
  877. // potentially crashing us).
  878. //
  879. pIEventControl->put_AllowInprocActivation(FALSE);
  880. AllocateBstrFromString(bstrMethodName, DESTINATION_REACHABLE_NOQOC_METHOD);
  881. hr = NetEventsFilter.Initialize(bstrMethodName, pIEventControl);
  882. if (FAILED(hr))
  883. {
  884. SensPrint(SENS_ERR, (SENS_STRING("\t| initialize't set PublisherFilters for ReachabilityEvent - ")
  885. SENS_STRING("hr = 0x%x\n"), hr));
  886. goto Cleanup;
  887. }
  888. hr = pIEventControl->SetPublisherFilter(
  889. bstrMethodName,
  890. &NetEventsFilter
  891. );
  892. if (FAILED(hr))
  893. {
  894. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't set PublisherFilters for ReachabilityEvent - ")
  895. SENS_STRING("hr = 0x%x\n"), hr));
  896. goto Cleanup;
  897. }
  898. //
  899. // Fire the Reachability events
  900. //
  901. AllocateBstrFromString(bstrConnectionName, pData->strConnection);
  902. AllocateBstrFromString(bstrDestinationName, pData->Destination);
  903. //
  904. // DestinationReachableNoQOCInfo event
  905. //
  906. hr = pISensNetwork->DestinationReachableNoQOCInfo(
  907. bstrDestinationName,
  908. bstrConnectionName,
  909. pData->QocInfo.dwFlags
  910. );
  911. if (FAILED(hr))
  912. {
  913. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire DestinationReachableNoQOCInfo - ")
  914. SENS_STRING("hr = 0x%x\n"), hr));
  915. goto Cleanup;
  916. }
  917. SensPrint(SENS_INFO, (SENS_STRING("\t| DestinationReachableNoQOCInfo() returned 0x%x\n"), hr));
  918. //
  919. // DestinationReachable event
  920. //
  921. FreeBstr(bstrMethodName);
  922. AllocateBstrFromString(bstrMethodName, DESTINATION_REACHABLE_METHOD);
  923. hr = NetEventsFilter.Initialize(bstrMethodName, pIEventControl);
  924. if (FAILED(hr))
  925. {
  926. SensPrint(SENS_ERR, (SENS_STRING("\t| initialize't set PublisherFilters for ReachabilityEvent - ")
  927. SENS_STRING("hr = 0x%x\n"), hr));
  928. goto Cleanup;
  929. }
  930. hr = pIEventControl->SetPublisherFilter(
  931. bstrMethodName,
  932. &NetEventsFilter
  933. );
  934. if (FAILED(hr))
  935. {
  936. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't set PublisherFilters for ReachabilityEvent - ")
  937. SENS_STRING("hr = 0x%x\n"), hr));
  938. goto Cleanup;
  939. }
  940. memcpy(&SensQocInfo, &pData->QocInfo, sizeof(SENS_QOCINFO));
  941. hr = pISensNetwork->DestinationReachable(
  942. bstrDestinationName,
  943. bstrConnectionName,
  944. pData->QocInfo.dwFlags,
  945. &SensQocInfo
  946. );
  947. if (FAILED(hr))
  948. {
  949. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire DestinationReachable - ")
  950. SENS_STRING("hr = 0x%x\n"), hr));
  951. goto Cleanup;
  952. }
  953. SensPrint(SENS_INFO, (SENS_STRING("\t| DestinationReachable() returned 0x%x\n"), hr));
  954. Cleanup:
  955. //
  956. // Cleanup
  957. //
  958. if (pIEventControl)
  959. {
  960. pIEventControl->Release();
  961. }
  962. if (pISensNetwork)
  963. {
  964. pISensNetwork->Release();
  965. }
  966. FreeBstr(bstrMethodName);
  967. FreeBstr(bstrConnectionName);
  968. FreeBstr(bstrDestinationName);
  969. return hr;
  970. }
  971. HRESULT
  972. SensFireWinlogonEventHelper(
  973. LPWSTR strArg,
  974. DWORD dwSessionId,
  975. SENS_EVENT_TYPE eType
  976. )
  977. /*++
  978. Routine Description:
  979. Helps fire the SENS Winlogon event.
  980. Arguments:
  981. strArg - DomainName\UserName
  982. dwSessionId - Session Id of the session on which this event was fired.
  983. eType - Type of Winlogon event.
  984. Return Value:
  985. S_OK, if successful.
  986. Failure hr, otherwise.
  987. --*/
  988. {
  989. HRESULT hr;
  990. HRESULT hr2;
  991. BOOL bLogon2;
  992. BSTR bstrUserName;
  993. ISensLogon *pISensLogon;
  994. ISensLogon2 *pISensLogon2;
  995. hr = S_OK;
  996. hr2 = S_OK;
  997. bstrUserName = NULL;
  998. pISensLogon = NULL;
  999. pISensLogon2 = NULL;
  1000. //
  1001. // Get the ISensLogon Object
  1002. //
  1003. hr = CoCreateInstance(
  1004. SENSGUID_EVENTCLASS_LOGON,
  1005. NULL,
  1006. CLSCTX_SERVER,
  1007. IID_ISensLogon,
  1008. (LPVOID *) &pISensLogon
  1009. );
  1010. if (FAILED(hr))
  1011. {
  1012. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't get ISensLogon object - ")
  1013. SENS_STRING("hr = 0x%x\n"), hr));
  1014. goto Cleanup;
  1015. }
  1016. SensPrint(SENS_INFO, (SENS_STRING("\t| Successfully created ISensLogon Object\n")));
  1017. //
  1018. // Get the ISensLogon2 Object
  1019. //
  1020. hr2 = CoCreateInstance(
  1021. SENSGUID_EVENTCLASS_LOGON2,
  1022. NULL,
  1023. CLSCTX_SERVER,
  1024. IID_ISensLogon2,
  1025. (LPVOID *) &pISensLogon2
  1026. );
  1027. if (FAILED(hr2))
  1028. {
  1029. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't get ISensLogon2 object - ")
  1030. SENS_STRING("hr = 0x%x\n"), hr2));
  1031. goto Cleanup;
  1032. }
  1033. SensPrint(SENS_INFO, (SENS_STRING("\t| Successfully created ISensLogon2 Object\n")));
  1034. AllocateBstrFromString(bstrUserName, strArg);
  1035. switch (eType)
  1036. {
  1037. case SENS_EVENT_LOGON:
  1038. hr = pISensLogon->Logon(bstrUserName);
  1039. hr2 = pISensLogon2->Logon(bstrUserName, dwSessionId);
  1040. break;
  1041. case SENS_EVENT_LOGOFF:
  1042. hr = pISensLogon->Logoff(bstrUserName);
  1043. hr2 = pISensLogon2->Logoff(bstrUserName, dwSessionId);
  1044. break;
  1045. case SENS_EVENT_STARTSHELL:
  1046. hr = pISensLogon->StartShell(bstrUserName);
  1047. break;
  1048. case SENS_EVENT_POSTSHELL:
  1049. hr2 = pISensLogon2->PostShell(bstrUserName, dwSessionId);
  1050. break;
  1051. case SENS_EVENT_SESSION_DISCONNECT:
  1052. hr2 = pISensLogon2->SessionDisconnect(bstrUserName, dwSessionId);
  1053. break;
  1054. case SENS_EVENT_SESSION_RECONNECT:
  1055. hr2 = pISensLogon2->SessionReconnect(bstrUserName, dwSessionId);
  1056. break;
  1057. case SENS_EVENT_LOCK:
  1058. hr = pISensLogon->DisplayLock(bstrUserName);
  1059. break;
  1060. case SENS_EVENT_UNLOCK:
  1061. hr = pISensLogon->DisplayUnlock(bstrUserName);
  1062. break;
  1063. case SENS_EVENT_STARTSCREENSAVER:
  1064. hr = pISensLogon->StartScreenSaver(bstrUserName);
  1065. break;
  1066. case SENS_EVENT_STOPSCREENSAVER:
  1067. hr = pISensLogon->StopScreenSaver(bstrUserName);
  1068. break;
  1069. default:
  1070. SensPrint(SENS_WARN, (SENS_STRING("\t| Bad Winlogon Event - %d\n"), eType));
  1071. break;
  1072. }
  1073. //
  1074. // Check for failures
  1075. //
  1076. if (FAILED(hr))
  1077. {
  1078. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire ISensLogon->WinlogonEvent - ")
  1079. SENS_STRING("hr = 0x%x\n"), hr));
  1080. }
  1081. else
  1082. {
  1083. SensPrint(SENS_INFO, (SENS_STRING("\t| ISensLogon->WinlogonEvent() returned 0x%x\n"), hr));
  1084. }
  1085. if (FAILED(hr2))
  1086. {
  1087. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire ISensLogon2->WinlogonEvent(%d) - ")
  1088. SENS_STRING("hr = 0x%x\n"), dwSessionId, hr2));
  1089. }
  1090. else
  1091. {
  1092. SensPrint(SENS_INFO, (SENS_STRING("\t| ISensLogon2->WinlogonEvent(%d) returned 0x%x\n"), dwSessionId, hr));
  1093. }
  1094. Cleanup:
  1095. //
  1096. // Cleanup
  1097. //
  1098. if (pISensLogon)
  1099. {
  1100. pISensLogon->Release();
  1101. }
  1102. if (pISensLogon2)
  1103. {
  1104. pISensLogon2->Release();
  1105. }
  1106. FreeBstr(bstrUserName);
  1107. return hr;
  1108. }
  1109. HRESULT
  1110. SensFirePowerEventHelper(
  1111. SYSTEM_POWER_STATUS PowerStatus,
  1112. SENS_EVENT_TYPE eType
  1113. )
  1114. /*++
  1115. Routine Description:
  1116. Helps fire the SENS Power event.
  1117. Arguments:
  1118. PowerStatus - Power Status event structure
  1119. eType - Type of the Power event.
  1120. Return Value:
  1121. S_OK, if successful.
  1122. Failure hr, otherwise.
  1123. --*/
  1124. {
  1125. HRESULT hr;
  1126. ISensOnNow *pISensOnNow;
  1127. hr = S_OK;
  1128. pISensOnNow = NULL;
  1129. //
  1130. // Get the ISensOnNow Object
  1131. //
  1132. hr = CoCreateInstance(
  1133. SENSGUID_EVENTCLASS_ONNOW,
  1134. NULL,
  1135. CLSCTX_SERVER,
  1136. IID_ISensOnNow,
  1137. (LPVOID *) &pISensOnNow
  1138. );
  1139. if (FAILED(hr))
  1140. {
  1141. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't get ISensOnNow object - ")
  1142. SENS_STRING("hr = 0x%x\n"), hr));
  1143. goto Cleanup;
  1144. }
  1145. SensPrint(SENS_INFO, (SENS_STRING("\t| Successfully created ISensOnNow Object\n")));
  1146. switch (eType)
  1147. {
  1148. case SENS_EVENT_POWER_ON_ACPOWER:
  1149. hr = pISensOnNow->OnACPower();
  1150. break;
  1151. case SENS_EVENT_POWER_ON_BATTERYPOWER:
  1152. hr = pISensOnNow->OnBatteryPower(PowerStatus.BatteryLifePercent);
  1153. break;
  1154. case SENS_EVENT_POWER_BATTERY_LOW:
  1155. hr = pISensOnNow->BatteryLow(PowerStatus.BatteryLifePercent);
  1156. break;
  1157. default:
  1158. SensPrint(SENS_WARN, (SENS_STRING("\t| Bad Power Event - %d\n"), eType));
  1159. break;
  1160. }
  1161. if (FAILED(hr))
  1162. {
  1163. SensPrint(SENS_ERR, (SENS_STRING("\t| Couldn't fire ISensOnNow->PowerEvent - ")
  1164. SENS_STRING("hr = 0x%x\n"), hr));
  1165. //SensPrintToDebugger(SENS_DEB, ("\t| Couldn't fire ISensOnNow->PowerEvent - "
  1166. // "hr = 0x%x\n", hr));
  1167. goto Cleanup;
  1168. }
  1169. SensPrint(SENS_INFO, (SENS_STRING("\t| ISensOnNow->PowerEvent() returned 0x%x\n"), hr));
  1170. //SensPrintToDebugger(SENS_DEB, ("\t| ISensOnNow->PowerEvent() returned 0x%x\n", hr));
  1171. Cleanup:
  1172. //
  1173. // Cleanup
  1174. //
  1175. if (pISensOnNow)
  1176. {
  1177. pISensOnNow->Release();
  1178. }
  1179. return hr;
  1180. }