Use generated tidl codes 98/263598/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 7 Sep 2021 00:47:28 +0000 (09:47 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 7 Sep 2021 00:47:28 +0000 (09:47 +0900)
The C Generator will be refactored. Some APIs that generated by tidlc
are modified.

Related:
 - https://review.tizen.org/gerrit/#/c/platform/core/uifw/tts/+/263169/

Change-Id: If5705a1ed677f7daf7e2baeb1f07fb67fe670fdc
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
client/tts_proxy.c [new file with mode: 0644]
client/tts_proxy.h [new file with mode: 0644]
packaging/tts.spec
server/ttsd_stub.c [new file with mode: 0644]
server/ttsd_stub.h [new file with mode: 0644]

diff --git a/client/tts_proxy.c b/client/tts_proxy.c
new file mode 100644 (file)
index 0000000..be1f874
--- /dev/null
@@ -0,0 +1,1353 @@
+/*
+ * Generated by tidlc 1.4.9.
+ */
+
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <glib.h>
+#include <dlog.h>
+#include <rpc-port.h>
+#include <rpc-port-parcel.h>
+
+#include "tts_proxy.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "RPC_PORT_PROXY"
+
+#ifdef _E
+#undef _E
+#endif
+
+#ifdef _W
+#undef _W
+#endif
+
+#ifdef _I
+#undef _I
+#endif
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+
+typedef void (*proxy_delegate)(GList **list, rpc_port_parcel_h parcel, int seq_id, int id);
+
+struct array_char_s {
+       rpc_port_parcelable_t parcelable;
+       char *array_chars;
+       int array_chars_size;
+};
+
+static void __array_char_to(rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_array_char_h h = data;
+
+       if (!parcel || !h) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       rpc_port_parcel_write_array_count(parcel, h->array_chars_size);
+       do {
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       rpc_port_parcel_write_byte(parcel, h->array_chars[i]);
+               }
+       } while (0);
+}
+
+static void __array_char_from(rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_array_char_h h = data;
+
+       if (!parcel || !h) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       do {
+               rpc_port_parcel_read_array_count(parcel, &h->array_chars_size);
+
+               h->array_chars = calloc(h->array_chars_size, sizeof(*h->array_chars));
+               if (!h->array_chars) {
+                       _E("Out of memory");
+                       return;
+               }
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       char value = 0;
+
+                       rpc_port_parcel_read_byte(parcel, &value);
+                       h->array_chars[i] = value;
+               }
+       } while (0);
+}
+
+int rpc_port_array_char_create(rpc_port_array_char_h *h)
+{
+       struct array_char_s *handle;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       handle = calloc(1, sizeof(struct array_char_s));
+       if (!handle) {
+               _E("Out of memory");
+               return -1;
+       }
+
+       handle->parcelable.to = __array_char_to;
+       handle->parcelable.from = __array_char_from;
+
+       *h = handle;
+
+       return 0;
+}
+
+int rpc_port_array_char_destroy(rpc_port_array_char_h h)
+{
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       if (h->array_chars)
+               free(h->array_chars);
+
+       free(h);
+
+       return 0;
+}
+
+int rpc_port_array_char_clone(rpc_port_array_char_h h, rpc_port_array_char_h *clone)
+{
+       rpc_port_array_char_h handle = NULL;
+
+       if (!h || !clone) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       rpc_port_array_char_create(&handle);
+       if (!handle) {
+               _E("Failed to create array_char handle");
+               return -1;
+       }
+
+       do {
+               if (h->array_chars_size == 0) {
+                       _W("array_chars is empty");
+                       break;
+               }
+
+               handle->array_chars = calloc(h->array_chars_size, sizeof(*h->array_chars));
+               if (!handle->array_chars) {
+                       _E("Out of memory");
+                       rpc_port_array_char_destroy(handle);
+                       return -1;
+               }
+               handle->array_chars_size = h->array_chars_size;
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       handle->array_chars[i] = h->array_chars[i];
+               }
+       } while (0);
+
+       *clone = handle;
+
+       return 0;
+}
+
+int rpc_port_array_char_set_array_chars(rpc_port_array_char_h h, char *array_chars, int array_chars_size)
+{
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       if (h->array_chars)
+               free(h->array_chars);
+
+       h->array_chars = NULL;
+
+       do {
+               h->array_chars = calloc(array_chars_size, sizeof(*array_chars));
+               if (!h->array_chars) {
+                       _E("Out of memory");
+                       return -1;
+               }
+               h->array_chars_size = array_chars_size;
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       h->array_chars[i] = array_chars[i];
+               }
+       } while (0);
+
+       return 0;
+}
+
+int rpc_port_array_char_get_array_chars(rpc_port_array_char_h h, char **array_chars, int *array_chars_size)
+{
+       if (!h || !array_chars || !array_chars_size) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       do {
+               if (h->array_chars_size == 0) {
+                       _W("array_chars is empty");
+                       break;
+               }
+
+               *array_chars = calloc(h->array_chars_size, sizeof(*h->array_chars));
+               if (!*array_chars) {
+                       _E("Out of memory");
+                       return -1;
+               }
+               *array_chars_size = h->array_chars_size;
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       (*array_chars)[i] = h->array_chars[i];
+               }
+       } while (0);
+
+       return 0;
+}
+
+enum tts_method_e {
+       tts_METHOD_Result,
+       tts_METHOD_Callback,
+       tts_METHOD_register_cb,
+       tts_METHOD_register_cb_sync,
+       tts_METHOD_set_mode,
+       tts_METHOD_initialize,
+       tts_METHOD_finalize,
+       tts_METHOD_add_text,
+       tts_METHOD_stop,
+       tts_METHOD_pause,
+       tts_METHOD_play_pcm,
+       tts_METHOD_stop_pcm,
+       tts_METHOD_set_private,
+       tts_METHOD_get_private,
+       tts_METHOD_play,
+       tts_METHOD_add_pcm,
+};
+
+enum tts_delegate_e {
+       tts_DELEGATE_notify_cb = 1,
+};
+
+struct tts_s {
+       char *stub_appid;
+       rpc_port_proxy_h proxy;
+       rpc_port_h port;
+       rpc_port_h callback_port;
+       rpc_port_proxy_tts_callback_s callback;
+       void *user_data;
+       GList *delegates;
+       GRecMutex mutex;
+};
+
+struct tts_notify_cb_s {
+       rpc_port_parcelable_t parcelable;
+       int id;
+       int seq_id;
+       tts_notify_cb callback;
+       bool once;
+       void *user_data;
+};
+
+static void __tts_notify_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+       struct tts_notify_cb_s *handle = data;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       rpc_port_parcel_write_int32(parcel, handle->id);
+       rpc_port_parcel_write_int32(parcel, handle->seq_id);
+       rpc_port_parcel_write_bool(parcel, handle->once);
+       _I("id(%d), seq_id(%d), once(%s)", handle->id, handle->seq_id, handle->once ? "true" : "false");
+}
+
+static void __tts_notify_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+       struct tts_notify_cb_s *handle = data;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       rpc_port_parcel_read_int32(parcel, &handle->id);
+       rpc_port_parcel_read_int32(parcel, &handle->seq_id);
+       rpc_port_parcel_read_bool(parcel, &handle->once);
+       _I("id(%d), seq_id(%d), once(%s)", handle->id, handle->seq_id, handle->once ? "true" : "false");
+}
+
+rpc_port_tts_notify_cb_h rpc_port_tts_notify_cb_create(tts_notify_cb callback, bool once, void *user_data)
+{
+       struct tts_notify_cb_s *handle;
+       static int seq_num;
+
+       handle = calloc(1, sizeof(struct tts_notify_cb_s));
+       if (!handle) {
+               _E("Out of memory");
+               return NULL;
+       }
+
+       handle->parcelable.to = __tts_notify_cb_to;
+       handle->parcelable.from= __tts_notify_cb_from;
+       handle->id = tts_DELEGATE_notify_cb;
+       handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1;
+       handle->callback = callback;
+       handle->once = once;
+       handle->user_data = user_data;
+       _I("id(%d), seq_id(%d)", handle->id, handle->seq_id);
+
+       return handle;
+}
+
+int rpc_port_tts_notify_cb_destroy(rpc_port_tts_notify_cb_h delegate)
+{
+       if (!delegate) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       free(delegate);
+
+       return 0;
+}
+
+int rpc_port_proxy_tts_notify_cb_dispose(rpc_port_proxy_tts_h proxy, rpc_port_tts_notify_cb_h delegate)
+{
+       struct tts_notify_cb_s *handle;
+       GList *iter;
+
+       if (!proxy || !delegate) {
+               _E("Invalid handle %p %p", proxy, delegate);
+               return -1;
+       }
+
+       iter = proxy->delegates;
+       while (iter) {
+               handle = (struct tts_notify_cb_s *)iter->data;
+               if (handle == delegate) {
+                       _W("id(%d), seq_id(%d), once(%s)", handle->id, handle->seq_id, handle->once ? "true" : "false");
+                       proxy->delegates = g_list_remove_link(proxy->delegates, iter);
+                       free(handle);
+                       g_list_free(iter);
+                       return 0;
+               }
+               iter = g_list_next(iter);
+       }
+
+       return -1;
+}
+
+static void __tts_delegate_notify_cb(GList **list, rpc_port_parcel_h parcel, int seq_id, int id)
+{
+       int pid = -1;
+       int uid = -1;
+       bundle *msg = NULL;
+
+       rpc_port_parcel_read_int32(parcel, &pid);
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_parcel_read_bundle(parcel, &msg);
+
+       do {
+               struct tts_notify_cb_s *handle;
+               GList *iter;
+
+               iter = *list;
+               while (iter) {
+                       handle = (struct tts_notify_cb_s *)iter->data;
+                       if (handle->seq_id == seq_id && handle->id == id) {
+                               bool once = handle->once;
+
+                               _W("Invoke id(%d), seq_id(%d)", id, seq_id);
+                               handle->callback(handle->user_data, pid, uid, msg);
+
+                               if (once) {
+                                       _W("Dispose");
+                                       *list = g_list_remove_link(*list, iter);
+                                       free(handle);
+                                       g_list_free(iter);
+                               }
+                               break;
+                       }
+                       iter = g_list_next(iter);
+               }
+       } while (0);
+
+       bundle_free(msg);
+}
+
+static proxy_delegate __tts_delegate_table[] = {
+       [tts_DELEGATE_notify_cb] = __tts_delegate_notify_cb,
+};
+
+static void __tts_process_received_event(GList **list, rpc_port_parcel_h parcel)
+{
+       int id;
+       int seq_id;
+       bool once;
+
+       rpc_port_parcel_read_int32(parcel, &id);
+       rpc_port_parcel_read_int32(parcel, &seq_id);
+       rpc_port_parcel_read_bool(parcel, &once);
+       _W("id(%d), seq_id(%d)", id, seq_id);
+
+       if (id > 0 && id < (sizeof(__tts_delegate_table) / sizeof(__tts_delegate_table[0]))) {
+               if (__tts_delegate_table[id])
+                       __tts_delegate_table[id](list, parcel, seq_id, id);
+       } else {
+               _W("Unknown id(%d)", id);
+       }
+}
+
+static rpc_port_parcel_h __tts_consume_command(rpc_port_proxy_tts_h h)
+{
+       rpc_port_parcel_h parcel = NULL;
+       int cmd = -1;
+
+       do {
+               rpc_port_parcel_create_from_port(&parcel, h->port);
+               if (!parcel)
+                       break;
+
+               rpc_port_parcel_read_int32(parcel, &cmd);
+               if (cmd == tts_METHOD_Result)
+                       return parcel;
+
+               rpc_port_parcel_destroy(parcel);
+               parcel = NULL;
+       } while (true);
+
+       return NULL;
+}
+
+static void __tts_on_connected(const char *endpoint, const char *port_name, rpc_port_h port, void *data)
+{
+       rpc_port_proxy_tts_h handle = data;
+
+       handle->port = port;
+       rpc_port_proxy_get_port(handle->proxy, RPC_PORT_PORT_CALLBACK, &handle->callback_port);
+       if (handle->callback.connected)
+               handle->callback.connected(handle, handle->user_data);
+       _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+
+static void __tts_on_disconnected(const char *endpoint, const char *port_name, void *data)
+{
+       rpc_port_proxy_tts_h handle = data;
+
+       handle->port = NULL;
+       if (handle->callback.disconnected)
+               handle->callback.disconnected(handle, handle->user_data);
+       _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+
+static void __tts_on_rejected(const char *endpoint, const char *port_name, void *data)
+{
+       rpc_port_proxy_tts_h handle = data;
+
+       handle->port = NULL;
+       if (handle->callback.rejected)
+               handle->callback.rejected(handle, handle->user_data);
+       _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+
+static void __tts_on_received(const char *endpoint, const char *port_name, void *data)
+{
+       rpc_port_proxy_tts_h handle = data;
+       rpc_port_parcel_h parcel_received = NULL;
+       int cmd = -1;
+
+       rpc_port_parcel_create_from_port(&parcel_received, handle->callback_port);
+       if (!parcel_received) {
+               _E("Failed to create parcel from port(%s)", port_name);
+               return;
+       }
+
+       rpc_port_parcel_read_int32(parcel_received, &cmd);
+       if (cmd != tts_METHOD_Callback) {
+               _E("Invalid protocol");
+               rpc_port_parcel_destroy(parcel_received);
+               return;
+       }
+
+       __tts_process_received_event(&handle->delegates, parcel_received);
+       rpc_port_parcel_destroy(parcel_received);
+       _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+
+void rpc_port_proxy_tts_invoke_register_cb(rpc_port_proxy_tts_h h, int pid, int uid, rpc_port_tts_notify_cb_h callback)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+
+       if (!h || !callback) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_register_cb);
+       rpc_port_parcel_write_int32(parcel, pid);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       do {
+               struct tts_notify_cb_s *handle = callback;
+
+               rpc_port_parcel_write(parcel, &handle->parcelable, handle);
+               h->delegates = g_list_append(h->delegates, handle);
+       } while (0);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+       set_last_result(r);
+}
+
+int rpc_port_proxy_tts_invoke_register_cb_sync(rpc_port_proxy_tts_h h, int pid, int uid, rpc_port_tts_notify_cb_h callback)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h || !callback) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_register_cb_sync);
+       rpc_port_parcel_write_int32(parcel, pid);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       do {
+               struct tts_notify_cb_s *handle = callback;
+
+               rpc_port_parcel_write(parcel, &handle->parcelable, handle);
+               h->delegates = g_list_append(h->delegates, handle);
+       } while (0);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_set_mode(rpc_port_proxy_tts_h h, int mode)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_set_mode);
+       rpc_port_parcel_write_int32(parcel, mode);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_initialize(rpc_port_proxy_tts_h h, int pid, int uid, bool *credential_needed)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h || !credential_needed) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_initialize);
+       rpc_port_parcel_write_int32(parcel, pid);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+               bool out_credential_needed;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_bool(parcel_received, &out_credential_needed);
+               *credential_needed = out_credential_needed;
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_finalize(rpc_port_proxy_tts_h h, int uid)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_finalize);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_add_text(rpc_port_proxy_tts_h h, int uid, const char *text, const char *lang, int vctype, int speed, int uttid, const char *credential)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_add_text);
+       rpc_port_parcel_write_int32(parcel, uid);
+       rpc_port_parcel_write_string(parcel, text ? text : "");
+       rpc_port_parcel_write_string(parcel, lang ? lang : "");
+       rpc_port_parcel_write_int32(parcel, vctype);
+       rpc_port_parcel_write_int32(parcel, speed);
+       rpc_port_parcel_write_int32(parcel, uttid);
+       rpc_port_parcel_write_string(parcel, credential ? credential : "");
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_stop(rpc_port_proxy_tts_h h, int uid)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_stop);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_pause(rpc_port_proxy_tts_h h, int uid)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_pause);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_play_pcm(rpc_port_proxy_tts_h h, int uid)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_play_pcm);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_stop_pcm(rpc_port_proxy_tts_h h, int uid)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_stop_pcm);
+       rpc_port_parcel_write_int32(parcel, uid);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_set_private(rpc_port_proxy_tts_h h, int uid, const char *key, const char *priv_data)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_set_private);
+       rpc_port_parcel_write_int32(parcel, uid);
+       rpc_port_parcel_write_string(parcel, key ? key : "");
+       rpc_port_parcel_write_string(parcel, priv_data ? priv_data : "");
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_get_private(rpc_port_proxy_tts_h h, int uid, const char *key, char **priv_data)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h || !priv_data) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_get_private);
+       rpc_port_parcel_write_int32(parcel, uid);
+       rpc_port_parcel_write_string(parcel, key ? key : "");
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+               char *out_priv_data;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_string(parcel_received, &out_priv_data);
+               *priv_data = out_priv_data;
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_play(rpc_port_proxy_tts_h h, int uid, const char *credential)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_play);
+       rpc_port_parcel_write_int32(parcel, uid);
+       rpc_port_parcel_write_string(parcel, credential ? credential : "");
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+int rpc_port_proxy_tts_invoke_add_pcm(rpc_port_proxy_tts_h h, int uid, int event, rpc_port_array_char_h pcm_data, int data_size, int audio_type, int rate)
+{
+       rpc_port_parcel_h parcel;
+       int r;
+       int ret = -1;
+
+       if (!h || !pcm_data) {
+               _E("Invalid parameter");
+               return ret;
+       }
+
+       if (!h->port) {
+               _E("Not connected");
+               return ret;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_add_pcm);
+       rpc_port_parcel_write_int32(parcel, uid);
+       rpc_port_parcel_write_int32(parcel, event);
+       rpc_port_parcel_write(parcel, &pcm_data->parcelable, pcm_data);
+       rpc_port_parcel_write_int32(parcel, data_size);
+       rpc_port_parcel_write_int32(parcel, audio_type);
+       rpc_port_parcel_write_int32(parcel, rate);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       if (r != RPC_PORT_ERROR_NONE) {
+               _E("Failed to send parcel. result(%d)", r);
+               r = RPC_PORT_ERROR_IO_ERROR;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       g_rec_mutex_lock(&h->mutex);
+       do {
+               rpc_port_parcel_h parcel_received;
+
+               parcel_received = __tts_consume_command(h);
+               if (!parcel_received) {
+                       _E("Invalid protocol");
+                       r = RPC_PORT_ERROR_IO_ERROR;
+                       break;
+               }
+
+               rpc_port_parcel_read_int32(parcel_received, &ret);
+
+               rpc_port_parcel_destroy(parcel_received);
+       } while (0);
+       g_rec_mutex_unlock(&h->mutex);
+       set_last_result(r);
+
+       return ret;
+}
+
+static struct tts_s *__create_tts(const char *stub_appid, rpc_port_proxy_tts_callback_s *callback, void *user_data)
+{
+       struct tts_s *handle;
+
+       handle = calloc(1, sizeof(struct tts_s));
+       if (!handle) {
+               _E("Out of memory");
+               return NULL;
+       }
+
+       handle->stub_appid = strdup(stub_appid);
+       if (!handle->stub_appid) {
+               _E("Out of memory");
+               free(handle);
+               return NULL;
+       }
+
+       rpc_port_proxy_create(&handle->proxy);
+       if (!handle->proxy) {
+               _E("Failed to create proxy");
+               free(handle->stub_appid);
+               free(handle);
+               return NULL;
+       }
+
+       g_rec_mutex_init(&handle->mutex);
+
+       handle->callback = *callback;
+       handle->user_data = user_data;
+
+       return handle;
+}
+
+static void __destroy_tts(struct tts_s *h)
+{
+       if (!h)
+               return;
+
+       g_rec_mutex_clear(&h->mutex);
+
+       if (h->delegates)
+               g_list_free_full(h->delegates, free);
+
+       if (h->proxy)
+               rpc_port_proxy_destroy(h->proxy);
+
+       if (h->stub_appid)
+               free(h->stub_appid);
+
+       free(h);
+}
+
+int rpc_port_proxy_tts_create(const char *stub_appid, rpc_port_proxy_tts_callback_s *callback, void *user_data, rpc_port_proxy_tts_h *h)
+{
+       struct tts_s *handle;
+       int r;
+
+       if (!stub_appid || !callback || !h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       handle = __create_tts(stub_appid, callback, user_data);
+       if (!handle)
+               return -1;
+
+       r = rpc_port_proxy_add_connected_event_cb(handle->proxy, __tts_on_connected, handle);
+       if (r != 0) {
+               _E("Failed to add connected event cb. err = %d", r);
+               __destroy_tts(handle);
+               return r;
+       }
+
+       r = rpc_port_proxy_add_disconnected_event_cb(handle->proxy, __tts_on_disconnected, handle);
+       if (r != 0) {
+               _E("Failed to add disconnected event cb. err = %d", r);
+               __destroy_tts(handle);
+               return r;
+       }
+
+       r = rpc_port_proxy_add_rejected_event_cb(handle->proxy, __tts_on_rejected, handle);
+       if (r != 0) {
+               _E("Failed to add rejected event cb. err = %d", r);
+               __destroy_tts(handle);
+               return r;
+       }
+
+       r = rpc_port_proxy_add_received_event_cb(handle->proxy, __tts_on_received, handle);
+       if (r != 0) {
+               _E("Failed to add received event cb. err = %d", r);
+               __destroy_tts(handle);
+               return r;
+       }
+
+       *h = handle;
+
+       return 0;
+}
+
+int rpc_port_proxy_tts_connect(rpc_port_proxy_tts_h h)
+{
+       int r;
+
+       if (!h || !h->proxy) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       r = rpc_port_proxy_connect(h->proxy, h->stub_appid, "tts");
+       if (r != 0) {
+               _E("Failed to connect tts(%s)", h->stub_appid);
+               return r;
+       }
+
+       return 0;
+}
+
+int rpc_port_proxy_tts_destroy(rpc_port_proxy_tts_h h)
+{
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       __destroy_tts(h);
+       return 0;
+}
+
+int rpc_port_proxy_tts_connect_sync(rpc_port_proxy_tts_h h)
+{
+       int r;
+
+       if (!h || !h->proxy) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       r = rpc_port_proxy_connect_sync(h->proxy, h->stub_appid, "tts");
+       if (r != 0) {
+               _E("Failed to connect sync tts(%s)", h->stub_appid);
+               return r;
+       }
+
+       return 0;
+}
diff --git a/client/tts_proxy.h b/client/tts_proxy.h
new file mode 100644 (file)
index 0000000..3d9d969
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Generated by tidlc 1.4.9.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct array_char_s *rpc_port_array_char_h;
+
+int rpc_port_array_char_create(rpc_port_array_char_h *h);
+
+int rpc_port_array_char_destroy(rpc_port_array_char_h h);
+
+int rpc_port_array_char_clone(rpc_port_array_char_h h, rpc_port_array_char_h *clone);
+
+int rpc_port_array_char_set_array_chars(rpc_port_array_char_h h, char *array_chars, int array_chars_size);
+
+int rpc_port_array_char_get_array_chars(rpc_port_array_char_h h, char **array_chars, int *array_chars_size);
+
+typedef struct tts_s *rpc_port_proxy_tts_h;
+
+typedef struct {
+       void (*connected)(rpc_port_proxy_tts_h h, void *user_data);
+       void (*disconnected)(rpc_port_proxy_tts_h h, void *user_data);
+       void (*rejected)(rpc_port_proxy_tts_h h, void *user_data);
+} rpc_port_proxy_tts_callback_s;
+
+typedef struct tts_notify_cb_s *rpc_port_tts_notify_cb_h;
+
+typedef void (*tts_notify_cb)(void *user_data, int pid, int uid, bundle *msg);
+
+rpc_port_tts_notify_cb_h rpc_port_tts_notify_cb_create(tts_notify_cb callback, bool once, void *user_data);
+
+int rpc_port_tts_notify_cb_destroy(rpc_port_tts_notify_cb_h delegate);
+
+int rpc_port_proxy_tts_notify_cb_dispose(rpc_port_proxy_tts_h proxy, rpc_port_tts_notify_cb_h delegate);
+
+int rpc_port_proxy_tts_create(const char *stub_appid,
+        rpc_port_proxy_tts_callback_s *callback, void *user_data,
+        rpc_port_proxy_tts_h *h);
+
+int rpc_port_proxy_tts_connect(rpc_port_proxy_tts_h h);
+
+int rpc_port_proxy_tts_destroy(rpc_port_proxy_tts_h h);
+
+void rpc_port_proxy_tts_invoke_register_cb(rpc_port_proxy_tts_h h, int pid, int uid, rpc_port_tts_notify_cb_h callback);
+
+int rpc_port_proxy_tts_invoke_register_cb_sync(rpc_port_proxy_tts_h h, int pid, int uid, rpc_port_tts_notify_cb_h callback);
+
+int rpc_port_proxy_tts_invoke_set_mode(rpc_port_proxy_tts_h h, int mode);
+
+int rpc_port_proxy_tts_invoke_initialize(rpc_port_proxy_tts_h h, int pid, int uid, bool *credential_needed);
+
+int rpc_port_proxy_tts_invoke_finalize(rpc_port_proxy_tts_h h, int uid);
+
+int rpc_port_proxy_tts_invoke_add_text(rpc_port_proxy_tts_h h, int uid, const char *text, const char *lang, int vctype, int speed, int uttid, const char *credential);
+
+int rpc_port_proxy_tts_invoke_stop(rpc_port_proxy_tts_h h, int uid);
+
+int rpc_port_proxy_tts_invoke_pause(rpc_port_proxy_tts_h h, int uid);
+
+int rpc_port_proxy_tts_invoke_play_pcm(rpc_port_proxy_tts_h h, int uid);
+
+int rpc_port_proxy_tts_invoke_stop_pcm(rpc_port_proxy_tts_h h, int uid);
+
+int rpc_port_proxy_tts_invoke_set_private(rpc_port_proxy_tts_h h, int uid, const char *key, const char *priv_data);
+
+int rpc_port_proxy_tts_invoke_get_private(rpc_port_proxy_tts_h h, int uid, const char *key, char **priv_data);
+
+int rpc_port_proxy_tts_invoke_play(rpc_port_proxy_tts_h h, int uid, const char *credential);
+
+int rpc_port_proxy_tts_invoke_add_pcm(rpc_port_proxy_tts_h h, int uid, int event, rpc_port_array_char_h pcm_data, int data_size, int audio_type, int rate);
+
+int rpc_port_proxy_tts_connect_sync(rpc_port_proxy_tts_h h);
+
+#ifdef __cplusplus
+}
+#endif
index a95b2db63b52247db631e89814083d05203d7344..a5e274962a9b50000f98d0ebd3a3e6202e893014 100644 (file)
@@ -90,11 +90,13 @@ GTest for TTS
 %setup -q -n %{name}-%{version}
 cp %{SOURCE1001} %{SOURCE1002} .
 
+%if 0%{?tidlc:1}
 tidlc -p -l C -i tidl/tts.tidl -o tts_proxy
 tidlc -s -l C -i tidl/tts.tidl -o ttsd_stub
 
 mv tts_proxy* client
 mv ttsd_stub* server
+%endif
 
 %build
 export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
diff --git a/server/ttsd_stub.c b/server/ttsd_stub.c
new file mode 100644 (file)
index 0000000..0d5986e
--- /dev/null
@@ -0,0 +1,1196 @@
+/*
+ * Generated by tidlc 1.4.9.
+ */
+
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <glib.h>
+#include <dlog.h>
+#include <rpc-port.h>
+#include <rpc-port-parcel.h>
+
+#include "ttsd_stub.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "RPC_PORT_STUB"
+
+#ifdef _E
+#undef _E
+#endif
+
+#ifdef _W
+#undef _W
+#endif
+
+#ifdef _I
+#undef _I
+#endif
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+
+typedef int (*stub_method)(rpc_port_h, rpc_port_parcel_h, void *data);
+
+struct array_char_s {
+       rpc_port_parcelable_t parcelable;
+       char *array_chars;
+       int array_chars_size;
+};
+
+static void __array_char_to(rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_array_char_h h = data;
+
+       if (!parcel || !h) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       rpc_port_parcel_write_array_count(parcel, h->array_chars_size);
+       do {
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       rpc_port_parcel_write_byte(parcel, h->array_chars[i]);
+               }
+       } while (0);
+}
+
+static void __array_char_from(rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_array_char_h h = data;
+
+       if (!parcel || !h) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       do {
+               rpc_port_parcel_read_array_count(parcel, &h->array_chars_size);
+
+               h->array_chars = calloc(h->array_chars_size, sizeof(*h->array_chars));
+               if (!h->array_chars) {
+                       _E("Out of memory");
+                       return;
+               }
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       char value = 0;
+
+                       rpc_port_parcel_read_byte(parcel, &value);
+                       h->array_chars[i] = value;
+               }
+       } while (0);
+}
+
+int rpc_port_array_char_create(rpc_port_array_char_h *h)
+{
+       struct array_char_s *handle;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       handle = calloc(1, sizeof(struct array_char_s));
+       if (!handle) {
+               _E("Out of memory");
+               return -1;
+       }
+
+       handle->parcelable.to = __array_char_to;
+       handle->parcelable.from = __array_char_from;
+
+       *h = handle;
+
+       return 0;
+}
+
+int rpc_port_array_char_destroy(rpc_port_array_char_h h)
+{
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       if (h->array_chars)
+               free(h->array_chars);
+
+       free(h);
+
+       return 0;
+}
+
+int rpc_port_array_char_clone(rpc_port_array_char_h h, rpc_port_array_char_h *clone)
+{
+       rpc_port_array_char_h handle = NULL;
+
+       if (!h || !clone) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       rpc_port_array_char_create(&handle);
+       if (!handle) {
+               _E("Failed to create array_char handle");
+               return -1;
+       }
+
+       do {
+               if (h->array_chars_size == 0) {
+                       _W("array_chars is empty");
+                       break;
+               }
+
+               handle->array_chars = calloc(h->array_chars_size, sizeof(*h->array_chars));
+               if (!handle->array_chars) {
+                       _E("Out of memory");
+                       rpc_port_array_char_destroy(handle);
+                       return -1;
+               }
+               handle->array_chars_size = h->array_chars_size;
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       handle->array_chars[i] = h->array_chars[i];
+               }
+       } while (0);
+
+       *clone = handle;
+
+       return 0;
+}
+
+int rpc_port_array_char_set_array_chars(rpc_port_array_char_h h, char *array_chars, int array_chars_size)
+{
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       if (h->array_chars)
+               free(h->array_chars);
+
+       h->array_chars = NULL;
+
+       do {
+               h->array_chars = calloc(array_chars_size, sizeof(*array_chars));
+               if (!h->array_chars) {
+                       _E("Out of memory");
+                       return -1;
+               }
+               h->array_chars_size = array_chars_size;
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       h->array_chars[i] = array_chars[i];
+               }
+       } while (0);
+
+       return 0;
+}
+
+int rpc_port_array_char_get_array_chars(rpc_port_array_char_h h, char **array_chars, int *array_chars_size)
+{
+       if (!h || !array_chars || !array_chars_size) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       do {
+               if (h->array_chars_size == 0) {
+                       _W("array_chars is empty");
+                       break;
+               }
+
+               *array_chars = calloc(h->array_chars_size, sizeof(*h->array_chars));
+               if (!*array_chars) {
+                       _E("Out of memory");
+                       return -1;
+               }
+               *array_chars_size = h->array_chars_size;
+
+               for (int i = 0; i < h->array_chars_size; i++) {
+                       (*array_chars)[i] = h->array_chars[i];
+               }
+       } while (0);
+
+       return 0;
+}
+
+enum tts_method_e {
+       tts_METHOD_Result,
+       tts_METHOD_Callback,
+       tts_METHOD_register_cb,
+       tts_METHOD_register_cb_sync,
+       tts_METHOD_set_mode,
+       tts_METHOD_initialize,
+       tts_METHOD_finalize,
+       tts_METHOD_add_text,
+       tts_METHOD_stop,
+       tts_METHOD_pause,
+       tts_METHOD_play_pcm,
+       tts_METHOD_stop_pcm,
+       tts_METHOD_set_private,
+       tts_METHOD_get_private,
+       tts_METHOD_play,
+       tts_METHOD_add_pcm,
+};
+
+enum tts_delegate_e {
+       tts_DELEGATE_notify_cb = 1,
+};
+
+static rpc_port_stub_h __tts_stub;
+static rpc_port_stub_tts_callback_s __tts_callback;
+static void *__tts_user_data;
+static GList *__tts_contexts;
+
+struct tts_context_s {
+       char *sender;
+       char *instance;
+       rpc_port_h port;
+       void *tag;
+       rpc_port_stub_tts_callback_s callback;
+       void *user_data;
+};
+
+static struct tts_context_s *__create_tts_context(const char *sender, const char *instance)
+{
+       struct tts_context_s *handle;
+
+       handle = calloc(1, sizeof(struct tts_context_s));
+       if (!handle) {
+               _E("Out of memory");
+               return NULL;
+       }
+
+       handle->sender = strdup(sender);
+       if (!handle->sender) {
+               _E("Out of memory");
+               free(handle);
+               return NULL;
+       }
+
+       handle->instance = strdup(instance);
+       if (!handle->instance) {
+               _E("Out of memory");
+               free(handle->sender);
+               free(handle);
+               return NULL;
+       }
+
+       handle->callback = __tts_callback;
+       handle->user_data = __tts_user_data;
+
+       return handle;
+}
+
+static void __destroy_tts_context(gpointer data)
+{
+       struct tts_context_s *handle = data;
+
+       if (!handle) {
+               _E("Critical error!");
+               return;
+       }
+
+       free(handle->instance);
+       free(handle->sender);
+
+       free(handle);
+}
+
+static struct tts_context_s *__find_tts_context(const char *instance)
+{
+       struct tts_context_s *handle;
+       GList *iter;
+
+       iter = __tts_contexts;
+       while (iter) {
+               handle = (struct tts_context_s *)iter->data;
+               if (!strcmp(handle->instance, instance))
+                       return handle;
+               iter = g_list_next(iter);
+       }
+
+       return NULL;
+}
+
+int rpc_port_stub_tts_context_set_tag(rpc_port_stub_tts_context_h ctx, void *tag)
+{
+       if (!ctx) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       ctx->tag = tag;
+
+       return 0;
+}
+
+int rpc_port_stub_tts_context_get_tag(rpc_port_stub_tts_context_h ctx, void **tag)
+{
+       if (!ctx || !tag) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       *tag = ctx->tag;
+
+       return 0;
+}
+
+int rpc_port_stub_tts_context_get_sender(rpc_port_stub_tts_context_h ctx, char **sender)
+{
+       if (!ctx || !sender) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       *sender = strdup(ctx->sender);
+       if (*sender == NULL) {
+               _E("Out of memory");
+               return -1;
+       }
+
+       return 0;
+}
+
+struct tts_notify_cb_s {
+       rpc_port_parcelable_t parcelable;
+       rpc_port_h port;
+       int id;
+       int seq_id;
+       bool once;
+       bool valid;
+};
+
+static void __tts_notify_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_tts_notify_cb_h handle = data;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       rpc_port_parcel_write_int32(parcel, handle->id);
+       rpc_port_parcel_write_int32(parcel, handle->seq_id);
+       rpc_port_parcel_write_bool(parcel, handle->once);
+       _I("id(%d), seq_id(%d), once(%s)", handle->id, handle->seq_id, handle->once ? "true" : "false");
+}
+
+static void __tts_notify_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_tts_notify_cb_h handle = data;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       rpc_port_parcel_read_int32(parcel, &handle->id);
+       rpc_port_parcel_read_int32(parcel, &handle->seq_id);
+       rpc_port_parcel_read_bool(parcel, &handle->once);
+       _I("id(%d), seq_id(%d), once(%s)", handle->id, handle->seq_id, handle->once ? "true" : "false");
+}
+
+static int rpc_port_tts_notify_cb_create(rpc_port_tts_notify_cb_h *h)
+{
+       struct tts_notify_cb_s *handle;
+       static int seq_num;
+
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       handle = calloc(1, sizeof(struct tts_notify_cb_s));
+       if (!handle) {
+               _E("Out of memory");
+               return -1;
+       }
+
+       handle->parcelable.to = __tts_notify_cb_to;
+       handle->parcelable.from = __tts_notify_cb_from;
+       handle->id = tts_DELEGATE_notify_cb;
+       handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1;
+       handle->once = false;
+       handle->valid = true;
+
+       *h = handle;
+
+       return 0;
+}
+
+int rpc_port_tts_notify_cb_destroy(rpc_port_tts_notify_cb_h h)
+{
+       if (!h) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       free(h);
+
+       return 0;
+}
+
+int rpc_port_tts_notify_cb_clone(rpc_port_tts_notify_cb_h h, rpc_port_tts_notify_cb_h *clone)
+{
+       rpc_port_tts_notify_cb_h handle;
+
+       if (!h || !clone) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       handle = calloc(1, sizeof(struct tts_notify_cb_s));
+       if (!handle) {
+               _E("Out of memory");
+               return -1;
+       }
+
+       handle->parcelable = h->parcelable;
+       handle->port = h->port;
+       handle->id = h->id;
+       handle->seq_id = h->seq_id;
+       handle->once = h->once;
+       handle->valid = h->valid;
+       _I("id(%d), seq_id(%d), once(%s)", handle->id, handle->seq_id, handle->once ? "true" : "false");
+
+       *clone = handle;
+
+       return 0;
+}
+
+int rpc_port_tts_notify_cb_invoke(rpc_port_tts_notify_cb_h h, int pid, int uid, bundle *msg)
+{
+       rpc_port_parcel_h parcel = NULL;
+       int r;
+
+       if (!h || !h->port) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       if (h->once && !h->valid) {
+               _E("Invalid callback");
+               return -1;
+       }
+
+       rpc_port_parcel_create(&parcel);
+       if (!parcel) {
+               _E("Failed to create parcel");
+               return -1;
+       }
+
+       rpc_port_parcel_write_int32(parcel, tts_METHOD_Callback);
+       rpc_port_parcel_write(parcel, &h->parcelable, h);
+       rpc_port_parcel_write_int32(parcel, pid);
+       rpc_port_parcel_write_int32(parcel, uid);
+       rpc_port_parcel_write_bundle(parcel, msg);
+
+       r = rpc_port_parcel_send(parcel, h->port);
+       rpc_port_parcel_destroy(parcel);
+       h->valid = false;
+
+       return r;
+}
+
+int rpc_port_tts_notify_cb_set_port(rpc_port_tts_notify_cb_h h, rpc_port_h port)
+{
+       if (!h || !port) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       h->port = port;
+
+       return 0;
+}
+
+static int __tts_method_register_cb(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int pid;
+       int uid;
+       rpc_port_tts_notify_cb_h callback = NULL;
+
+       rpc_port_parcel_read_int32(parcel, &pid);
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_tts_notify_cb_create(&callback);
+
+       if (!callback) {
+               _E("Failed to create handle");
+               return -1;
+       }
+
+       rpc_port_tts_notify_cb_set_port(callback, callback_port);
+       rpc_port_parcel_read(parcel, &callback->parcelable, callback);
+
+       context->callback.register_cb(context, pid, uid, callback, context->user_data);
+
+       rpc_port_tts_notify_cb_destroy(callback);
+       return r;
+}
+
+static int __tts_method_register_cb_sync(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int pid;
+       int uid;
+       rpc_port_tts_notify_cb_h callback = NULL;
+
+       rpc_port_parcel_read_int32(parcel, &pid);
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_tts_notify_cb_create(&callback);
+
+       if (!callback) {
+               _E("Failed to create handle");
+               return -1;
+       }
+
+       rpc_port_tts_notify_cb_set_port(callback, callback_port);
+       rpc_port_parcel_read(parcel, &callback->parcelable, callback);
+
+       int ret = context->callback.register_cb_sync(context, pid, uid, callback, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       rpc_port_tts_notify_cb_destroy(callback);
+       return r;
+}
+
+static int __tts_method_set_mode(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int mode;
+
+       rpc_port_parcel_read_int32(parcel, &mode);
+
+       int ret = context->callback.set_mode(context, mode, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       return r;
+}
+
+static int __tts_method_initialize(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int pid;
+       int uid;
+       bool credential_needed;
+
+       rpc_port_parcel_read_int32(parcel, &pid);
+       rpc_port_parcel_read_int32(parcel, &uid);
+
+       int ret = context->callback.initialize(context, pid, uid, &credential_needed, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_bool(result, credential_needed);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       return r;
+}
+
+static int __tts_method_finalize(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+
+       int ret = context->callback.finalize(context, uid, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       return r;
+}
+
+static int __tts_method_add_text(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+       char *text;
+       char *lang;
+       int vctype;
+       int speed;
+       int uttid;
+       char *credential;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_parcel_read_string(parcel, &text);
+       rpc_port_parcel_read_string(parcel, &lang);
+       rpc_port_parcel_read_int32(parcel, &vctype);
+       rpc_port_parcel_read_int32(parcel, &speed);
+       rpc_port_parcel_read_int32(parcel, &uttid);
+       rpc_port_parcel_read_string(parcel, &credential);
+
+       int ret = context->callback.add_text(context, uid, text, lang, vctype, speed, uttid, credential, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       free(text);
+       free(lang);
+
+       free(credential);
+       return r;
+}
+
+static int __tts_method_stop(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+
+       int ret = context->callback.stop(context, uid, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       return r;
+}
+
+static int __tts_method_pause(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+
+       int ret = context->callback.pause(context, uid, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       return r;
+}
+
+static int __tts_method_play_pcm(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+
+       int ret = context->callback.play_pcm(context, uid, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       return r;
+}
+
+static int __tts_method_stop_pcm(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+
+       int ret = context->callback.stop_pcm(context, uid, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       return r;
+}
+
+static int __tts_method_set_private(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+       char *key;
+       char *priv_data;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_parcel_read_string(parcel, &key);
+       rpc_port_parcel_read_string(parcel, &priv_data);
+
+       int ret = context->callback.set_private(context, uid, key, priv_data, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       free(key);
+       free(priv_data);
+       return r;
+}
+
+static int __tts_method_get_private(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+       char *key;
+       char *priv_data;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_parcel_read_string(parcel, &key);
+
+       int ret = context->callback.get_private(context, uid, key, &priv_data, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_string(result, priv_data ? priv_data : "");
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       free(key);
+       free(priv_data);
+       return r;
+}
+
+static int __tts_method_play(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+       char *credential;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_parcel_read_string(parcel, &credential);
+
+       int ret = context->callback.play(context, uid, credential, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       free(credential);
+       return r;
+}
+
+static int __tts_method_add_pcm(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+       rpc_port_stub_tts_context_h context = data;
+       rpc_port_h callback_port;
+       int r;
+
+       r = rpc_port_stub_get_port(__tts_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+       if (r != 0) {
+               _E("Failed to get callback port");
+               return -1;
+       }
+
+       int uid;
+       int event;
+       rpc_port_array_char_h pcm_data = NULL;
+       int data_size;
+       int audio_type;
+       int rate;
+
+       rpc_port_parcel_read_int32(parcel, &uid);
+       rpc_port_parcel_read_int32(parcel, &event);
+       rpc_port_array_char_create(&pcm_data);
+       rpc_port_parcel_read(parcel, &pcm_data->parcelable, pcm_data);
+       rpc_port_parcel_read_int32(parcel, &data_size);
+       rpc_port_parcel_read_int32(parcel, &audio_type);
+       rpc_port_parcel_read_int32(parcel, &rate);
+
+       int ret = context->callback.add_pcm(context, uid, event, pcm_data, data_size, audio_type, rate, context->user_data);
+       do {
+               rpc_port_parcel_h result;
+
+               rpc_port_parcel_create(&result);
+               rpc_port_parcel_write_int32(result, tts_METHOD_Result);
+               rpc_port_parcel_write_int32(result, ret);
+               r = rpc_port_parcel_send(result, port);
+               rpc_port_parcel_destroy(result);
+       } while (0);
+
+       rpc_port_array_char_destroy(pcm_data);
+
+       return r;
+}
+
+static stub_method __tts_method_table[] = {
+       [tts_METHOD_register_cb] = __tts_method_register_cb,
+       [tts_METHOD_register_cb_sync] = __tts_method_register_cb_sync,
+       [tts_METHOD_set_mode] = __tts_method_set_mode,
+       [tts_METHOD_initialize] = __tts_method_initialize,
+       [tts_METHOD_finalize] = __tts_method_finalize,
+       [tts_METHOD_add_text] = __tts_method_add_text,
+       [tts_METHOD_stop] = __tts_method_stop,
+       [tts_METHOD_pause] = __tts_method_pause,
+       [tts_METHOD_play_pcm] = __tts_method_play_pcm,
+       [tts_METHOD_stop_pcm] = __tts_method_stop_pcm,
+       [tts_METHOD_set_private] = __tts_method_set_private,
+       [tts_METHOD_get_private] = __tts_method_get_private,
+       [tts_METHOD_play] = __tts_method_play,
+       [tts_METHOD_add_pcm] = __tts_method_add_pcm,
+};
+
+static void __tts_on_connected(const char *sender, const char *instance, void *data)
+{
+       rpc_port_stub_tts_context_h context;
+
+       _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+       context = __create_tts_context(sender, instance);
+       if (!context)
+               return;
+
+       if (context->callback.create)
+               context->callback.create(context, context->user_data);
+       __tts_contexts = g_list_append(__tts_contexts, context);
+}
+
+static void __tts_on_disconnected(const char *sender, const char *instance, void *data)
+{
+       rpc_port_stub_tts_context_h context;
+
+       _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+       context = __find_tts_context(instance);
+       if (!context)
+               return;
+
+       if (context->callback.terminate)
+               context->callback.terminate(context, context->user_data);
+       __tts_contexts = g_list_remove(__tts_contexts, context);
+       __destroy_tts_context(context);
+}
+
+static int __tts_on_received(const char *sender, const char *instance, rpc_port_h port, void *data)
+{
+       rpc_port_stub_tts_context_h context;
+       rpc_port_parcel_h parcel;
+       int cmd = -1;
+       int r;
+
+       _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+       context = __find_tts_context(instance);
+       if (!context) {
+               _E("Failed to find tts context(%s)", instance);
+               return -1;
+       }
+
+       context->port = port;
+       r = rpc_port_parcel_create_from_port(&parcel, port);
+       if (r != 0) {
+               _E("Failed to create parcel from port");
+               return r;
+       }
+
+       rpc_port_parcel_read_int32(parcel, &cmd);
+       if (cmd > 1 && cmd < (sizeof(__tts_method_table) / sizeof(__tts_method_table[0]))) {
+               if (__tts_method_table[cmd])
+                       r = __tts_method_table[cmd](port, parcel, context);
+       } else {
+               _E("Unknown Command(%d)", cmd);
+               r = -1;
+       }
+
+       rpc_port_parcel_destroy(parcel);
+
+       return r;
+}
+
+static int __tts_add_privileges(void)
+{
+
+       return 0;
+}
+
+int rpc_port_stub_tts_register(rpc_port_stub_tts_callback_s *callback, void *user_data)
+{
+       int r;
+
+       if (__tts_stub) {
+               _W("Already exists");
+               return -1;
+       }
+
+       if (!callback) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       __tts_callback = *callback;
+       __tts_user_data = user_data;
+       r = rpc_port_stub_create(&__tts_stub, "tts");
+       if (r != 0) {
+               _E("Failed to create stub handle");
+               return r;
+       }
+
+       r = rpc_port_stub_add_received_event_cb(__tts_stub, __tts_on_received, NULL);
+       if (r != 0) {
+               _E("Failed to add received event callback");
+               rpc_port_stub_destroy(__tts_stub);
+               __tts_stub = NULL;
+               return r;
+       }
+
+       r = rpc_port_stub_add_connected_event_cb(__tts_stub, __tts_on_connected, NULL);
+       if (r != 0) {
+               _E("Failed to add connected event callback");
+               rpc_port_stub_destroy(__tts_stub);
+               __tts_stub = NULL;
+               return r;
+       }
+
+       r = rpc_port_stub_add_disconnected_event_cb(__tts_stub, __tts_on_disconnected, NULL);
+       if (r != 0) {
+               _E("Failed to add disconnected event callback");
+               rpc_port_stub_destroy(__tts_stub);
+               __tts_stub = NULL;
+               return r;
+       }
+
+       r = __tts_add_privileges();
+       if (r != 0) {
+               _E("Failed to add privileges");
+               rpc_port_stub_destroy(__tts_stub);
+               __tts_stub = NULL;
+               return r;
+       }
+
+       r = rpc_port_stub_listen(__tts_stub);
+       if (r != 0) {
+               _E("Failed to listen stub");
+               rpc_port_stub_destroy(__tts_stub);
+               __tts_stub = NULL;
+               return r;
+       }
+
+       return 0;
+}
+
+int rpc_port_stub_tts_unregister(void)
+{
+       int r;
+
+       if (!__tts_stub)
+               return -1;
+
+       if (__tts_contexts) {
+               g_list_free_full(__tts_contexts, __destroy_tts_context);
+               __tts_contexts = NULL;
+       }
+
+       r = rpc_port_stub_destroy(__tts_stub);
+       __tts_stub = NULL;
+
+       return r;
+}
+
+int rpc_port_stub_tts_get_client_number(unsigned int *n)
+{
+       if (!n) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       if (!__tts_stub) {
+               _E("tts Stub is not ready");
+               return -1;
+       }
+
+       *n = g_list_length(__tts_contexts);
+
+       return 0;
+}
diff --git a/server/ttsd_stub.h b/server/ttsd_stub.h
new file mode 100644 (file)
index 0000000..aa976d1
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Generated by tidlc 1.4.9.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct array_char_s *rpc_port_array_char_h;
+
+int rpc_port_array_char_create(rpc_port_array_char_h *h);
+
+int rpc_port_array_char_destroy(rpc_port_array_char_h h);
+
+int rpc_port_array_char_clone(rpc_port_array_char_h h, rpc_port_array_char_h *clone);
+
+int rpc_port_array_char_set_array_chars(rpc_port_array_char_h h, char *array_chars, int array_chars_size);
+
+int rpc_port_array_char_get_array_chars(rpc_port_array_char_h h, char **array_chars, int *array_chars_size);
+
+typedef struct tts_context_s* rpc_port_stub_tts_context_h;
+
+int rpc_port_stub_tts_context_set_tag(rpc_port_stub_tts_context_h ctx, void *tag);
+
+int rpc_port_stub_tts_context_get_tag(rpc_port_stub_tts_context_h ctx, void **tag);
+
+int rpc_port_stub_tts_context_get_sender(rpc_port_stub_tts_context_h ctx, char **sender);
+
+typedef struct tts_notify_cb_s *rpc_port_tts_notify_cb_h;
+
+int rpc_port_tts_notify_cb_destroy(rpc_port_tts_notify_cb_h h);
+
+int rpc_port_tts_notify_cb_clone(rpc_port_tts_notify_cb_h h, rpc_port_tts_notify_cb_h *clone);
+
+int rpc_port_tts_notify_cb_invoke(rpc_port_tts_notify_cb_h h, int pid, int uid, bundle *msg);
+
+typedef struct {
+       void (*create)(rpc_port_stub_tts_context_h context, void *user_data);
+       void (*terminate)(rpc_port_stub_tts_context_h context, void *user_data);
+
+       void (*register_cb)(rpc_port_stub_tts_context_h context, int pid, int uid, rpc_port_tts_notify_cb_h callback, void *user_data);
+       int (*register_cb_sync)(rpc_port_stub_tts_context_h context, int pid, int uid, rpc_port_tts_notify_cb_h callback, void *user_data);
+       int (*set_mode)(rpc_port_stub_tts_context_h context, int mode, void *user_data);
+       int (*initialize)(rpc_port_stub_tts_context_h context, int pid, int uid, bool *credential_needed, void *user_data);
+       int (*finalize)(rpc_port_stub_tts_context_h context, int uid, void *user_data);
+       int (*add_text)(rpc_port_stub_tts_context_h context, int uid, const char *text, const char *lang, int vctype, int speed, int uttid, const char *credential, void *user_data);
+       int (*stop)(rpc_port_stub_tts_context_h context, int uid, void *user_data);
+       int (*pause)(rpc_port_stub_tts_context_h context, int uid, void *user_data);
+       int (*play_pcm)(rpc_port_stub_tts_context_h context, int uid, void *user_data);
+       int (*stop_pcm)(rpc_port_stub_tts_context_h context, int uid, void *user_data);
+       int (*set_private)(rpc_port_stub_tts_context_h context, int uid, const char *key, const char *priv_data, void *user_data);
+       int (*get_private)(rpc_port_stub_tts_context_h context, int uid, const char *key, char **priv_data, void *user_data);
+       int (*play)(rpc_port_stub_tts_context_h context, int uid, const char *credential, void *user_data);
+       int (*add_pcm)(rpc_port_stub_tts_context_h context, int uid, int event, rpc_port_array_char_h pcm_data, int data_size, int audio_type, int rate, void *user_data);
+} rpc_port_stub_tts_callback_s;
+
+int rpc_port_stub_tts_register(rpc_port_stub_tts_callback_s *callback, void *user_data);
+
+int rpc_port_stub_tts_unregister(void);
+
+int rpc_port_stub_tts_get_client_number(unsigned int *n);
+
+#ifdef __cplusplus
+}
+#endif