From a0ec6afec1abce0477ac4ba836a3b84148fe0bd8 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 12 Oct 2015 05:58:36 +0200 Subject: osc requests get now acked --- apps/osc.c | 13 ++++++++++--- apps/osc.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'apps') diff --git a/apps/osc.c b/apps/osc.c index 9d3c3c1..9172625 100644 --- a/apps/osc.c +++ b/apps/osc.c @@ -40,6 +40,11 @@ static int lang_handler(const char *path, const char *types, lo_arg ** argv, if(argc != 1 || !lo_is_string_type((lo_type)types[0])) return 1; + lo_address from = lo_message_get_source(msg); + const char* host = lo_address_get_hostname(from); + const char* port = lo_address_get_port(from); + assert(host && port); + osc_t* o = (osc_t*)user_data; assert(o); osc_done_data_t* done_data = malloc(sizeof(osc_done_data_t)); @@ -48,6 +53,8 @@ static int lang_handler(const char *path, const char *types, lo_arg ** argv, done_data->self_ = o; done_data->state_ = 0; assert((done_data->lang_ = strdup(&(argv[0]->s)))); + done_data->addr_ = lo_address_new(host, port); + assert(done_data->addr_); done_data->msg_ = lo_message_new(); assert(done_data->msg_); assert(!lo_message_add(done_data->msg_, "s", done_data->lang_)); @@ -62,6 +69,7 @@ void free_osc_done_data(void* ptr) osc_done_data_t* done_data = (osc_done_data_t*)ptr; lo_message_free(done_data->msg_); + lo_address_free(done_data->addr_); free(done_data->lang_); free(done_data); } @@ -70,9 +78,8 @@ 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 + lo_send_message_from(d->addr_, d->self_->server_, "/lang/ack", d->msg_); slist_remove(&(d->self_->done_data_), d); } @@ -84,7 +91,7 @@ int osc_init(osc_t* o, const char* port) if(!o->server_) return -1; - if(!lo_server_add_method(o->server_, "/lang", "s", lang_handler, (void*)o)) + if(!lo_server_add_method(o->server_, "/lang/switch", "s", lang_handler, (void*)o)) return -1; slist_init(&(o->done_data_), free_osc_done_data); diff --git a/apps/osc.h b/apps/osc.h index ae851b3..40210b3 100644 --- a/apps/osc.h +++ b/apps/osc.h @@ -38,6 +38,7 @@ typedef struct { osc_t* self_; int state_; char* lang_; + lo_address addr_; lo_message msg_; } osc_done_data_t; -- cgit v1.2.3