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.

98 lines
2.8 KiB

  1. #include "shsrvice.h"
  2. #include "mischlpr.h"
  3. #include "dbg.h"
  4. #include "tfids.h"
  5. #include <strsafe.h>
  6. #define ARRAYSIZE(a) (sizeof((a))/sizeof((a)[0]))
  7. //static
  8. HRESULT CGenericServiceManager::_RegisterServiceCtrlHandler(
  9. LPCWSTR pszServiceName, SERVICEENTRY* pse)
  10. {
  11. ASSERT(pse);
  12. HRESULT hres = E_FAIL;
  13. TRACE(TF_SERVICE, TEXT("Entered _RegisterServiceCtrlHandler"));
  14. pse->_ssh = RegisterServiceCtrlHandlerExW(pszServiceName,
  15. _ServiceHandler, pse);
  16. if (pse->_ssh)
  17. {
  18. #ifdef DEBUG
  19. SHOULDNOTFAIL(SUCCEEDED(StringCchCopy(pse->_szServiceName, ARRAYSIZE(pse->_szServiceName),
  20. pszServiceName)));
  21. #endif
  22. hres = S_OK;
  23. }
  24. else
  25. {
  26. // convert GetLastError to some HRESULT
  27. }
  28. return hres;
  29. }
  30. BOOL CGenericServiceManager::_SetServiceStatus(SERVICEENTRY* pse)
  31. {
  32. #ifdef DEBUG
  33. WCHAR sz[256];
  34. SHOULDNOTFAIL(SUCCEEDED(StringCchCopy(sz, ARRAYSIZE(sz), pse->_szServiceName)));
  35. switch (pse->_servicestatus.dwCurrentState)
  36. {
  37. case SERVICE_STOPPED:
  38. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": SERVICE_STOPPED"))));
  39. break;
  40. case SERVICE_START_PENDING:
  41. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": SERVICE_START_PENDING"))));
  42. break;
  43. case SERVICE_STOP_PENDING:
  44. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": SERVICE_STOP_PENDING"))));
  45. break;
  46. case SERVICE_RUNNING:
  47. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": SERVICE_RUNNING"))));
  48. break;
  49. case SERVICE_CONTINUE_PENDING:
  50. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": SERVICE_CONTINUE_PENDING"))));
  51. break;
  52. case SERVICE_PAUSE_PENDING:
  53. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": SERVICE_PAUSE_PENDING"))));
  54. break;
  55. case SERVICE_PAUSED:
  56. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": SERVICE_PAUSED"))));
  57. break;
  58. default:
  59. SHOULDNOTFAIL(SUCCEEDED(StringCchCat(sz, ARRAYSIZE(sz), TEXT(": Unknown state"))));
  60. break;
  61. }
  62. TRACE(TF_SERVICE, sz);
  63. #endif
  64. BOOL b = SetServiceStatus(pse->_ssh, &(pse->_servicestatus));
  65. #ifdef DEBUG
  66. if (!b)
  67. {
  68. TRACE(TF_SERVICE, TEXT("SetServiceStatus FAILED: GLE = 0x%08X"), GetLastError());
  69. }
  70. #endif
  71. return b;
  72. }
  73. // static
  74. HRESULT CGenericServiceManager::_HandleWantsDeviceEvents(
  75. LPCWSTR UNREF_PARAM(pszServiceName), BOOL fWantsDeviceEvents)
  76. {
  77. if (fWantsDeviceEvents)
  78. {
  79. TRACE(TF_SERVICE, TEXT("Wants Device Events"));
  80. }
  81. return S_OK;
  82. }