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.

209 lines
4.3 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Module: ins.h
  4. //
  5. // Description: KS Instance base class definition
  6. //
  7. //
  8. //@@BEGIN_MSINTERNAL
  9. // Development Team:
  10. // Mike McLaughlin
  11. //
  12. // History: Date Author Comment
  13. //
  14. //@@END_MSINTERNAL
  15. //---------------------------------------------------------------------------
  16. //
  17. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  18. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  19. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  20. // PURPOSE.
  21. //
  22. // Copyright (c) 1996-1999 Microsoft Corporation. All Rights Reserved.
  23. //
  24. //---------------------------------------------------------------------------
  25. //---------------------------------------------------------------------------
  26. // Globals
  27. //---------------------------------------------------------------------------
  28. extern "C" const KSDISPATCH_TABLE DispatchTable;
  29. //---------------------------------------------------------------------------
  30. // Classes
  31. //---------------------------------------------------------------------------
  32. typedef class CInstance
  33. {
  34. friend class ListDoubleField<CInstance>;
  35. public:
  36. CInstance(
  37. IN PPARENT_INSTANCE pParentInstance
  38. );
  39. ~CInstance(
  40. );
  41. static NTSTATUS
  42. DispatchClose(
  43. IN PDEVICE_OBJECT pDeviceObject,
  44. IN PIRP pIrp
  45. );
  46. static NTSTATUS
  47. DispatchForwardIrp(
  48. IN PDEVICE_OBJECT pDeviceObject,
  49. IN PIRP pIrp
  50. );
  51. VOID
  52. Invalidate(
  53. );
  54. PFILE_OBJECT
  55. GetNextFileObject(
  56. )
  57. {
  58. return(pNextFileObject);
  59. };
  60. PPIN_INSTANCE
  61. GetParentInstance( // inline body in pins.h
  62. );
  63. NTSTATUS
  64. SetNextFileObject(
  65. HANDLE handle
  66. )
  67. {
  68. return(ObReferenceObjectByHandle(
  69. handle,
  70. GENERIC_READ | GENERIC_WRITE,
  71. NULL,
  72. KernelMode,
  73. (PVOID*)&pNextFileObject,
  74. NULL));
  75. };
  76. NTSTATUS
  77. DispatchCreate(
  78. IN PIRP pIrp,
  79. IN UTIL_PFN pfnDispatchCreate,
  80. IN OUT PVOID pReference,
  81. IN ULONG cCreateItems = 0,
  82. IN PKSOBJECT_CREATE_ITEM pCreateItems = NULL,
  83. IN const KSDISPATCH_TABLE *pDispatchTable = &DispatchTable
  84. );
  85. VOID GrabMutex()
  86. {
  87. ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
  88. AssertStatus(
  89. KeWaitForMutexObject(pMutex, Executive, KernelMode, FALSE, NULL));
  90. };
  91. VOID ReleaseMutex()
  92. {
  93. ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
  94. KeReleaseMutex(pMutex, FALSE);
  95. };
  96. #ifdef DEBUG
  97. ENUMFUNC
  98. Dump(
  99. )
  100. {
  101. dprintf("CINS: %08x OH %08x PFO %08x NFO %08x NDO %08x PI %08x\n",
  102. this,
  103. pObjectHeader,
  104. pParentFileObject,
  105. pNextFileObject,
  106. pNextDeviceObject,
  107. pParentInstance);
  108. return (STATUS_CONTINUE);
  109. };
  110. ENUMFUNC
  111. DumpAddress(
  112. )
  113. {
  114. Assert(this);
  115. dprintf(" %08x", this);
  116. return(STATUS_CONTINUE);
  117. };
  118. #endif
  119. private:
  120. VOID
  121. AddList(
  122. CListDouble *pld
  123. )
  124. {
  125. ldiNext.AddList(pld);
  126. };
  127. VOID
  128. RemoveList(
  129. )
  130. {
  131. ldiNext.RemoveList();
  132. };
  133. //
  134. // This pointer to the dispatch table is used in the common
  135. // dispatch routines to route the IRP to the appropriate
  136. // handlers. This structure is referenced by the device driver
  137. // with IoGetCurrentIrpStackLocation( pIrp ) -> FsContext
  138. //
  139. PVOID pObjectHeader;
  140. PFILE_OBJECT pParentFileObject;
  141. PDEVICE_OBJECT pNextDeviceObject;
  142. PPARENT_INSTANCE pParentInstance;
  143. PFILE_OBJECT pNextFileObject;
  144. CLIST_DOUBLE_ITEM ldiNext;
  145. KMUTEX *pMutex;
  146. public:
  147. DefineSignature(0x534e4943); // CINS
  148. } INSTANCE, *PINSTANCE;
  149. //---------------------------------------------------------------------------
  150. typedef ListDoubleField<INSTANCE> LIST_INSTANCE, *PLIST_INSTANCE;
  151. //---------------------------------------------------------------------------
  152. typedef class CParentInstance
  153. {
  154. friend class CInstance;
  155. public:
  156. VOID
  157. Invalidate(
  158. );
  159. BOOL
  160. IsChildInstance(
  161. )
  162. {
  163. return(lstChildInstance.IsLstEmpty());
  164. };
  165. #ifdef DEBUG
  166. ENUMFUNC
  167. Dump()
  168. {
  169. lstChildInstance.Dump();
  170. return(STATUS_CONTINUE);
  171. };
  172. ENUMFUNC
  173. DumpAddress()
  174. {
  175. lstChildInstance.DumpAddress();
  176. return(STATUS_CONTINUE);
  177. };
  178. #endif
  179. LIST_INSTANCE lstChildInstance;
  180. DefineSignature(0x52415043); // CPAR
  181. } PARENT_INSTANCE, *PPARENT_INSTANCE;
  182. //---------------------------------------------------------------------------