summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.c3
-rw-r--r--src/program.h17
-rw-r--r--src/rbug.c58
-rw-r--r--src/shader.c19
-rw-r--r--src/texture.c34
5 files changed, 93 insertions, 38 deletions
diff --git a/src/main.c b/src/main.c
index 9801bd9..b847dbb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -405,7 +405,8 @@ void main_quit(struct program *p)
rbug_disconnect(p->rbug.con);
g_io_channel_unref(p->rbug.channel);
g_source_remove(p->rbug.event);
- g_hash_table_unref(p->rbug.hash);
+ g_hash_table_unref(p->rbug.hash_event);
+ g_hash_table_unref(p->rbug.hash_reply);
}
g_free(p->ask.host);
diff --git a/src/program.h b/src/program.h
index aa38d8a..36d6a41 100644
--- a/src/program.h
+++ b/src/program.h
@@ -30,9 +30,15 @@
#include "rbug/rbug.h"
+struct program;
struct texture_action_read;
struct shader_action_info;
+struct rbug_event
+{
+ gboolean (*func)(struct rbug_event *, struct rbug_header *, struct program *);
+};
+
enum columns {
COLUMN_ID = 0,
COLUMN_TYPE,
@@ -131,7 +137,8 @@ struct program
struct rbug_connection *con;
GIOChannel *channel;
gint event;
- GHashTable *hash;
+ GHashTable *hash_event;
+ GHashTable *hash_reply;
} rbug;
struct {
@@ -139,11 +146,6 @@ struct program
} icon;
};
-struct rbug_event
-{
- void (*func)(struct rbug_event *, struct rbug_header *, struct program *);
-};
-
/* src/ask.c */
void ask_window_create(struct program *p);
@@ -159,7 +161,8 @@ GdkPixbuf* icon_get(const char *name, struct program *p);
/* src/rbug.c */
-void rbug_add_event(struct rbug_event *e, uint32_t serial, struct program *p);
+void rbug_add_reply(struct rbug_event *e, uint32_t serial, struct program *p);
+void rbug_add_event(struct rbug_event *e, int16_t op, struct program *p);
void rbug_glib_io_watch(struct program *p);
void rbug_finish_and_emit_events(struct program *p);
diff --git a/src/rbug.c b/src/rbug.c
index 32adf9c..6e8ed60 100644
--- a/src/rbug.c
+++ b/src/rbug.c
@@ -24,6 +24,9 @@
#include "program.h"
+#define OP2KEY(o) ((void*)(long)o)
+#define KEY2OP(k) ((int16_t)(long)k)
+
#define SERIAL2KEY(s) ((void*)(unsigned long)s)
#define KEY2SERIAL(k) ((uint32_t)(unsigned long)k)
@@ -37,7 +40,33 @@ static gboolean equal_func(gconstpointer a, gconstpointer b)
return KEY2SERIAL(a) == KEY2SERIAL(b);
}
-static void rbug_handle_header(struct rbug_header *header, struct program *p)
+static void rbug_handle_header_event(struct rbug_header *header, struct program *p)
+{
+ struct rbug_event *e;
+ gboolean ret;
+ int16_t op;
+ void *ptr;
+
+ g_assert(header->opcode >= 0);
+ op = header->opcode;
+
+ ptr = g_hash_table_lookup(p->rbug.hash_event, OP2KEY(op));
+
+ if (!ptr) {
+ g_print("unknown event/request with op: %i\n", (int)op);
+ return;
+ }
+
+ e = (struct rbug_event *)ptr;
+ ret = e->func(e, header, p);
+
+ if (!ret)
+ g_hash_table_remove(p->rbug.hash_event, OP2KEY(op));
+
+ rbug_free_header(header);
+}
+
+static void rbug_handle_header_reply(struct rbug_header *header, struct program *p)
{
struct rbug_event *e;
uint32_t serial;
@@ -46,8 +75,8 @@ static void rbug_handle_header(struct rbug_header *header, struct program *p)
g_assert(header->opcode < 0);
serial = *(uint32_t*)&header[1];
- ptr = g_hash_table_lookup(p->rbug.hash, SERIAL2KEY(serial));
- g_hash_table_remove(p->rbug.hash, SERIAL2KEY(serial));
+ ptr = g_hash_table_lookup(p->rbug.hash_reply, SERIAL2KEY(serial));
+ g_hash_table_remove(p->rbug.hash_reply, SERIAL2KEY(serial));
if (!ptr) {
g_print("lost message with id %u\n", serial);
@@ -74,7 +103,10 @@ static gboolean rbug_event(GIOChannel *channel, GIOCondition c, gpointer data)
return false;
}
- rbug_handle_header(header, p);
+ if (header->opcode >= 0)
+ rbug_handle_header_event(header, p);
+ else
+ rbug_handle_header_reply(header, p);
}
if (c & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
@@ -115,7 +147,11 @@ void rbug_finish_and_emit_events(struct program *p)
}
}
- rbug_handle_header(header, p);
+ if (header->opcode >= 0)
+ rbug_handle_header_event(header, p);
+ else
+ rbug_handle_header_reply(header, p);
+
header = NULL;
} while (1);
@@ -126,9 +162,14 @@ void rbug_finish_and_emit_events(struct program *p)
rbug_free_header(header);
}
-void rbug_add_event(struct rbug_event *e, uint32_t serial, struct program *p)
+void rbug_add_reply(struct rbug_event *e, uint32_t serial, struct program *p)
+{
+ g_hash_table_insert(p->rbug.hash_reply, SERIAL2KEY(serial), e);
+}
+
+void rbug_add_event(struct rbug_event *e, int16_t op, struct program *p)
{
- g_hash_table_insert(p->rbug.hash, SERIAL2KEY(serial), e);
+ g_hash_table_insert(p->rbug.hash_event, OP2KEY(op), e);
}
void rbug_glib_io_watch(struct program *p)
@@ -138,5 +179,6 @@ void rbug_glib_io_watch(struct program *p)
p->rbug.channel = g_io_channel_unix_new(p->rbug.socket);
p->rbug.event = g_io_add_watch(p->rbug.channel, mask, rbug_event, p);
g_io_channel_set_encoding(p->rbug.channel, NULL, NULL);
- p->rbug.hash = g_hash_table_new(hash_func, equal_func);
+ p->rbug.hash_event = g_hash_table_new(hash_func, equal_func);
+ p->rbug.hash_reply = g_hash_table_new(hash_func, equal_func);
}
diff --git a/src/shader.c b/src/shader.c
index 79fc91d..867e78d 100644
--- a/src/shader.c
+++ b/src/shader.c
@@ -239,9 +239,9 @@ static void shader_action_info_clean(struct shader_action_info *action, struct p
g_free(action);
}
-static void shader_action_info_info(struct rbug_event *e,
- struct rbug_header *header,
- struct program *p)
+static gboolean shader_action_info_info(struct rbug_event *e,
+ struct rbug_header *header,
+ struct program *p)
{
struct rbug_proto_shader_info_reply *info;
struct shader_action_info *action;
@@ -286,6 +286,7 @@ static void shader_action_info_info(struct rbug_event *e,
out:
shader_action_info_clean(action, p);
+ return FALSE;
}
static struct shader_action_info *
@@ -310,7 +311,7 @@ shader_start_info_action(rbug_context_t c,
action->pending = TRUE;
action->running = TRUE;
- rbug_add_event(&action->e, serial, p);
+ rbug_add_reply(&action->e, serial, p);
return action;
}
@@ -336,9 +337,9 @@ struct shader_action_list
GtkTreeIter parent;
};
-static void shader_action_list_list(struct rbug_event *e,
- struct rbug_header *header,
- struct program *p)
+static gboolean shader_action_list_list(struct rbug_event *e,
+ struct rbug_header *header,
+ struct program *p)
{
struct rbug_proto_shader_list_reply *list;
@@ -364,6 +365,8 @@ static void shader_action_list_list(struct rbug_event *e,
}
g_free(action);
+
+ return FALSE;
}
static void shader_start_list_action(GtkTreeStore *store, GtkTreeIter *parent,
@@ -383,5 +386,5 @@ static void shader_start_list_action(GtkTreeStore *store, GtkTreeIter *parent,
action->store = store;
action->parent = *parent;
- rbug_add_event(&action->e, serial, p);
+ rbug_add_reply(&action->e, serial, p);
}
diff --git a/src/texture.c b/src/texture.c
index 0fcd762..dc19b79 100644
--- a/src/texture.c
+++ b/src/texture.c
@@ -369,9 +369,9 @@ static void texture_action_read_upload(struct texture_action_read *action,
p->texture.height = action->height;
}
-static void texture_action_read_read(struct rbug_event *e,
- struct rbug_header *header,
- struct program *p)
+static gboolean texture_action_read_read(struct rbug_event *e,
+ struct rbug_header *header,
+ struct program *p)
{
struct rbug_proto_texture_read_reply *read;
struct texture_action_read *action;
@@ -418,15 +418,17 @@ static void texture_action_read_read(struct rbug_event *e,
texture_action_read_clean(action, p);
}
- return;
+ return FALSE;
error:
texture_stop_read_action(action, p);
+
+ return FALSE;
}
-static void texture_action_read_info(struct rbug_event *e,
- struct rbug_header *header,
- struct program *p)
+static gboolean texture_action_read_info(struct rbug_event *e,
+ struct rbug_header *header,
+ struct program *p)
{
struct rbug_connection *con = p->rbug.con;
struct rbug_proto_texture_info_reply *info;
@@ -505,12 +507,14 @@ static void texture_action_read_info(struct rbug_event *e,
/* hock up event callback */
action->e.func = texture_action_read_read;
- rbug_add_event(&action->e, serial, p);
+ rbug_add_reply(&action->e, serial, p);
- return;
+ return FALSE;
error:
texture_stop_read_action(action, p);
+
+ return FALSE;
}
static void texture_stop_read_action(struct texture_action_read *action, struct program *p)
@@ -561,7 +565,7 @@ texture_start_read_action(rbug_texture_t t, GtkTreeIter *iter, struct program *p
action->pending = TRUE;
action->running = TRUE;
- rbug_add_event(&action->e, serial, p);
+ rbug_add_reply(&action->e, serial, p);
return action;
}
@@ -574,9 +578,9 @@ struct texture_action_list
GtkTreeIter parent;
};
-static void texture_action_list_list(struct rbug_event *e,
- struct rbug_header *header,
- struct program *p)
+static gboolean texture_action_list_list(struct rbug_event *e,
+ struct rbug_header *header,
+ struct program *p)
{
struct rbug_proto_texture_list_reply *list;
@@ -602,6 +606,8 @@ static void texture_action_list_list(struct rbug_event *e,
}
g_free(action);
+
+ return FALSE;
}
static void texture_start_list_action(GtkTreeStore *store, GtkTreeIter *parent, struct program *p)
@@ -619,5 +625,5 @@ static void texture_start_list_action(GtkTreeStore *store, GtkTreeIter *parent,
action->store = store;
action->parent = *parent;
- rbug_add_event(&action->e, serial, p);
+ rbug_add_reply(&action->e, serial, p);
}