lots of changes
diff --git a/objects/host_watchdog_obj.c b/objects/host_watchdog_obj.c
new file mode 100644
index 0000000..6396658
--- /dev/null
+++ b/objects/host_watchdog_obj.c
@@ -0,0 +1,146 @@
+#include "interfaces/watchdog.h"
+#include "openbmc.h"
+
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static const gchar* dbus_object_path = "/org/openbmc/watchdog/HostWatchdog";
+static const gchar* dbus_name = "org.openbmc.watchdog.HostWatchdog";
+
+static GDBusObjectManagerServer *manager = NULL;
+
+
+static gboolean
+poll_watchdog(gpointer user_data)
+{
+ Watchdog *watchdog = object_get_watchdog((Object*)user_data);
+
+ guint count = watchdog_get_watchdog(watchdog);
+ g_print("Polling watchdog: %d\n",count);
+
+ if (count == 0)
+ {
+ watchdog_emit_watchdog_error(watchdog);
+ }
+
+ //reset watchdog
+ watchdog_set_watchdog(watchdog,0);
+ return TRUE;
+}
+
+static gboolean
+on_start (Watchdog *wd,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ guint poll_interval = watchdog_get_poll_interval(wd);
+ g_timeout_add(poll_interval, poll_watchdog, user_data);
+ watchdog_complete_start(wd,invocation);
+ return TRUE;
+}
+
+static gboolean
+on_poke (Watchdog *wd,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ watchdog_set_watchdog(wd,1);
+ watchdog_complete_poke(wd,invocation);
+ return TRUE;
+}
+
+
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_print ("Acquired a message bus connection: %s\n",name);
+
+ cmdline *cmd = user_data;
+ if (cmd->argc < 2)
+ {
+ g_print("No objects created. Put object name(s) on command line\n");
+ return;
+ }
+ manager = g_dbus_object_manager_server_new (dbus_object_path);
+ int i=0;
+ for (i=1;i<cmd->argc;i++)
+ {
+ gchar *s;
+ s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
+ ObjectSkeleton *object = object_skeleton_new (s);
+ g_free (s);
+
+ Watchdog *wd = watchdog_skeleton_new ();
+ object_skeleton_set_watchdog (object, wd);
+ g_object_unref (wd);
+
+ // set properties
+ watchdog_set_watchdog(wd,1);
+
+ //define method callbacks here
+ g_signal_connect (wd,
+ "handle-start",
+ G_CALLBACK (on_start),
+ object); /* user_data */
+
+ g_signal_connect (wd,
+ "handle-poke",
+ G_CALLBACK (on_poke),
+ object); /* user_data */
+
+
+ /* Export the object (@manager takes its own reference to @object) */
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
+ }
+
+ /* Export all objects */
+ g_dbus_object_manager_server_set_connection (manager, connection);
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_print ("Acquired the name %s\n", name);
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_print ("Lost the name %s\n", name);
+}
+
+
+gint
+main (gint argc, gchar *argv[])
+{
+ GMainLoop *loop;
+ cmdline cmd;
+ cmd.argc = argc;
+ cmd.argv = argv;
+ guint id;
+ loop = g_main_loop_new (NULL, FALSE);
+
+ id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ dbus_name,
+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
+ G_BUS_NAME_OWNER_FLAGS_REPLACE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ &cmd,
+ NULL);
+
+ g_main_loop_run (loop);
+
+ g_bus_unown_name (id);
+ g_main_loop_unref (loop);
+ return 0;
+}
diff --git a/objects/power_control_obj.c b/objects/power_control_obj.c
index c0047bd..ce9144b 100644
--- a/objects/power_control_obj.c
+++ b/objects/power_control_obj.c
@@ -42,23 +42,6 @@
control_power_emit_power_good(control_power);
}
}
- //}
- //else
- //{
- //TODO: error handling
- /* GVariantBuilder *b;
- GVariant *dict;
- b = g_variant_builder_new (G_VARIANT_TYPE ("a{ss}"));
- g_variant_builder_add (b, "{ss}", "object",dbus_object_path);
- g_variant_builder_add (b, "{ss}", "message", "Unable to read pgood gpio");
- char buf[254];
- sprintf(buf,"%s/gpio%d",pgood.dev,pgood.num);
- g_variant_builder_add (b, "{ss}", "gpio",buf);
-
- dict = g_variant_builder_end (b);
- event_log_emit_event_log(event_log,dict);
-
- }*/
return TRUE;
}
@@ -77,23 +60,31 @@
"Invalid power state");
return TRUE;
}
+ // return from method call
+ control_power_complete_set_power_state(pwr,invocation);
if (state == control_power_get_state(pwr))
{
- g_dbus_method_invocation_return_dbus_error (invocation,
- "org.openbmc.ControlPower.Error.Failed",
- "Power Control is already at requested state");
- return TRUE;
+ g_print("Power already at requested state: %d\n",state);
}
+ else
+ {
+ g_print("Set power state: %d\n",state);
+ gpio_open(&power_pin);
+ gpio_write(&power_pin,!state);
+ gpio_close(&power_pin);
+ control_power_set_state(pwr,state);
+ }
+ return TRUE;
+}
- //go ahead and return from method call
- control_power_complete_set_power_state(pwr,invocation);
-
- g_print("Set power state: %d\n",state);
- gpio_open(&power_pin);
- gpio_write(&power_pin,!state);
- gpio_close(&power_pin);
-
- control_power_set_state(pwr,state);
+static gboolean
+on_init (Control *control,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ guint poll_interval = control_get_poll_interval(control);
+ g_timeout_add(poll_interval, poll_pgood, user_data);
+ control_complete_init(control,invocation);
return TRUE;
}
@@ -152,7 +143,12 @@
G_CALLBACK (on_get_power_state),
NULL); /* user_data */
- g_timeout_add(5000, poll_pgood, object);
+ g_signal_connect (control,
+ "handle-init",
+ G_CALLBACK (on_init),
+ object); /* user_data */
+
+
/* Export the object (@manager takes its own reference to @object) */
g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
diff --git a/objects/sensor_host_status_obj.c b/objects/sensor_host_status_obj.c
index a085220..bd16935 100644
--- a/objects/sensor_host_status_obj.c
+++ b/objects/sensor_host_status_obj.c
@@ -1,48 +1,45 @@
#include "interfaces/sensor.h"
#include "openbmc.h"
-
+#define BOOTED 100
/* ---------------------------------------------------------------------------------------------------- */
static const gchar* dbus_object_path = "/org/openbmc/sensors/HostStatus";
static const gchar* dbus_name = "org.openbmc.sensors.HostStatus";
-static const guint poll_interval = 3000;
static guint heartbeat = 0;
static GDBusObjectManagerServer *manager = NULL;
-/*
-static gboolean
-on_get_units (SensorValue *sen,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- const gchar* val = sensor_value_get_units(sen);
- sensor_value_complete_get_units(sen,invocation,val);
- return TRUE;
-}
static gboolean
-on_get (SensorValue *sen,
+on_set_value (SensorValue *sen,
GDBusMethodInvocation *invocation,
+ GVariant* value,
gpointer user_data)
{
- guint reading = sensor_value_get_value(sen);
- sensor_value_complete_get_value(sen,invocation,reading);
- return TRUE;
-}
-static gboolean
-on_set (SensorValue *sen,
- GDBusMethodInvocation *invocation,
- guint value,
- gpointer user_data)
-{
- GVariant* v = NEW_VARIANT_U(value);
- sensor_value_set_value(sen,v);
- sensor_value_emit_changed(sen,v,sensor_value_get_units(sen));
+ SensorMatch *match = object_get_sensor_match((Object*)user_data);
+ sensor_value_set_value(sen,value);
+ sensor_value_emit_changed(sen,value,"");
+ // Important host status values
+ guchar host_status = g_variant_get_byte(g_variant_get_variant(value));
+
+ if (host_status == BOOTED)
+ {
+ sensor_match_set_state(match,host_status);
+ sensor_match_emit_sensor_match(match,host_status);
+ }
sensor_value_complete_set_value(sen,invocation);
return TRUE;
}
-*/
+
+static gboolean
+on_init (SensorValue *sen,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ sensor_value_complete_init(sen,invocation);
+ return TRUE;
+}
+
static void
on_bus_acquired (GDBusConnection *connection,
const gchar *name,
@@ -68,26 +65,28 @@
SensorValue *sensor = sensor_value_skeleton_new ();
object_skeleton_set_sensor_value (object, sensor);
g_object_unref (sensor);
+
+ SensorMatch *match = sensor_match_skeleton_new ();
+ object_skeleton_set_sensor_match (object, match);
+ g_object_unref (match);
//must init variant
- GVariant* v = NEW_VARIANT_U(0);
+ GVariant* v = NEW_VARIANT_B(0);
sensor_value_set_value(sensor,v);
- // set units
+ // set units
sensor_value_set_units(sensor,"");
+ sensor_value_set_settable(sensor,TRUE);
+
//define method callbacks here
- //g_signal_connect (sensor,
- // "handle-get-value",
- // G_CALLBACK (on_get),
- // NULL); /* user_data */
- //g_signal_connect (sensor,
- // "handle-get-units",
- // G_CALLBACK (on_get_units),
- // NULL); /* user_data */
- //g_signal_connect (sensor,
- // "handle-set-value",
- // G_CALLBACK (on_set),
- // NULL); /* user_data */
+ g_signal_connect (sensor,
+ "handle-init",
+ G_CALLBACK (on_init),
+ NULL); /* user_data */
+ g_signal_connect (sensor,
+ "handle-set-value",
+ G_CALLBACK (on_set_value),
+ object); /* user_data */
/* Export the object (@manager takes its own reference to @object) */
g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
diff --git a/objects/sensor_temperature_ambient_obj.c b/objects/sensor_temperature_ambient_obj.c
index 70787dd..4f1b32a 100644
--- a/objects/sensor_temperature_ambient_obj.c
+++ b/objects/sensor_temperature_ambient_obj.c
@@ -7,25 +7,20 @@
static const gchar* dbus_object_path = "/org/openbmc/sensors/Temperature/Ambient";
static const gchar* dbus_name = "org.openbmc.sensors.Temperature.Ambient";
-static const guint poll_interval = 3000;
static guint heartbeat = 0;
static GDBusObjectManagerServer *manager = NULL;
-static gboolean inited = FALSE;
-
static gboolean
poll_sensor(gpointer user_data)
{
- if (!inited)
- {
- return TRUE;
- }
SensorValue *sensor = object_get_sensor_value((Object*)user_data);
SensorThreshold *threshold = object_get_sensor_threshold((Object*)user_data);
SensorI2c *i2c = object_get_sensor_i2c((Object*)user_data);
GVariant* v_value = sensor_value_get_value(sensor);
+ guint poll_interval = sensor_value_get_poll_interval(sensor);
+
//TODO: Change to actually read sensor
double value = GET_VARIANT_D(v_value);
g_print("Reading I2C = %s; Address = %s; %f\n",
@@ -46,17 +41,13 @@
// End actually reading sensor
//if changed, set property and emit signal
- // if (value != sensor_value_get_value(sensor)
if (value != GET_VARIANT_D(v_value))
{
- // they don't appear to provide a function to modify float value in varait
- // so it seems I have to create a new one
GVariant* v_new_value = NEW_VARIANT_D(value);
sensor_value_set_value(sensor,v_new_value);
-
- sensor_value_set_value(sensor,v_new_value);
- //sensor_value_emit_changed(sensor,v_new_value,sensor_value_get_units(sensor));
- check_thresholds(threshold,v_new_value);
+ const gchar* units = sensor_value_get_units(sensor);
+ sensor_value_emit_changed(sensor,v_new_value,units);
+ check_thresholds(threshold,v_new_value);
}
return TRUE;
}
@@ -66,9 +57,11 @@
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- inited = TRUE;
- sensor_value_complete_init(sen,invocation);
- return TRUE;
+
+ guint poll_interval = sensor_value_get_poll_interval(sen);
+ g_timeout_add(poll_interval, poll_sensor, user_data);
+ sensor_value_complete_init(sen,invocation);
+ return TRUE;
}
@@ -112,6 +105,7 @@
GVariant* value = g_variant_new_variant(g_variant_new_double(1.0));
sensor_value_set_value(sensor,value);
sensor_value_set_units(sensor,"C");
+ sensor_value_set_settable(sensor,FALSE);
sensor_threshold_set_state(threshold,NOT_SET);
sensor_threshold_set_upper_critical(threshold,
@@ -128,14 +122,14 @@
g_signal_connect (sensor,
"handle-init",
G_CALLBACK (on_init),
- NULL); /* user_data */
+ object); /* user_data */
g_signal_connect (threshold,
"handle-get-state",
G_CALLBACK (get_threshold_state),
NULL); /* user_data */
- g_timeout_add(poll_interval, poll_sensor, object);
+
/* Export the object (@manager takes its own reference to @object) */
g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));