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.

187 lines
5.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996
  5. //
  6. // File: crequest.hxx
  7. //
  8. // Contents: Client side of catalog and query requests to the service
  9. //
  10. // Classes: CPipeClient
  11. // CRequestClient
  12. // CEnableNotify
  13. //
  14. // History: 16-Sep-96 dlee Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #pragma once
  18. #include <dbgproxy.hxx>
  19. #define CI_PIPE_TESTING CIDBG
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Class: CPipeClient
  23. //
  24. // Synopsis: Base class for a client named pipe
  25. //
  26. // History: 16-Sep-96 dlee Created.
  27. //
  28. //--------------------------------------------------------------------------
  29. class CPipeClient
  30. {
  31. protected:
  32. CPipeClient();
  33. void Init( WCHAR const * pwcMachine, WCHAR const * pwcPipe );
  34. ~CPipeClient()
  35. {
  36. prxDebugOut(( DEB_ITRACE, "~CPipeClient: 0x%x\n", _hPipe ));
  37. Close();
  38. }
  39. void TransactSync( void * pvWrite,
  40. DWORD cbToWrite,
  41. void * pvRead,
  42. DWORD cbReadRequest,
  43. DWORD & cbRead );
  44. void WriteSync( void * pvWrite,
  45. DWORD cbToWrite );
  46. void ReadSync( void * pvRead,
  47. DWORD cbToRead,
  48. DWORD & cbRead );
  49. BOOL ReadSync( void * pvRead,
  50. DWORD cbToRead,
  51. DWORD & cbRead,
  52. HANDLE hEvent );
  53. void Close();
  54. BOOL IsServerRemote() { return _fServerIsRemote; }
  55. HANDLE GetPipe() { return _hPipe; }
  56. private:
  57. HANDLE _hPipe;
  58. BOOL _fServerIsRemote; // is the pipe remoted via the rdr/svr?
  59. OVERLAPPED _overlapped; // 5 DWORDs for xacts and reads
  60. OVERLAPPED _overlappedWrite; // 5 DWORDs for writes
  61. CEventSem _event; // for completion of xacts and reads
  62. CEventSem _eventWrite; // for completion of writes
  63. #if CI_PIPE_TESTING
  64. typedef SCODE (* PipeTraceBeforeCall) ( HANDLE hPipe,
  65. ULONG cbWrite,
  66. void * pvWrite,
  67. ULONG & rcbWritten,
  68. void *& rpvWritten );
  69. typedef SCODE (* PipeTraceAfterCall) ( HANDLE hPipe,
  70. ULONG cbWrite,
  71. void * pvWrite,
  72. ULONG cbWritten,
  73. void * pvWritten,
  74. ULONG cbRead,
  75. void * pvRead );
  76. PipeTraceBeforeCall _pTraceBefore;
  77. PipeTraceAfterCall _pTraceAfter;
  78. HINSTANCE _hTraceDll;
  79. public:
  80. BOOL IsPipeTracingEnabled() { return 0 != _hTraceDll; }
  81. private:
  82. #endif // CI_PIPE_TESTING
  83. };
  84. //+-------------------------------------------------------------------------
  85. //
  86. // Class: CRequestClient
  87. //
  88. // Synopsis: Handles the client side of communication
  89. //
  90. // History: 16-Sep-96 dlee Created.
  91. //
  92. //--------------------------------------------------------------------------
  93. class CRequestClient : public CPipeClient
  94. {
  95. public:
  96. CRequestClient( WCHAR const *pwcMachine,
  97. IDBProperties * pDbProperties );
  98. void TerminateRudelyNoThrow() { Close(); }
  99. void Disconnect();
  100. void EnableNotify();
  101. void DisableNotify();
  102. void DataWrite( void * pvWrite, DWORD cbWrite );
  103. void DataWriteRead( void * pvWrite,
  104. DWORD cbWrite,
  105. void * pvRead,
  106. DWORD cbToRead,
  107. DWORD & cbRead );
  108. BOOL NotifyWriteRead( HANDLE hEvent,
  109. void * pvWrite,
  110. DWORD cbWrite,
  111. void * pvData,
  112. DWORD cbBuffer,
  113. DWORD & cbRead );
  114. int GetServerVersion() { return _ServerVersion; }
  115. BOOL IsServer64() { return IsCi64( _ServerVersion ); }
  116. private:
  117. BOOL _fNotifyOn; // TRUE if notifications are on
  118. BOOL _fNotifyEverOn; // TRUE if notifications were ever on
  119. BOOL _fReadPending; // TRUE if data thread has a read pending
  120. void * _pvDataTemp; // where the data is handed off
  121. ULONG _cbDataTemp; // size of the data handed off
  122. int _ServerVersion; // version of the server
  123. CAutoEventSem _eventData; // set when notify thread has data for
  124. // a data thread
  125. CAutoEventSem _eventDataDone; // set when data thread is done, so
  126. // notify thread can continue
  127. CMutexSem _mutex; // mutex for all methods
  128. CMutexSem _mutexData; // mutex for DataX methods
  129. };
  130. //+-------------------------------------------------------------------------
  131. //
  132. // Class: CEnableNotify
  133. //
  134. // Synopsis: Turns on notification in a request client, then turns it
  135. // off in the destructor.
  136. //
  137. // History: 16-Sep-96 dlee Created.
  138. //
  139. //--------------------------------------------------------------------------
  140. class CEnableNotify
  141. {
  142. public:
  143. CEnableNotify( CRequestClient & client ) : _client( client )
  144. {
  145. _client.EnableNotify();
  146. }
  147. ~CEnableNotify()
  148. {
  149. _client.DisableNotify();
  150. }
  151. private:
  152. CRequestClient & _client;
  153. };