Debian Codegraph @

agent/mibgroup/ip-mib/ipSystemStatsTable/ipSystemStatsTable_data_access.c

raw
1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * version : 1.17 $ of : mfd-data-access.m2c,v $
4 *
5 * $Id$
6 */
7 /*
8 * standard Net-SNMP includes
9 */
10 #include <net-snmp/net-snmp-config.h>
11 #include <net-snmp/net-snmp-includes.h>
12 #include <net-snmp/agent/net-snmp-agent-includes.h>
13
14 /*
15 * include our parent header
16 */
17 #include "ipSystemStatsTable.h"
18
19
20 #include "ipSystemStatsTable_data_access.h"
21
22 static int ipss_cache_refresh = IPSYSTEMSTATSTABLE_CACHE_TIMEOUT;
23
24 /** @ingroup interface
25 * @addtogroup data_access data_access: Routines to access data
26 *
27 * These routines are used to locate the data used to satisfy
28 * requests.
29 *
30 * @{
31 */
32 /**********************************************************************
33 **********************************************************************
34 ***
35 *** Table ipSystemStatsTable
36 ***
37 **********************************************************************
38 **********************************************************************/
39 /*
40 * IP-MIB::ipSystemStatsTable is subid 1 of ipTrafficStats.
41 * Its status is Current.
42 * OID: .1.3.6.1.2.1.4.31.1, length: 9
43 */
44
45 /**
46 * initialization for ipSystemStatsTable data access
47 *
48 * This function is called during startup to allow you to
49 * allocate any resources you need for the data table.
50 *
51 * @param ipSystemStatsTable_reg
52 * Pointer to ipSystemStatsTable_registration
53 *
54 * @retval MFD_SUCCESS : success.
55 * @retval MFD_ERROR : unrecoverable error.
56 */
57 int
58 ipSystemStatsTable_init_data(ipSystemStatsTable_registration *
59 ipSystemStatsTable_reg)
60 {
61 DEBUGMSGTL(("verbose:ipSystemStatsTable:ipSystemStatsTable_init_data",
62 "called\n"));
63
64 /*
65 * TODO:303:o: Initialize ipSystemStatsTable data.
66 */
67
68 netsnmp_access_systemstats_init();
69 return MFD_SUCCESS;
70 } /* ipSystemStatsTable_init_data */
71
72 /**
73 * container overview
74 *
75 */
76
77 /**
78 * container initialization
79 *
80 * @param container_ptr_ptr A pointer to a container pointer. If you
81 * create a custom container, use this parameter to return it
82 * to the MFD helper. If set to NULL, the MFD helper will
83 * allocate a container for you.
84 * @param cache A pointer to a cache structure. You can set the timeout
85 * and other cache flags using this pointer.
86 *
87 * This function is called at startup to allow you to customize certain
88 * aspects of the access method. For the most part, it is for advanced
89 * users. The default code should suffice for most cases. If no custom
90 * container is allocated, the MFD code will create one for your.
91 *
92 * This is also the place to set up cache behavior. The default, to
93 * simply set the cache timeout, will work well with the default
94 * container. If you are using a custom container, you may want to
95 * look at the cache helper documentation to see if there are any
96 * flags you want to set.
97 *
98 * @remark
99 * This would also be a good place to do any initialization needed
100 * for you data source. For example, opening a connection to another
101 * process that will supply the data, opening a database, etc.
102 */
103 void
104 ipSystemStatsTable_container_init(netsnmp_container **container_ptr_ptr,
105 netsnmp_cache * cache)
106 {
107 DEBUGMSGTL(("verbose:ipSystemStatsTable:ipSystemStatsTable_container_init", "called\n"));
108
109 if (NULL == container_ptr_ptr) {
110 snmp_log(LOG_ERR,
111 "bad container param to ipSystemStatsTable_container_init\n");
112 return;
113 }
114
115 /*
116 * For advanced users, you can use a custom container. If you
117 * do not create one, one will be created for you.
118 */
119
120
121 *container_ptr_ptr = netsnmp_container_find("ipSystemStatsTable:table_container");
122 if (NULL != *container_ptr_ptr)
123 (*container_ptr_ptr)->container_name = strdup("ipSystemStatsTable");
124
125 if (NULL == cache) {
126 snmp_log(LOG_ERR,
127 "bad cache param to ipSystemStatsTable_container_init\n");
128 return;
129 }
130
131 /*
132 * TODO:345:A: Set up ipSystemStatsTable cache properties.
133 *
134 * Also for advanced users, you can set parameters for the
135 * cache. Do not change the magic pointer, as it is used
136 * by the MFD helper. To completely disable caching, set
137 * cache->enabled to 0.
138 */
139 cache->timeout = IPSYSTEMSTATSTABLE_CACHE_TIMEOUT; /* seconds */
140
141 /*
142 * don't release resources
143 */
144 cache->flags |=
145 (NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_FREE_EXPIRED
146 | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD |
147 NETSNMP_CACHE_AUTO_RELOAD);
148 ipSystemStatsTable_container_load(*container_ptr_ptr);
149 } /* ipSystemStatsTable_container_init */
150
151 /**
152 * check entry for update
153 */
154 static void
155 _check_for_updates(void *p, void *q)
156 {
157 ipSystemStatsTable_rowreq_ctx *rowreq_ctx = p;
158 netsnmp_container *stats = q;
159 /*
160 * check for matching entry. works because indexes are the same.
161 */
162 netsnmp_systemstats_entry *systemstats_entry = (netsnmp_systemstats_entry*)
163 CONTAINER_FIND(stats, rowreq_ctx->data);
164 if (NULL == systemstats_entry) {
165 DEBUGMSGTL(("ipSystemStatsTable:access",
166 "updating missing entry\n"));
167
168 /*
169 * mark row as missing, so we can set discontinuity
170 * when it comes back.
171 *
172 * what else should we do? set refresh to 0? that's not quite right...
173 */
174 rowreq_ctx->known_missing = 1;
175 } else {
176 DEBUGMSGTL(("ipSystemStatsTable:access",
177 "updating existing entry\n"));
178
179 /*
180 * Check for changes & update
181 */
182 netsnmp_access_systemstats_entry_update(rowreq_ctx->data,
183 systemstats_entry);
184
185 /*
186 * set discontinuity if previously missing.
187 */
188 if (1 == rowreq_ctx->known_missing) {
189 rowreq_ctx->known_missing = 0;
190 rowreq_ctx->ipSystemStatsDiscontinuityTime =
191 netsnmp_get_agent_uptime();
192 }
193
194 /*
195 * remove entry from container
196 */
197 CONTAINER_REMOVE(stats, systemstats_entry);
198 netsnmp_access_systemstats_entry_free(systemstats_entry);
199 }
200 }
201
202 /**
203 * add new entry
204 */
205 static void
206 _add_new(void *p, void *q)
207 {
208 netsnmp_systemstats_entry *systemstats_entry = p;
209 netsnmp_container *container = q;
210 ipSystemStatsTable_rowreq_ctx *rowreq_ctx;
211
212 DEBUGMSGTL(("ipSystemStatsTable:access", "creating new entry\n"));
213
214 netsnmp_assert(NULL != systemstats_entry);
215 netsnmp_assert(NULL != container);
216
217 /*
218 * allocate an row context and set the index(es)
219 */
220 rowreq_ctx =
221 ipSystemStatsTable_allocate_rowreq_ctx(systemstats_entry, NULL);
222 if ((NULL != rowreq_ctx)
223 && (MFD_SUCCESS ==
224 ipSystemStatsTable_indexes_set(rowreq_ctx,
225 systemstats_entry->
226 index[0]))) {
227 rowreq_ctx->ipSystemStatsRefreshRate = ipss_cache_refresh * 1000; /* milli-seconds */
228 CONTAINER_INSERT(container, rowreq_ctx);
229 } else {
230 if (NULL != rowreq_ctx) {
231 snmp_log(LOG_ERR, "error setting index while loading "
232 "ipSystemStatsTable cache.\n");
233 ipSystemStatsTable_release_rowreq_ctx(rowreq_ctx);
234 } else {
235 snmp_log(LOG_ERR, "memory allocation failed while loading "
236 "ipSystemStatsTable cache.\n");
237 netsnmp_access_systemstats_entry_free(systemstats_entry);
238 }
239 }
240 }
241
242 /**
243 * container shutdown
244 *
245 * @param container_ptr A pointer to the container.
246 *
247 * This function is called at shutdown to allow you to customize certain
248 * aspects of the access method. For the most part, it is for advanced
249 * users. The default code should suffice for most cases.
250 *
251 * This function is called before ipSystemStatsTable_container_free().
252 *
253 * @remark
254 * This would also be a good place to do any cleanup needed
255 * for you data source. For example, closing a connection to another
256 * process that supplied the data, closing a database, etc.
257 */
258 void
259 ipSystemStatsTable_container_shutdown(netsnmp_container *container_ptr)
260 {
261 DEBUGMSGTL(("verbose:ipSystemStatsTable:ipSystemStatsTable_container_shutdown", "called\n"));
262
263 if (NULL == container_ptr) {
264 snmp_log(LOG_ERR,
265 "bad params to ipSystemStatsTable_container_shutdown\n");
266 return;
267 }
268
269 } /* ipSystemStatsTable_container_shutdown */
270
271 /**
272 * load initial data
273 *
274 * TODO:350:M: Implement ipSystemStatsTable data load
275 * This function will also be called by the cache helper to load
276 * the container again (after the container free function has been
277 * called to free the previous contents).
278 *
279 * @param container container to which items should be inserted
280 *
281 * @retval MFD_SUCCESS : success.
282 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
283 * @retval MFD_ERROR : other error.
284 *
285 * This function is called to load the index(es) (and data, optionally)
286 * for the every row in the data set.
287 *
288 * @remark
289 * While loading the data, the only important thing is the indexes.
290 * If access to your data is cheap/fast (e.g. you have a pointer to a
291 * structure in memory), it would make sense to update the data here.
292 * If, however, the accessing the data involves more work (e.g. parsing
293 * some other existing data, or performing calculations to derive the data),
294 * then you can limit yourself to setting the indexes and saving any
295 * information you will need later. Then use the saved information in
296 * ipSystemStatsTable_row_prep() for populating data.
297 *
298 * @note
299 * If you need consistency between rows (like you want statistics
300 * for each row to be from the same time frame), you should set all
301 * data here.
302 *
303 */
304 int
305 ipSystemStatsTable_container_load(netsnmp_container *container)
306 {
307 netsnmp_container *stats =
308 netsnmp_access_systemstats_container_load(NULL, 0);
309
310
311 DEBUGMSGTL(("verbose:ipSystemStatsTable:ipSystemStatsTable_cache_load",
312 "called\n"));
313
314 netsnmp_assert(NULL != container);
315
316 if (NULL == stats)
317 return MFD_RESOURCE_UNAVAILABLE; /* msg already logged */
318 /*
319 * TODO:351:M: |-> Load/update data in the ipSystemStatsTable container.
320 * loop over your ipSystemStatsTable data, allocate a rowreq context,
321 * set the index(es) [and data, optionally] and insert into
322 * the container.
323 */
324 /*
325 * we just got a fresh copy of data. compare it to
326 * what we've already got, and make any adjustements...
327 */
328 CONTAINER_FOR_EACH(container, _check_for_updates, stats);
329
330 /*
331 * now add any new entries
332 */
333 CONTAINER_FOR_EACH(stats, _add_new, container);
334
335 /*
336 * free the container. we've either claimed each ifentry, or released it,
337 * so the dal function doesn't need to clear the container.
338 */
339 netsnmp_access_systemstats_container_free(stats,
340 NETSNMP_ACCESS_SYSTEMSTATS_FREE_DONT_CLEAR);
341
342 DEBUGMSGT(("verbose:ipSystemStatsTable:ipSystemStatsTable_cache_load",
343 "%" NETSNMP_PRIz "u records\n", CONTAINER_SIZE(container)));
344
345 return MFD_SUCCESS;
346 } /* ipSystemStatsTable_container_load */
347
348 /**
349 * container clean up
350 *
351 * @param container container with all current items
352 *
353 * This optional callback is called prior to all
354 * item's being removed from the container. If you
355 * need to do any processing before that, do it here.
356 *
357 * @note
358 * The MFD helper will take care of releasing all the row contexts.
359 *
360 */
361 void
362 ipSystemStatsTable_container_free(netsnmp_container *container)
363 {
364 DEBUGMSGTL(("verbose:ipSystemStatsTable:ipSystemStatsTable_container_free", "called\n"));
365
366 /*
367 * TODO:380:M: Free ipSystemStatsTable container data.
368 */
369 } /* ipSystemStatsTable_container_free */
370
371 /**
372 * prepare row for processing.
373 *
374 * When the agent has located the row for a request, this function is
375 * called to prepare the row for processing. If you fully populated
376 * the data context during the index setup phase, you may not need to
377 * do anything.
378 *
379 * @param rowreq_ctx pointer to a context.
380 *
381 * @retval MFD_SUCCESS : success.
382 * @retval MFD_ERROR : other error.
383 */
384 int
385 ipSystemStatsTable_row_prep(ipSystemStatsTable_rowreq_ctx * rowreq_ctx)
386 {
387 DEBUGMSGTL(("verbose:ipSystemStatsTable:ipSystemStatsTable_row_prep",
388 "called\n"));
389
390 netsnmp_assert(NULL != rowreq_ctx);
391
392 /*
393 * TODO:390:o: Prepare row for request.
394 * If populating row data was delayed, this is the place to
395 * fill in the row for this request.
396 */
397
398 return MFD_SUCCESS;
399 } /* ipSystemStatsTable_row_prep */
400
401 /** @} */