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.

84 lines
3.7 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: APIDispatcher.h
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // A class that handles API requests in the server on a separate thread. Each
  7. // thread is dedicated to respond to a single client. This is acceptable for
  8. // a lightweight server.
  9. //
  10. // History: 1999-11-07 vtan created
  11. // 2000-08-25 vtan moved from Neptune to Whistler
  12. // --------------------------------------------------------------------------
  13. #ifndef _APIDispatcher_
  14. #define _APIDispatcher_
  15. #include "KernelResources.h"
  16. #include "PortMessage.h"
  17. #include "Queue.h"
  18. #include "WorkItem.h"
  19. class CAPIRequest; // This would be circular otherwise
  20. // --------------------------------------------------------------------------
  21. // CAPIDispatcher
  22. //
  23. // Purpose: This class processes requests from a client when signaled to.
  24. // CAPIDispatcher::QueueRequest is called by a thread which
  25. // monitors an LPC port. Once the request is queued an event is
  26. // signaled to wake the thread which processes client requests.
  27. // The thread processes all queued requests and wait for the
  28. // event to be signaled again.
  29. //
  30. // History: 1999-11-07 vtan created
  31. // 2000-08-25 vtan moved from Neptune to Whistler
  32. // --------------------------------------------------------------------------
  33. class CAPIDispatcher : public CWorkItem
  34. {
  35. private:
  36. friend class CCatchCorruptor;
  37. CAPIDispatcher (void);
  38. public:
  39. CAPIDispatcher (HANDLE hClientProcess);
  40. virtual ~CAPIDispatcher (void);
  41. HANDLE GetClientProcess (void) const;
  42. DWORD GetClientSessionID (void) const;
  43. void SetPort (HANDLE hPort);
  44. HANDLE GetSection (void);
  45. void* GetSectionAddress (void) const;
  46. NTSTATUS CloseConnection (void);
  47. NTSTATUS QueueRequest (const CPortMessage& portMessage);
  48. NTSTATUS ExecuteRequest (const CPortMessage& portMessage);
  49. NTSTATUS RejectRequest (const CPortMessage& portMessage, NTSTATUS status) const;
  50. virtual NTSTATUS CreateAndQueueRequest (const CPortMessage& portMessage) = 0;
  51. virtual NTSTATUS CreateAndExecuteRequest (const CPortMessage& portMessage) = 0;
  52. protected:
  53. virtual void Entry (void);
  54. NTSTATUS Execute (CAPIRequest *pAPIRequest) const;
  55. virtual NTSTATUS CreateSection (void);
  56. NTSTATUS SignalRequestPending (void);
  57. private:
  58. NTSTATUS SendReply (const CPortMessage& portMessage) const;
  59. #ifdef DEBUG
  60. static bool ExcludedStatusCodeForDebug (NTSTATUS status);
  61. #endif /* DEBUG */
  62. static LONG WINAPI DispatcherExceptionFilter (struct _EXCEPTION_POINTERS *pExceptionInfo);
  63. protected:
  64. HANDLE _hSection;
  65. void* _pSection;
  66. CQueue _queue;
  67. private:
  68. HANDLE _hProcessClient;
  69. HANDLE _hPort;
  70. bool _fRequestsPending,
  71. _fConnectionClosed;
  72. CCriticalSection _lock;
  73. };
  74. #endif /* _APIDispatcher_ */