summaryrefslogtreecommitdiff
path: root/apps/osc.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-12 05:27:58 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-10-12 05:27:58 +0200
commitf1a0c283e4fe5227fa9a0e95c2e8324475e12d01 (patch)
tree1a38cef3b302c1af1f40ff58b8c56bc618670586 /apps/osc.c
parentdone data hangling for midi works now (diff)
osc messages to trigger language switch are implemented
Diffstat (limited to 'apps/osc.c')
-rw-r--r--apps/osc.c66
1 files changed, 54 insertions, 12 deletions
diff --git a/apps/osc.c b/apps/osc.c
index 1dbb53e..9d3c3c1 100644
--- a/apps/osc.c
+++ b/apps/osc.c
@@ -34,21 +34,47 @@ static void print_error(int num, const char *msg, const char *path)
error(0, 0, "liblo server error %d in path %s: %s", num, path, msg);
}
-static int generic_handler(const char *path, const char *types, lo_arg ** argv,
- int argc, void *data, void *user_data)
+static int lang_handler(const char *path, const char *types, lo_arg ** argv,
+ int argc, lo_message msg, void *user_data)
{
- int i;
+ if(argc != 1 || !lo_is_string_type((lo_type)types[0]))
+ return 1;
- printf("OSC(%s):%s", path, argc ? " ": " <no arguments>\n");
- for(i = 0; i < argc; i++) {
- printf("arg %d '%c'", i, types[i]);
- lo_arg_pp((lo_type)types[i], argv[i]);
- printf("%s", i >= (argc-1) ? "\n" : ", ");
- }
+ osc_t* o = (osc_t*)user_data;
+ assert(o);
+ osc_done_data_t* done_data = malloc(sizeof(osc_done_data_t));
+ assert(done_data);
- return 1;
+ done_data->self_ = o;
+ done_data->state_ = 0;
+ assert((done_data->lang_ = strdup(&(argv[0]->s))));
+ done_data->msg_ = lo_message_new();
+ assert(done_data->msg_);
+ assert(!lo_message_add(done_data->msg_, "s", done_data->lang_));
+
+ assert(slist_add(&(o->done_data_), done_data));
+
+ return 0;
}
+void free_osc_done_data(void* ptr)
+{
+ osc_done_data_t* done_data = (osc_done_data_t*)ptr;
+
+ lo_message_free(done_data->msg_);
+ free(done_data->lang_);
+ free(done_data);
+}
+
+void osc_lang_switch_done(void* data)
+{
+ assert(data);
+ osc_done_data_t* d = data;
+ d->state_ = 2;
+
+ // TODO: remove this as soon as acks are sent
+ slist_remove(&(d->self_->done_data_), d);
+}
int osc_init(osc_t* o, const char* port)
{
@@ -58,9 +84,11 @@ int osc_init(osc_t* o, const char* port)
if(!o->server_)
return -1;
- if(!lo_server_add_method(o->server_, NULL, NULL, generic_handler, NULL))
+ if(!lo_server_add_method(o->server_, "/lang", "s", lang_handler, (void*)o))
return -1;
+ slist_init(&(o->done_data_), free_osc_done_data);
+
return 0;
}
@@ -94,5 +122,19 @@ int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds, mixer_t* x)
lo_server_recv_noblock(o->server_, 0);
- return 0;
+ int ret = 0;
+ slist_element_t* tmp;
+ for(tmp = o->done_data_.first_; tmp; tmp = tmp->next_) {
+ osc_done_data_t* d = (osc_done_data_t*)(tmp->data_);
+ if(d->state_ == 0) {
+ ret = mixer_switch_lang(x, d->lang_, &osc_lang_switch_done, d);
+ if(ret)
+ break;
+
+ d->state_ = 1;
+ }
+ }
+
+
+ return ret;
}