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.

456 lines
14 KiB

  1. /*
  2. * HrSWRunPerfEntry.c v0.10
  3. * Generated in conjunction with Management Factory scripts:
  4. * script version: SNMPv1, 0.16, Apr 25, 1996
  5. * project: D:\TEMP\EXAMPLE\HOSTMIB
  6. ****************************************************************************
  7. * *
  8. * (C) Copyright 1995 DIGITAL EQUIPMENT CORPORATION *
  9. * *
  10. * This software is an unpublished work protected under the *
  11. * the copyright laws of the United States of America, all *
  12. * rights reserved. *
  13. * *
  14. * In the event this software is licensed for use by the United *
  15. * States Government, all use, duplication or disclosure by the *
  16. * United States Government is subject to restrictions as set *
  17. * forth in either subparagraph (c)(1)(ii) of the Rights in *
  18. * Technical Data And Computer Software Clause at DFARS *
  19. * 252.227-7013, or the Commercial Computer Software Restricted *
  20. * Rights Clause at FAR 52.221-19, whichever is applicable. *
  21. * *
  22. ****************************************************************************
  23. *
  24. * Facility:
  25. *
  26. * Windows NT SNMP Extension Agent
  27. *
  28. * Abstract:
  29. *
  30. * This module contains the code for dealing with the get, set, and
  31. * instance name routines for the HrSWRunPerfEntry. Actual instrumentation code is
  32. * supplied by the developer.
  33. *
  34. * Functions:
  35. *
  36. * A get and set routine for each attribute in the class.
  37. *
  38. * The routines for instances within the class.
  39. *
  40. * Author:
  41. *
  42. * D. D. Burns @ Webenable Inc
  43. *
  44. * Revision History:
  45. *
  46. * V1.00 - 05/14/97 D. D. Burns Genned: Thu Nov 07 16:48:05 1996
  47. *
  48. */
  49. #include <windows.h>
  50. #include <malloc.h>
  51. #include <snmp.h>
  52. #include "mib.h"
  53. #include "smint.h"
  54. #include "hostmsmi.h"
  55. #include "user.h" /* Developer supplied include file */
  56. #include "HMCACHE.H" /* Cache-related definitions */
  57. /*
  58. | NOTE:
  59. | The cache used by this table is the same one created for hrSWRun. The
  60. | CACHEHEAD structure for it is located in "HRSWRUNE.C".
  61. */
  62. /*
  63. * GetHrSWRunPerfCPU
  64. * The number of centi-seconds of the total system's CPU resources consumed
  65. * by this process. Note that on a multi-processor syste
  66. *
  67. * Gets the value for HrSWRunPerfCPU.
  68. *
  69. * Arguments:
  70. *
  71. * outvalue address to return variable value
  72. * accesss Reserved for future security use
  73. * instance address of instance name as ordered native
  74. * data type(s)
  75. *
  76. * Return Codes:
  77. *
  78. * Standard PDU error codes.
  79. *
  80. * SNMP_ERRORSTATUS_NOERROR Successful get
  81. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  82. * mibtget.c v0.10
  83. *
  84. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  85. | hrSWRunPerfCPU
  86. |
  87. | ACCESS SYNTAX
  88. | read-only INTEGER
  89. |
  90. | "The number of centi-seconds of the total system's CPU resources consumed by
  91. | this process. Note that on a multi-processor system, this value may increment
  92. | by more than one centi-second in one centi-second of real (wall clock) time."
  93. |
  94. | DISCUSSION:
  95. |
  96. | <POA-22> Given the performance monitoring counters available in the Registry,
  97. | how do we compute this SNMP attribute value for a given process?
  98. |
  99. | RESOLVED >>>>>>>>
  100. | <POA-22> I think we should just use the PerfMon code for this.
  101. | RESOLVED >>>>>>>>
  102. |
  103. |============================================================================
  104. | 1.3.6.1.2.1.25.5.1.1.1.<instance>
  105. | | | | |
  106. | | | | *-hrSWRunPerfCPU
  107. | | | *-hrSWRunPerfEntry
  108. | | *-hrSWRunPerfTable
  109. | *-hrSWRunPerf
  110. */
  111. UINT
  112. GetHrSWRunPerfCPU(
  113. OUT Integer *outvalue ,
  114. IN Access_Credential *access ,
  115. IN InstanceName *instance )
  116. {
  117. ULONG index; /* As fetched from instance structure */
  118. CACHEROW *row; /* Row entry fetched from cache */
  119. /*
  120. | Grab the instance information
  121. */
  122. index = GET_INSTANCE(0);
  123. /*
  124. | Use it to find the right entry in the cache
  125. */
  126. if ((row = FindTableRow(index, &hrSWRunTable_cache)) == NULL) {
  127. return SNMP_ERRORSTATUS_GENERR;
  128. }
  129. *outvalue = row->attrib_list[HRSP_CPU].u.number_value;
  130. return SNMP_ERRORSTATUS_NOERROR ;
  131. } /* end of GetHrSWRunPerfCPU() */
  132. /*
  133. * GetHrSWRunPerfMem
  134. * The total amount of real system memory allocated to this process.
  135. *
  136. * Gets the value for HrSWRunPerfMem.
  137. *
  138. * Arguments:
  139. *
  140. * outvalue address to return variable value
  141. * accesss Reserved for future security use
  142. * instance address of instance name as ordered native
  143. * data type(s)
  144. *
  145. * Return Codes:
  146. *
  147. * Standard PDU error codes.
  148. *
  149. * SNMP_ERRORSTATUS_NOERROR Successful get
  150. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  151. * mibtget.c v0.10
  152. *
  153. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  154. | hrSWRunPerfMem
  155. |
  156. | ACCESS SYNTAX
  157. | read-only KBytes
  158. |
  159. | "The total amount of real system memory allocated to this process."
  160. |
  161. | DISCUSSION:
  162. |
  163. | <POA-23> Given the performance monitoring counters available in the Registry,
  164. | how do we compute this SNMP attribute value for a given process?
  165. |
  166. | RESOLVED >>>>>>>>
  167. | <POA-22> I think we should just use the PerfMon code for this.
  168. | RESOLVED >>>>>>>>
  169. |
  170. |============================================================================
  171. | 1.3.6.1.2.1.25.5.1.1.2.<instance>
  172. | | | | |
  173. | | | | *-hrSWRunPerfMem
  174. | | | *-hrSWRunPerfEntry
  175. | | *-hrSWRunPerfTable
  176. | *-hrSWRunPerf
  177. */
  178. UINT
  179. GetHrSWRunPerfMem(
  180. OUT KBytes *outvalue ,
  181. IN Access_Credential *access ,
  182. IN InstanceName *instance )
  183. {
  184. ULONG index; /* As fetched from instance structure */
  185. CACHEROW *row; /* Row entry fetched from cache */
  186. /*
  187. | Grab the instance information
  188. */
  189. index = GET_INSTANCE(0);
  190. /*
  191. | Use it to find the right entry in the cache
  192. */
  193. if ((row = FindTableRow(index, &hrSWRunTable_cache)) == NULL) {
  194. return SNMP_ERRORSTATUS_GENERR;
  195. }
  196. *outvalue = row->attrib_list[HRSP_MEM].u.number_value;
  197. return SNMP_ERRORSTATUS_NOERROR ;
  198. } /* end of GetHrSWRunPerfMem() */
  199. /*
  200. * HrSWRunPerfEntryFindInstance
  201. *
  202. * This routine is used to verify that the specified instance is
  203. * valid.
  204. *
  205. * Arguments:
  206. *
  207. * FullOid Address for the full oid - group, variable,
  208. * and instance information
  209. * instance Address for instance specification as an oid
  210. *
  211. * Return Codes:
  212. *
  213. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  214. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  215. *
  216. */
  217. UINT
  218. HrSWRunPerfEntryFindInstance( IN ObjectIdentifier *FullOid ,
  219. IN OUT ObjectIdentifier *instance )
  220. {
  221. UINT tmp_instance ;
  222. //
  223. // Developer instrumentation code to find appropriate instance goes here.
  224. // For non-tables, it is not necessary to modify this routine. However, if
  225. // there is any context that needs to be set, it can be done here.
  226. //
  227. if ( FullOid->idLength <= HRSWRUNPERFENTRY_VAR_INDEX )
  228. // No instance was specified
  229. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  230. else if ( FullOid->idLength != HRSWRUNPERFENTRY_VAR_INDEX + 1 )
  231. // Instance length is more than 1
  232. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  233. else
  234. // The only valid instance for a non-table are instance 0. If this
  235. // is a non-table, the following code validates the instances. If this
  236. // is a table, developer modification is necessary below.
  237. tmp_instance = FullOid->ids[ HRSWRUNPERFENTRY_VAR_INDEX ] ;
  238. /*
  239. | Check for age-out and possibly refresh the entire cache for the
  240. | hrSWRun(Perf) table before we check to see if the instance is there.
  241. */
  242. if (hrSWRunCache_Refresh() == FALSE) {
  243. return SNMP_ERRORSTATUS_GENERR;
  244. }
  245. /*
  246. | For hrSWRunPerf, the instance arc(s) is a single arc, and it must
  247. | correctly select an entry in the hrSWRun(Perf) Table cache.
  248. | Check that here.
  249. */
  250. if ( FindTableRow(tmp_instance, &hrSWRunTable_cache) == NULL ) {
  251. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  252. }
  253. else
  254. {
  255. // the instance is valid. Create the instance portion of the OID
  256. // to be returned from this call.
  257. instance->ids[ 0 ] = tmp_instance ;
  258. instance->idLength = 1 ;
  259. }
  260. return SNMP_ERRORSTATUS_NOERROR ;
  261. } /* end of HrSWRunPerfEntryFindInstance() */
  262. /*
  263. * HrSWRunPerfEntryFindNextInstance
  264. *
  265. * This routine is called to get the next instance. If no instance
  266. * was passed than return the first instance (1).
  267. *
  268. * Arguments:
  269. *
  270. * FullOid Address for the full oid - group, variable,
  271. * and instance information
  272. * instance Address for instance specification as an oid
  273. *
  274. * Return Codes:
  275. *
  276. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  277. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  278. *
  279. */
  280. UINT
  281. HrSWRunPerfEntryFindNextInstance( IN ObjectIdentifier *FullOid ,
  282. IN OUT ObjectIdentifier *instance )
  283. {
  284. //
  285. // Developer supplied code to find the next instance of class goes here.
  286. // If this is a class with cardinality 1, no modification of this routine
  287. // is necessary unless additional context needs to be set.
  288. // If the FullOid does not specify an instance, then the only instance
  289. // of the class is returned. If this is a table, the first row of the
  290. // table is returned.
  291. //
  292. // If an instance is specified and this is a non-table class, then NOSUCHNAME
  293. // is returned so that correct MIB rollover processing occurs. If this is
  294. // a table, then the next instance is the one following the current instance.
  295. // If there are no more instances in the table, return NOSUCHNAME.
  296. //
  297. CACHEROW *row;
  298. ULONG tmp_instance;
  299. if ( FullOid->idLength <= HRSWRUNPERFENTRY_VAR_INDEX )
  300. {
  301. /*
  302. | Too short: must return the instance arc that selects the first
  303. | entry in the table if there is one.
  304. */
  305. tmp_instance = 0;
  306. }
  307. else {
  308. /*
  309. | There is at least one instance arc. Even if it is the only arc
  310. | we use it as the "index" in a request for the "NEXT" one.
  311. */
  312. tmp_instance = FullOid->ids[ HRSWRUNPERFENTRY_VAR_INDEX ] ;
  313. }
  314. /*
  315. | Check for age-out and possibly refresh the entire cache for the
  316. | hrSWRun(Perf) table before we check to see if the instance is there.
  317. */
  318. if (hrSWRunCache_Refresh() == FALSE) {
  319. return SNMP_ERRORSTATUS_GENERR;
  320. }
  321. /* Now go off and try to find the next instance in the table */
  322. if ((row = FindNextTableRow(tmp_instance, &hrSWRunTable_cache)) == NULL) {
  323. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  324. }
  325. instance->ids[ 0 ] = row->index ;
  326. instance->idLength = 1 ;
  327. return SNMP_ERRORSTATUS_NOERROR ;
  328. } /* end of HrSWRunPerfEntryFindNextInstance() */
  329. /*
  330. * HrSWRunPerfEntryConvertInstance
  331. *
  332. * This routine is used to convert the object id specification of an
  333. * instance into an ordered native representation. The object id format
  334. * is that object identifier that is returned from the Find Instance
  335. * or Find Next Instance routines. It is NOT the full object identifier
  336. * that contains the group and variable object ids as well. The native
  337. * representation is an argc/argv-like structure that contains the
  338. * ordered variables that define the instance. This is specified by
  339. * the MIB's INDEX clause. See RFC 1212 for information about the INDEX
  340. * clause.
  341. *
  342. *
  343. * Arguments:
  344. *
  345. * oid_spec Address of the object id instance specification
  346. * native_spec Address to return the ordered native instance
  347. * specification
  348. *
  349. * Return Codes:
  350. *
  351. * SUCCESS Conversion complete successfully
  352. * FAILURE Unable to convert object id into native format
  353. *
  354. */
  355. UINT
  356. HrSWRunPerfEntryConvertInstance( IN ObjectIdentifier *oid_spec ,
  357. IN OUT InstanceName *native_spec )
  358. {
  359. static char *array; /* The address of this (char *) is passed back */
  360. /* as though it were an array of length 1 of these */
  361. /* types. */
  362. static ULONG inst; /* The address of this ULONG is passed back */
  363. /* (Obviously, no "free()" action is needed) */
  364. /* We only expect the one arc in "oid_spec" */
  365. inst = oid_spec->ids[0];
  366. array = (char *) &inst;
  367. native_spec->count = 1;
  368. native_spec->array = &array;
  369. return SUCCESS ;
  370. } /* end of HrSWRunPerfEntryConvertInstance() */
  371. /*
  372. * HrSWRunPerfEntryFreeInstance
  373. *
  374. * This routine is used to free an ordered native representation of an
  375. * instance name.
  376. *
  377. * Arguments:
  378. *
  379. * instance Address to return the ordered native instance
  380. * specification
  381. *
  382. * Return Codes:
  383. *
  384. *
  385. */
  386. void
  387. HrSWRunPerfEntryFreeInstance( IN OUT InstanceName *instance )
  388. {
  389. //
  390. // Developer supplied code to free native representation of instance name goes here.
  391. //
  392. } /* end of HrSWRunPerfEntryFreeInstance() */