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.

227 lines
4.1 KiB

  1. // MyALG.cpp : Implementation of CAlgICQ
  2. #include "stdafx.h"
  3. #include "MyALG.h"
  4. #include "MyAdapterNotify.h"
  5. #pragma comment(lib, "wsock32.lib")
  6. IApplicationGatewayServices* g_IAlgServicesp = NULL;
  7. IAdapterNotificationSink * g_IAdapterNotificationSinkp = NULL;
  8. DWORD g_AdapterSinkCookie = 0;
  9. //HANDLE hTranslatorHandle;
  10. // RedirectionInterface RI;
  11. PCOMPONENT_SYNC g_IcqComponentReferencep = NULL;
  12. CRITICAL_SECTION GlobalIcqLock;
  13. //
  14. //
  15. //
  16. STDMETHODIMP
  17. CAlgICQ::Initialize(
  18. IApplicationGatewayServices* IAlgServicesp
  19. )
  20. {
  21. WSADATA wd;
  22. CComObject<CMyAdapterNotify>* IAdapterNotifyp;
  23. HRESULT Result;
  24. PROFILER(TM_MSG, TL_ERROR, ("> Initialize"));
  25. InitDebuger();
  26. ASSERT(IAlgServicesp);
  27. //
  28. // Get the Services Interface
  29. //
  30. IAlgServicesp->QueryInterface(IID_IApplicationGatewayServices,
  31. (void**)&g_IAlgServicesp);
  32. ASSERT(g_IAlgServicesp);
  33. //
  34. // Initialize the socket library.
  35. //
  36. if ( WSAStartup(MAKEWORD(2,2), &wd) != 0)
  37. {
  38. ICQ_TRC(TM_DEFAULT, TL_ERROR,
  39. ("WSAStartup Error %u", WSAGetLastError()));
  40. ErrorOut();
  41. }
  42. NhInitializeBufferManagement();
  43. __try
  44. {
  45. InitializeCriticalSection(&GlobalIcqLock);
  46. }
  47. __except (EXCEPTION_EXECUTE_HANDLER)
  48. {
  49. ErrorOut();
  50. return S_FALSE;
  51. }
  52. //
  53. // NOTE: the ipnathlp.dll connection is severed.
  54. //
  55. // This is the Initialization for the Redirection Interface stolen
  56. // from the IPNATHLP.DLL hopefully if we just change the interfaces
  57. // to something else at least this part should be reusable.
  58. //
  59. // RI.Initialize();
  60. //
  61. // g_IcqPrxp = new IcqPrx;
  62. //
  63. // *
  64. // Get the Adapter Notify interface
  65. //
  66. CComObject<CMyAdapterNotify>::CreateInstance(&IAdapterNotifyp);
  67. if(IAdapterNotifyp is NULL)
  68. {
  69. ICQ_TRC(TM_DEFAULT, TL_ERROR,
  70. ("Can't Instantiate the Adapter Notification Interface"));
  71. return S_FALSE;
  72. }
  73. //
  74. // Get the AdapterNotification Interface for further Use.
  75. //
  76. Result = IAdapterNotifyp->QueryInterface(
  77. IID_IAdapterNotificationSink,
  78. (void**)&g_IAdapterNotificationSinkp
  79. );
  80. if( FAILED(Result) )
  81. {
  82. ICQ_TRC(TM_DEFAULT, TL_ERROR,
  83. (" Query Interface for the Interface Notification Sink has failed"));
  84. return S_FALSE;
  85. }
  86. //
  87. // Initialize the TimerQueue
  88. //
  89. g_TimerQueueHandle = CreateTimerQueue();
  90. if(g_TimerQueueHandle is NULL)
  91. {
  92. Result = GetLastError();
  93. ICQ_TRC(TM_DEFAULT, TL_ERROR,
  94. ("Timer initialization has failed Error is %u", Result));
  95. return S_FALSE;
  96. }
  97. //
  98. // Start the Adapter Notifications.
  99. //
  100. Result = g_IAlgServicesp->StartAdapterNotifications(g_IAdapterNotificationSinkp,
  101. &g_AdapterSinkCookie);
  102. if ( FAILED(Result) )
  103. {
  104. ICQ_TRC(TM_DEFAULT, TL_ERROR,
  105. ("Start Adapter Notification has failed %u", Result));
  106. return Result;
  107. }
  108. // *
  109. return Result;
  110. } // Initialize
  111. STDMETHODIMP
  112. CAlgICQ::Stop(void)
  113. {
  114. HRESULT Error = NO_ERROR;
  115. //
  116. // Stop Adapter Notification and Release the Interface
  117. //
  118. if(g_AdapterSinkCookie &&
  119. g_IAdapterNotificationSinkp)
  120. {
  121. Error = g_IAlgServicesp->StopAdapterNotifications(g_AdapterSinkCookie);
  122. if( FAILED(Error) )
  123. {
  124. }
  125. g_IAdapterNotificationSinkp->Release();
  126. }
  127. //
  128. // Delete the Timer Queue
  129. //
  130. if(g_TimerQueueHandle != NULL)
  131. {
  132. DeleteTimerQueueEx(g_TimerQueueHandle, INVALID_HANDLE_VALUE);
  133. g_TimerQueueHandle = NULL;
  134. }
  135. DeleteCriticalSection(&GlobalIcqLock);
  136. WSACleanup();
  137. g_IAlgServicesp->Release();
  138. NhShutdownBufferManagement();
  139. DestroyDebuger();
  140. return S_OK;
  141. }