Skip to content

Commit

Permalink
scope - GArray thread_groups -> ScpTreeStore
Browse files Browse the repository at this point in the history
  • Loading branch information
zhekov committed May 2, 2013
1 parent 06cb7d4 commit e461171
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 55 deletions.
7 changes: 7 additions & 0 deletions scope/ChangeLog
@@ -1,3 +1,9 @@
2013-05-02 Dimitar Zhekov <dimitar.zhekov@gmail.com>

* data/scope.glade, src/thread.c:
GArray thread_groups -> ScpTreeStore.


2013-04-25 Dimitar Zhekov <dimitar.zhekov@gmail.com>

* src/break.c, src/utils.c:
Expand All @@ -7,6 +13,7 @@
* src/store/scptreestore.html:
ScpTreeStore documentation fixes.


2013-04-04 Dimitar Zhekov <dimitar.zhekov@gmail.com>

* data/scope.glade, src/Makefile.am, src/break.c, src/common.h,
Expand Down
9 changes: 9 additions & 0 deletions scope/data/scope.glade
Expand Up @@ -1227,6 +1227,15 @@
</object>
</child>
</object>
<object class="ScpTreeStore" id="thread_group_store">
<property name="sublevels">False</property>
<columns>
<!-- column-name thread_group_store_id -->
<column type="gchararray" utf8_collate="false"/>
<!-- column-name thread_group_store_pid -->
<column type="gchararray" utf8_collate="false"/>
</columns>
</object>
<object class="ScpTreeStore" id="thread_store">
<property name="sublevels">False</property>
<columns>
Expand Down
93 changes: 38 additions & 55 deletions scope/src/thread.c
Expand Up @@ -32,40 +32,27 @@
#include <windows.h>
#endif

typedef struct _ThreadGroup
{
char *gid;
char *pid;
} ThreadGroup;

static GArray *thread_groups = NULL;

static ThreadGroup *find_thread_group(const char *gid)
enum
{
ThreadGroup *group = (ThreadGroup *) array_find(thread_groups, gid, FALSE);

if (G_UNLIKELY(!group))
dc_error("%s: gid not found", gid);
GROUP_ID,
GROUP_PID
};

return group;
}
static ScpTreeStore *groups = NULL;

void on_thread_group_started(GArray *nodes)
{
const char *gid = parse_lead_value(nodes);
const char *pid = parse_find_value(nodes, "pid");

ui_set_statusbar(TRUE, _("Thread group %s started."), pid ? pid : gid ? gid : "");
ui_set_statusbar(TRUE, _("Thread group %s started."), pid ? pid : gid);

iff (pid, "no pid")
{
ThreadGroup *group = find_thread_group(gid);
GtkTreeIter iter;

if (group)
{
g_free(group->pid);
group->pid = g_strdup(pid);
}
iff (store_find(groups, &iter, GROUP_ID, gid), "%s: gid not found", gid)
scp_tree_store_set(groups, &iter, GROUP_PID, pid, -1);
}
}

Expand All @@ -74,16 +61,24 @@ void on_thread_group_exited(GArray *nodes)
const char *gid = parse_lead_value(nodes);
const char *exit_code = parse_find_value(nodes, "exit-code");
GString *status = g_string_new(_("Thread group "));
ThreadGroup *group = find_thread_group(gid);
GtkTreeIter iter;

if (group && group->pid)
if (store_find(groups, &iter, GROUP_ID, gid))
{
g_string_append(status, group->pid);
g_free(group->pid);
group->pid = NULL;
const char *pid;

scp_tree_store_get(groups, &iter, GROUP_PID, &pid, -1);
if (pid)
{
g_string_append(status, pid);
scp_tree_store_set(groups, &iter, GROUP_PID, NULL, -1);
}
}
else
{
dc_error("%s: gid not found", gid);
g_string_append(status, gid);
}

g_string_append(status, _(" exited"));
if (exit_code)
Expand All @@ -100,26 +95,18 @@ void on_thread_group_exited(GArray *nodes)

void on_thread_group_added(GArray *nodes)
{
ThreadGroup *group = (ThreadGroup *) array_append(thread_groups);
group->gid = g_strdup(parse_lead_value(nodes));
group->pid = NULL;
}

static void thread_group_free(ThreadGroup *group)
{
g_free(group->gid);
g_free(group->pid);
GtkTreeIter iter;
scp_tree_store_append(groups, &iter, NULL);
scp_tree_store_set(groups, &iter, GROUP_ID, parse_lead_value(nodes), -1);
}

void on_thread_group_removed(GArray *nodes)
{
ThreadGroup *group = find_thread_group(parse_lead_value(nodes));
const char *gid = parse_lead_value(nodes);
GtkTreeIter iter;

if (group)
{
thread_group_free(group);
array_remove(thread_groups, group);
}
iff (store_find(groups, &iter, GROUP_ID, gid), "%s: gid not found", gid)
scp_tree_store_remove(groups, &iter);
}

enum
Expand Down Expand Up @@ -454,20 +441,16 @@ void on_thread_created(GArray *nodes)
iff (tid, "no tid")
{
GtkTreeIter iter;
const char *pid = NULL;

iff (gid, "no gid")
iff (store_find(groups, &iter, GROUP_ID, gid), "%s: gid not found", gid)
scp_tree_store_get(groups, &iter, GROUP_PID, &pid, -1);

scp_tree_store_append_with_values(store, &iter, NULL, THREAD_ID, tid, THREAD_STATE,
"", -1);
"", THREAD_GROUP_ID, gid, THREAD_PID, pid, -1);
debug_send_format(N, "04-thread-info %s", tid);

if (gid)
{
ThreadGroup *group = find_thread_group(gid);

scp_tree_store_set(store, &iter, THREAD_GROUP_ID, gid, -1);
if (group && group->pid)
scp_tree_store_set(store, &iter, THREAD_PID, group->pid, -1);
}

if (thread_count == 1)
set_gdb_thread(tid, TRUE);
}
Expand Down Expand Up @@ -602,7 +585,7 @@ void threads_mark(GeanyDocument *doc)
void threads_clear(void)
{
store_foreach(store, (GFunc) thread_iter_unmark, GINT_TO_POINTER(TRUE));
array_clear(thread_groups, (GFreeFunc) thread_group_free);
store_clear(groups);
store_clear(store);
set_gdb_thread(NULL, FALSE);
thread_count = 0;
Expand Down Expand Up @@ -901,7 +884,8 @@ void thread_init(void)
g_signal_connect(tree, "query-tooltip", G_CALLBACK(on_view_query_tooltip),
get_column("thread_base_name_column"));

thread_groups = array_new(ThreadGroup, 0x10);
groups = SCP_TREE_STORE(get_object("thread_group_store"));
scp_tree_store_set_sort_column_id(groups, GROUP_ID, GTK_SORT_ASCENDING);
RUNNING = _("Running");
STOPPED = _("Stopped");
g_signal_connect(tree, "key-press-event", G_CALLBACK(on_view_key_press),
Expand All @@ -920,6 +904,5 @@ void thread_init(void)
void thread_finalize(void)
{
store_foreach(store, (GFunc) thread_iter_unmark, NULL);
array_free(thread_groups, (GFreeFunc) thread_group_free);
set_gdb_thread(NULL, FALSE);
}

0 comments on commit e461171

Please sign in to comment.