aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugin.c')
-rw-r--r--src/plugin.c304
1 files changed, 122 insertions, 182 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 9e6fb2e..92488fa 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 OpenedHand Ltd.
+ * Copyright (C) 2007, 2008 OpenedHand Ltd.
* Authored by: Rob Bradford <rob@o-hand.com>
*
* This is free software: you can redistribute it and/or modify it under the
@@ -35,7 +35,6 @@
#define g_timeout_add_seconds(interval, function, data) g_timeout_add ((interval) * 1000, function, data)
#endif
-
#define PREFS_PROP_SDK_ROOT "sdk.root"
#define PREFS_PROP_TRIPLET "sdk.triplet"
#define PREFS_PROP_POKY_ROOT "sdk.poky_root"
@@ -52,9 +51,6 @@
#define SSH_OPTIONS "-o", "CheckHostIP no", "-o", \
"StrictHostKeyChecking no", "-o", "UserKnownHostsFile /dev/null"
-#define QEMU_IP_ADDRESS "192.168.7.2"
-
-#define QEMU_SCRIPT "poky-qemu"
#define CONFIGURE_COMMAND "./configure --host=%s"
#define AUTOGEN_COMMAND "./autogen.sh --host=%s"
@@ -169,8 +165,6 @@ static GtkActionEntry actions_sdk[] = {
/* Misc callback prototypes */
static void message_view_buffer_flushed_cb (IAnjutaMessageView *view,
gchar *data, gpointer userdata);
-static void qemu_launcher_child_exited_cb (AnjutaLauncher *launcher,
- gint child_pid, gint status, gulong time, gpointer userdata);
static void remote_launcher_child_exited_cb (AnjutaLauncher *launcher,
gint child_pid, gint status, gulong time, gpointer userdata);
static void remote_gdb_launcher_child_exited_cb (AnjutaLauncher *launcher,
@@ -236,26 +230,6 @@ deploy_launcher_data_cb (AnjutaLauncher *launcher,
}
static void
-qemu_launcher_data_cb (AnjutaLauncher *launcher,
- AnjutaLauncherOutputType type, const gchar *chars, gpointer userdata)
-{
- AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
- GError *error = NULL;
-
- if (sp->qemu_msg_view)
- {
- /* Append to the buffer for the message view to deal with the newlines */
- ianjuta_message_view_buffer_append (sp->qemu_msg_view, chars, &error);
-
- if (error != NULL)
- {
- g_warning ("Error appending to message view: %s", error->message);
- g_clear_error (&error);
- }
- }
-}
-
-static void
remote_gdb_launcher_data_cb (AnjutaLauncher *launcher,
AnjutaLauncherOutputType type, const gchar *chars, gpointer userdata)
{
@@ -428,9 +402,11 @@ deploy_do_local_install (AnjutaPluginSdk *sp)
static void
deploy_do_copy (AnjutaPluginSdk *sp)
{
+ const gchar *ip_address = NULL;
gchar *copy_cmd = NULL;
- copy_cmd = g_strdup_printf (DEPLOY_COMMAND, sp->deploy_path, QEMU_IP_ADDRESS);
+ ip_address = beaver_target_get_ip_address (sp->target);
+ copy_cmd = g_strdup_printf (DEPLOY_COMMAND, sp->deploy_path, ip_address);
ianjuta_message_view_append (sp->deploy_msg_view, IANJUTA_MESSAGE_VIEW_TYPE_INFO,
_("Copying files to target"), "", NULL);
@@ -510,21 +486,21 @@ static void
action_shutdown_qemu_activate_cb (GtkAction *actio, gpointer userdata)
{
AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
- gchar *args[] = { "ssh", SSH_OPTIONS,
- "root@"QEMU_IP_ADDRESS, "reboot", NULL};
- if (!sp->remote_launcher)
+ if (BEAVER_IS_TARGET_QEMU (sp->target))
{
- sp->remote_launcher = anjuta_launcher_new ();
- g_signal_connect (sp->remote_launcher, "child-exited",
- (GCallback)remote_launcher_child_exited_cb, sp);
+ beaver_target_qemu_shutdown (BEAVER_TARGET_QEMU (sp->target), NULL);
}
+}
- if (anjuta_launcher_execute_v (sp->remote_launcher, args, NULL, NULL))
+static void
+action_start_qemu_activate_cb (GtkAction *action, gpointer userdata)
+{
+ AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
+
+ if (BEAVER_IS_TARGET_QEMU (sp->target))
{
- gtk_action_set_sensitive (sp->qemu_shutdown_action, FALSE);
- } else {
- g_warning ("Error whilst launching reboot (for shutdown) command");
+ beaver_target_qemu_start (BEAVER_TARGET_QEMU(sp->target), NULL);
}
}
@@ -532,8 +508,12 @@ static void
action_remote_debug_stop_activate_cb (GtkAction *action, gpointer userdata)
{
AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
- gchar *args[] = { "ssh", SSH_OPTIONS,
- "root@"QEMU_IP_ADDRESS, "killall gdbserver", NULL};
+ gchar *args[] = { "ssh",
+ SSH_OPTIONS,
+ "-l", "root",
+ (gchar *)beaver_target_get_ip_address (sp->target),
+ "killall gdbserver",
+ NULL};
if (!sp->remote_launcher)
{
@@ -558,94 +538,6 @@ action_deploy_activate_cb (GtkAction *action, gpointer userdata)
deploy_set_state (sp, DEPLOY_STATE_INITIAL);
}
-static void
-action_start_qemu_activate_cb (GtkAction *action, gpointer userdata)
-{
- AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
- GError *error = NULL;
- IAnjutaMessageManager *msg_manager = NULL;
-
- /* Get the message view manager */
- msg_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (sp)->shell,
- IAnjutaMessageManager, &error);
-
- if (!msg_manager)
- {
- g_warning ("Error getting implementation of IAnjutaMessageManager: %s",
- error->message);
- g_clear_error (&error);
-
- return;
- }
-
- if (!sp->qemu_msg_view)
- {
- /* Create a new view */
- sp->qemu_msg_view = ianjuta_message_manager_add_view (msg_manager,
- _("QEMU"), ICON_FILE, &error);
-
- if (!sp->qemu_msg_view)
- {
- g_warning ("Error getting view: %s", error->message);
- g_clear_error (&error);
- return;
- }
-
- g_signal_connect (sp->qemu_msg_view, "buffer-flushed",
- (GCallback)message_view_buffer_flushed_cb, sp);
-
- /* When the view is destroyed make the pointer to it null */
- g_object_add_weak_pointer (G_OBJECT (sp->qemu_msg_view),
- (gpointer *)&sp->qemu_msg_view);
- }
-
- ianjuta_message_manager_set_current_view (msg_manager, sp->qemu_msg_view,
- &error);
-
- if (error != NULL)
- {
- g_warning ("Error setting current message view: %s", error->message);
- g_clear_error (&error);
-
- return;
- }
-
- if (!sp->qemu_launcher)
- {
- sp->qemu_launcher = anjuta_launcher_new ();
- g_signal_connect (sp->qemu_launcher, "child-exited",
- (GCallback)qemu_launcher_child_exited_cb, sp);
- }
-
- if (sp->kernel && sp->rootfs)
- {
- gchar *args[] = {QEMU_SCRIPT, sp->kernel, sp->rootfs, NULL};
-
- if (!anjuta_launcher_execute_v (sp->qemu_launcher, args, qemu_launcher_data_cb, sp))
- {
- g_warning ("Error launching QEMU");
- } else {
- gtk_action_set_sensitive (sp->qemu_start_action, FALSE);
- gtk_action_set_sensitive (sp->qemu_shutdown_action, TRUE);
- gtk_action_set_sensitive (sp->remote_run_action, TRUE);
-
- if (sp->triplet && sp->sdk_root)
- gtk_action_set_sensitive (sp->remote_debug_action, TRUE);
-
- if (anjuta_util_prog_is_installed ("oprofile-viewer", FALSE))
- {
- gtk_action_set_sensitive (sp->remote_profile_action, TRUE);
- }
-
- /* Make the actions sensitive if we have a project root*/
- if (sp->project_root_uri)
- {
- gtk_action_set_sensitive (sp->deploy_action, TRUE);
- }
- }
- }
-}
-
static gint
remote_debug_dialog (AnjutaPluginSdk *sp)
{
@@ -826,7 +718,8 @@ do_local_gdb (AnjutaPluginSdk *sp)
}
gdb_prefix = g_build_filename (sp->sdk_root, sp->triplet, NULL);
- script_contents = g_strdup_printf (GDB_SCRIPT, gdb_prefix, QEMU_IP_ADDRESS);
+ script_contents = g_strdup_printf (GDB_SCRIPT, gdb_prefix,
+ beaver_target_get_ip_address (sp->target));
channel = g_io_channel_unix_new (fd);
@@ -945,7 +838,9 @@ do_remote_gdb (AnjutaPluginSdk *sp)
return;
}
- cmd = g_strdup_printf (REMOTE_GDB_COMMAND, QEMU_IP_ADDRESS, sp->gdb_remote_command);
+ cmd = g_strdup_printf (REMOTE_GDB_COMMAND,
+ beaver_target_get_ip_address (sp->target),
+ sp->gdb_remote_command);
/* start the remote gdbserver */
if (anjuta_launcher_execute (sp->remote_gdb_launcher, cmd,
@@ -1034,7 +929,9 @@ action_remote_run_activate_cb (GtkAction *action,
switch (res)
{
case GTK_RESPONSE_ACCEPT:
- cmd = g_strdup_printf (REMOTE_COMMAND, QEMU_IP_ADDRESS, sp->remote_command);
+ cmd = g_strdup_printf (REMOTE_COMMAND,
+ beaver_target_get_ip_address (sp->target),
+ sp->remote_command);
ianjuta_terminal_execute_command (terminal, cur_dir, cmd, &error);
break;
default:
@@ -1060,7 +957,9 @@ action_remote_profile_activate_cb (GtkAction *action, gpointer userdata)
}
search_path = g_build_filename (sp->sdk_root, sp->triplet, NULL);
- cmd = g_strdup_printf (OPROFILEUI_COMMAND, QEMU_IP_ADDRESS, search_path);
+ cmd = g_strdup_printf (OPROFILEUI_COMMAND,
+ beaver_target_get_ip_address (sp->target),
+ search_path);
if (anjuta_launcher_execute (sp->oprofileui_launcher, cmd, NULL, NULL))
{
@@ -1074,24 +973,7 @@ action_remote_profile_activate_cb (GtkAction *action, gpointer userdata)
}
/* Callback for when qemu launcher finished */
-static void
-qemu_launcher_child_exited_cb (AnjutaLauncher *launcher, gint child_pid,
- gint status, gulong time, gpointer userdata)
-{
- AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
- gtk_action_set_sensitive (sp->qemu_start_action, TRUE);
- gtk_action_set_sensitive (sp->qemu_shutdown_action, FALSE);
-
- /* Make the deploy insensitive */
- gtk_action_set_sensitive (sp->deploy_action, FALSE);
-
- gtk_action_set_sensitive (sp->remote_debug_action, FALSE);
- gtk_action_set_sensitive (sp->remote_run_action, FALSE);
- gtk_action_set_sensitive (sp->remote_debug_stop_action, FALSE);
-
- gtk_action_set_sensitive (sp->remote_profile_action, FALSE);
-}
static void
remote_launcher_child_exited_cb (AnjutaLauncher *launcher, gint child_pid,
@@ -1107,8 +989,8 @@ remote_gdb_launcher_child_exited_cb (AnjutaLauncher *launcher, gint child_pid,
{
AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
- if (sp->triplet && sp->sdk_root && sp->qemu_launcher &&
- anjuta_launcher_is_busy (sp->qemu_launcher))
+ if (sp->triplet && sp->sdk_root &&
+ beaver_target_get_state (sp->target) == TARGET_STATE_READY)
{
gtk_action_set_sensitive (sp->remote_debug_action, TRUE);
}
@@ -1126,7 +1008,7 @@ oprofileui_launcher_child_exited_cb (AnjutaLauncher *launcher, gint child_pid,
{
AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
- if (sp->qemu_launcher && anjuta_launcher_is_busy (sp->qemu_launcher))
+ if (beaver_target_get_state (sp->target) == TARGET_STATE_READY)
{
if (anjuta_util_prog_is_installed ("oprofile-viewer", FALSE))
{
@@ -1415,13 +1297,12 @@ rootfs_preference_notify_cb (GConfClient *client, guint cnxn_id,
GConfEntry *entry, gpointer userdata)
{
AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
+ gchar *rootfs = NULL;
- g_free (sp->rootfs);
- sp->rootfs = anjuta_preferences_get (sp->prefs, PREFS_PROP_ROOTFS);
-
- if (sp->rootfs && sp->kernel)
+ if (BEAVER_IS_TARGET_QEMU (sp->target))
{
- gtk_action_set_sensitive (sp->qemu_start_action, TRUE);
+ rootfs = anjuta_preferences_get (sp->prefs, PREFS_PROP_ROOTFS);
+ g_object_set (sp->target, "rootfs", rootfs, NULL);
}
}
@@ -1430,13 +1311,12 @@ kernel_preference_notify_cb (GConfClient *client, guint cnxn_id,
GConfEntry *entry, gpointer userdata)
{
AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
+ gchar *kernel = NULL;
- g_free (sp->kernel);
- sp->kernel = anjuta_preferences_get (sp->prefs, PREFS_PROP_KERNEL);
-
- if (sp->rootfs && sp->kernel)
+ if (BEAVER_IS_TARGET_QEMU (sp->target))
{
- gtk_action_set_sensitive (sp->qemu_start_action, TRUE);
+ kernel = anjuta_preferences_get (sp->prefs, PREFS_PROP_KERNEL);
+ g_object_set (sp->target, "kernel", kernel, NULL);
}
}
@@ -1477,8 +1357,7 @@ project_root_uri_value_added (AnjutaPlugin *plugin, const gchar *name,
g_free (sp->project_root_uri);
sp->project_root_uri = g_value_dup_string (value);
- /* if qemu is already running then turn these actions on */
- if (sp->qemu_launcher && anjuta_launcher_is_busy (sp->qemu_launcher))
+ if (beaver_target_get_state (sp->target) == TARGET_STATE_READY)
{
gtk_action_set_sensitive (sp->deploy_action, TRUE);
}
@@ -1524,12 +1403,69 @@ shell_session_save_cb (AnjutaShell *shell, AnjutaSessionPhase phase,
sp->gdb_remote_command);
}
+static void
+target_state_changed_cb (BeaverTarget *target, gpointer userdata)
+{
+ AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata;
+ BeaverTargetState state;
+
+ state = beaver_target_get_state (target);
+
+ if (BEAVER_IS_TARGET_QEMU (target))
+ {
+ switch (state)
+ {
+ case TARGET_STATE_UNKNOWN:
+ gtk_action_set_sensitive (sp->qemu_start_action, FALSE);
+ break;
+ case TARGET_STATE_STOPPED:
+ gtk_action_set_sensitive (sp->qemu_start_action, TRUE);
+ break;
+ case TARGET_STATE_READY:
+ gtk_action_set_sensitive (sp->qemu_start_action, FALSE);
+ gtk_action_set_sensitive (sp->qemu_shutdown_action, TRUE);
+ case TARGET_STATE_BUSY:
+ gtk_action_set_sensitive (sp->qemu_shutdown_action, FALSE);
+ default:
+ break;
+ }
+ }
+
+ switch (state)
+ {
+ case TARGET_STATE_UNKNOWN:
+ case TARGET_STATE_STOPPED:
+ case TARGET_STATE_BUSY:
+ gtk_action_set_sensitive (sp->deploy_action, FALSE);
+ gtk_action_set_sensitive (sp->remote_profile_action, FALSE);
+ gtk_action_set_sensitive (sp->qemu_shutdown_action, FALSE);
+ gtk_action_set_sensitive (sp->remote_run_action, FALSE);
+ gtk_action_set_sensitive (sp->remote_debug_action, FALSE);
+ break;
+ case TARGET_STATE_READY:
+ /* Can only turn on if have a project */
+ if (sp->project_root_uri)
+ gtk_action_set_sensitive (sp->deploy_action, TRUE);
+
+ if (anjuta_util_prog_is_installed ("oprofile-viewer", FALSE))
+ gtk_action_set_sensitive (sp->remote_profile_action, TRUE);
+
+ gtk_action_set_sensitive (sp->qemu_shutdown_action, TRUE);
+ gtk_action_set_sensitive (sp->remote_run_action, TRUE);
+ gtk_action_set_sensitive (sp->remote_debug_action, TRUE);
+ break;
+ }
+}
+
static gboolean
anjuta_plugin_sdk_activate (AnjutaPlugin *plugin)
{
AnjutaPluginSdk *sp = (AnjutaPluginSdk *)plugin;
AnjutaUI *ui;
GError *error = NULL;
+ IAnjutaMessageManager *msg_manager;
+ gchar *kernel = NULL;
+ gchar *rootfs = NULL;
ui = anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin)->shell, NULL);
@@ -1583,16 +1519,28 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin)
sp->sdk_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_SDK_ROOT);
sp->triplet = anjuta_preferences_get (sp->prefs, PREFS_PROP_TRIPLET);
- sp->kernel = anjuta_preferences_get (sp->prefs, PREFS_PROP_KERNEL);
- sp->rootfs = anjuta_preferences_get (sp->prefs, PREFS_PROP_ROOTFS);
+
sp->poky_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_POKY_ROOT);
sp->poky_mode = anjuta_preferences_get_int (sp->prefs, PREFS_PROP_POKY_MODE);
- if (sp->kernel == NULL || sp->rootfs == NULL)
+ msg_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (sp)->shell,
+ IAnjutaMessageManager, &error);
+
+ if (!msg_manager)
{
- gtk_action_set_sensitive (sp->qemu_start_action, FALSE);
+ g_warning ("Error getting implementation of IAnjutaMessageManager: %s",
+ error->message);
+ g_clear_error (&error);
}
+ sp->target = beaver_target_qemu_new (ANJUTA_PLUGIN (plugin)->shell);
+ g_signal_connect (sp->target, "state-changed",
+ (GCallback)target_state_changed_cb, sp);
+
+ kernel = anjuta_preferences_get (sp->prefs, PREFS_PROP_KERNEL);
+ rootfs = anjuta_preferences_get (sp->prefs, PREFS_PROP_ROOTFS);
+ g_object_set (sp->target, "kernel", kernel, "rootfs", rootfs, NULL);
+
update_environment (sp);
setup_buildable (sp);
@@ -1630,19 +1578,12 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin)
sp->deploy_msg_view = NULL;
}
- if (sp->qemu_msg_view)
- {
- ianjuta_message_manager_remove_view (msg_manager, sp->qemu_msg_view, NULL);
- sp->qemu_msg_view = NULL;
- }
-
if (sp->remote_msg_view)
{
ianjuta_message_manager_remove_view (msg_manager, sp->remote_msg_view, NULL);
sp->remote_msg_view = NULL;
}
-
if (sp->buildable)
{
ianjuta_buildable_reset_commands (sp->buildable, &error);
@@ -1667,7 +1608,6 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin)
g_signal_handlers_disconnect_by_func (plugin->shell, shell_session_load_cb, sp);
g_signal_handlers_disconnect_by_func (plugin->shell, shell_session_save_cb, sp);
-
/*
* Do lots of things you'd normally expect to see in a dispose/finalize,
* i.e. to free up memory but because a plugin won't get disposed/finalized
@@ -1680,12 +1620,6 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin)
sp->deploy_launcher = NULL;
}
- if (sp->qemu_launcher)
- {
- g_object_unref (sp->qemu_launcher);
- sp->qemu_launcher = NULL;
- }
-
if (sp->remote_launcher)
{
g_object_unref (sp->remote_launcher);
@@ -1710,6 +1644,12 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin)
sp->prefs_icon = NULL;
}
+ if (sp->target)
+ {
+ g_object_unref (sp->target);
+ sp->target = NULL;
+ }
+
/*
* Must set these to NULL because the plugin object might get reused after
* deactivation.