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.

226 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. RemoteDesktopServer
  5. Abstract:
  6. The RemoteDesktopServer is the interface for dealing
  7. with the salem server classes. It just presents
  8. the methods necessary for this application to use.
  9. Author:
  10. Marc Reyhner 7/5/2000
  11. --*/
  12. #include "stdafx.h"
  13. #ifdef TRC_FILE
  14. #undef TRC_FILE
  15. #endif
  16. #define TRC_FILE "rcrds"
  17. #include "RemoteDesktopServer.h"
  18. #include "RemoteDesktopServerEventSink.h"
  19. #include "exception.h"
  20. #include "resource.h"
  21. CRemoteDesktopServer::CRemoteDesktopServer(
  22. )
  23. /*++
  24. Routine Description:
  25. This is the constructor for CRemoteDesktopServer. It creates
  26. a server host object and then gets an IRemoteDesktopServer
  27. from the server host. The server host is then destroyed.
  28. Arguments:
  29. None
  30. Return Value:
  31. None
  32. --*/
  33. {
  34. HRESULT hr;
  35. DC_BEGIN_FN("CRemoteDesktopServer::CRemoteDesktopServer");
  36. m_rServerHost = NULL;
  37. m_rServerSession = NULL;
  38. hr = CoCreateInstance(CLSID_SAFRemoteDesktopServerHost,NULL,CLSCTX_ALL ,
  39. IID_ISAFRemoteDesktopServerHost,(LPVOID*)&m_rServerHost);
  40. if (hr != S_OK) {
  41. TRC_ERR((TB,TEXT("Error creating ISAFRemoteDesktopServerHost: 0x%0X"),hr));
  42. goto FAILURE;
  43. }
  44. DC_END_FN();
  45. return;
  46. FAILURE:
  47. if (m_rServerHost) {
  48. m_rServerHost->Release();
  49. }
  50. throw CException(IDS_SERVERRRORCREATE);
  51. }
  52. CRemoteDesktopServer::~CRemoteDesktopServer(
  53. )
  54. /*++
  55. Routine Description:
  56. The destructor just makes sure to destroy the RemoteDesktopServer.
  57. Arguments:
  58. None
  59. Return Value:
  60. None
  61. --*/
  62. {
  63. DC_BEGIN_FN("CRemoteDesktopServer::~CRemoteDesktopServer");
  64. if (m_rServerSession) {
  65. m_rServerSession->CloseRemoteDesktopSession();
  66. m_rServerSession->Release();
  67. }
  68. if (m_rServerHost) {
  69. m_rServerHost->Release();
  70. }
  71. DC_END_FN();
  72. }
  73. BSTR
  74. CRemoteDesktopServer::StartListening(
  75. )
  76. /*++
  77. Routine Description:
  78. This starts the server listening and gets the connection parameters
  79. from ISAFRemoteDesktopSession.
  80. Arguments:
  81. None
  82. Return Value:
  83. BSTR - The connection paremters a client can use to connect
  84. to the server.
  85. --*/
  86. {
  87. HRESULT hr;
  88. BSTR parms;
  89. DC_BEGIN_FN("CRemoteDesktopServer::StartListening");
  90. hr = m_rServerHost->CreateRemoteDesktopSession(CONTROLDESKTOP_PERMISSION_REQUIRE,
  91. NULL,0,&m_rServerSession);
  92. if (hr != S_OK) {
  93. TRC_ERR((TB,TEXT("Error getting ISAFRemoteDesktopSession from host: 0x%0X"),hr));
  94. goto FAILURE;
  95. }
  96. hr = m_rServerSession->get_ConnectParms(&parms);
  97. if (hr != S_OK) {
  98. TRC_ERR((TB,TEXT("Error getting connection parameters 0x%0X"),hr));
  99. goto FAILURE;
  100. }
  101. DC_END_FN();
  102. return parms;
  103. FAILURE:
  104. throw CException(IDS_SERVERERRORLISTEN);
  105. }
  106. VOID
  107. CRemoteDesktopServer::StopListening(
  108. )
  109. /*++
  110. Routine Description:
  111. This stops the server listening on the remote session.
  112. Arguments:
  113. None
  114. Return Value:
  115. None
  116. --*/
  117. {
  118. HRESULT hr;
  119. DC_BEGIN_FN("CRemoteDesktopServer::StopListening");
  120. if (m_rServerSession) {
  121. hr = m_rServerSession->CloseRemoteDesktopSession();
  122. if (hr != S_OK) {
  123. TRC_ERR((TB,TEXT("Error in CloseRemoteDesktopSession 0x%0X"),hr));
  124. goto FAILURE;
  125. }
  126. m_rServerSession->Release();
  127. }
  128. m_rServerSession = NULL;
  129. DC_END_FN();
  130. return;
  131. FAILURE:
  132. throw CException(IDS_RDSERRORSTOPLISTENING);
  133. }
  134. HRESULT
  135. CRemoteDesktopServer::EventSinkAdvise(
  136. IN CRemoteDesktopServerEventSink *rSink
  137. )
  138. /*++
  139. Routine Description:
  140. This starts the passed in event sink listening
  141. for events from the IRemoteDesktopServer
  142. Arguments:
  143. rSink - The event sink that wants to be advised of events.
  144. Return Value:
  145. None
  146. --*/
  147. {
  148. DC_BEGIN_FN("CRemoteDesktopServer::EventSinkAdvise");
  149. return rSink->DispEventAdvise(m_rServerSession);
  150. DC_END_FN();
  151. }