| 31 #include <stdio.h> |
31 #include <stdio.h> |
| 32 #include <stdlib.h> |
32 #include <stdlib.h> |
| 33 #include <unistd.h> |
33 #include <unistd.h> |
| 34 |
34 |
| 35 #include "message.h" |
35 #include "message.h" |
| |
36 |
| |
37 int uic_message_send_(UiMessageHandler *handler, cxstring msg) { |
| |
38 return handler->send(handler, msg); |
| |
39 } |
| 36 |
40 |
| 37 UiMessageHandler* uic_simple_msg_handler(int in, int out, msg_received_callback callback) { |
41 UiMessageHandler* uic_simple_msg_handler(int in, int out, msg_received_callback callback) { |
| 38 UiSimpleMessageHandler *handler = malloc(sizeof(UiSimpleMessageHandler)); |
42 UiSimpleMessageHandler *handler = malloc(sizeof(UiSimpleMessageHandler)); |
| 39 handler->handler.start = uic_simple_msg_handler_start; |
43 handler->handler.start = uic_simple_msg_handler_start; |
| 40 handler->handler.stop = uic_simple_msg_handler_stop; |
44 handler->handler.stop = uic_simple_msg_handler_stop; |
| 77 } |
81 } |
| 78 |
82 |
| 79 int uic_simple_msg_handler_send(UiMessageHandler *handler, cxstring msg) { |
83 int uic_simple_msg_handler_send(UiMessageHandler *handler, cxstring msg) { |
| 80 UiSimpleMessageHandler *sh = (UiSimpleMessageHandler*)handler; |
84 UiSimpleMessageHandler *sh = (UiSimpleMessageHandler*)handler; |
| 81 pthread_mutex_lock(&sh->queue_lock); |
85 pthread_mutex_lock(&sh->queue_lock); |
| |
86 char header[32]; |
| |
87 snprintf(header, 32, "%zu\n", msg.length); |
| |
88 cxBufferPutString(sh->outbuf, header); |
| 82 cxBufferWrite(msg.ptr, 1, msg.length, sh->outbuf); |
89 cxBufferWrite(msg.ptr, 1, msg.length, sh->outbuf); |
| 83 pthread_cond_signal(&sh->available); |
90 pthread_cond_signal(&sh->available); |
| 84 pthread_mutex_unlock(&sh->queue_lock); |
91 pthread_mutex_unlock(&sh->queue_lock); |
| 85 return 0; |
92 return 0; |
| 86 } |
93 } |