Change public API calls in the Host API to have the mh_ prefix on their
names.
In passing, make mh_host_get_cpu_details() no longer public, because it
doesn't return anything. It's just used internally to the host API to
initialize some data for other API calls to pull from.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/host/matahari-host-dbus.c | 34 ++++++++++++------------
src/host/matahari-host.cpp | 34 ++++++++++++------------
src/include/matahari/host.h | 44 ++++++++++++++----------------
src/lib/host.c | 59 ++++++++++++++--------------------------
4 files changed, 76 insertions(+), 95 deletions(-)
diff --git a/src/host/matahari-host-dbus.c b/src/host/matahari-host-dbus.c
index 1a2caf7..86b09ea 100644
--- a/src/host/matahari-host-dbus.c
+++ b/src/host/matahari-host-dbus.c
@@ -69,7 +69,7 @@ Host_shutdown(Matahari* matahari, DBusGMethodInvocation *context)
dbus_g_method_return_error(context, error);
return FALSE;
}
- host_shutdown();
+ mh_host_shutdown();
dbus_g_method_return(context, TRUE);
return TRUE;
}
@@ -83,7 +83,7 @@ Host_reboot(Matahari* matahari, DBusGMethodInvocation *context)
dbus_g_method_return_error(context, error);
return FALSE;
}
- host_reboot();
+ mh_host_reboot();
dbus_g_method_return(context, TRUE);
return TRUE;
}
@@ -121,37 +121,37 @@ matahari_get_property(GObject *object, guint property_id, GValue
*value,
switch (property_id)
{
case PROP_UUID:
- g_value_set_string (value, host_get_uuid());
+ g_value_set_string (value, mh_host_get_uuid());
break;
case PROP_HOSTNAME:
- g_value_set_string (value, host_get_hostname());
+ g_value_set_string (value, mh_host_get_hostname());
break;
case PROP_OS:
- g_value_set_string (value, host_get_operating_system());
+ g_value_set_string (value, mh_host_get_operating_system());
break;
case PROP_ARCH:
- g_value_set_string (value, host_get_architecture());
+ g_value_set_string (value, mh_host_get_architecture());
break;
case PROP_WORDSIZE:
- g_value_set_uint (value, host_get_cpu_wordsize());
+ g_value_set_uint (value, mh_host_get_cpu_wordsize());
break;
case PROP_MEMORY:
- g_value_set_uint64 (value, host_get_memory());
+ g_value_set_uint64 (value, mh_host_get_memory());
break;
case PROP_SWAP:
- g_value_set_uint64 (value, host_get_swap());
+ g_value_set_uint64 (value, mh_host_get_swap());
break;
case PROP_CPU_COUNT:
- g_value_set_uint (value, host_get_cpu_count());
+ g_value_set_uint (value, mh_host_get_cpu_count());
break;
case PROP_CPU_CORES:
- g_value_set_uint (value, host_get_cpu_number_of_cores());
+ g_value_set_uint (value, mh_host_get_cpu_number_of_cores());
break;
case PROP_CPU_MODEL:
- g_value_set_string (value, host_get_cpu_model());
+ g_value_set_string (value, mh_host_get_cpu_model());
break;
case PROP_CPU_FLAGS:
- g_value_set_string (value, host_get_cpu_flags());
+ g_value_set_string (value, mh_host_get_cpu_flags());
break;
case PROP_UPDATE_INTERVAL:
g_value_set_uint (value, priv.update_interval);
@@ -163,14 +163,14 @@ matahari_get_property(GObject *object, guint property_id, GValue
*value,
// Not used in DBus module
break;
case PROP_FREE_MEM:
- g_value_set_uint64 (value, host_get_mem_free());
+ g_value_set_uint64 (value, mh_host_get_mem_free());
break;
case PROP_FREE_SWAP:
- g_value_set_uint64 (value, host_get_swap_free());
+ g_value_set_uint64 (value, mh_host_get_swap_free());
break;
case PROP_LOAD:
// 1/5/15 minute load average - map
- host_get_load_averages(&avg);
+ mh_host_get_load_averages(&avg);
dict = dict_new(value);
g_value_init (&value_value, G_TYPE_DOUBLE);
@@ -187,7 +187,7 @@ matahari_get_property(GObject *object, guint property_id, GValue
*value,
break;
case PROP_PROCESS_STATISTICS:
// Process statistics is type map string -> int
- host_get_processes(&procs);
+ mh_host_get_processes(&procs);
dict = dict_new(value);
g_value_init (&value_value, G_TYPE_INT);
diff --git a/src/host/matahari-host.cpp b/src/host/matahari-host.cpp
index 8a8ef07..1ae3786 100644
--- a/src/host/matahari-host.cpp
+++ b/src/host/matahari-host.cpp
@@ -77,9 +77,9 @@ HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
gpointer use
const std::string& methodName(event.getMethodName());
if (methodName == "shutdown") {
- host_shutdown();
+ mh_host_shutdown();
} else if (methodName == "reboot") {
- host_reboot();
+ mh_host_reboot();
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
@@ -98,17 +98,17 @@ HostAgent::setup(qmf::AgentSession session)
_instance = qmf::Data(_package.data_Host);
_instance.setProperty("update_interval", 5);
- _instance.setProperty("uuid", host_get_uuid());
- _instance.setProperty("hostname", host_get_hostname());
- _instance.setProperty("os", host_get_operating_system());
- _instance.setProperty("wordsize", host_get_cpu_wordsize());
- _instance.setProperty("arch", host_get_architecture());
- _instance.setProperty("memory", host_get_memory());
- _instance.setProperty("swap", host_get_swap());
- _instance.setProperty("cpu_count", host_get_cpu_count());
- _instance.setProperty("cpu_cores", host_get_cpu_number_of_cores());
- _instance.setProperty("cpu_model", host_get_cpu_model());
- _instance.setProperty("cpu_flags", host_get_cpu_flags());
+ _instance.setProperty("uuid", mh_host_get_uuid());
+ _instance.setProperty("hostname", mh_host_get_hostname());
+ _instance.setProperty("os", mh_host_get_operating_system());
+ _instance.setProperty("wordsize", mh_host_get_cpu_wordsize());
+ _instance.setProperty("arch", mh_host_get_architecture());
+ _instance.setProperty("memory", mh_host_get_memory());
+ _instance.setProperty("swap", mh_host_get_swap());
+ _instance.setProperty("cpu_count", mh_host_get_cpu_count());
+ _instance.setProperty("cpu_cores", mh_host_get_cpu_number_of_cores());
+ _instance.setProperty("cpu_model", mh_host_get_cpu_model());
+ _instance.setProperty("cpu_flags", mh_host_get_cpu_flags());
session.addData(_instance);
return 0;
@@ -140,19 +140,19 @@ HostAgent::heartbeat()
_instance.setProperty("last_updated", now);
_instance.setProperty("sequence", _heartbeat_sequence);
- _instance.setProperty("free_swap", host_get_swap_free());
- _instance.setProperty("free_mem", host_get_mem_free());
+ _instance.setProperty("free_swap", mh_host_get_swap_free());
+ _instance.setProperty("free_mem", mh_host_get_mem_free());
::qpid::types::Variant::Map load;
memset(&avg, 0, sizeof(sigar_loadavg_t));
- host_get_load_averages(&avg);
+ mh_host_get_load_averages(&avg);
load["1"] = ::qpid::types::Variant((double)avg.loadavg[0]);
load["5"] = ::qpid::types::Variant((double)avg.loadavg[1]);
load["15"] = ::qpid::types::Variant((double)avg.loadavg[2]);
_instance.setProperty("load", load);
::qpid::types::Variant::Map proc;
- host_get_processes(&procs);
+ mh_host_get_processes(&procs);
proc["total"] = ::qpid::types::Variant((int)procs.total);
proc["idle"] = ::qpid::types::Variant((int)procs.idle);
proc["zombie"] = ::qpid::types::Variant((int)procs.zombie);
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index 3b6f390..5f78564 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -22,37 +22,35 @@
* \ingroup coreapi
*/
-#ifndef __HOST_H
-#define __HOST_H
+#ifndef __MH_HOST_H__
+#define __MH_HOST_H__
#include <stdint.h>
#include <stdlib.h>
#include <sigar.h>
-extern const char *host_get_uuid(void);
-extern const char *host_get_hostname(void);
-extern const char *host_get_operating_system(void);
+extern const char *mh_host_get_uuid(void);
+extern const char *mh_host_get_hostname(void);
+extern const char *mh_host_get_operating_system(void);
-extern const char *host_get_architecture(void);
-extern const char *host_get_cpu_model(void);
-extern const char *host_get_cpu_flags(void);
+extern const char *mh_host_get_architecture(void);
+extern const char *mh_host_get_cpu_model(void);
+extern const char *mh_host_get_cpu_flags(void);
-extern uint64_t host_get_memory(void);
-extern uint64_t host_get_mem_free(void);
-extern uint64_t host_get_swap(void);
-extern uint64_t host_get_swap_free(void);
+extern uint64_t mh_host_get_memory(void);
+extern uint64_t mh_host_get_mem_free(void);
+extern uint64_t mh_host_get_swap(void);
+extern uint64_t mh_host_get_swap_free(void);
-extern int host_get_cpu_count(void);
-extern int host_get_cpu_number_of_cores(void);
-extern int host_get_cpu_wordsize(void);
+extern int mh_host_get_cpu_count(void);
+extern int mh_host_get_cpu_number_of_cores(void);
+extern int mh_host_get_cpu_wordsize(void);
-extern void host_identify(const unsigned int iterations);
+extern void mh_host_identify(const unsigned int iterations);
-extern void host_reboot(void);
-extern void host_shutdown(void);
-extern void host_get_load_averages(sigar_loadavg_t *avg);
-extern void host_get_processes(sigar_proc_stat_t *procs);
+extern void mh_host_reboot(void);
+extern void mh_host_shutdown(void);
+extern void mh_host_get_load_averages(sigar_loadavg_t *avg);
+extern void mh_host_get_processes(sigar_proc_stat_t *procs);
-extern void host_get_cpu_details(void);
-
-#endif // __HOST_H
+#endif // __MH_HOST_H__
diff --git a/src/lib/host.c b/src/lib/host.c
index 4a18dd4..c5a34a2 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -63,8 +63,9 @@ static cpuinfo_t cpuinfo = {
.cores = 0,
};
-static void
-init(void)
+static void host_get_cpu_details(void);
+
+static void init(void)
{
if(host_init.sigar_init) {
return;
@@ -73,20 +74,17 @@ init(void)
host_init.sigar_init = TRUE;
}
-const char *
-host_get_uuid(void)
+const char *mh_host_get_uuid(void)
{
return matahari_uuid();
}
-const char *
-host_get_hostname(void)
+const char *mh_host_get_hostname(void)
{
return matahari_hostname();
}
-const char *
-host_get_operating_system(void)
+const char *mh_host_get_operating_system(void)
{
static const char *operating_system = NULL;
@@ -102,14 +100,12 @@ host_get_operating_system(void)
return operating_system;
}
-int
-host_get_cpu_wordsize(void)
+int mh_host_get_cpu_wordsize(void)
{
return (int)(CHAR_BIT * sizeof(size_t));
}
-const char *
-host_get_architecture(void)
+const char *mh_host_get_architecture(void)
{
static const char *arch = NULL;
@@ -125,61 +121,52 @@ host_get_architecture(void)
return arch;
}
-void
-host_reboot(void)
+void mh_host_reboot(void)
{
host_os_reboot();
}
-void
-host_shutdown(void)
+void mh_host_shutdown(void)
{
host_os_shutdown();
}
-const char*
-host_get_cpu_model(void)
+const char *mh_host_get_cpu_model(void)
{
host_get_cpu_details();
return cpuinfo.model;
}
-const char *
-host_get_cpu_flags(void)
+const char *mh_host_get_cpu_flags(void)
{
return host_os_get_cpu_flags();
}
-int
-host_get_cpu_count(void)
+int mh_host_get_cpu_count(void)
{
host_get_cpu_details();
return cpuinfo.cpus;
}
-int
-host_get_cpu_number_of_cores(void)
+int mh_host_get_cpu_number_of_cores(void)
{
host_get_cpu_details();
return cpuinfo.cores;
}
-void
-host_get_load_averages(sigar_loadavg_t *avg)
+void mh_host_get_load_averages(sigar_loadavg_t *avg)
{
init();
sigar_loadavg_get(host_init.sigar, avg);
}
-void
-host_get_processes(sigar_proc_stat_t *procs)
+void mh_host_get_processes(sigar_proc_stat_t *procs)
{
init();
sigar_proc_stat_get(host_init.sigar, procs);
}
-uint64_t
-host_get_memory(void)
+uint64_t mh_host_get_memory(void)
{
sigar_mem_t mem;
uint64_t total;
@@ -190,8 +177,7 @@ host_get_memory(void)
return total;
}
-uint64_t
-host_get_mem_free(void)
+uint64_t mh_host_get_mem_free(void)
{
sigar_mem_t mem;
uint64_t free;
@@ -202,8 +188,7 @@ host_get_mem_free(void)
return free;
}
-uint64_t
-host_get_swap(void)
+uint64_t mh_host_get_swap(void)
{
sigar_swap_t swap;
uint64_t total;
@@ -214,8 +199,7 @@ host_get_swap(void)
return total;
}
-uint64_t
-host_get_swap_free(void)
+uint64_t mh_host_get_swap_free(void)
{
sigar_swap_t swap;
uint64_t free;
@@ -226,8 +210,7 @@ host_get_swap_free(void)
return free;
}
-void
-host_get_cpu_details(void)
+static void host_get_cpu_details(void)
{
int lpc = 0;
sigar_cpu_info_list_t cpus;
--
1.7.4.4