summaryrefslogtreecommitdiff
path: root/communication_source.c
diff options
context:
space:
mode:
Diffstat (limited to 'communication_source.c')
-rw-r--r--communication_source.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/communication_source.c b/communication_source.c
new file mode 100644
index 0000000..b0a03cb
--- /dev/null
+++ b/communication_source.c
@@ -0,0 +1,46 @@
+#include "communication_source.h"
+#include "servers.h"
+
+static GQueue *jobqueue = NULL;
+
+void communication_job_add(struct server *server) {
+ g_queue_push_head(jobqueue, server);
+}
+
+gboolean comsrc_prepare(GSource *source, gint *timeout) {
+ g_debug("comsrc_prepare()");
+ *timeout = 2000;
+ return g_queue_get_length(jobqueue) > 0 ? TRUE : FALSE;
+}
+
+gboolean comsrc_check(GSource *source) {
+ g_debug("comsrc_check()");
+ return g_queue_get_length(jobqueue) > 0 ? TRUE : FALSE;
+}
+
+gboolean comsrc_dispatch(GSource *source, GSourceFuncs callback, gpointer user_data) {
+ g_debug("comsrc_dispatch(), callback is %x, user_data is %x", callback, user_data);
+ struct server *server = g_queue_pop_tail(jobqueue);
+ server_sync(server);
+ return TRUE;
+}
+
+void comsrc_finalize(GSource *source) {
+}
+
+static const GSourceFuncs com_src_funcs = {
+ .prepare = comsrc_prepare,
+ .check = comsrc_check,
+ .dispatch = comsrc_dispatch,
+ .finalize = comsrc_finalize,
+};
+
+void communication_source_init(GMainLoop *mainloop) {
+ jobqueue = g_queue_new();
+
+ GMainContext *context = g_main_loop_get_context(mainloop);
+ GSource *source = g_source_new(&com_src_funcs, sizeof(GSource));
+ g_source_attach(source, context);
+
+ communication_job_add(servers->data);
+}