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.

286 lines
7.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1995
  4. * TITLE: ENTRY.CPP
  5. * VERSION: 1.0
  6. * AUTHOR: jsenior
  7. * DATE: 10/28/1998
  8. *
  9. ********************************************************************************
  10. *
  11. * CHANGE LOG:
  12. *
  13. * DATE REV DESCRIPTION
  14. * ---------- ------- ----------------------------------------------------------
  15. * 10/28/1998 jsenior Original implementation.
  16. *
  17. *******************************************************************************/
  18. #include "BandPage.h"
  19. #include "PowrPage.h"
  20. #include "UsbPopup.h"
  21. #include "debug.h"
  22. #include "usbapp.h"
  23. HINSTANCE gHInst = 0;
  24. extern "C" {
  25. BOOL APIENTRY
  26. DllMain(HANDLE hDll,
  27. DWORD dwReason,
  28. LPVOID lpReserved)
  29. {
  30. switch (dwReason) {
  31. case DLL_PROCESS_ATTACH:
  32. gHInst = (HINSTANCE) hDll;
  33. UsbPropertyPage::SetHandle(hDll);
  34. InitCommonControls();
  35. break;
  36. case DLL_PROCESS_DETACH:
  37. break;
  38. case DLL_THREAD_DETACH:
  39. break;
  40. case DLL_THREAD_ATTACH:
  41. break;
  42. default:
  43. break;
  44. }
  45. return TRUE;
  46. }
  47. BOOL APIENTRY
  48. UsbControlPanelApplet()
  49. {
  50. UsbApplet *applet = new UsbApplet();
  51. if (applet) {
  52. return applet->CustomDialog();
  53. }
  54. return FALSE;
  55. }
  56. BOOL APIENTRY
  57. USBControllerPropPageProvider(LPVOID pinfo,
  58. LPFNADDPROPSHEETPAGE pfnAdd,
  59. LPARAM lParam)
  60. {
  61. PSP_PROPSHEETPAGE_REQUEST request;
  62. HPROPSHEETPAGE hBandwidth; //, hPower;
  63. BandwidthPage *bandwidth;
  64. // PowerPage *power;
  65. request = (PSP_PROPSHEETPAGE_REQUEST) pinfo;
  66. if (request->PageRequested != SPPSR_ENUM_ADV_DEVICE_PROPERTIES)
  67. return FALSE;
  68. bandwidth = new BandwidthPage(request->DeviceInfoSet,
  69. request->DeviceInfoData);
  70. if (!bandwidth) {
  71. USBERROR((_T("Out of memory!\n")));
  72. return FALSE;
  73. }
  74. AddChunk(bandwidth);
  75. hBandwidth = bandwidth->Create();
  76. if (!hBandwidth) {
  77. DeleteChunk(bandwidth);
  78. delete bandwidth;
  79. CheckMemory();
  80. return FALSE;
  81. }
  82. if (!pfnAdd(hBandwidth, lParam)) {
  83. DestroyPropertySheetPage(hBandwidth);
  84. DeleteChunk(bandwidth);
  85. delete bandwidth;
  86. CheckMemory();
  87. return FALSE;
  88. }
  89. return TRUE;
  90. }
  91. BOOL APIENTRY
  92. USBDevicePropPageProvider(LPVOID pinfo,
  93. LPFNADDPROPSHEETPAGE pfnAdd,
  94. LPARAM lParam)
  95. {
  96. PSP_PROPSHEETPAGE_REQUEST request;
  97. HPROPSHEETPAGE hDevicePage; //, hPower;
  98. GenericPage *generic;
  99. // PowerPage *power;
  100. request = (PSP_PROPSHEETPAGE_REQUEST) pinfo;
  101. if (request->PageRequested != SPPSR_ENUM_ADV_DEVICE_PROPERTIES)
  102. return FALSE;
  103. generic = new GenericPage(request->DeviceInfoSet,
  104. request->DeviceInfoData);
  105. if (!generic) {
  106. USBERROR((_T("Out of memory!\n")));
  107. return FALSE;
  108. }
  109. AddChunk(generic);
  110. hDevicePage = generic->Create();
  111. if (!hDevicePage) {
  112. DeleteChunk(generic);
  113. delete generic;
  114. CheckMemory();
  115. return FALSE;
  116. }
  117. if (!pfnAdd(hDevicePage, lParam)) {
  118. DestroyPropertySheetPage(hDevicePage);
  119. DeleteChunk(generic);
  120. delete generic;
  121. CheckMemory();
  122. return FALSE;
  123. }
  124. return TRUE;
  125. }
  126. BOOL APIENTRY
  127. USBHubPropPageProvider(LPVOID pinfo,
  128. LPFNADDPROPSHEETPAGE pfnAdd,
  129. LPARAM lParam)
  130. {
  131. PSP_PROPSHEETPAGE_REQUEST request;
  132. HPROPSHEETPAGE hPower;
  133. PowerPage *power;
  134. request = (PSP_PROPSHEETPAGE_REQUEST) pinfo;
  135. if (request->PageRequested != SPPSR_ENUM_ADV_DEVICE_PROPERTIES)
  136. return FALSE;
  137. power = new PowerPage(request->DeviceInfoSet,
  138. request->DeviceInfoData);
  139. if (!power) {
  140. USBERROR((_T("Out of memory!\n")));
  141. return FALSE;
  142. }
  143. AddChunk(power);
  144. hPower = power->Create();
  145. if (!hPower) {
  146. DeleteChunk(power);
  147. delete power;
  148. CheckMemory();
  149. return FALSE;
  150. }
  151. if (!pfnAdd(hPower, lParam)) {
  152. DestroyPropertySheetPage(hPower);
  153. DeleteChunk(power);
  154. delete power;
  155. CheckMemory();
  156. return FALSE;
  157. }
  158. return TRUE;
  159. }
  160. BOOL
  161. USBControllerBandwidthPage(HWND hWndParent,
  162. LPCSTR DeviceName)
  163. {
  164. BandwidthPage *band;
  165. band = new BandwidthPage(hWndParent, DeviceName);
  166. if (!band) {
  167. USBERROR((_T("Out of memory!\n")));
  168. return FALSE;
  169. }
  170. AddChunk(band);
  171. band->CreateIndependent();
  172. delete band;
  173. return TRUE;
  174. }
  175. BOOL
  176. USBHubPowerPage(HWND hWndParent,
  177. LPCSTR DeviceName)
  178. {
  179. PowerPage *power;
  180. power = new PowerPage(hWndParent, DeviceName);
  181. if (!power) {
  182. USBERROR((_T("Out of memory!\n")));
  183. return FALSE;
  184. }
  185. AddChunk(power);
  186. power->CreateIndependent();
  187. delete power;
  188. return TRUE;
  189. }
  190. void USBErrorHandler(PUSB_CONNECTION_NOTIFICATION usbConnectionNotification,
  191. LPTSTR strInstanceName)
  192. {
  193. static LONG bandwidthPopupExists = 0;
  194. static LONG powerPopupExists = 0;
  195. static LONG legacyPopupExists = 0;
  196. static LONG overcurrentPopupExists = 0;
  197. static LPTSTR currentInstanceName = NULL;
  198. static HANDLE hMutex = NULL;
  199. if (!hMutex) {
  200. hMutex = CreateMutex(NULL, TRUE, NULL);
  201. } else {
  202. WaitForSingleObject(hMutex, INFINITE);
  203. }
  204. //
  205. // Call the appropriate handler
  206. //
  207. USBTRACE((_T("Error Notification - %d\n"), usbConnectionNotification->NotificationType));
  208. switch (usbConnectionNotification->NotificationType) {
  209. case InsufficentBandwidth:
  210. USBTRACE((_T("Insufficent Bandwidth\n")));
  211. if (InterlockedIncrement(&bandwidthPopupExists) == 1) {
  212. UsbBandwidthPopup popup;
  213. popup.Make(usbConnectionNotification, strInstanceName);
  214. }
  215. InterlockedDecrement(&bandwidthPopupExists);
  216. break;
  217. case InsufficentPower: {
  218. USBTRACE((_T("Insufficent Power\n")));
  219. UsbPowerPopup popup;
  220. popup.Make(usbConnectionNotification, strInstanceName);
  221. break; }
  222. case OverCurrent: {
  223. USBTRACE((_T("Over Current\n")));
  224. UsbOvercurrentPopup popup;
  225. popup.Make(usbConnectionNotification, strInstanceName);
  226. break; }
  227. case EnumerationFailure: {
  228. USBTRACE((_T("Enumeration Failure\n")));
  229. UsbEnumFailPopup popup;
  230. popup.Make(usbConnectionNotification, strInstanceName);
  231. break; }
  232. case ModernDeviceInLegacyHub: {
  233. USBTRACE((_T("ModernDeviceInLegacyHub\n")));
  234. UsbLegacyPopup popup;
  235. popup.Make(usbConnectionNotification, strInstanceName);
  236. break; }
  237. case HubNestedTooDeeply: {
  238. USBTRACE((_T("HubNestedTooDeeply\n")));
  239. UsbNestedHubPopup popup;
  240. popup.Make(usbConnectionNotification, strInstanceName);
  241. break; }
  242. case ResetOvercurrent:
  243. default:
  244. break;
  245. }
  246. CheckMemory();
  247. ReleaseMutex(hMutex);
  248. }
  249. } // extern "C"
  250.