diff options
Diffstat (limited to 'src/plugin.c')
-rw-r--r-- | src/plugin.c | 219 |
1 files changed, 149 insertions, 70 deletions
diff --git a/src/plugin.c b/src/plugin.c index 0ea32c6..0662abd 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -162,6 +162,7 @@ static void remote_gdb_launcher_child_exited_cb (AnjutaLauncher *launcher, gint child_pid, gint status, gulong time, gpointer userdata); static void oprofileui_launcher_child_exited_cb (AnjutaLauncher *launcher, gint child_pid, gint status, gulong time, gpointer userdata); +static void target_state_changed_cb (BeaverTarget *target, gpointer userdata); /* Prototypes for deployment related activities */ static void deploy_set_state (AnjutaPluginSdk *sp, DeployState deploy_state); @@ -1209,6 +1210,115 @@ update_environment (AnjutaPluginSdk *sp) } static void +update_state (AnjutaPluginSdk *sp) +{ + BeaverTargetState state; + + state = beaver_target_get_state (sp->target); + + if (BEAVER_IS_TARGET_QEMU (sp->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; + } + } else { + gtk_action_set_sensitive (sp->qemu_start_action, FALSE); + gtk_action_set_sensitive (sp->qemu_shutdown_action, FALSE); + } + + 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->remote_run_action, TRUE); + gtk_action_set_sensitive (sp->remote_debug_action, TRUE); + break; + } +} + + +static void +setup_target (AnjutaPluginSdk *sp) +{ + switch (sp->target_mode) + { + case TARGET_MODE_QEMU: + { + gchar *kernel = NULL; + gchar *rootfs = NULL; + + if (sp->target && + BEAVER_IS_TARGET_QEMU (sp->target)) + return; + + if (sp->target) + g_object_unref (sp->target); + + sp->target = beaver_target_qemu_new (ANJUTA_PLUGIN (sp)->shell); + + 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); + g_free (kernel); + g_free (rootfs); + break; + } + case TARGET_MODE_DEVICE: + { + gchar *ip_address = NULL; + if (sp->target && + BEAVER_IS_TARGET_DEVICE (sp->target)) + return; + + if (sp->target) + g_object_unref (sp->target); + + sp->target = beaver_target_device_new (ANJUTA_PLUGIN (sp)->shell); + + ip_address = anjuta_preferences_get (sp->prefs, PREFS_PROP_TARGET_IP); + g_object_set (sp->target, "ip-address", ip_address, NULL); + g_free (ip_address); + + break; + } + } + + g_signal_connect (sp->target, "state-changed", + (GCallback)target_state_changed_cb, sp); + + update_state (sp); +} + + +static void setup_buildable (AnjutaPluginSdk *sp) { gchar *command = NULL; @@ -1294,6 +1404,7 @@ rootfs_preference_notify_cb (GConfClient *client, guint cnxn_id, { rootfs = anjuta_preferences_get (sp->prefs, PREFS_PROP_ROOTFS); g_object_set (sp->target, "rootfs", rootfs, NULL); + g_free (rootfs); } } @@ -1308,6 +1419,7 @@ kernel_preference_notify_cb (GConfClient *client, guint cnxn_id, { kernel = anjuta_preferences_get (sp->prefs, PREFS_PROP_KERNEL); g_object_set (sp->target, "kernel", kernel, NULL); + g_free (kernel); } } @@ -1334,6 +1446,33 @@ poky_root_preference_notify_cb (GConfClient *client, guint cnxn_id, update_environment (sp); } +static void +target_mode_preference_notify_cb (GConfClient *client, guint cnxn_id, + GConfEntry *entry, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + + sp->target_mode = anjuta_preferences_get_int (sp->prefs, PREFS_PROP_TARGET_MODE); + + setup_target (sp); +} + +static void +target_ip_preference_notify_cb (GConfClient *client, guint cnxn_id, + GConfEntry *entry, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + gchar *ip_address = NULL; + + if (sp->target && + BEAVER_IS_TARGET_DEVICE (sp->target)) + { + ip_address = anjuta_preferences_get (sp->prefs, PREFS_PROP_TARGET_IP); + g_object_set (sp->target, "ip-address", ip_address, NULL); + g_free (ip_address); + } +} + /* * Callbacks for when a value for "project_root_uri" is added to the shell aka * when a project is opened @@ -1398,54 +1537,7 @@ 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; - } + update_state (sp); } static gboolean @@ -1454,7 +1546,6 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) AnjutaPluginSdk *sp = (AnjutaPluginSdk *)plugin; AnjutaUI *ui; GError *error = NULL; - IAnjutaMessageManager *msg_manager; gchar *kernel = NULL; gchar *rootfs = NULL; @@ -1488,6 +1579,7 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) sp->remote_profile_action = anjuta_ui_get_action (ui, "ActionGroupSdk", "ActionRemoteProfile"); + gtk_action_set_sensitive (sp->qemu_start_action, FALSE); gtk_action_set_sensitive (sp->qemu_shutdown_action, FALSE); gtk_action_set_sensitive (sp->deploy_action, FALSE); gtk_action_set_sensitive (sp->remote_run_action, FALSE); @@ -1507,6 +1599,10 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) PREFS_PROP_POKY_ROOT, poky_root_preference_notify_cb, sp, NULL); sp->poky_mode_notifyid = anjuta_preferences_notify_add (sp->prefs, PREFS_PROP_POKY_MODE, poky_mode_preference_notify_cb, sp, NULL); + sp->target_mode_notifyid = anjuta_preferences_notify_add (sp->prefs, + PREFS_PROP_TARGET_MODE, target_mode_preference_notify_cb, sp, NULL); + sp->target_ip_notifyid = anjuta_preferences_notify_add (sp->prefs, + PREFS_PROP_TARGET_IP, target_ip_preference_notify_cb, sp, NULL); sp->sdk_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_SDK_ROOT); sp->triplet = anjuta_preferences_get (sp->prefs, PREFS_PROP_TRIPLET); @@ -1514,24 +1610,9 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) 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); - 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); - } - - 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); + sp->target_mode = anjuta_preferences_get_int (sp->prefs, PREFS_PROP_TARGET_MODE); + setup_target (sp); update_environment (sp); setup_buildable (sp); @@ -1593,6 +1674,8 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) anjuta_preferences_notify_remove (sp->prefs, sp->kernel_notifyid); anjuta_preferences_notify_remove (sp->prefs, sp->poky_root_notifyid); anjuta_preferences_notify_remove (sp->prefs, sp->poky_mode_notifyid); + anjuta_preferences_notify_remove (sp->prefs, sp->target_mode_notifyid); + anjuta_preferences_notify_remove (sp->prefs, sp->target_ip_notifyid); anjuta_plugin_remove_watch (plugin, sp->project_root_uri_watch, FALSE); @@ -1648,8 +1731,6 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) g_free (sp->sdk_root); g_free (sp->triplet); - g_free (sp->kernel); - g_free (sp->rootfs); g_free (sp->poky_root); g_free (sp->project_root_uri); @@ -1660,8 +1741,6 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) sp->sdk_root = NULL; sp->triplet = NULL; - sp->kernel = NULL; - sp->rootfs = NULL; sp->poky_root = NULL; sp->project_root_uri = NULL; |