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.

179 lines
6.9 KiB

  1. //
  2. // LPC.H Local Remote Procedure Call
  3. //
  4. // History:
  5. // 2/27/94 JosephJ Created.
  6. //
  7. //#define NEW_LPC
  8. #ifdef NEW_LPC
  9. enum {
  10. eSRVR_UNREG=0,
  11. eSRVR_IDLE,
  12. eSRVR_BUSY
  13. } SERVER_STATE;
  14. enum {
  15. eCALL_NONE=0,
  16. eCALL_REQUESTED,
  17. eCALL_PROCESSING,
  18. eCALL_ABANDONED,
  19. eCALL_DONE,
  20. eCALL_DONE_ACK
  21. } CALL_STATE;
  22. #define dwSIG_SHARED 0x567D56DBL
  23. #define dwSIG_SERVER 0x50704B2BL
  24. #define dwSIG_CLIENT 0xBF9B1A63L
  25. typedef struct {
  26. DWORD dwSig; // Must be dwSIG_SHARED above
  27. DWORD dwClientIDs; // Bitmap of currently bound client IDs;
  28. DWORD dwSrvrID; // ID of current server.
  29. DWORD dwSrvrState; // SERVER_STATE enum
  30. DWORD dwCallState; // CALL_STATE enum
  31. DWORD dwCallClientID; // ID of client that placed current call.
  32. DWORD dwDataSize; // Size of following data
  33. BYTE rgbData[];
  34. } SHARED_DATA, FAR * LPSHARED_DATA;
  35. #endif // NEW_LPC
  36. typedef struct {
  37. // Service name
  38. char rgchService[MAX_PATHNAME_SIZE+1];
  39. // Shared Memory
  40. HANDLE hMap; // hMap of shared data.
  41. HANDLE hMtx; // Controls access to the shared data.
  42. // Created by anyone (thread that
  43. // created it is responsible for initializing the
  44. // shared memory it guards).
  45. // Only the server can grab it for extended periods
  46. // of time -- precisely when it is processing a call.
  47. BOOL fGrabbed; // True if mutex grabbed by this process.
  48. // Events;
  49. HANDLE hevSrvrFree;// Used to signal to clients that the server is idle.
  50. // AUTO reset, created non-signalled by anyone.
  51. HANDLE hevCallAvail;// Used to signal to the server that a call is avilable
  52. // Manual reset. Created non-signalled by anyone.
  53. HANDLE hevCallDone; // If Server: event of client that placed current
  54. // call. Used to signal to the client that it's
  55. // call is done. It is also used determine if the
  56. // client is still around by trying to open this
  57. // named event.
  58. // If Client: it's event, signalled by server. Created
  59. // when calling ClientBind.
  60. // Manual reset. ONE per client. Created nonsignalled
  61. // by client when doing a ClientBind.
  62. HANDLE hevCallDoneAck; // Used to signal to the server that the call-done
  63. // has been picked up by the client.
  64. // Manual reset. Created non-signalled by anyone.
  65. #ifdef NEW_LPC
  66. LPSHARED_DATA lpSharedData; // Pointer to shared data.
  67. DWORD dwSrvrID; // Server: My ID; Client: Server I last dealt with.
  68. DWORD dwClientID; // Server: Client I last dealt with. Server: My ID.
  69. #else // !NEW_LPC
  70. DWORD dwSharedDataSize;
  71. LPVOID lpvSharedData;
  72. // Events
  73. HANDLE hevSrvcReg;
  74. enum {eSS_UNDEF=0, eSS_REG, eSS_UNREG} eState;
  75. #endif // !NEW_LPC
  76. } SHARED_STATE, FAR * LPSHARED_STATE;
  77. typedef struct {
  78. #ifdef NEW_LPC
  79. DWORD dwSig; // MUST be dwSIG_SERVER above.
  80. #else // !NEW_LPC
  81. DWORD dwInstanceID;
  82. enum {eS_UNINIT=0, eS_INIT} eState;
  83. #endif // !NEW_LPC
  84. HANDLE hDummyEvent;
  85. SHARED_STATE SState;
  86. } SERVER_LOCAL_STATE, FAR * LPSERVER_LOCAL_STATE;
  87. typedef struct {
  88. #ifdef NEW_LPC
  89. DWORD dwSig; // MUST be dwSIG_CLIENT above.
  90. #else NEW_LPC
  91. DWORD dwInstanceID;
  92. DWORD dwServerInstanceID;
  93. #endif //!NEW_LPC
  94. SHARED_STATE SState;
  95. } CLIENT_LOCAL_STATE, FAR * LPCLIENT_LOCAL_STATE;
  96. typedef void (FAR *LPFNCALLHANDLER)(DWORD dwID,
  97. DWORD dwDataSize, LPBYTE lpbData);
  98. // Server call handling function.
  99. BOOL ServerRegister(LPSTR lpszService, LPSERVER_LOCAL_STATE);
  100. // Registers a server. Only one server can be registered for
  101. // a particular service name.
  102. // Initializes server_local_state. Returns TRUE on success.
  103. BOOL ServerUnRegister(LPSERVER_LOCAL_STATE);
  104. // Unregisters the service. Invalidates data in server_local_state.
  105. // Returns true on success.
  106. #ifdef NEW_LPC
  107. BOOL ClientCheckIfServerPresent(LPSTR lpszService);
  108. // Returns true iff a server for this service exists. May be called
  109. // at any time (even before ClientBind). It may be used for the client
  110. // to determine whether to launch the server.
  111. // This is not foolproof: for example, the server may exit just after
  112. // this call returns true, or the server may exist, but be hung.
  113. #endif // NEW_LPC
  114. BOOL ClientBind(LPSTR lpszService, DWORD dwTimeout, LPCLIENT_LOCAL_STATE);
  115. // Binds to the specified service, initializes client_local_state.
  116. // Returns TRUE on success.
  117. BOOL ClientUnBind(LPCLIENT_LOCAL_STATE lpClient);
  118. // Binds from the specified service.
  119. // Returns TRUE on success.
  120. BOOL ClientMakeCall(LPCLIENT_LOCAL_STATE, DWORD dwTimeout,
  121. DWORD dwID, DWORD dwSize, LPBYTE lpbData);
  122. // Returns only when complete...
  123. // Copies all data to shared mem, and copies back when
  124. // done. Never times out. Returns FALSE if there was
  125. // some problem with the rpc system, or if bad parameters.
  126. BOOL ClientMakeCallEx(LPSTR lpszService, DWORD dwID, DWORD dwSize, LPBYTE lpbData);
  127. // Immediate binding version of ClientMakeCall.
  128. // Returns only when complete...
  129. // Copies all data to shared mem, and copies back when
  130. // done. Never times out. Returns FALSE if there was
  131. // some problem with the rpc system, or if bad parameters.
  132. BOOL ServerListen(LPSERVER_LOCAL_STATE, LPFNCALLHANDLER, HANDLE hev2, DWORD dwTimeout);
  133. // Blocks until call received, then
  134. // calls lpfnCallHandler(id,size,data) once and returns when call is
  135. // handled. Returns FALSE iff listen timed out. The intension here
  136. // is for the server to repeatedly call ServerListen. Each time
  137. // either one call is handled or the function times out.
  138. // Following functions are for calling only by LibEntry, on process
  139. // Creation and termination.... When the LPC functionality is moved
  140. // into a separate DLL, this will migrate into an internal header file.
  141. void LPCInternalInit(void);
  142. void LPCInternalDeInit(void);