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.

236 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vststmsg.hxx
  5. Abstract:
  6. Declaration of test message classes
  7. Brian Berkowitz [brianb] 05/22/2000
  8. TBD:
  9. Revision History:
  10. Name Date Comments
  11. brianb 05/22/2000 Created
  12. ssteiner 06/07/2000 Split client and server portions into
  13. two files. vststmsgclient.hxx contains
  14. the client and shared portion.
  15. --*/
  16. #ifndef _VSTSTMSG_H_
  17. #define _VSTSTMSG_H_
  18. #include "vststmsgclient.hxx"
  19. #include "vststntlog.hxx"
  20. typedef enum VSTST_READER_STATUS
  21. {
  22. VSTST_RS_UNDEFINED,
  23. VSTST_RS_DISCONNECTED,
  24. VSTST_RS_READDISABLED,
  25. VSTST_RS_ERROR,
  26. VSTST_RS_NOTCONNECTED
  27. };
  28. // forward declaration
  29. class CVsTstMsgHandler;
  30. // a pipe instance
  31. class CVsTstPipe
  32. {
  33. friend class CVsTstMsgHandler;
  34. public:
  35. // constructor
  36. CVsTstPipe(CVsTstMsgHandler *pHandler);
  37. // destructor
  38. ~CVsTstPipe();
  39. // initialize a pipe
  40. HRESULT Initialize(UINT cbMaxMsgSize);
  41. // force termination of thread
  42. static void ForceTermination(HANDLE hThread);
  43. private:
  44. // setup overlap structure in preparation for read or connection
  45. void SetupOverlapped();
  46. // free data associated with this object
  47. void FreeData();
  48. // wait for a connection to be established
  49. bool WaitForConnection();
  50. // startup message reading thread
  51. static DWORD StartReaderThread(void *pv);
  52. // routine to read messages
  53. VSTST_READER_STATUS ReadMessages(bool bConnect);
  54. // handle to the pipe
  55. HANDLE m_hPipe;
  56. // message buffer
  57. BYTE *m_rgbMsg;
  58. // size of message
  59. UINT m_cbMsg;
  60. // overlapped structure
  61. OVERLAPPED m_overlap;
  62. // handle for overlapped operations
  63. HANDLE m_hevtOverlapped;
  64. // reading thread
  65. HANDLE m_hThreadReader;
  66. // next in chain
  67. CVsTstPipe *m_prev;
  68. // previous in chain
  69. CVsTstPipe *m_next;
  70. // whether reader is linked in the chain
  71. bool m_bLinked;
  72. // test handler
  73. CVsTstMsgHandler *m_pHandler;
  74. // is pipe connected
  75. bool m_bConnected;
  76. };
  77. // controller used by test controller to read and process messages
  78. // immediately or by a worker thread. Immediate messages or processed
  79. // when read and are not queued to be processed by a background thread
  80. class CVsTstMsgHandler
  81. {
  82. friend class CVsTstPipe;
  83. public:
  84. // constructor
  85. CVsTstMsgHandler(
  86. IN LPCWSTR pwszLogFileName = VS_TST_DEFAULT_NTLOG_FILENAME
  87. );
  88. // destructor
  89. ~CVsTstMsgHandler();
  90. // create pipe, worker thread, etc.
  91. HRESULT Initialize(UINT cbMaxMsgSize);
  92. // start processing messages
  93. void StartProcessingMessages();
  94. // stop processing messages
  95. void StopProcessingMessages();
  96. // force termination of message worker
  97. void ForceTermination();
  98. // launch a reader thread
  99. HRESULT LaunchReader();
  100. // gets pointer to the test log object
  101. CVsTstNtLog *GetTstNtLogP() { return &m_cNtLog; }
  102. private:
  103. // link pipe into chain
  104. void LinkPipe(CVsTstPipe *pipe);
  105. // unlink pipe from chain
  106. void UnlinkPipe(CVsTstPipe *pipe);
  107. // startup worker thread
  108. static DWORD StartWorkerThread(void *pv);
  109. // routine to do work
  110. bool DoWork();
  111. // free data associated with class
  112. void FreeData();
  113. // adjust message pointers
  114. bool AdjustPointers(VSTST_MSG_HDR *phdr);
  115. // process message immediately
  116. bool ProcessMsgImmediate(VSTST_MSG_HDR *phdr);
  117. // queue message for processing by worker thread
  118. bool QueueMsg(VSTST_MSG_HDR *phdr);
  119. // wait for queue to complete
  120. void WaitForQueueToComplete();
  121. // maximum message size
  122. UINT m_cbMaxMsgLength;
  123. // head of message queue
  124. VSTST_MSG_HDR *m_pmsgFirst;
  125. // tail of message queue
  126. VSTST_MSG_HDR *m_pmsgLast;
  127. // critical section protecting pipe list
  128. CComCriticalSection m_csPipeList;
  129. // list of pipes
  130. CVsTstPipe *m_pipeList;
  131. // critical section to protect the queue
  132. CComCriticalSection m_csQueue;
  133. // handle to worker event
  134. HANDLE m_hevtWorker;
  135. // handle to reader event
  136. HANDLE m_hevtReader;
  137. // connection thread handle
  138. HANDLE m_hThreadConnection;
  139. // worker thread handle
  140. HANDLE m_hThreadWorker;
  141. // number of reader threads
  142. HANDLE m_hThreadReader;
  143. // is critical section initailized
  144. bool m_bcsQueueInitialized;
  145. // terminate worker thread
  146. bool m_bTerminateWorker;
  147. // terminate reader thread
  148. bool m_bTerminateReader;
  149. // enable reading
  150. bool m_bReadEnabled;
  151. // is pipe list critical section created sucessfully
  152. bool m_bcsPipeListInitialized;
  153. // the test log file object
  154. CVsTstNtLog m_cNtLog;
  155. };
  156. void LogInvalidMessage(VSTST_MSG_HDR *phdr);
  157. void ReadPipeError(DWORD dwErr);
  158. #endif _VSTSTMSG_H_