lots of changes
diff --git a/objects/chassis_identify_obj.c b/objects/chassis_identify_obj.c
index 69ba7a7..53cf893 100644
--- a/objects/chassis_identify_obj.c
+++ b/objects/chassis_identify_obj.c
@@ -1,8 +1,8 @@
 #include "interfaces/led.h"

 

 /* ---------------------------------------------------------------------------------------------------- */

-static const gchar* dbus_object_path = "/org/openbmc/control/ChassisControl";

-static const gchar* dbus_name        = "org.openbmc.control.ChassisControl";

+static const gchar* dbus_object_path = "/org/openbmc/leds/ChassisIdentify";

+static const gchar* dbus_name        = "org.openbmc.leds.ChassisIdentify";

 

 static GDBusObjectManagerServer *manager = NULL;

 //static Led *led = NULL;

diff --git a/objects/host_control_obj.c b/objects/host_control_obj.c
deleted file mode 100644
index 014fe92..0000000
--- a/objects/host_control_obj.c
+++ /dev/null
@@ -1,99 +0,0 @@
-#include "interfaces/host_control.h"

-

-/* ---------------------------------------------------------------------------------------------------- */

-static const gchar* dbus_object_path = "/org/openbmc/control/Host";

-static const gchar* dbus_name        = "org.openbmc.control.Host";

-

-static GDBusObjectManagerServer *manager = NULL;

-static HostControl *host_control = NULL;

-

-static guint gpio_fsiclk = 27;

-static guint gpio_fsidat = 28;

-

-static gboolean

-on_boot         (HostControl        *host,

-                GDBusMethodInvocation  *invocation,

-                gpointer                user_data)

-{

-  // TODO: Implement gpio toggling

-  g_print("Boot");

-  host_control_complete_boot(host,invocation);

-  host_control_emit_booted(host);

-  return TRUE;

-}

-

-static void 

-on_bus_acquired (GDBusConnection *connection,

-                 const gchar     *name,

-                 gpointer         user_data)

-{

-  ObjectSkeleton *object;

-  guint n;

-

-  g_print ("Acquired a message bus connection: %s\n",name);

-

-  manager = g_dbus_object_manager_server_new (dbus_object_path);

-

-  gchar *s;

-  s = g_strdup_printf ("%s/0",dbus_object_path);

-  object = object_skeleton_new (s);

-  g_free (s);

-  host_control = host_control_skeleton_new ();

-  object_skeleton_set_host_control (object, host_control);

-  g_object_unref (host_control);

-

-  //define method callbacks here

-  g_signal_connect (host_control,

-                    "handle-boot",

-                    G_CALLBACK (on_boot),

-                    NULL); /* 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;

-

-  guint id;

-  //g_type_init ();

-  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,

-                       loop,

-                       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 4dacbe9..a290653 100644
--- a/objects/power_control_obj.c
+++ b/objects/power_control_obj.c
@@ -7,88 +7,59 @@
 #include <sys/stat.h>

 #include <sys/mman.h>

 #include "interfaces/power_control.h"

+#include "objects/openbmc_utilities.h"

 

 /* ---------------------------------------------------------------------------------------------------- */

 static const gchar* dbus_object_path = "/org/openbmc/control/Power";

 static const gchar* dbus_name        = "org.openbmc.control.Power";

 

-// Platform specific config

-

-#define FSI_CLK		4	//GPIOA4

-#define FSI_DAT		5	//GPIOA5

-#define CRONUS_SEL	6	//GPIOA6

-#define PCIE_RST_N	13	//GPIOB5

-#define PEX_PERST_N	14	//GPIOB6

-#define POWER		33    	//GPIOE1

-#define PGOOD		23    	//GPIOC7

-#define FSI_ENABLE      24      //GPIOD0

-

-/* Where to put the firmware image if booting from memory */

-#define MEM_IMG_BASE (0x54000000)

-

-/* Start of flash memory if booting from flash */

-#define FLASH_IMG_BASE (0x30000000)

-

-/* LPC registers */

-#define LPC_BASE		0x1e789000

-#define LPC_HICR6		0x80

-#define LPC_HICR7		0x88

-#define LPC_HICR8		0x8c

-

-

-

+GPIO power_pin    = (GPIO){ "POWER_PIN" };

+GPIO pgood        = (GPIO){ "PGOOD" };

 

 static GDBusObjectManagerServer *manager = NULL;

-static PowerControl *power_control = NULL;

-

-static guint tmp_pgood = 0;

+static ControlPower *control_power = NULL;

 

 static gboolean

-on_set_power_state (PowerControl          *pwr,

+on_set_power_state (ControlPower          *pwr,

                 GDBusMethodInvocation  *invocation,

                 guint                   state,

                 gpointer                user_data)

 {

-  if (state > 1)

-  {

-      g_dbus_method_invocation_return_dbus_error (invocation,

-                                                  "org.openbmc.PowerControl.Error.Failed",

-                                                  "Invalid power state");

-      return TRUE;

-  }

-  if (state == power_control_get_state(pwr))

-  {

-      g_dbus_method_invocation_return_dbus_error (invocation,

-                                                  "org.openbmc.PowerControl.Error.Failed",

-                                                  "Power Control is already at requested state");

-      return TRUE;     

-  }

+	if (state > 1)

+	{

+		g_dbus_method_invocation_return_dbus_error (invocation,

+                                                "org.openbmc.ControlPower.Error.Failed",

+                                                "Invalid power state");

+		return TRUE;

+	}

+	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;     

+	}

 

-  // TODO: Implement gpio toggling

-  g_print("Set power state: %d\n",state);

-  if (state==1)

-  {

-    g_print("Turn on\n");

-    tmp_pgood=1;

-  }

-  else

-  {

-    g_print("Turn off\n");

-    tmp_pgood=0;

-  }

-  power_control_set_state(pwr,state);

-  power_control_complete_set_power_state(pwr,invocation);

-  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);

+	return TRUE;

 }

 

 static gboolean

-on_get_power_state (PowerControl          *pwr,

+on_get_power_state (ControlPower          *pwr,

                 GDBusMethodInvocation  *invocation,

                 gpointer                user_data)

 {

-  guint pgood = power_control_get_pgood(pwr);

-  power_control_complete_get_power_state(pwr,invocation,pgood);

-  return TRUE;

+	guint pgood = control_power_get_pgood(pwr);

+	control_power_complete_get_power_state(pwr,invocation,pgood);

+	return TRUE;

 }

 

 static void 

@@ -96,39 +67,41 @@
                  const gchar     *name,

                  gpointer         user_data)

 {

-  ObjectSkeleton *object;

-  guint n;

+	ObjectSkeleton *object;

+	g_print ("Acquired a message bus connection: %s\n",name);

 

-  g_print ("Acquired a message bus connection: %s\n",name);

+	manager = g_dbus_object_manager_server_new (dbus_object_path);

+	gchar *s;

+  	s = g_strdup_printf ("%s/0",dbus_object_path);

+  	object = object_skeleton_new (s);

+  	g_free (s);

 

-  manager = g_dbus_object_manager_server_new (dbus_object_path);

+	control_power = control_power_skeleton_new ();

+	object_skeleton_set_control_power (object, control_power);

+	g_object_unref (control_power);

 

-  gchar *s;

-  s = g_strdup_printf ("%s/0",dbus_object_path);

-  object = object_skeleton_new (s);

-  g_free (s);

-

-  power_control = power_control_skeleton_new ();

-  object_skeleton_set_power_control (object, power_control);

-  g_object_unref (power_control);

-

-  //define method callbacks here

-  g_signal_connect (power_control,

+	//define method callbacks here

+	g_signal_connect (control_power,

                     "handle-set-power-state",

                     G_CALLBACK (on_set_power_state),

                     NULL); /* user_data */

 

-  g_signal_connect (power_control,

+	g_signal_connect (control_power,

                     "handle-get-power-state",

                     G_CALLBACK (on_get_power_state),

                     NULL); /* 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 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);

+	/* Export all objects */

+	g_dbus_object_manager_server_set_connection (manager, connection);

+

+	// get gpio device paths

+	gpio_init(connection,&power_pin);

+	gpio_init(connection,&pgood);

+	gpio_open(&pgood);

 }

 

 static void

@@ -150,28 +123,37 @@
 static gboolean

 poll_pgood()

 {

-  guint pgood = power_control_get_pgood(power_control);

-  //TOOD:  Change to actually read gpio

-  guint gpio = tmp_pgood;

+	if (pgood.fd >= 0)

+	{

+		uint8_t gpio = gpio_read(&pgood);

 

-  g_print("Polling pgood:  %d\n",gpio);

-

-  //if changed, set property and emit signal

-  if (gpio != power_control_get_pgood(power_control))

-  {

-     power_control_set_pgood(power_control,gpio);

-     if (gpio==0)

-     {

-       power_control_emit_power_lost(power_control);

-     }

-     else

-     {

-       power_control_emit_power_good(power_control);

-     }

-  }

-  return TRUE;

+		//if changed, set property and emit signal

+		if (gpio != control_power_get_pgood(control_power))

+		{

+ 			control_power_set_pgood(control_power,gpio);

+ 			if (gpio==0)

+ 			{

+ 				control_power_emit_power_lost(control_power);

+ 			}

+ 			else

+ 			{

+ 				control_power_emit_power_good(control_power);

+ 			}

+		}

+	}

+	else

+	{

+		//TODO: error handling

+		printf("Unable to read pgood\n");

+	}

+	return TRUE;

 }

 

+

+

+/*----------------------------------------------------------------*/

+/* Main Event Loop                                                */

+

 gint

 main (gint argc, gchar *argv[])

 {

diff --git a/objects/sensor_temperature_ambient_obj.c b/objects/sensor_temperature_ambient_obj.c
index 1f2ed47..8a05fd2 100644
--- a/objects/sensor_temperature_ambient_obj.c
+++ b/objects/sensor_temperature_ambient_obj.c
@@ -1,15 +1,24 @@
 #include "interfaces/sensor.h"

 

+

+

 /* ---------------------------------------------------------------------------------------------------- */

+typedef enum { NORMAL,LOWER_CRITICAL,LOWER_WARNING,UPPER_WARNING,UPPER_CRITICAL } threshold_states;

+

+

 static const gchar* dbus_object_path = "/org/openbmc/sensors/Temperature/Ambient";

 static const gchar* dbus_name        = "org.openbmc.sensors.Temperature.Ambient";

 

+

+

 static GDBusObjectManagerServer *manager = NULL;

 static SensorInteger *sensor = NULL;

 

 static gchar* i2c_bus = "";

 static gchar* i2c_address = "";

-static gboolean go = FALSE;

+static gboolean thresholds_set = FALSE;

+

+

 

 static gboolean

 on_get_units    (SensorInteger  *sen,

@@ -40,10 +49,74 @@
   g_print("I2C bus = %s\n",config[0]);

   g_print("I2C addr = %s\n",config[1]);

   sensor_integer_complete_set_config_data(sen,invocation);

-  go = TRUE;

   return TRUE;

 }

 

+static gboolean

+on_set_thresholds (SensorInteger                 *sen,

+                   GDBusMethodInvocation  *invocation,

+		   guint                  lc,

+		   guint                  lw,

+		   guint                  uw,

+		   guint                  uc,

+                   gpointer               user_data)

+{

+  sensor_integer_set_threshold_lower_critical(sen,lc);

+  sensor_integer_set_threshold_lower_warning(sen,lw);

+  sensor_integer_set_threshold_upper_warning(sen,uw);

+  sensor_integer_set_threshold_upper_critical(sen,uc);

+  sensor_integer_complete_set_thresholds(sen,invocation);

+  thresholds_set = TRUE;

+  return TRUE;

+}

+

+static gboolean

+on_get_threshold_state (SensorInteger                 *sen,

+                   GDBusMethodInvocation  *invocation,

+                   gpointer               user_data)

+{

+  guint state = sensor_integer_get_threshold_state(sen);

+  sensor_integer_complete_get_threshold_state(sen,invocation,state);

+  return TRUE;

+}

+

+

+static gboolean

+check_thresholds()

+{

+  if (thresholds_set == TRUE) {

+  threshold_states state = NORMAL;

+  guint value = sensor_integer_get_value(sensor);

+

+  if (value < sensor_integer_get_threshold_lower_critical(sensor)) {

+    state = LOWER_CRITICAL;

+  }

+  else if(value < sensor_integer_get_threshold_lower_warning(sensor)) {

+    state = LOWER_WARNING;

+  }

+  else if(value > sensor_integer_get_threshold_upper_critical(sensor)) {

+    state = UPPER_CRITICAL;

+  }

+  else if(value > sensor_integer_get_threshold_upper_warning(sensor)) {

+    state = UPPER_WARNING;

+  }

+  // only emit signal if threshold state changes

+  if (state != sensor_integer_get_threshold_state(sensor))

+  {

+     sensor_integer_set_threshold_state(sensor,state);

+     if (state == LOWER_CRITICAL || state == UPPER_CRITICAL)

+     {

+       sensor_integer_emit_critical(sensor);

+       g_print("Critical\n");

+     }

+     else if (state == LOWER_WARNING || state == UPPER_WARNING)

+     {

+       sensor_integer_emit_warning(sensor);

+       g_print("Warning\n");

+     }

+  }

+  }

+}

 

 static void 

 on_bus_acquired (GDBusConnection *connection,

@@ -81,7 +154,16 @@
                     "handle-set-config-data",

                     G_CALLBACK (on_set_config),

                     NULL); /* user_data */

+ 

+  g_signal_connect (sensor,

+                    "handle-set-thresholds",

+                    G_CALLBACK (on_set_thresholds),

+                    NULL); /* user_data */

 

+  g_signal_connect (sensor,

+                    "handle-get-threshold-state",

+                    G_CALLBACK (on_get_threshold_state),

+                    NULL); /* user_data */

 

 

   /* Export the object (@manager takes its own reference to @object) */

@@ -111,8 +193,6 @@
 static gboolean

 poll_sensor()

 {

-  if (go)

-  {

     guint value = sensor_integer_get_value(sensor);

     //TOOD:  Change to actually read sensor

     value = value+1;

@@ -121,11 +201,14 @@
     //if changed, set property and emit signal

     if (value != sensor_integer_get_value(sensor))

     {

-       g_print("Sensor changed");

+       g_print("Sensor changed\n");

        sensor_integer_set_value(sensor,value);

        sensor_integer_emit_changed(sensor,value);

+       if (thresholds_set == TRUE)

+       {

+         check_thresholds();

+       }

     }

-  }

     return TRUE;

 }