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.

310 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. conn.h
  5. Abstract:
  6. Handling connection for applications, which open STI devices
  7. Author:
  8. Vlad Sadovsky (vlads) 10-Feb-1997
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. 26-Feb-1997 VladS created
  13. --*/
  14. #ifndef _STI_CONN_H_
  15. #define _STI_CONN_H_
  16. #include <base.h>
  17. #include <buffer.h>
  18. #include "device.h"
  19. #include "stirpc.h"
  20. /***********************************************************
  21. * Type Definitions
  22. ************************************************************/
  23. #define CONN_SIGNATURE (DWORD)'CONN'
  24. #define CONN_SIGNATURE_FREE (DWORD)'CONf'
  25. #define NOTIFY_SIGNATURE (DWORD)'NOTI'
  26. #define NOTIFY_SIGNATURE_FREE (DWORD)'NOTf'
  27. class STI_NOTIFICATION {
  28. public:
  29. STI_NOTIFICATION::STI_NOTIFICATION(IN LPSTINOTIFY pNotify)
  30. {
  31. Reset();
  32. if (pNotify) {
  33. m_uiAllocSize = pNotify->dwSize;
  34. m_pNotifyData = new BYTE[m_uiAllocSize];
  35. // ASSERT(m_pNotifyData);
  36. if (m_pNotifyData) {
  37. memcpy(m_pNotifyData,(LPBYTE)pNotify,m_uiAllocSize);
  38. m_dwSignature = NOTIFY_SIGNATURE;
  39. m_fValid = TRUE;
  40. }
  41. }
  42. }
  43. STI_NOTIFICATION::~STI_NOTIFICATION()
  44. {
  45. if (IsValid()) {
  46. if (m_pNotifyData) {
  47. delete [] m_pNotifyData;
  48. }
  49. Reset();
  50. }
  51. }
  52. inline BOOL
  53. IsValid(
  54. VOID
  55. )
  56. {
  57. return (m_fValid) && (m_dwSignature == NOTIFY_SIGNATURE);
  58. }
  59. inline VOID
  60. Reset(
  61. VOID
  62. )
  63. {
  64. m_ListEntry.Flink = m_ListEntry.Blink = NULL;
  65. m_uiAllocSize = 0;
  66. m_dwSignature = NOTIFY_SIGNATURE_FREE;
  67. m_fValid = FALSE;
  68. }
  69. inline UINT
  70. QueryAllocSize(
  71. VOID
  72. )
  73. {
  74. return m_uiAllocSize;
  75. }
  76. inline LPBYTE
  77. QueryNotifyData(
  78. VOID
  79. )
  80. {
  81. return m_pNotifyData;
  82. }
  83. LIST_ENTRY m_ListEntry;
  84. private:
  85. DWORD m_dwSignature;
  86. BOOL m_fValid;
  87. UINT m_uiAllocSize;
  88. LPBYTE m_pNotifyData;
  89. };
  90. //
  91. // Flags for connection object
  92. //
  93. #define CONN_FLAG_SHUTDOWN 0x0001
  94. class STI_CONN : public BASE {
  95. friend class TAKE_STI_CONN;
  96. public:
  97. // *** IUnknown methods ***
  98. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  99. STDMETHODIMP_(ULONG) AddRef( void);
  100. STDMETHODIMP_(ULONG) Release( void);
  101. STI_CONN::STI_CONN(
  102. IN LPCTSTR lpszDeviceName,
  103. IN DWORD dwMode,
  104. IN DWORD dwProcessId
  105. );
  106. STI_CONN::~STI_CONN() ;
  107. inline BOOL
  108. IsValid(
  109. VOID
  110. )
  111. {
  112. return (m_fValid) && (m_dwSignature == CONN_SIGNATURE);
  113. }
  114. inline void
  115. EnterCrit(VOID)
  116. {
  117. _try {
  118. EnterCriticalSection(&m_CritSec);
  119. }
  120. _except (EXCEPTION_EXECUTE_HANDLER) {
  121. // What do we do now?
  122. }
  123. }
  124. inline void
  125. LeaveCrit(VOID)
  126. {
  127. LeaveCriticalSection(&m_CritSec);
  128. }
  129. inline DWORD
  130. SetFlags(
  131. DWORD dwNewFlags
  132. )
  133. {
  134. DWORD dwTemp = m_dwFlags;
  135. m_dwFlags = dwNewFlags;
  136. return dwTemp;
  137. }
  138. inline DWORD
  139. QueryFlags(
  140. VOID
  141. )
  142. {
  143. return m_dwFlags;
  144. }
  145. inline HANDLE
  146. QueryID(
  147. VOID
  148. )
  149. {
  150. return m_hUniqueId;
  151. }
  152. inline DWORD
  153. QueryOpenMode(
  154. VOID
  155. )
  156. {
  157. return m_dwOpenMode;
  158. }
  159. BOOL
  160. SetSubscribeInfo(
  161. PLOCAL_SUBSCRIBE_CONTAINER pSubscribe
  162. );
  163. BOOL
  164. QueueNotificationToProcess(
  165. LPSTINOTIFY pStiNotification
  166. );
  167. DWORD
  168. GetNotification(
  169. PVOID pBuffer,
  170. DWORD *pdwSize
  171. );
  172. VOID DumpObject(VOID)
  173. {
  174. /* The cast (char*) m_dwSignature will cause problems in 64bit land.
  175. DPRINTF(DM_TRACE,TEXT("Connection: Dumping itself:this(%X) Sign(%4c) DeviceListEntry(%X,%X,%X) \n \
  176. GlocalListEntry(%X,%X,%X) Ser#(%d)"), \
  177. this,(char *)m_dwSignature,
  178. &m_DeviceListEntry,m_DeviceListEntry.Flink,m_DeviceListEntry.Blink,
  179. &m_GlocalListEntry,m_GlocalListEntry.Flink,m_GlocalListEntry.Blink,
  180. m_dwUniqueId);
  181. */
  182. }
  183. LIST_ENTRY m_GlocalListEntry;
  184. LIST_ENTRY m_DeviceListEntry;
  185. LIST_ENTRY m_NotificationListHead;
  186. DWORD m_dwSignature;
  187. private:
  188. BOOL m_fValid;
  189. CRITICAL_SECTION m_CritSec;
  190. ACTIVE_DEVICE *m_pOpenedDevice;
  191. HANDLE m_hUniqueId;
  192. StiCString strDeviceName;
  193. DWORD m_dwFlags;
  194. DWORD m_dwSubscribeFlags;
  195. DWORD m_dwOpenMode;
  196. DWORD m_dwProcessId;
  197. DWORD m_dwNotificationMessage;
  198. HWND m_hwndProcessWindow;
  199. HANDLE m_hevProcessEvent;
  200. UINT m_uiNotificationMessage;
  201. };
  202. //
  203. // Take connection class
  204. //
  205. class TAKE_STI_CONN
  206. {
  207. private:
  208. STI_CONN* m_pConn;
  209. public:
  210. void Take(void) {m_pConn->EnterCrit();}
  211. void Release(void) {m_pConn->LeaveCrit();}
  212. TAKE_STI_CONN(STI_CONN* pconn) : m_pConn(pconn) { Take(); }
  213. ~TAKE_STI_CONN() { Release(); }
  214. };
  215. BOOL
  216. CreateDeviceConnection(
  217. LPCTSTR pwszDeviceName,
  218. DWORD dwMode,
  219. DWORD dwProcessId,
  220. HANDLE *phConnection
  221. );
  222. //
  223. // Find connection object by given handle
  224. //
  225. BOOL
  226. LookupConnectionByHandle(
  227. HANDLE hConnection,
  228. STI_CONN **ppConnectionObject
  229. );
  230. //
  231. //
  232. // Remove connection object from the list
  233. //
  234. BOOL
  235. DestroyDeviceConnection(
  236. HANDLE lUniqueId,
  237. BOOL fForce
  238. );
  239. #endif // _CONN_H_