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.

388 lines
14 KiB

  1. /*
  2. * File HMCACHE.H
  3. *
  4. * Facility:
  5. *
  6. * Windows NT SNMP Extension Agent
  7. *
  8. * Abstract:
  9. *
  10. * This module is contains definitions pertaining to the HostMIB
  11. * cacheing mechanism.
  12. *
  13. * Author:
  14. *
  15. * D. D. Burns @ WebEnable, Inc.
  16. *
  17. *
  18. * Revision History:
  19. *
  20. * V1.0 - 04/17/97 D. D. Burns Original Creation
  21. */
  22. #ifndef hmcache_h
  23. #define hmcache_h
  24. /*
  25. |==============================================================================
  26. | Debug Cache Dump Support
  27. |
  28. | Define "CACHE_DUMP" to get function "PrintCache" defined to enable
  29. | debug-dumping of any cache for which a debug_print function is defined
  30. | (in a CACHEHEAD_INSTANCE() macro that defines the list-head of the cache).
  31. |
  32. | Define "DUMP_FILE" to specify where the dump file is generated. All
  33. | opens on this file are for "append", so you must explicitly delete the
  34. | file if you want to start fresh. All entries are time-stamped, so any
  35. | confusion is your own, though.
  36. |
  37. | NOTE 1: After defining "CACHE_DUMP", grep the sources to see what caches
  38. | "PrintCache()" may be being invoked on and where. Typically
  39. | all caches are dumped immediately after they are built. The
  40. | cache for hrSWRun(Perf) table is re-built if it is older than
  41. | "CACHE_MAX_AGE" (defined in "HRSWRUNE.C") when a request for
  42. | something in the tables served by the cache comes in. So it
  43. | may also be dumped after each (re-)build.
  44. |
  45. | NOTE 2: Define "PROC_CACHE" to get a periodic dump to "PROC_FILE" of
  46. | the hrProcessorLoad-specific cache. This dump occurs on a
  47. | 1-minute timer and will rapidly use up disk space if left
  48. | running for any long period. This cache and dump is special
  49. | to the "hrProcessorLoad" variable in hrProcessor sub-table.
  50. | (Opens on this file are also for "append").
  51. */
  52. //#define CACHE_DUMP 1
  53. #define DUMP_FILE \
  54. "c:\\nt\\private\\net\\snmp\\subagent\\hostmib\\HostMib_Cache.dmp"
  55. //#define PROC_CACHE 1
  56. #define PROC_FILE \
  57. "c:\\nt\\private\\net\\snmp\\subagent\\hostmib\\Processor_Cache.dmp"
  58. #if defined(CACHE_DUMP) || defined(PROC_CACHE)
  59. #include <stdio.h>
  60. #include <time.h>
  61. #endif
  62. /*
  63. |==============================================================================
  64. | hrStorage Attribute Defines
  65. |
  66. | Each attribute defined for hrStorage table is associated with one of the
  67. | #defines below. These symbols are used as C indices into the list of
  68. | attributes within a cached-row.
  69. |
  70. | These symbols are globally accessible so that logic that builds hrFSTable
  71. | can "peek" at values stored in the hrStorageTable cache.
  72. */
  73. #define HRST_INDEX 0 // hrStorageIndex
  74. #define HRST_TYPE 1 // hrStorageType
  75. #define HRST_DESCR 2 // hrStorageDescr
  76. #define HRST_ALLOC 3 // hrStorageAllocationUnits
  77. #define HRST_SIZE 4 // hrStorageSize
  78. #define HRST_USED 5 // hrStorageUsed
  79. #define HRST_FAILS 6 // hrStorageAllocationFailures
  80. //-->Add more here, change count below!
  81. #define HRST_ATTRIB_COUNT 7
  82. /*
  83. |==============================================================================
  84. | hrFSTable Attribute Defines
  85. |
  86. | Each attribute defined for hrFSTable is associated with one of the
  87. | #defines below. These symbols are used as C indices into the array of
  88. | attributes within a cached-row.
  89. |
  90. | These symbols are globally accessible so that logic that builds
  91. | hrPartition can "peek" at values stored in the hrFSEntry Table cache.
  92. */
  93. #define HRFS_INDEX 0 // hrFSIndex
  94. #define HRFS_MOUNTPT 1 // hrFSMountPoint
  95. #define HRFS_RMOUNTPT 2 // hrFSRemoteMountPoint
  96. #define HRFS_TYPE 3 // hrFSType
  97. #define HRFS_ACCESS 4 // hrFSAccess
  98. #define HRFS_BOOTABLE 5 // hrFSBootable
  99. #define HRFS_STORINDX 6 // hrFSStorageIndex
  100. #define HRFS_LASTFULL 7 // hrFSLastFullBackupDate
  101. #define HRFS_LASTPART 8 // hrFSLastPartialBackupDate
  102. //-->Add more here, change count below!
  103. #define HRFS_ATTRIB_COUNT 9
  104. /*
  105. |==============================================================================
  106. | hrSWRun(Perf) Table Attribute Defines
  107. |
  108. | Each attribute defined for hrSWRun Table and hrSWRunPerf Table is
  109. | associated with one of the #defines below. These symbols are used as
  110. | C indices into the array of attributes within a cached-row.
  111. |
  112. | These symbols are globally accessible so that logic for hrSWRunPerf table
  113. | (in "HRSWPREN.C") can reference these as well as logic for hrSWRun table
  114. | (in "HRSWRUNE.C") since both tables share the same cache.
  115. |
  116. | Note that "HrSWRunID" is not cached.
  117. */
  118. #define HRSR_INDEX 0 // HrSWRunIndex
  119. #define HRSR_NAME 1 // HrSWRunName
  120. #define HRSR_PATH 2 // HrSWRunPath
  121. #define HRSR_PARAM 3 // HRSWRunParameters
  122. #define HRSR_TYPE 4 // HrSWRunType
  123. #define HRSR_STATUS 5 // HrSWRunStatus
  124. #define HRSP_CPU 6 // HrSWRunPerfCPU - Performance
  125. #define HRSP_MEM 7 // HrSWRunPerfMem - Performance
  126. //-->Add more here, change count below!
  127. #define HRSR_ATTRIB_COUNT 8
  128. /*
  129. |==============================================================================
  130. | These structures are used in the implementation of an in-memory cache
  131. | for the Host Resources MIB subagent. For a broad overview of the cache
  132. | scheme, see the documentation at the front of "HMCACHE.C".
  133. |==============================================================================
  134. */
  135. /*
  136. |==============================================================================
  137. | ATTRIB_TYPE
  138. |
  139. | This enumerated type lists the data-type of a value of an attribute
  140. | stored in an instance of a ATTRIB structure (one of typically many
  141. | in a CACHEROW structure for a given table row).
  142. |
  143. | "CA_STRING"
  144. | The value is a null-terminated string sitting in 'malloc'ed storage
  145. | within an ATTRIB structure.
  146. |
  147. | "CA_NUMBER"
  148. | The value is a binary numeric value stored directly in the ATTRIB
  149. | structure. No additional malloc storage is associated with this
  150. | type.
  151. |
  152. | "CA_COMPUTED"
  153. | The value is not stored in the ATTRIB structure at all, but is
  154. | dynamic and is computed and returned by the support subagent
  155. | "get" function.
  156. |
  157. | "CA_CACHE"
  158. | The value is a pointer to a CACHEHEAD structure that describes
  159. | another cache. The CACHEHEAD structure is in 'malloc'ed storage.
  160. | This is used for "multiply-indexed" tables.
  161. |
  162. | Note that the instance of this enumerated type (in ATTRIB below) is mainly
  163. | of use in debugging and memory management (when we get to the point where
  164. | cached-rows may be freed). Generally the "Get" function that is going to
  165. | reach into the cache is already going to be coded according to what is
  166. | there, and may not even look to see what "type" the value is.
  167. |==============================================================================
  168. */
  169. typedef
  170. enum {
  171. CA_UNKNOWN, /* Not yet set */
  172. CA_STRING, /* ('malloc'ed storage) */
  173. CA_NUMBER, /* (no 'malloc'ed storage) */
  174. CA_COMPUTED, /* (no 'malloc'ed storage) */
  175. CA_CACHE /* ('malloc'ed storage) */
  176. } ATTRIB_TYPE;
  177. /*
  178. |==============================================================================
  179. | ATTRIB
  180. |
  181. | An array of these structures is logically allocated inside each
  182. | instance of a CACHEROW structure.
  183. |
  184. | An instance of this structure describes the value of one attribute
  185. | in the cache (in general; in the "CA_COMPUTED" case there is no value
  186. | present, the GET function "knows" what to do).
  187. |==============================================================================
  188. */
  189. typedef
  190. struct {
  191. ATTRIB_TYPE attrib_type; /* STRING, NUMBER, (COMPUTED) */
  192. union {
  193. LPSTR string_value; /* CA_STRING (malloc) */
  194. ULONG unumber_value; /* CA_NUMBER (unsigned) */
  195. LONG number_value; /* CA_NUMBER (signed) */
  196. void *cache; /* CA_CACHE (malloc) */
  197. } u;
  198. } ATTRIB;
  199. /*
  200. |==============================================================================
  201. | CACHEROW
  202. |
  203. | An instance of this structure occurs for each row in a table. Instances
  204. | are strung on a list maintained by a CACHEHEAD structure (below), ordered
  205. | by the value of "index".
  206. |
  207. | The "attrib_list[]" array storage is malloc'ed to the appropriate size
  208. | at the time an instance of this structure is created. The indices into
  209. | this array are #DEFINED symbols, all according to the table definition
  210. | of the attributes in the table. Typically the #defines are placed in
  211. | the source module that implements the table.
  212. |
  213. | The internal arrangement of this structure (and underlying structures)
  214. | is meant to be such that function "DestroyTableRow()" can release all
  215. | storage for an instance of this structure without "knowing" the #DEFINE
  216. | index symbols above (or anything else).
  217. |==============================================================================
  218. */
  219. typedef
  220. struct rc_tag{
  221. ULONG index; /* SNMP index of table */
  222. struct rc_tag *next; /* Next in the cache list */
  223. /*
  224. | Contents of this table row:
  225. */
  226. ULONG attrib_count; /* # of elements in "attrib_list"[] */
  227. ATTRIB *attrib_list; /* --> array of attributes */
  228. } CACHEROW;
  229. /*
  230. |==============================================================================
  231. | CACHEHEAD
  232. |
  233. | An instance of this structure (created by the macro CACHEHEAD_INSTANCE)
  234. | occurs for each SNMP "table" cached.
  235. |
  236. | All CACHEROW elements of the list are ordered by their index values
  237. | as they are inserted by general function "AddTableRow()".
  238. |
  239. | See documentation in "HMCACHE.C".
  240. |
  241. |NOTE: If you modify this structure or the macro that initializes static
  242. | instances of it, be sure to add/change code in "HRPARTIT.C" where
  243. | instances in dynamic (malloc) memory are created.
  244. |==============================================================================
  245. */
  246. typedef
  247. struct {
  248. ULONG list_count; /* (Mainly for ease of debugging) */
  249. CACHEROW *list; /* The row list itself */
  250. void (*print_row)(); /* Debug Print-A-Row function */
  251. } CACHEHEAD;
  252. #if defined(CACHE_DUMP)
  253. #define CACHEHEAD_INSTANCE(name,debug_print) \
  254. CACHEHEAD name={ 0, NULL, debug_print };
  255. #else
  256. #define CACHEHEAD_INSTANCE(name,debug_print) \
  257. CACHEHEAD name={ 0, NULL, NULL };
  258. #endif
  259. /*
  260. |==============================================================================
  261. | HMCACHE.C - Function Prototypes
  262. */
  263. /* CreateTableRow - Create a CACHEROW structure for attributes in a table */
  264. CACHEROW *
  265. CreateTableRow(
  266. ULONG attribute_count
  267. );
  268. /* DestroyTable - Destroy all rows in CACHEHEAD structure (Release Storage) */
  269. void
  270. DestroyTable(
  271. CACHEHEAD *cache /* Cache whose rows are to be Released */
  272. );
  273. /* DestroyTableRow - Destroy a CACHEROW structure (Release Storage) */
  274. void
  275. DestroyTableRow(
  276. CACHEROW *row /* Row to be Released */
  277. );
  278. /* AddTableRow - Adds a specific "row" into a cached "table" */
  279. BOOL
  280. AddTableRow(
  281. ULONG index, /* Index for row desired */
  282. CACHEROW *row, /* Row to be added to .. */
  283. CACHEHEAD *cache /* this cache */
  284. );
  285. /* FindTableRow - Finds a specific "row" in a cached "table" */
  286. CACHEROW *
  287. FindTableRow(
  288. ULONG index, /* Index for row desired */
  289. CACHEHEAD *cache /* Table cache to search */
  290. );
  291. /* FindNextTableRow - Finds Next row after a specific "row" in a cache */
  292. CACHEROW *
  293. FindNextTableRow(
  294. ULONG index, /* Index for row desired */
  295. CACHEHEAD *cache /* Table cache to search */
  296. );
  297. /* GetNextTableRow - Gets Next row after a specific "row" or NULL if none */
  298. #define GetNextTableRow(row) row->next
  299. /* ====== DEBUG DUMP SUPPORT ====== */
  300. #if defined(CACHE_DUMP)
  301. /* PrintCache - Dumps for debugging the contents of a cache */
  302. void
  303. PrintCache(
  304. CACHEHEAD *cache /* Table cache to dump */
  305. );
  306. /* Debug Print Output channel used by PrintCache & "Print-A-Row" functions*/
  307. #define OFILE Ofile
  308. extern FILE *Ofile;
  309. #endif
  310. /*
  311. |==============================================================================
  312. | Function Prototypes for cache-related function found in other modules:
  313. */
  314. /* Gen_Hrstorage_Cache - Generate a initial cache for HrStorage Table */
  315. BOOL Gen_Hrstorage_Cache( void ); /* "HRSTOENT.C" */
  316. extern CACHEHEAD hrStorage_cache; /* This cache is globally accessible */
  317. /* Gen_HrFSTable_Cache - Generate a initial cache for HrFSTable */
  318. BOOL Gen_HrFSTable_Cache( void ); /* "HRFSENTR.C" */
  319. extern CACHEHEAD hrFSTable_cache; /* This cache is globally accessible */
  320. /* Gen_HrDevice_Cache - Generate a initial cache for HrDevice Table */
  321. BOOL Gen_HrDevice_Cache( void ); /* "HRDEVENT.C" */
  322. extern CACHEHEAD hrDevice_cache; /* This cache is globally accessible */
  323. extern ULONG InitLoadDev_index; /* From hrDevice for hrSystem */
  324. /* Gen_HrSWInstalled_Cache - Generate a cache for HrSWInstalled Table */
  325. BOOL Gen_HrSWInstalled_Cache( void ); /* "HESWINEN.C" */
  326. /* Gen_HrSWRun_Cache - Generate a initial cache for HrSWRun(Perf) Table */
  327. BOOL Gen_HrSWRun_Cache( void ); /* "HRSWRUNE.C" */
  328. extern CACHEHEAD hrSWRunTable_cache; /* Globally accessible for ref from */
  329. /* "HRSWPREN.C" */
  330. extern ULONG SWOSIndex; /* From "HRSWRUNE.C" for "HRSWRUN.C" */
  331. /* hrSWRunCache_Refresh - hrSWRun(Perf) Cache Refresh-Check Routine */
  332. BOOL hrSWRunCache_Refresh( void );
  333. /* hrStorageCache_hrFSTableCache_Refresh Cache Refresh-Check Routine */
  334. BOOL hrStorageCache_hrFSTableCache_Refresh( void );
  335. #endif /* hmcache_h */