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.

204 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. cmmsprop.h
  5. Abstract:
  6. This module contains the definition of the special property class
  7. Author:
  8. Keith Lau (keithlau@microsoft.com)
  9. Revision History:
  10. keithlau 04/19/98 created
  11. --*/
  12. #ifndef _CMMVPROP_H_
  13. #define _CMMVPROP_H_
  14. #include "propid.h"
  15. // Define a generic accessor function to access special properties
  16. typedef HRESULT (*GET_ACCESSOR_FUNCTION)(
  17. PROP_ID idProp,
  18. LPVOID pContext,
  19. LPVOID pParam,
  20. DWORD cbLength,
  21. LPDWORD pcbLength,
  22. LPBYTE pbBuffer
  23. );
  24. typedef HRESULT (*PUT_ACCESSOR_FUNCTION)(
  25. PROP_ID idProp,
  26. LPVOID pContext,
  27. LPVOID pParam,
  28. DWORD cbLength,
  29. LPBYTE pbBuffer
  30. );
  31. // Define the property item structure
  32. //
  33. // Note: In this implementation, all special properties are volatile
  34. // We can do Serialize() and Restore() operations in the future if we want.
  35. //
  36. typedef struct _SPECIAL_PROPERTY_ITEM
  37. {
  38. PROP_ID idProp; // Property ID of property
  39. DWORD ptBaseType:16; // Lowest 16 bits: property type
  40. DWORD fAccess:15; // Upper 15 bits: access rights
  41. DWORD fVolatile:1; // MSB: TRUE if property is volatile
  42. GET_ACCESSOR_FUNCTION pfnGetAccessor; // Accessor to get property value
  43. PUT_ACCESSOR_FUNCTION pfnPutAccessor; // Accessor to set property value
  44. } SPECIAL_PROPERTY_ITEM, *LPSPECIAL_PROPERTY_ITEM;
  45. // Define a generic structure to define a set of properties
  46. typedef struct _PTABLE
  47. {
  48. LPSPECIAL_PROPERTY_ITEM pProperties; // Actual property table
  49. DWORD dwProperties; // Count
  50. BOOL fIsSorted; // Prop table sorted by PROP_ID?
  51. } PTABLE, *LPPTABLE;
  52. // Enumerated types representing type of access on property
  53. typedef enum _PROPERTY_ACCESS
  54. {
  55. PA_NONE = 0,
  56. PA_READ = 1,
  57. PA_WRITE = 2,
  58. PA_READ_WRITE = PA_READ | PA_WRITE,
  59. PA_MAXPA
  60. } _PROPERTY_ACCESS;
  61. // Enumerated types representing property types
  62. typedef enum _PROPERTY_DATA_TYPES
  63. {
  64. PT_NONE = 0,
  65. PT_STRING,
  66. PT_DWORD,
  67. PT_BOOL,
  68. PT_INTERFACE,
  69. PT_MAXPT
  70. } PROPERTY_DATA_TYPES;
  71. // =================================================================
  72. // class for searching special properties
  73. //
  74. class CSpecialPropertyTable
  75. {
  76. public:
  77. CSpecialPropertyTable(
  78. LPPTABLE pPropertyTable
  79. );
  80. ~CSpecialPropertyTable();
  81. //
  82. // Synopsis:
  83. // Method to retrieve a special property item, if exists in the
  84. // special property table.
  85. //
  86. // Arguments:
  87. // idProp - Property ID
  88. // pContext - context for accessor function
  89. // ptBaseType - one of the values in PROPERTY_DATA_TYPES. If specified,
  90. // this type will be checked against the base type of the special
  91. // property. A perfect type match would then be required. If this
  92. // is PT_NONE, then a type check is not performed.
  93. // cbLength - length of buffer provided
  94. // pcbLength - returns length of property value
  95. // pbBuffer - buffer to receive property value
  96. // fCheckAccess - [optional] TRUE if the caller wants an access check on
  97. // the property, FALSE (default) skips the check
  98. //
  99. // Return values:
  100. // S_OK - success, the specified property if found and its value returned
  101. // S_FALSE - success, the specified property is not found in the table
  102. // E_INVALIDARG - error, one or more arguments are invalid
  103. // E_ACCESSDENIED - error, desired access to the specified property is
  104. // denied
  105. // TYPE_E_TYPEMISMATCH - error, a specific data type is given, but the
  106. // specified and actual types don't match
  107. // HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) - error, the specified
  108. // buffer is not large enough to hold the property value.
  109. // *pcbLength should contain the required length in bytes.
  110. // Or any other HRESULT from the get accessor
  111. //
  112. HRESULT GetProperty(
  113. PROP_ID idProp,
  114. LPVOID pContext,
  115. LPVOID pParam,
  116. DWORD ptBaseType,
  117. DWORD cbLength,
  118. DWORD *pcbLength,
  119. LPBYTE pbBuffer,
  120. BOOL fCheckAccess = FALSE
  121. );
  122. //
  123. // Synopsis:
  124. // Method to set a special property item, if exists in the
  125. // special property table.
  126. //
  127. // Arguments:
  128. // idProp - Property ID
  129. // pContext - context for accessor function
  130. // ptBaseType - one of the values in PROPERTY_DATA_TYPES. If specified,
  131. // this type will be checked against the base type of the special
  132. // property. A perfect type match would then be required. If this
  133. // is PT_NONE, then a type check is not performed.
  134. // cbLength - length of buffer provided
  135. // pcbLength - returns length of property value
  136. // pbBuffer - buffer to receive property value
  137. // fCheckAccess - [optional] TRUE if the caller wants an access check on
  138. // the property, FALSE (default) skips the check
  139. //
  140. // Return values:
  141. // S_OK - success, the specified property if found and its value is set
  142. // S_FALSE - success, the specified property is not found in the table
  143. // E_INVALIDARG - error, one or more arguments are invalid
  144. // E_ACCESSDENIED - error, desired access to the specified property is
  145. // denied
  146. // TYPE_E_TYPEMISMATCH - error, a specific data type is given, but the
  147. // specified and actual types don't match
  148. // Or any other HRESULT from the put accessor
  149. //
  150. HRESULT PutProperty(
  151. PROP_ID idProp,
  152. LPVOID pContext,
  153. LPVOID pParam,
  154. DWORD ptBaseType,
  155. DWORD cbLength,
  156. LPBYTE pbBuffer,
  157. BOOL fCheckAccess = FALSE
  158. );
  159. private:
  160. // Method to search the property table and return the associated
  161. // property item, if found
  162. LPSPECIAL_PROPERTY_ITEM SearchForProperty(
  163. PROP_ID idProp
  164. );
  165. // Pointer to property table and count of items
  166. LPSPECIAL_PROPERTY_ITEM m_pProperties;
  167. DWORD m_dwProperties;
  168. // TRUE if the table of properties is sorted, will use
  169. // binary search if so. Otherwise, a linear scan is performed
  170. BOOL m_fIsSorted;
  171. };
  172. #endif