skeleton: Add BMC warmReset() method to org.openbmc.control.Bmc dbus interface

1.The host sends IPMI 'warm reset' command to reset BMC. Ipmid
calls the org.openbmc.control.Bmc::warmReset() to do reset.
warmReset() just invokes "reboot", which in effect
same as a 'warm' reset.
2.Add control.bmc to Palmetto.py/Barreleye.py to initialize this dbus method.
3.Comment g_idle_add() for loop issue.

Signed-off-by: Nan Li <bjlinan@cn.ibm.com>
diff --git a/objects/control_bmc_obj.c b/objects/control_bmc_obj.c
index 6b92235..f1a47c7 100644
--- a/objects/control_bmc_obj.c
+++ b/objects/control_bmc_obj.c
@@ -67,7 +67,6 @@
 

 	//UART

 

-	

 	bmcreg = memmap(mem_fd,UART_BASE);

 	devmem(bmcreg+0x00,0x00000000);  //Set Baud rate divisor -> 13 (Baud 115200)

 	devmem(bmcreg+0x04,0x00000000);  //Set Baud rate divisor -> 13 (Baud 115200)

@@ -109,9 +108,31 @@
 	//#endif

 	control_complete_init(control,invocation);

 	//control_emit_goto_system_state(control,"BMC_STARTING");

-	

 	return TRUE;

 }

+
+static gboolean
+on_warm_reset (ControlBmc            	*bmc,
+               GDBusMethodInvocation	*invocation,
+               gpointer		            user_data)
+{
+	GError *err = NULL;
+	/* Wait a while before reboot, so the caller can be responded.
+	 * Note that g_spawn_command_line_async() cannot parse ';' as
+	 * a command separator. Need to use 'sh -c' to let shell parse it.
+	 */
+	gchar *reboot_command = "/bin/sh -c 'sleep 3;reboot'";
+
+	g_spawn_command_line_async(reboot_command, &err);
+	if (err != NULL) {
+		fprintf(stderr, "warmReset() error: %s\n", err->message);
+		g_error_free(err);
+	}
+
+	control_bmc_complete_warm_reset(bmc, invocation);
+	return TRUE;
+}
+
 gboolean go(gpointer user_data)

 {

  	cmdline *cmd = user_data;

@@ -124,8 +145,8 @@
 	//g_main_loop_quit(cmd->loop);

 	return FALSE;

 }

-

-static void 

+
+static void
 on_bus_acquired (GDBusConnection *connection,

                  const gchar     *name,

                  gpointer         user_data)

@@ -153,6 +174,12 @@
                	    G_CALLBACK (on_init),

                	    NULL); /* user_data */

 

+
+	g_signal_connect (control_bmc,
+		"handle-warm-reset",
+		G_CALLBACK (on_warm_reset),
+		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);

@@ -163,7 +190,7 @@
 	//TODO:  This is a bad hack to wait for object to be on bus

 	//sleep(1);

 	cmd->user_data = object;

-	g_idle_add(go,cmd);

+	//g_idle_add(go,cmd);

 }

 

 

@@ -210,7 +237,7 @@
                        NULL);

 

   g_main_loop_run (loop);

-  

+
   g_bus_unown_name (id);

   g_main_loop_unref (loop);

   return 0;