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.

270 lines
6.5 KiB

  1. /* ----------------------------------------------------------------------
  2. Module: ULS.DLL (Service Provider)
  3. File: sppqueue.h
  4. Content: This file contains the pending item/queue objects definition.
  5. History:
  6. 10/15/96 Chu, Lon-Chan [lonchanc]
  7. Created.
  8. Copyright (c) Microsoft Corporation 1996-1997
  9. ---------------------------------------------------------------------- */
  10. #ifndef _ILS_SP_PRQUEUE_H_
  11. #define _ILS_SP_PRQUEUE_H_
  12. #include <pshpack8.h>
  13. /* ------------- Request Scheduler --------------- */
  14. #define WM_ILS_REFRESH ((ULONG) -1)
  15. typedef struct tagReqMarshal
  16. {
  17. struct tagReqMarshal *next;
  18. ULONG cbTotalSize; // for debug checking
  19. BYTE *pb; // running pointer
  20. ULONG uRespID; // for cancel and error notification
  21. ULONG uNotifyMsg;
  22. ULONG cParams;
  23. DWORD_PTR aParams[1];
  24. // more data follows...
  25. }
  26. MARSHAL_REQ;
  27. MARSHAL_REQ *MarshalReq_Alloc ( ULONG uNotifyMsg, ULONG cbSize, ULONG cParams );
  28. HRESULT MarshalReq_SetParam ( MARSHAL_REQ *p, ULONG nIndex, DWORD_PTR dwParam, ULONG cbParamSize );
  29. DWORD_PTR MarshalReq_GetParam ( MARSHAL_REQ *p, ULONG nIndex );
  30. HRESULT MarshalReq_SetParamServer ( MARSHAL_REQ *p, ULONG nIndex, SERVER_INFO *pServer, ULONG cbServer );
  31. enum { INVALID_RESP_ID = -1 };
  32. class SP_CRequestQueue
  33. {
  34. friend class SP_CResponseQueue;
  35. friend HRESULT UlsLdap_Cancel ( ULONG );
  36. public:
  37. SP_CRequestQueue ( VOID );
  38. ~SP_CRequestQueue ( VOID );
  39. HRESULT Enter ( MARSHAL_REQ *p );
  40. VOID Schedule ( VOID );
  41. VOID Dispatch ( MARSHAL_REQ *p );
  42. HRESULT Cancel ( ULONG uRespID );
  43. BOOL IsEmptyQueue ( VOID ) { return (m_ItemList == NULL); }
  44. BOOL IsAnyReqInQueue ( VOID ) { return (m_ItemList != NULL); }
  45. BOOL IsCurrentRequestCancelled ( VOID ) { return (m_uCurrOpRespID == INVALID_RESP_ID); }
  46. protected:
  47. VOID LockCurrOp ( VOID ) { EnterCriticalSection (&m_csCurrOp); }
  48. VOID UnlockCurrOp ( VOID ) { LeaveCriticalSection (&m_csCurrOp); }
  49. VOID WriteLock ( VOID ) { EnterCriticalSection (&m_csReqQ); }
  50. VOID WriteUnlock ( VOID ) { LeaveCriticalSection (&m_csReqQ); }
  51. private:
  52. VOID ReadLock ( VOID ) { WriteLock (); }
  53. VOID ReadUnlock ( VOID ) { WriteUnlock (); }
  54. MARSHAL_REQ *m_ItemList;
  55. CRITICAL_SECTION m_csReqQ;
  56. ULONG m_uCurrOpRespID;
  57. CRITICAL_SECTION m_csCurrOp;
  58. };
  59. extern SP_CRequestQueue *g_pReqQueue;
  60. /* ------------- Response Scheduler --------------- */
  61. #define ILS_MIN_RESP_TIMEOUT ((ULONG) (20 * 1000)) // 20 seconds
  62. #define ILS_DEF_RESP_TIMEOUT ((ULONG) (90 * 1000)) // 90 seconds
  63. #define ILS_BK_RESP_TIMEOUT_SEC 90 // 90 seconds
  64. extern ULONG g_uResponseTimeout;
  65. #define ILS_MIN_RESP_POLL_PERIOD ((ULONG) 50) // 50 ms
  66. #define ILS_DEF_RESP_POLL_PERIOD ((ULONG) 100) // 100 ms per PatLam's experiment
  67. extern ULONG g_uResponsePollPeriod;
  68. #define Minute2TickCount(m) ((m) * 60 * 1000)
  69. #define ILS_DEF_REFRESH_MINUTE 2
  70. #define ILS_DEF_REFRESH_MARGIN_MINUTE 2
  71. typedef struct
  72. {
  73. // ldap specific
  74. LDAP *ld;
  75. ULONG uMsgID[2];
  76. // notification specific
  77. ULONG uRespID;
  78. ULONG uNotifyMsg;
  79. // object specific
  80. HANDLE hObject; // user, app, prot object
  81. // mutual dependency specific
  82. HRESULT hrDependency; // S_OK if not used
  83. // for extended attributes
  84. ULONG cAnyAttrs;
  85. TCHAR *pszAnyAttrNameList;
  86. // for resolving protocol
  87. TCHAR *pszProtNameToResolve;
  88. }
  89. RESP_INFO;
  90. class SP_CResponse
  91. {
  92. friend class SP_CResponseQueue;
  93. public:
  94. SP_CResponse ( VOID );
  95. ~SP_CResponse ( VOID );
  96. LDAPMessage *GetResult ( VOID ) { return m_pLdapMsg; }
  97. RESP_INFO *GetRespInfo ( VOID ) { return &m_ri; }
  98. SP_CSession *GetSession ( VOID ) { return m_pSession; }
  99. LDAP *GetLd ( VOID ) { return m_ri.ld; }
  100. protected:
  101. VOID EnterResult ( LDAPMessage *pLdapMsg );
  102. VOID EnterRequest ( SP_CSession *pSession, RESP_INFO *pInfo )
  103. {
  104. m_pSession = pSession;
  105. m_ri = *pInfo;
  106. m_tcTimeout = m_pSession->GetServerTimeoutInTickCount ();
  107. }
  108. SP_CResponse *GetNext ( VOID ) { return m_next; }
  109. VOID SetNext ( SP_CResponse *pItem ) { m_next = pItem; }
  110. private:
  111. VOID UpdateLastModifiedTime ( VOID ) { m_tcLastModifiedTime = GetTickCount (); }
  112. BOOL IsExpired ( VOID ) { return (GetTickCount () - m_tcLastModifiedTime >= m_tcTimeout); }
  113. RESP_INFO m_ri;
  114. SP_CSession *m_pSession;
  115. LDAPMessage *m_pLdapMsg;
  116. SP_CResponse *m_next;
  117. ULONG m_tcLastModifiedTime;
  118. ULONG m_tcTimeout;
  119. };
  120. class SP_CResponseQueue
  121. {
  122. friend class SP_CRequestQueue;
  123. friend HRESULT UlsLdap_Cancel ( ULONG );
  124. public:
  125. SP_CResponseQueue ( VOID );
  126. ~SP_CResponseQueue ( VOID );
  127. HRESULT EnterRequest ( SP_CSession *pSession, RESP_INFO *pInfo );
  128. HRESULT PollLdapResults ( LDAP_TIMEVAL *pTimeout );
  129. HRESULT Cancel ( ULONG uRespID );
  130. protected:
  131. VOID WriteLock ( VOID ) { EnterCriticalSection (&m_csRespQ); }
  132. VOID WriteUnlock ( VOID ) { LeaveCriticalSection (&m_csRespQ); }
  133. private:
  134. VOID ReadLock ( VOID ) { WriteLock (); }
  135. VOID ReadUnlock ( VOID ) { WriteUnlock (); }
  136. SP_CResponse *m_ItemList;
  137. CRITICAL_SECTION m_csRespQ;
  138. };
  139. extern SP_CResponseQueue *g_pRespQueue;
  140. VOID FillDefRespInfo ( RESP_INFO *pInfo, ULONG uRespID, LDAP *ld, ULONG uMsgID, ULONG u2ndMsgID );
  141. /* ------------- Refersh Message Scheduler --------------- */
  142. class SP_CRefreshScheduler
  143. {
  144. public:
  145. SP_CRefreshScheduler ( VOID );
  146. ~SP_CRefreshScheduler ( VOID );
  147. HRESULT SendRefreshMessages ( UINT uTimerID );
  148. HRESULT EnterClientObject ( SP_CClient *pClient );
  149. HRESULT RemoveClientObject ( SP_CClient *pClient ) { return RemoveObject ((VOID *) pClient); }
  150. #ifdef ENABLE_MEETING_PLACE
  151. HRESULT EnterMtgObject ( SP_CMeeting *pMtg );
  152. HRESULT RemoveMtgObject ( SP_CMeeting *pMtg ) { return RemoveObject ((VOID *) pMtg); }
  153. #endif
  154. protected:
  155. private:
  156. VOID WriteLock ( VOID ) { EnterCriticalSection (&m_csRefreshScheduler); }
  157. VOID WriteUnlock ( VOID ) { LeaveCriticalSection (&m_csRefreshScheduler); }
  158. VOID ReadLock ( VOID ) { WriteLock (); }
  159. VOID ReadUnlock ( VOID ) { WriteUnlock (); }
  160. typedef enum { UNK_OBJ, CLIENT_OBJ, MTG_OBJ } PrivateObjType;
  161. typedef struct tagREFRESH_ITEM
  162. {
  163. INT nIndex;
  164. PrivateObjType ObjectType;
  165. VOID *pObject;
  166. ULONG uTTL;
  167. struct tagREFRESH_ITEM *next;
  168. }
  169. REFRESH_ITEM;
  170. INT TimerID2Index ( UINT uTimerID ) { return (INT) uTimerID - KEEP_ALIVE_TIMER_BASE; }
  171. UINT Index2TimerID ( INT nIndex ) { return (UINT) (nIndex + KEEP_ALIVE_TIMER_BASE); }
  172. VOID *AllocItem ( BOOL fNeedLock );
  173. HRESULT EnterObject ( PrivateObjType ObjectType, VOID *pObject, ULONG uInitialTTL );
  174. HRESULT RemoveObject ( VOID *pObject );
  175. REFRESH_ITEM *m_ListHead;
  176. CRITICAL_SECTION m_csRefreshScheduler;
  177. };
  178. extern SP_CRefreshScheduler *g_pRefreshScheduler;
  179. #include <poppack.h>
  180. #endif // _ILS_SP_PRQUEUE_H_
  181.