2 * librouteros - src/interface.c
3 * Copyright (C) 2009 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
22 #ifndef _ISOC99_SOURCE
23 # define _ISOC99_SOURCE
26 #ifndef _POSIX_C_SOURCE
27 # define _POSIX_C_SOURCE 200112L
40 #include "routeros_api.h"
41 #include "ros_parse.h"
46 struct rt_internal_data_s
48 ros_system_resource_handler_t handler;
51 typedef struct rt_internal_data_s rt_internal_data_t;
56 static int rt_reply_to_system_resource (const ros_reply_t *r, /* {{{ */
57 ros_system_resource_t *ret)
62 if (strcmp ("re", ros_reply_status (r)) != 0)
63 return (rt_reply_to_system_resource (ros_reply_next (r), ret));
67 ret->version = ros_reply_param_val_by_key (r, "version");
68 ret->architecture_name = ros_reply_param_val_by_key (r, "architecture-name");
69 ret->board_name = ros_reply_param_val_by_key (r, "board-name");
71 ret->cpu_model = ros_reply_param_val_by_key (r, "cpu");
72 ret->cpu_count = sstrtoui (ros_reply_param_val_by_key (r, "cpu-count"));
73 ret->cpu_load = sstrtoui (ros_reply_param_val_by_key (r, "cpu-load"));
74 ret->cpu_frequency = sstrtoui64 (ros_reply_param_val_by_key (r, "cpu-frequency"));
76 ret->free_memory = sstrtoui64 (ros_reply_param_val_by_key (r, "free-memory"));
77 ret->total_memory = sstrtoui64 (ros_reply_param_val_by_key (r, "total-memory"));
79 ret->free_hdd_space = sstrtoui64 (ros_reply_param_val_by_key (r, "free-hdd-space"));
80 ret->total_hdd_space = sstrtoui64 (ros_reply_param_val_by_key (r, "total-hdd-space"));
82 ret->write_sect_since_reboot = sstrtoui64 (ros_reply_param_val_by_key (r, "write-sect-since-reboot"));
83 ret->write_sect_total = sstrtoui64 (ros_reply_param_val_by_key (r, "write-sect-total"));
84 ret->bad_blocks = sstrtoui64 (ros_reply_param_val_by_key (r, "bad-blocks"));
87 } /* }}} int rt_reply_to_system_resource */
89 static int sr_internal_handler (ros_connection_t *c, /* {{{ */
90 const ros_reply_t *r, void *user_data)
92 ros_system_resource_t sys_res;
93 rt_internal_data_t *internal_data;
96 memset (&sys_res, 0, sizeof (sys_res));
97 status = rt_reply_to_system_resource (r, &sys_res);
101 internal_data = user_data;
103 status = internal_data->handler (c, &sys_res, internal_data->user_data);
106 } /* }}} int sr_internal_handler */
111 int ros_system_resource (ros_connection_t *c, /* {{{ */
112 ros_system_resource_handler_t handler, void *user_data)
114 rt_internal_data_t data;
116 if ((c == NULL) || (handler == NULL))
119 data.handler = handler;
120 data.user_data = user_data;
122 return (ros_query (c, "/system/resource/print",
123 /* args_num = */ 0, /* args = */ NULL,
124 sr_internal_handler, &data));
125 } /* }}} int ros_system_resource */
127 /* vim: set ts=2 sw=2 noet fdm=marker : */