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.

150 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 2000.
  5. //
  6. // File: N M H N E T . C P P
  7. //
  8. // Contents: Home networking support routines
  9. //
  10. // Notes:
  11. //
  12. // Author: jonburs 15 August 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "nmbase.h"
  18. #include "nmhnet.h"
  19. //
  20. // Exported globals
  21. //
  22. IHNetCfgMgr *g_pHNetCfgMgr;
  23. LONG g_lHNetModifiedEra;
  24. //
  25. // Private globals
  26. //
  27. CRITICAL_SECTION g_csHNetCfgMgr;
  28. BOOLEAN g_fCreatingHNetCfgMgr;
  29. VOID
  30. InitializeHNetSupport(
  31. VOID
  32. )
  33. {
  34. g_pHNetCfgMgr = NULL;
  35. g_lHNetModifiedEra = 0;
  36. g_fCreatingHNetCfgMgr = FALSE;
  37. __try
  38. {
  39. InitializeCriticalSection(&g_csHNetCfgMgr);
  40. }
  41. __except(EXCEPTION_EXECUTE_HANDLER)
  42. {
  43. AssertSz(FALSE, "InitializeHNetSupport: exception during InitializeCriticalSection");
  44. }
  45. }
  46. VOID
  47. CleanupHNetSupport(
  48. VOID
  49. )
  50. {
  51. ReleaseObj(g_pHNetCfgMgr);
  52. DeleteCriticalSection(&g_csHNetCfgMgr);
  53. }
  54. HRESULT
  55. HrGetHNetCfgMgr(
  56. IHNetCfgMgr **ppHNetCfgMgr
  57. )
  58. {
  59. HRESULT hr = S_OK;
  60. Assert(ppHNetCfgMgr);
  61. *ppHNetCfgMgr = NULL;
  62. //
  63. // Make sure that the service is in the correct state.
  64. //
  65. if (SERVICE_RUNNING != _Module.DwServiceStatus ())
  66. {
  67. hr = E_UNEXPECTED;
  68. }
  69. else
  70. {
  71. if (NULL == g_pHNetCfgMgr)
  72. {
  73. EnterCriticalSection(&g_csHNetCfgMgr);
  74. if (!g_fCreatingHNetCfgMgr && NULL == g_pHNetCfgMgr)
  75. {
  76. IHNetCfgMgr *pHNetCfgMgr;
  77. g_fCreatingHNetCfgMgr = TRUE;
  78. LeaveCriticalSection(&g_csHNetCfgMgr);
  79. hr = HrCreateInstance(
  80. CLSID_HNetCfgMgr,
  81. CLSCTX_INPROC_SERVER,
  82. &pHNetCfgMgr
  83. );
  84. EnterCriticalSection(&g_csHNetCfgMgr);
  85. Assert(NULL == g_pHNetCfgMgr);
  86. g_fCreatingHNetCfgMgr = FALSE;
  87. g_pHNetCfgMgr = pHNetCfgMgr;
  88. }
  89. else if (NULL == g_pHNetCfgMgr)
  90. {
  91. //
  92. // Another thread is already trying to create the
  93. // object. (Spin for a small amount of time to see
  94. // if that thread succeeds?)
  95. //
  96. hr = HRESULT_FROM_WIN32(ERROR_BUSY);
  97. }
  98. LeaveCriticalSection(&g_csHNetCfgMgr);
  99. }
  100. Assert(g_pHNetCfgMgr || FAILED(hr));
  101. if (SUCCEEDED(hr))
  102. {
  103. *ppHNetCfgMgr = g_pHNetCfgMgr;
  104. AddRefObj(*ppHNetCfgMgr);
  105. }
  106. }
  107. return hr;
  108. }
  109. //
  110. // CNetConnectionHNetUtil implementation -- INetConnectionHNetUtil routines
  111. //
  112. STDMETHODIMP
  113. CNetConnectionHNetUtil::NotifyUpdate(
  114. VOID
  115. )
  116. {
  117. InterlockedIncrement(&g_lHNetModifiedEra);
  118. return S_OK;
  119. }