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.

184 lines
3.4 KiB

  1. //
  2. // Copyright (C) 1993-1997 Microsoft Corporation. All Rights Reserved.
  3. //
  4. // MODULE: nmmgr.cpp
  5. //
  6. // PURPOSE: Implements the body of the service.
  7. //
  8. // FUNCTIONS:
  9. // MNMServiceStart(DWORD dwArgc, LPTSTR *lpszArgv);
  10. // MNMServiceStop( );
  11. //
  12. // COMMENTS: The functions implemented in nmmgr.c are
  13. // prototyped in nmmgr.h
  14. //
  15. //
  16. // AUTHOR: Claus Giloi
  17. //
  18. #include <precomp.h>
  19. #define NMSRVC_TEXT "SalemSrvc"
  20. // DEBUG only -- Define debug zone
  21. #ifdef DEBUG
  22. HDBGZONE ghZone = NULL;
  23. static PTCHAR rgZones[] = {
  24. NMSRVC_TEXT,
  25. "Warning",
  26. "Trace",
  27. "Function"
  28. };
  29. #endif // DEBUG
  30. extern DWORD g_dwMainThreadID;
  31. //
  32. // FUNCTION: MNMServiceStart
  33. //
  34. // PURPOSE: Actual code of the service
  35. // that does the work.
  36. //
  37. // PARAMETERS:
  38. // dwArgc - number of command line arguments
  39. // lpszArgv - array of command line arguments
  40. //
  41. // RETURN VALUE:
  42. // none
  43. //
  44. // COMMENTS:
  45. //
  46. VOID MNMServiceStart (DWORD dwArgc, LPTSTR *lpszArgv)
  47. {
  48. HRESULT hRet;
  49. DWORD dwResult;
  50. MSG msg;
  51. DWORD dwError = NO_ERROR;
  52. int i;
  53. // Initialization
  54. DBGINIT(&ghZone, rgZones);
  55. InitDebugModule(NMSRVC_TEXT);
  56. g_dwMainThreadID = GetCurrentThreadId();
  57. DebugEntry(MNMServiceStart);
  58. //
  59. // report the status to the service control manager.
  60. //
  61. if (!ReportStatusToSCMgr( SERVICE_START_PENDING, NO_ERROR, 30000))
  62. {
  63. ERROR_OUT(("ReportStatusToSCMgr failed"));
  64. dwError = GetLastError();
  65. goto cleanup;
  66. }
  67. CoInitialize(NULL);
  68. SetConsoleCtrlHandler(ServiceCtrlHandler, TRUE);
  69. ////////////////////////////////////////////////////////
  70. //
  71. // Service is now running, perform work until shutdown
  72. //
  73. if (!MNMServiceActivate())
  74. {
  75. ERROR_OUT(("Unable to activate service"));
  76. goto cleanup;
  77. }
  78. while (GetMessage(&msg, NULL, 0, 0))
  79. {
  80. TranslateMessage(&msg);
  81. DispatchMessage(&msg);
  82. }
  83. cleanup:
  84. MNMServiceDeActivate();
  85. DebugExitVOID(MNMServiceStart);
  86. CoUninitialize();
  87. g_dwMainThreadID = 0;
  88. DBGDEINIT(&ghZone);
  89. ExitDebugModule();
  90. }
  91. BOOL MNMServiceActivate ( VOID )
  92. {
  93. DebugEntry(MNMServiceActivate);
  94. HRESULT hRet = InitConfMgr();
  95. if (FAILED(hRet))
  96. {
  97. ERROR_OUT(("ERROR %x initializing nmmanger", hRet));
  98. return FALSE;
  99. }
  100. AddTaskbarIcon();
  101. ReportStatusToSCMgr( SERVICE_RUNNING, NO_ERROR, 0);
  102. DebugExitBOOL(MNMServiceActivate,TRUE);
  103. return TRUE;
  104. }
  105. BOOL MNMServiceDeActivate ( VOID )
  106. {
  107. DebugEntry(MNMServiceDeActivate);
  108. RemoveTaskbarIcon();
  109. ReportStatusToSCMgr(SERVICE_PAUSED, NO_ERROR, 0);
  110. //
  111. // Leave Conference
  112. //
  113. if (NULL != g_pConference)
  114. {
  115. if ( FAILED(g_pConference->Leave()))
  116. {
  117. ERROR_OUT(("Conference Leave failed"));;
  118. }
  119. }
  120. //
  121. // Free the conference
  122. //
  123. FreeConference();
  124. //
  125. // Free the AS interface
  126. //
  127. ASSERT(g_pAS);
  128. UINT ret = g_pAS->Release();
  129. g_pAS = NULL;
  130. TRACE_OUT(("AS interface freed, ref %d after Release", ret));
  131. // not to call FreeConfMfr imediately after FreeConference to avoid
  132. // a bug in t120 will remove this sleep call after fix the bug in t120
  133. FreeConfMgr();
  134. ReportStatusToSCMgr( SERVICE_STOPPED, 0, 0);
  135. DebugExitBOOL(MNMServiceDeActivate,TRUE);
  136. return TRUE;
  137. }