summaryrefslogtreecommitdiff
path: root/client/osc.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/osc.c')
-rw-r--r--client/osc.c72
1 files changed, 26 insertions, 46 deletions
diff --git a/client/osc.c b/client/osc.c
index 4ecc28a..79bfd76 100644
--- a/client/osc.c
+++ b/client/osc.c
@@ -39,52 +39,32 @@ static void print_error(int num, const char *msg, const char *path)
static int lang_handler(const char *path, const char *types, lo_arg ** argv,
int argc, lo_message msg, void *user_data)
{
+ osc_t* o = (osc_t*)user_data;
+ assert(o);
+
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);
+ printf("got ack for: lang '%s'\n", &(argv[0]->s));
- osc_t* o = (osc_t*)user_data;
- assert(o);
- osc_task_t* task = malloc(sizeof(osc_task_t));
- assert(task);
+ /* search for right task ... */
+ /* if(task->done_cb_) */
+ /* task->done_cb_(task->done_data_); */
- task->self_ = o;
- task->state_ = 0;
- assert((task->lang_ = strdup(&(argv[0]->s))));
- task->addr_ = lo_address_new(host, port);
- assert(task->addr_);
- task->msg_ = lo_message_new();
- assert(task->msg_);
- assert(!lo_message_add(task->msg_, "s", task->lang_));
-
- assert(slist_add(&(o->tasks_), task));
+ /* slist_remove(&(o->tasks_), task); */
return 0;
}
void free_osc_task(void* ptr)
{
- osc_task_t* task = (osc_task_t*)ptr;
+ task_t* task = (task_t*)ptr;
+ assert(task);
- lo_message_free(task->msg_);
- lo_address_free(task->addr_);
free(task->lang_);
free(task);
}
-void osc_lang_switch_task(void* data)
-{
- assert(data);
- osc_task_t* d = data;
-
- lo_send_message_from(d->addr_, d->self_->server_, "/lang/switch", d->msg_);
- slist_remove(&(d->self_->tasks_), d);
-}
-
int osc_init(osc_t* o, const char* host, const char* port)
{
assert(o != NULL);
@@ -106,6 +86,21 @@ int osc_init(osc_t* o, const char* host, const char* port)
return 0;
}
+int osc_switch_lang(osc_t* o, const char* lang, void (*done_cb)(void*), void* done_data)
+{
+ task_t* task = malloc(sizeof(task_t));
+ assert(task);
+ task->state_ = 0;
+ assert((task->lang_ = strdup(lang)));
+ task->done_cb_ = done_cb;
+ task->done_data_ = done_data;
+ assert(slist_add(&(o->tasks_), task));
+
+ if(lo_send_from(o->target_, o->server_, LO_TT_IMMEDIATE, "/lang/switch", "s", task->lang_) > 0)
+ task->state_ = 1;
+
+ return 0;
+}
int osc_get_poll_fd_count(osc_t* o)
{
@@ -131,7 +126,6 @@ int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds)
return 0;
}
-//int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds, midi_t* m)
int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds)
{
assert(o);
@@ -148,19 +142,5 @@ int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds)
lo_server_recv_noblock(o->server_, 0);
- int ret = 0;
- slist_element_t* tmp;
- for(tmp = o->tasks_.first_; tmp; tmp = tmp->next_) {
- osc_task_t* d = (osc_task_t*)(tmp->data_);
- if(d->state_ == 0) {
-// ret = midi_switch_lang(x, d->lang_, &osc_lang_switch_task, d);
- if(ret)
- break;
-
- d->state_ = 1;
- }
- }
-
-
- return ret;
+ return 0;
}