Implemented "ros_system_resource", a high-level interface for /system/resource/print.
[routeros-api.git] / src / routeros_api.h
index aac39db..0811b7b 100644 (file)
 
 #define ROUTEROS_API_PORT "8728"
 
+/*
+ * C++ doesn't have _Bool. We can't simply "#define _Bool bool", because we
+ * don't know if "bool" and "_Bool" are of the same size. If they are not, this
+ * would result in ABI incompatible code.
+ *
+ * So we're doing a best-effort solution here: If we're compiled with the GNU
+ * C++ compiler, g++, we include <stdbool.h>. The GCC will, as a GNU extension,
+ * define _Bool for C++. Since it's the compiler doing the definition, it's
+ * kind of save to assume that it will be done in an ABI compatible manner.
+ *
+ * If this results in any problems for you, define "ROS_HAVE_CPP_BOOL" to true
+ * to have this magic disabled. You will then have to define _Bool yourself.
+ *
+ * TODO: Write a test program for the configure sript to figure out the size of
+ *   _Bool. Make this size available via <routeros_versioin.h> and define _Bool
+ *   to short, long, ... here.
+ */
 #ifdef __cplusplus
+# if !defined (ROS_HAVE_CPP_BOOL) || !ROS_HAVE_CPP_BOOL
+#  ifdef __GNUC__
+#   include <stdbool.h>
+#  endif /* __GNUC__ */
+# endif /* !defined (ROS_HAVE_CPP_BOOL) || !ROS_HAVE_CPP_BOOL */
+
 extern "C" {
 #endif
 
@@ -166,6 +189,41 @@ int ros_registration_table (ros_connection_t *c,
                ros_registration_table_handler_t handler, void *user_data);
 /* }}} /interface/wireless/registration-table */
 
+/* High-level function for accessing /system/resource {{{ */
+struct ros_system_resource_s;
+typedef struct ros_system_resource_s ros_system_resource_t;
+struct ros_system_resource_s
+{
+       uint64_t uptime;
+
+       const char *version;
+  const char *architecture_name;
+  const char *board_name;
+
+  const char *cpu_model;
+       unsigned int cpu_count;
+       unsigned int cpu_load;
+  uint64_t cpu_frequency;
+
+       uint64_t free_memory;
+       uint64_t total_memory;
+
+       uint64_t free_hdd_space;
+  uint64_t total_hdd_space;
+
+  uint64_t write_sect_since_reboot;
+  uint64_t write_sect_total;
+  uint64_t bad_blocks;
+};
+
+/* Callback function */
+typedef int (*ros_system_resource_handler_t) (ros_connection_t *c,
+               const ros_system_resource_t *r, void *user_data);
+
+int ros_system_resource (ros_connection_t *c,
+               ros_system_resource_handler_t handler, void *user_data);
+/* }}} /system/resource */
+
 #ifdef __cplusplus
 }
 #endif