--- /dev/null
+/*
+ * 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 "mmifw_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 focus_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ int timestamp;
+ bool focus_in;
+};
+
+static void __focus_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_focus_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_int32(parcel, h->timestamp);
+ rpc_port_parcel_write_bool(parcel, h->focus_in);
+}
+
+static void __focus_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_focus_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_int32(parcel, &h->timestamp);
+ rpc_port_parcel_read_bool(parcel, &h->focus_in);
+}
+
+int rpc_port_focus_event_create(rpc_port_focus_event_h *h)
+{
+ struct focus_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct focus_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __focus_event_to;
+ handle->parcelable.from = __focus_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_focus_event_destroy(rpc_port_focus_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_focus_event_clone(rpc_port_focus_event_h h, rpc_port_focus_event_h *clone)
+{
+ rpc_port_focus_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_focus_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create focus_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ handle->timestamp = h->timestamp;
+ handle->focus_in = h->focus_in;
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_focus_event_set_type(rpc_port_focus_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_focus_event_set_timestamp(rpc_port_focus_event_h h, int timestamp)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->timestamp = timestamp;
+ return 0;
+}
+
+int rpc_port_focus_event_set_focus_in(rpc_port_focus_event_h h, bool focus_in)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->focus_in = focus_in;
+ return 0;
+}
+
+int rpc_port_focus_event_get_type(rpc_port_focus_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_focus_event_get_timestamp(rpc_port_focus_event_h h, int *timestamp)
+{
+ if (!h || !timestamp) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *timestamp = h->timestamp;
+ return 0;
+}
+
+int rpc_port_focus_event_get_focus_in(rpc_port_focus_event_h h, bool *focus_in)
+{
+ if (!h || !focus_in) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *focus_in = h->focus_in;
+ return 0;
+}
+
+struct state_change_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ int timestamp;
+ int state;
+ int old_state;
+};
+
+static void __state_change_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_state_change_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_int32(parcel, h->timestamp);
+ rpc_port_parcel_write_int32(parcel, h->state);
+ rpc_port_parcel_write_int32(parcel, h->old_state);
+}
+
+static void __state_change_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_state_change_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_int32(parcel, &h->timestamp);
+ rpc_port_parcel_read_int32(parcel, &h->state);
+ rpc_port_parcel_read_int32(parcel, &h->old_state);
+}
+
+int rpc_port_state_change_event_create(rpc_port_state_change_event_h *h)
+{
+ struct state_change_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct state_change_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __state_change_event_to;
+ handle->parcelable.from = __state_change_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_state_change_event_destroy(rpc_port_state_change_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_state_change_event_clone(rpc_port_state_change_event_h h, rpc_port_state_change_event_h *clone)
+{
+ rpc_port_state_change_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_state_change_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create state_change_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ handle->timestamp = h->timestamp;
+ handle->state = h->state;
+ handle->old_state = h->old_state;
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_state_change_event_set_type(rpc_port_state_change_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_state_change_event_set_timestamp(rpc_port_state_change_event_h h, int timestamp)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->timestamp = timestamp;
+ return 0;
+}
+
+int rpc_port_state_change_event_set_state(rpc_port_state_change_event_h h, int state)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->state = state;
+ return 0;
+}
+
+int rpc_port_state_change_event_set_old_state(rpc_port_state_change_event_h h, int old_state)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->old_state = old_state;
+ return 0;
+}
+
+int rpc_port_state_change_event_get_type(rpc_port_state_change_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_state_change_event_get_timestamp(rpc_port_state_change_event_h h, int *timestamp)
+{
+ if (!h || !timestamp) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *timestamp = h->timestamp;
+ return 0;
+}
+
+int rpc_port_state_change_event_get_state(rpc_port_state_change_event_h h, int *state)
+{
+ if (!h || !state) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *state = h->state;
+ return 0;
+}
+
+int rpc_port_state_change_event_get_old_state(rpc_port_state_change_event_h h, int *old_state)
+{
+ if (!h || !old_state) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *old_state = h->old_state;
+ return 0;
+}
+
+struct wakeup_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ int timestamp;
+ char *source;
+};
+
+static void __wakeup_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_wakeup_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_int32(parcel, h->timestamp);
+ rpc_port_parcel_write_string(parcel, h->source ? h->source : "");
+}
+
+static void __wakeup_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_wakeup_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_int32(parcel, &h->timestamp);
+ rpc_port_parcel_read_string(parcel, &h->source);
+}
+
+int rpc_port_wakeup_event_create(rpc_port_wakeup_event_h *h)
+{
+ struct wakeup_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct wakeup_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __wakeup_event_to;
+ handle->parcelable.from = __wakeup_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_wakeup_event_destroy(rpc_port_wakeup_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source)
+ free(h->source);
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_wakeup_event_clone(rpc_port_wakeup_event_h h, rpc_port_wakeup_event_h *clone)
+{
+ rpc_port_wakeup_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_wakeup_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create wakeup_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ handle->timestamp = h->timestamp;
+ if (h->source) {
+ handle->source = strdup(h->source);
+ if (!handle->source) {
+ _E("Failed to duplicate h->source");
+ rpc_port_wakeup_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_wakeup_event_set_type(rpc_port_wakeup_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_wakeup_event_set_timestamp(rpc_port_wakeup_event_h h, int timestamp)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->timestamp = timestamp;
+ return 0;
+}
+
+int rpc_port_wakeup_event_set_source(rpc_port_wakeup_event_h h, const char *source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source) {
+ free(h->source);
+ h->source = NULL;
+ }
+
+ h->source = strdup(source);
+ if (!h->source) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_wakeup_event_get_type(rpc_port_wakeup_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_wakeup_event_get_timestamp(rpc_port_wakeup_event_h h, int *timestamp)
+{
+ if (!h || !timestamp) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *timestamp = h->timestamp;
+ return 0;
+}
+
+int rpc_port_wakeup_event_get_source(rpc_port_wakeup_event_h h, char **source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->source) {
+ _E("Invalid parameter: h->source is NULL");
+ return -1;
+ }
+
+ *source = strdup(h->source);
+ if (*source == NULL) {
+ _E("Failed to duplicate source");
+ return -1;
+ }
+
+ return 0;
+}
+
+struct key_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ int timestamp;
+ bool key_down;
+ int keycode;
+ char *keyname;
+ char *source;
+};
+
+static void __key_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_key_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_int32(parcel, h->timestamp);
+ rpc_port_parcel_write_bool(parcel, h->key_down);
+ rpc_port_parcel_write_int32(parcel, h->keycode);
+ rpc_port_parcel_write_string(parcel, h->keyname ? h->keyname : "");
+ rpc_port_parcel_write_string(parcel, h->source ? h->source : "");
+}
+
+static void __key_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_key_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_int32(parcel, &h->timestamp);
+ rpc_port_parcel_read_bool(parcel, &h->key_down);
+ rpc_port_parcel_read_int32(parcel, &h->keycode);
+ rpc_port_parcel_read_string(parcel, &h->keyname);
+ rpc_port_parcel_read_string(parcel, &h->source);
+}
+
+int rpc_port_key_event_create(rpc_port_key_event_h *h)
+{
+ struct key_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct key_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __key_event_to;
+ handle->parcelable.from = __key_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_key_event_destroy(rpc_port_key_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->keyname)
+ free(h->keyname);
+
+ if (h->source)
+ free(h->source);
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_key_event_clone(rpc_port_key_event_h h, rpc_port_key_event_h *clone)
+{
+ rpc_port_key_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_key_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create key_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ handle->timestamp = h->timestamp;
+ handle->key_down = h->key_down;
+ handle->keycode = h->keycode;
+ if (h->keyname) {
+ handle->keyname = strdup(h->keyname);
+ if (!handle->keyname) {
+ _E("Failed to duplicate h->keyname");
+ rpc_port_key_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ if (h->source) {
+ handle->source = strdup(h->source);
+ if (!handle->source) {
+ _E("Failed to duplicate h->source");
+ rpc_port_key_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_key_event_set_type(rpc_port_key_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_key_event_set_timestamp(rpc_port_key_event_h h, int timestamp)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->timestamp = timestamp;
+ return 0;
+}
+
+int rpc_port_key_event_set_key_down(rpc_port_key_event_h h, bool key_down)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->key_down = key_down;
+ return 0;
+}
+
+int rpc_port_key_event_set_keycode(rpc_port_key_event_h h, int keycode)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->keycode = keycode;
+ return 0;
+}
+
+int rpc_port_key_event_set_keyname(rpc_port_key_event_h h, const char *keyname)
+{
+ if (!h || !keyname) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->keyname) {
+ free(h->keyname);
+ h->keyname = NULL;
+ }
+
+ h->keyname = strdup(keyname);
+ if (!h->keyname) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_key_event_set_source(rpc_port_key_event_h h, const char *source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source) {
+ free(h->source);
+ h->source = NULL;
+ }
+
+ h->source = strdup(source);
+ if (!h->source) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_key_event_get_type(rpc_port_key_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_key_event_get_timestamp(rpc_port_key_event_h h, int *timestamp)
+{
+ if (!h || !timestamp) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *timestamp = h->timestamp;
+ return 0;
+}
+
+int rpc_port_key_event_get_key_down(rpc_port_key_event_h h, bool *key_down)
+{
+ if (!h || !key_down) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *key_down = h->key_down;
+ return 0;
+}
+
+int rpc_port_key_event_get_keycode(rpc_port_key_event_h h, int *keycode)
+{
+ if (!h || !keycode) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *keycode = h->keycode;
+ return 0;
+}
+
+int rpc_port_key_event_get_keyname(rpc_port_key_event_h h, char **keyname)
+{
+ if (!h || !keyname) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->keyname) {
+ _E("Invalid parameter: h->keyname is NULL");
+ return -1;
+ }
+
+ *keyname = strdup(h->keyname);
+ if (*keyname == NULL) {
+ _E("Failed to duplicate keyname");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_key_event_get_source(rpc_port_key_event_h h, char **source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->source) {
+ _E("Invalid parameter: h->source is NULL");
+ return -1;
+ }
+
+ *source = strdup(h->source);
+ if (*source == NULL) {
+ _E("Failed to duplicate source");
+ return -1;
+ }
+
+ return 0;
+}
+
+struct gesture_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ int timestamp;
+ char *source;
+};
+
+static void __gesture_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_gesture_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_int32(parcel, h->timestamp);
+ rpc_port_parcel_write_string(parcel, h->source ? h->source : "");
+}
+
+static void __gesture_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_gesture_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_int32(parcel, &h->timestamp);
+ rpc_port_parcel_read_string(parcel, &h->source);
+}
+
+int rpc_port_gesture_event_create(rpc_port_gesture_event_h *h)
+{
+ struct gesture_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct gesture_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __gesture_event_to;
+ handle->parcelable.from = __gesture_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_gesture_event_destroy(rpc_port_gesture_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source)
+ free(h->source);
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_gesture_event_clone(rpc_port_gesture_event_h h, rpc_port_gesture_event_h *clone)
+{
+ rpc_port_gesture_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_gesture_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create gesture_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ handle->timestamp = h->timestamp;
+ if (h->source) {
+ handle->source = strdup(h->source);
+ if (!handle->source) {
+ _E("Failed to duplicate h->source");
+ rpc_port_gesture_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_gesture_event_set_type(rpc_port_gesture_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_gesture_event_set_timestamp(rpc_port_gesture_event_h h, int timestamp)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->timestamp = timestamp;
+ return 0;
+}
+
+int rpc_port_gesture_event_set_source(rpc_port_gesture_event_h h, const char *source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source) {
+ free(h->source);
+ h->source = NULL;
+ }
+
+ h->source = strdup(source);
+ if (!h->source) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_gesture_event_get_type(rpc_port_gesture_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_gesture_event_get_timestamp(rpc_port_gesture_event_h h, int *timestamp)
+{
+ if (!h || !timestamp) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *timestamp = h->timestamp;
+ return 0;
+}
+
+int rpc_port_gesture_event_get_source(rpc_port_gesture_event_h h, char **source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->source) {
+ _E("Invalid parameter: h->source is NULL");
+ return -1;
+ }
+
+ *source = strdup(h->source);
+ if (*source == NULL) {
+ _E("Failed to duplicate source");
+ return -1;
+ }
+
+ return 0;
+}
+
+struct voice_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ char *source;
+};
+
+static void __voice_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_voice_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_string(parcel, h->source ? h->source : "");
+}
+
+static void __voice_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_voice_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_string(parcel, &h->source);
+}
+
+int rpc_port_voice_event_create(rpc_port_voice_event_h *h)
+{
+ struct voice_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct voice_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __voice_event_to;
+ handle->parcelable.from = __voice_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_voice_event_destroy(rpc_port_voice_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source)
+ free(h->source);
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_voice_event_clone(rpc_port_voice_event_h h, rpc_port_voice_event_h *clone)
+{
+ rpc_port_voice_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_voice_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create voice_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ if (h->source) {
+ handle->source = strdup(h->source);
+ if (!handle->source) {
+ _E("Failed to duplicate h->source");
+ rpc_port_voice_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_voice_event_set_type(rpc_port_voice_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_voice_event_set_source(rpc_port_voice_event_h h, const char *source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source) {
+ free(h->source);
+ h->source = NULL;
+ }
+
+ h->source = strdup(source);
+ if (!h->source) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_voice_event_get_type(rpc_port_voice_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_voice_event_get_source(rpc_port_voice_event_h h, char **source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->source) {
+ _E("Invalid parameter: h->source is NULL");
+ return -1;
+ }
+
+ *source = strdup(h->source);
+ if (*source == NULL) {
+ _E("Failed to duplicate source");
+ return -1;
+ }
+
+ return 0;
+}
+
+struct action_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ int timestamp;
+ char *cmd;
+ char **args;
+ int args_size;
+ int nargs;
+ char *source;
+};
+
+static void __action_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_action_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_int32(parcel, h->timestamp);
+ rpc_port_parcel_write_string(parcel, h->cmd ? h->cmd : "");
+ rpc_port_parcel_write_array_count(parcel, h->args_size);
+ do {
+ for (int i = 0; i < h->args_size; i++) {
+ rpc_port_parcel_write_string(parcel, h->args[i] ? h->args[i] : "");
+ }
+ } while (0);
+
+ rpc_port_parcel_write_int32(parcel, h->nargs);
+ rpc_port_parcel_write_string(parcel, h->source ? h->source : "");
+}
+
+static void __action_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_action_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_int32(parcel, &h->timestamp);
+ rpc_port_parcel_read_string(parcel, &h->cmd);
+
+ do {
+ rpc_port_parcel_read_array_count(parcel, &h->args_size);
+
+ h->args = calloc(h->args_size, sizeof(*h->args));
+ if (!h->args) {
+ _E("Out of memory");
+ return;
+ }
+
+ for (int i = 0; i < h->args_size; i++) {
+ char *value = NULL;
+
+ rpc_port_parcel_read_string(parcel, &value);
+ h->args[i] = value;
+ }
+ } while (0);
+
+ rpc_port_parcel_read_int32(parcel, &h->nargs);
+ rpc_port_parcel_read_string(parcel, &h->source);
+}
+
+int rpc_port_action_event_create(rpc_port_action_event_h *h)
+{
+ struct action_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct action_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __action_event_to;
+ handle->parcelable.from = __action_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_action_event_destroy(rpc_port_action_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->cmd)
+ free(h->cmd);
+
+ do {
+ for (int j = 0; j < h->args_size; j++) {
+ if (h->args[j])
+ free(h->args[j]);
+ }
+ free(h->args);
+ } while (0);
+ if (h->source)
+ free(h->source);
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_action_event_clone(rpc_port_action_event_h h, rpc_port_action_event_h *clone)
+{
+ rpc_port_action_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_action_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create action_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ handle->timestamp = h->timestamp;
+ if (h->cmd) {
+ handle->cmd = strdup(h->cmd);
+ if (!handle->cmd) {
+ _E("Failed to duplicate h->cmd");
+ rpc_port_action_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ do {
+ if (h->args_size == 0) {
+ _W("args is empty");
+ break;
+ }
+
+ handle->args = calloc(h->args_size, sizeof(*h->args));
+ if (!handle->args) {
+ _E("Out of memory");
+ rpc_port_action_event_destroy(handle);
+ return -1;
+ }
+ handle->args_size = h->args_size;
+
+ for (int i = 0; i < h->args_size; i++) {
+ handle->args[i] = strdup(h->args[i]);
+ }
+ } while (0);
+
+ handle->nargs = h->nargs;
+ if (h->source) {
+ handle->source = strdup(h->source);
+ if (!handle->source) {
+ _E("Failed to duplicate h->source");
+ rpc_port_action_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_action_event_set_type(rpc_port_action_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_action_event_set_timestamp(rpc_port_action_event_h h, int timestamp)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->timestamp = timestamp;
+ return 0;
+}
+
+int rpc_port_action_event_set_cmd(rpc_port_action_event_h h, const char *cmd)
+{
+ if (!h || !cmd) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->cmd) {
+ free(h->cmd);
+ h->cmd = NULL;
+ }
+
+ h->cmd = strdup(cmd);
+ if (!h->cmd) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_action_event_set_args(rpc_port_action_event_h h, char **args, int args_size)
+{
+ if (!h || !args) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ do {
+ for (int j = 0; j < h->args_size; j++) {
+ if (h->args[j])
+ free(h->args[j]);
+ }
+ free(h->args);
+ } while (0);
+
+ h->args = NULL;
+
+ do {
+ h->args = calloc(args_size, sizeof(*args));
+ if (!h->args) {
+ _E("Out of memory");
+ return -1;
+ }
+ h->args_size = args_size;
+
+ for (int i = 0; i < h->args_size; i++) {
+ h->args[i] = strdup(args[i]);
+ }
+ } while (0);
+
+ return 0;
+}
+
+int rpc_port_action_event_set_nargs(rpc_port_action_event_h h, int nargs)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->nargs = nargs;
+ return 0;
+}
+
+int rpc_port_action_event_set_source(rpc_port_action_event_h h, const char *source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->source) {
+ free(h->source);
+ h->source = NULL;
+ }
+
+ h->source = strdup(source);
+ if (!h->source) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_action_event_get_type(rpc_port_action_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_action_event_get_timestamp(rpc_port_action_event_h h, int *timestamp)
+{
+ if (!h || !timestamp) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *timestamp = h->timestamp;
+ return 0;
+}
+
+int rpc_port_action_event_get_cmd(rpc_port_action_event_h h, char **cmd)
+{
+ if (!h || !cmd) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->cmd) {
+ _E("Invalid parameter: h->cmd is NULL");
+ return -1;
+ }
+
+ *cmd = strdup(h->cmd);
+ if (*cmd == NULL) {
+ _E("Failed to duplicate cmd");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_action_event_get_args(rpc_port_action_event_h h, char ***args, int *args_size)
+{
+ if (!h || !args || !args_size) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ do {
+ if (h->args_size == 0) {
+ _W("args is empty");
+ break;
+ }
+
+ *args = calloc(h->args_size, sizeof(*h->args));
+ if (!*args) {
+ _E("Out of memory");
+ return -1;
+ }
+ *args_size = h->args_size;
+
+ for (int i = 0; i < h->args_size; i++) {
+ (*args)[i] = strdup(h->args[i]);
+ }
+ } while (0);
+
+ return 0;
+}
+
+int rpc_port_action_event_get_nargs(rpc_port_action_event_h h, int *nargs)
+{
+ if (!h || !nargs) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *nargs = h->nargs;
+ return 0;
+}
+
+int rpc_port_action_event_get_source(rpc_port_action_event_h h, char **source)
+{
+ if (!h || !source) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->source) {
+ _E("Invalid parameter: h->source is NULL");
+ return -1;
+ }
+
+ *source = strdup(h->source);
+ if (*source == NULL) {
+ _E("Failed to duplicate source");
+ return -1;
+ }
+
+ return 0;
+}
+
+struct feedback_event_s {
+ rpc_port_parcelable_t parcelable;
+ int type;
+ int timestamp;
+ char *feedback;
+ char *comment;
+};
+
+static void __feedback_event_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_feedback_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_int32(parcel, h->type);
+ rpc_port_parcel_write_int32(parcel, h->timestamp);
+ rpc_port_parcel_write_string(parcel, h->feedback ? h->feedback : "");
+ rpc_port_parcel_write_string(parcel, h->comment ? h->comment : "");
+}
+
+static void __feedback_event_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_feedback_event_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_read_int32(parcel, &h->type);
+ rpc_port_parcel_read_int32(parcel, &h->timestamp);
+ rpc_port_parcel_read_string(parcel, &h->feedback);
+ rpc_port_parcel_read_string(parcel, &h->comment);
+}
+
+int rpc_port_feedback_event_create(rpc_port_feedback_event_h *h)
+{
+ struct feedback_event_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct feedback_event_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __feedback_event_to;
+ handle->parcelable.from = __feedback_event_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_feedback_event_destroy(rpc_port_feedback_event_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->feedback)
+ free(h->feedback);
+
+ if (h->comment)
+ free(h->comment);
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_feedback_event_clone(rpc_port_feedback_event_h h, rpc_port_feedback_event_h *clone)
+{
+ rpc_port_feedback_event_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_feedback_event_create(&handle);
+ if (!handle) {
+ _E("Failed to create feedback_event handle");
+ return -1;
+ }
+
+ handle->type = h->type;
+ handle->timestamp = h->timestamp;
+ if (h->feedback) {
+ handle->feedback = strdup(h->feedback);
+ if (!handle->feedback) {
+ _E("Failed to duplicate h->feedback");
+ rpc_port_feedback_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ if (h->comment) {
+ handle->comment = strdup(h->comment);
+ if (!handle->comment) {
+ _E("Failed to duplicate h->comment");
+ rpc_port_feedback_event_destroy(handle);
+ return -1;
+ }
+ }
+
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_feedback_event_set_type(rpc_port_feedback_event_h h, int type)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->type = type;
+ return 0;
+}
+
+int rpc_port_feedback_event_set_timestamp(rpc_port_feedback_event_h h, int timestamp)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->timestamp = timestamp;
+ return 0;
+}
+
+int rpc_port_feedback_event_set_feedback(rpc_port_feedback_event_h h, const char *feedback)
+{
+ if (!h || !feedback) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->feedback) {
+ free(h->feedback);
+ h->feedback = NULL;
+ }
+
+ h->feedback = strdup(feedback);
+ if (!h->feedback) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_feedback_event_set_comment(rpc_port_feedback_event_h h, const char *comment)
+{
+ if (!h || !comment) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (h->comment) {
+ free(h->comment);
+ h->comment = NULL;
+ }
+
+ h->comment = strdup(comment);
+ if (!h->comment) {
+ _E("Failed to duplicate data");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_feedback_event_get_type(rpc_port_feedback_event_h h, int *type)
+{
+ if (!h || !type) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *type = h->type;
+ return 0;
+}
+
+int rpc_port_feedback_event_get_timestamp(rpc_port_feedback_event_h h, int *timestamp)
+{
+ if (!h || !timestamp) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *timestamp = h->timestamp;
+ return 0;
+}
+
+int rpc_port_feedback_event_get_feedback(rpc_port_feedback_event_h h, char **feedback)
+{
+ if (!h || !feedback) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->feedback) {
+ _E("Invalid parameter: h->feedback is NULL");
+ return -1;
+ }
+
+ *feedback = strdup(h->feedback);
+ if (*feedback == NULL) {
+ _E("Failed to duplicate feedback");
+ return -1;
+ }
+
+ return 0;
+}
+
+int rpc_port_feedback_event_get_comment(rpc_port_feedback_event_h h, char **comment)
+{
+ if (!h || !comment) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!h->comment) {
+ _E("Invalid parameter: h->comment is NULL");
+ return -1;
+ }
+
+ *comment = strdup(h->comment);
+ if (*comment == NULL) {
+ _E("Failed to duplicate comment");
+ return -1;
+ }
+
+ return 0;
+}
+
+struct array_string_s {
+ rpc_port_parcelable_t parcelable;
+ char **array_strings;
+ int array_strings_size;
+};
+
+static void __array_string_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_array_string_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ rpc_port_parcel_write_array_count(parcel, h->array_strings_size);
+ do {
+ for (int i = 0; i < h->array_strings_size; i++) {
+ rpc_port_parcel_write_string(parcel, h->array_strings[i] ? h->array_strings[i] : "");
+ }
+ } while (0);
+}
+
+static void __array_string_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_array_string_h h = data;
+
+ if (!parcel || !h) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ do {
+ rpc_port_parcel_read_array_count(parcel, &h->array_strings_size);
+
+ h->array_strings = calloc(h->array_strings_size, sizeof(*h->array_strings));
+ if (!h->array_strings) {
+ _E("Out of memory");
+ return;
+ }
+
+ for (int i = 0; i < h->array_strings_size; i++) {
+ char *value = NULL;
+
+ rpc_port_parcel_read_string(parcel, &value);
+ h->array_strings[i] = value;
+ }
+ } while (0);
+}
+
+int rpc_port_array_string_create(rpc_port_array_string_h *h)
+{
+ struct array_string_s *handle;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct array_string_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __array_string_to;
+ handle->parcelable.from = __array_string_from;
+
+ *h = handle;
+
+ return 0;
+}
+
+int rpc_port_array_string_destroy(rpc_port_array_string_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ do {
+ for (int j = 0; j < h->array_strings_size; j++) {
+ if (h->array_strings[j])
+ free(h->array_strings[j]);
+ }
+ free(h->array_strings);
+ } while (0);
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_array_string_clone(rpc_port_array_string_h h, rpc_port_array_string_h *clone)
+{
+ rpc_port_array_string_h handle = NULL;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ rpc_port_array_string_create(&handle);
+ if (!handle) {
+ _E("Failed to create array_string handle");
+ return -1;
+ }
+
+ do {
+ if (h->array_strings_size == 0) {
+ _W("array_strings is empty");
+ break;
+ }
+
+ handle->array_strings = calloc(h->array_strings_size, sizeof(*h->array_strings));
+ if (!handle->array_strings) {
+ _E("Out of memory");
+ rpc_port_array_string_destroy(handle);
+ return -1;
+ }
+ handle->array_strings_size = h->array_strings_size;
+
+ for (int i = 0; i < h->array_strings_size; i++) {
+ handle->array_strings[i] = strdup(h->array_strings[i]);
+ }
+ } while (0);
+
+ *clone = handle;
+
+ return 0;
+}
+
+int rpc_port_array_string_set_array_strings(rpc_port_array_string_h h, char **array_strings, int array_strings_size)
+{
+ if (!h || !array_strings) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ do {
+ for (int j = 0; j < h->array_strings_size; j++) {
+ if (h->array_strings[j])
+ free(h->array_strings[j]);
+ }
+ free(h->array_strings);
+ } while (0);
+
+ h->array_strings = NULL;
+
+ do {
+ h->array_strings = calloc(array_strings_size, sizeof(*array_strings));
+ if (!h->array_strings) {
+ _E("Out of memory");
+ return -1;
+ }
+ h->array_strings_size = array_strings_size;
+
+ for (int i = 0; i < h->array_strings_size; i++) {
+ h->array_strings[i] = strdup(array_strings[i]);
+ }
+ } while (0);
+
+ return 0;
+}
+
+int rpc_port_array_string_get_array_strings(rpc_port_array_string_h h, char ***array_strings, int *array_strings_size)
+{
+ if (!h || !array_strings || !array_strings_size) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ do {
+ if (h->array_strings_size == 0) {
+ _W("array_strings is empty");
+ break;
+ }
+
+ *array_strings = calloc(h->array_strings_size, sizeof(*h->array_strings));
+ if (!*array_strings) {
+ _E("Out of memory");
+ return -1;
+ }
+ *array_strings_size = h->array_strings_size;
+
+ for (int i = 0; i < h->array_strings_size; i++) {
+ (*array_strings)[i] = strdup(h->array_strings[i]);
+ }
+ } while (0);
+
+ return 0;
+}
+
+enum mmifw_method_e {
+ mmifw_METHOD_Result,
+ mmifw_METHOD_Callback,
+ mmifw_METHOD_register_cb,
+ mmifw_METHOD_deregister_cb,
+ mmifw_METHOD_get_focus,
+ mmifw_METHOD_set_state,
+};
+
+enum mmifw_delegate_e {
+ mmifw_DELEGATE_focus_event_cb = 1,
+ mmifw_DELEGATE_state_change_event_cb = 2,
+ mmifw_DELEGATE_wakeup_event_cb = 3,
+ mmifw_DELEGATE_key_event_cb = 4,
+ mmifw_DELEGATE_gesture_event_cb = 5,
+ mmifw_DELEGATE_voice_event_cb = 6,
+ mmifw_DELEGATE_action_event_cb = 7,
+ mmifw_DELEGATE_feedback_event_cb = 8,
+};
+
+static rpc_port_stub_h __mmifw_stub;
+static rpc_port_stub_mmifw_callback_s __mmifw_callback;
+static void *__mmifw_user_data;
+static GList *__mmifw_contexts;
+
+struct mmifw_context_s {
+ char *sender;
+ char *instance;
+ rpc_port_h port;
+ void *tag;
+ rpc_port_stub_mmifw_callback_s callback;
+ void *user_data;
+};
+
+static struct mmifw_context_s *__create_mmifw_context(const char *sender, const char *instance)
+{
+ struct mmifw_context_s *handle;
+
+ handle = calloc(1, sizeof(struct mmifw_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 = __mmifw_callback;
+ handle->user_data = __mmifw_user_data;
+
+ return handle;
+}
+
+static void __destroy_mmifw_context(gpointer data)
+{
+ struct mmifw_context_s *handle = data;
+
+ if (!handle) {
+ _E("Critical error!");
+ return;
+ }
+
+ free(handle->instance);
+ free(handle->sender);
+
+ free(handle);
+}
+
+static struct mmifw_context_s *__find_mmifw_context(const char *instance)
+{
+ struct mmifw_context_s *handle;
+ GList *iter;
+
+ iter = __mmifw_contexts;
+ while (iter) {
+ handle = (struct mmifw_context_s *)iter->data;
+ if (!strcmp(handle->instance, instance))
+ return handle;
+ iter = g_list_next(iter);
+ }
+
+ return NULL;
+}
+
+int rpc_port_stub_mmifw_context_set_tag(rpc_port_stub_mmifw_context_h ctx, void *tag)
+{
+ if (!ctx) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ ctx->tag = tag;
+
+ return 0;
+}
+
+int rpc_port_stub_mmifw_context_get_tag(rpc_port_stub_mmifw_context_h ctx, void **tag)
+{
+ if (!ctx || !tag) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *tag = ctx->tag;
+
+ return 0;
+}
+
+int rpc_port_stub_mmifw_context_get_sender(rpc_port_stub_mmifw_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 mmifw_focus_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_focus_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_focus_event_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 __mmifw_focus_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_focus_event_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_mmifw_focus_event_cb_create(rpc_port_mmifw_focus_event_cb_h *h)
+{
+ struct mmifw_focus_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_focus_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_focus_event_cb_to;
+ handle->parcelable.from = __mmifw_focus_event_cb_from;
+ handle->id = mmifw_DELEGATE_focus_event_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_mmifw_focus_event_cb_destroy(rpc_port_mmifw_focus_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_focus_event_cb_clone(rpc_port_mmifw_focus_event_cb_h h, rpc_port_mmifw_focus_event_cb_h *clone)
+{
+ rpc_port_mmifw_focus_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_focus_event_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_mmifw_focus_event_cb_invoke(rpc_port_mmifw_focus_event_cb_h h, rpc_port_focus_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_focus_event_cb_set_port(rpc_port_mmifw_focus_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+struct mmifw_state_change_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_state_change_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_state_change_event_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 __mmifw_state_change_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_state_change_event_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_mmifw_state_change_event_cb_create(rpc_port_mmifw_state_change_event_cb_h *h)
+{
+ struct mmifw_state_change_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_state_change_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_state_change_event_cb_to;
+ handle->parcelable.from = __mmifw_state_change_event_cb_from;
+ handle->id = mmifw_DELEGATE_state_change_event_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_mmifw_state_change_event_cb_destroy(rpc_port_mmifw_state_change_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_state_change_event_cb_clone(rpc_port_mmifw_state_change_event_cb_h h, rpc_port_mmifw_state_change_event_cb_h *clone)
+{
+ rpc_port_mmifw_state_change_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_state_change_event_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_mmifw_state_change_event_cb_invoke(rpc_port_mmifw_state_change_event_cb_h h, rpc_port_state_change_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_state_change_event_cb_set_port(rpc_port_mmifw_state_change_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+struct mmifw_wakeup_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_wakeup_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_wakeup_event_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 __mmifw_wakeup_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_wakeup_event_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_mmifw_wakeup_event_cb_create(rpc_port_mmifw_wakeup_event_cb_h *h)
+{
+ struct mmifw_wakeup_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_wakeup_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_wakeup_event_cb_to;
+ handle->parcelable.from = __mmifw_wakeup_event_cb_from;
+ handle->id = mmifw_DELEGATE_wakeup_event_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_mmifw_wakeup_event_cb_destroy(rpc_port_mmifw_wakeup_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_wakeup_event_cb_clone(rpc_port_mmifw_wakeup_event_cb_h h, rpc_port_mmifw_wakeup_event_cb_h *clone)
+{
+ rpc_port_mmifw_wakeup_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_wakeup_event_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_mmifw_wakeup_event_cb_invoke(rpc_port_mmifw_wakeup_event_cb_h h, rpc_port_wakeup_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_wakeup_event_cb_set_port(rpc_port_mmifw_wakeup_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+struct mmifw_key_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_key_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_key_event_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 __mmifw_key_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_key_event_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_mmifw_key_event_cb_create(rpc_port_mmifw_key_event_cb_h *h)
+{
+ struct mmifw_key_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_key_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_key_event_cb_to;
+ handle->parcelable.from = __mmifw_key_event_cb_from;
+ handle->id = mmifw_DELEGATE_key_event_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_mmifw_key_event_cb_destroy(rpc_port_mmifw_key_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_key_event_cb_clone(rpc_port_mmifw_key_event_cb_h h, rpc_port_mmifw_key_event_cb_h *clone)
+{
+ rpc_port_mmifw_key_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_key_event_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_mmifw_key_event_cb_invoke(rpc_port_mmifw_key_event_cb_h h, rpc_port_key_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_key_event_cb_set_port(rpc_port_mmifw_key_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+struct mmifw_gesture_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_gesture_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_gesture_event_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 __mmifw_gesture_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_gesture_event_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_mmifw_gesture_event_cb_create(rpc_port_mmifw_gesture_event_cb_h *h)
+{
+ struct mmifw_gesture_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_gesture_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_gesture_event_cb_to;
+ handle->parcelable.from = __mmifw_gesture_event_cb_from;
+ handle->id = mmifw_DELEGATE_gesture_event_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_mmifw_gesture_event_cb_destroy(rpc_port_mmifw_gesture_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_gesture_event_cb_clone(rpc_port_mmifw_gesture_event_cb_h h, rpc_port_mmifw_gesture_event_cb_h *clone)
+{
+ rpc_port_mmifw_gesture_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_gesture_event_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_mmifw_gesture_event_cb_invoke(rpc_port_mmifw_gesture_event_cb_h h, rpc_port_gesture_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_gesture_event_cb_set_port(rpc_port_mmifw_gesture_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+struct mmifw_voice_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_voice_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_voice_event_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 __mmifw_voice_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_voice_event_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_mmifw_voice_event_cb_create(rpc_port_mmifw_voice_event_cb_h *h)
+{
+ struct mmifw_voice_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_voice_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_voice_event_cb_to;
+ handle->parcelable.from = __mmifw_voice_event_cb_from;
+ handle->id = mmifw_DELEGATE_voice_event_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_mmifw_voice_event_cb_destroy(rpc_port_mmifw_voice_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_voice_event_cb_clone(rpc_port_mmifw_voice_event_cb_h h, rpc_port_mmifw_voice_event_cb_h *clone)
+{
+ rpc_port_mmifw_voice_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_voice_event_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_mmifw_voice_event_cb_invoke(rpc_port_mmifw_voice_event_cb_h h, rpc_port_voice_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_voice_event_cb_set_port(rpc_port_mmifw_voice_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+struct mmifw_action_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_action_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_action_event_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 __mmifw_action_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_action_event_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_mmifw_action_event_cb_create(rpc_port_mmifw_action_event_cb_h *h)
+{
+ struct mmifw_action_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_action_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_action_event_cb_to;
+ handle->parcelable.from = __mmifw_action_event_cb_from;
+ handle->id = mmifw_DELEGATE_action_event_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_mmifw_action_event_cb_destroy(rpc_port_mmifw_action_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_action_event_cb_clone(rpc_port_mmifw_action_event_cb_h h, rpc_port_mmifw_action_event_cb_h *clone)
+{
+ rpc_port_mmifw_action_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_action_event_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_mmifw_action_event_cb_invoke(rpc_port_mmifw_action_event_cb_h h, rpc_port_action_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_action_event_cb_set_port(rpc_port_mmifw_action_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+struct mmifw_feedback_event_cb_s {
+ rpc_port_parcelable_t parcelable;
+ rpc_port_h port;
+ int id;
+ int seq_id;
+ bool once;
+ bool valid;
+};
+
+static void __mmifw_feedback_event_cb_to(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_feedback_event_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 __mmifw_feedback_event_cb_from(rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_mmifw_feedback_event_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_mmifw_feedback_event_cb_create(rpc_port_mmifw_feedback_event_cb_h *h)
+{
+ struct mmifw_feedback_event_cb_s *handle;
+ static int seq_num;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_feedback_event_cb_s));
+ if (!handle) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ handle->parcelable.to = __mmifw_feedback_event_cb_to;
+ handle->parcelable.from = __mmifw_feedback_event_cb_from;
+ handle->id = mmifw_DELEGATE_feedback_event_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_mmifw_feedback_event_cb_destroy(rpc_port_mmifw_feedback_event_cb_h h)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ free(h);
+
+ return 0;
+}
+
+int rpc_port_mmifw_feedback_event_cb_clone(rpc_port_mmifw_feedback_event_cb_h h, rpc_port_mmifw_feedback_event_cb_h *clone)
+{
+ rpc_port_mmifw_feedback_event_cb_h handle;
+
+ if (!h || !clone) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ handle = calloc(1, sizeof(struct mmifw_feedback_event_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_mmifw_feedback_event_cb_invoke(rpc_port_mmifw_feedback_event_cb_h h, rpc_port_feedback_event_h args)
+{
+ 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, mmifw_METHOD_Callback);
+ rpc_port_parcel_write(parcel, &h->parcelable, h);
+ rpc_port_parcel_write(parcel, &args->parcelable, args);
+
+ r = rpc_port_parcel_send(parcel, h->port);
+ rpc_port_parcel_destroy(parcel);
+ h->valid = false;
+
+ return r;
+}
+
+int rpc_port_mmifw_feedback_event_cb_set_port(rpc_port_mmifw_feedback_event_cb_h h, rpc_port_h port)
+{
+ if (!h || !port) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ h->port = port;
+
+ return 0;
+}
+
+static int __mmifw_method_register_cb(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_stub_mmifw_context_h context = data;
+ rpc_port_h callback_port;
+ int r;
+
+ r = rpc_port_stub_get_port(__mmifw_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+ if (r != 0) {
+ _E("Failed to get callback port");
+ return -1;
+ }
+
+ rpc_port_mmifw_focus_event_cb_h focus_cb = NULL;
+ rpc_port_mmifw_state_change_event_cb_h state_cb = NULL;
+ rpc_port_mmifw_wakeup_event_cb_h wakeup_cb = NULL;
+ rpc_port_mmifw_key_event_cb_h key_cb = NULL;
+ rpc_port_mmifw_gesture_event_cb_h gesture_cb = NULL;
+ rpc_port_mmifw_voice_event_cb_h voice_cb = NULL;
+ rpc_port_mmifw_action_event_cb_h action_cb = NULL;
+ rpc_port_mmifw_feedback_event_cb_h feedback_cb = NULL;
+
+ rpc_port_mmifw_focus_event_cb_create(&focus_cb);
+
+ if (!focus_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_focus_event_cb_set_port(focus_cb, callback_port);
+ rpc_port_parcel_read(parcel, &focus_cb->parcelable, focus_cb);
+ rpc_port_mmifw_state_change_event_cb_create(&state_cb);
+
+ if (!state_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_state_change_event_cb_set_port(state_cb, callback_port);
+ rpc_port_parcel_read(parcel, &state_cb->parcelable, state_cb);
+ rpc_port_mmifw_wakeup_event_cb_create(&wakeup_cb);
+
+ if (!wakeup_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_wakeup_event_cb_set_port(wakeup_cb, callback_port);
+ rpc_port_parcel_read(parcel, &wakeup_cb->parcelable, wakeup_cb);
+ rpc_port_mmifw_key_event_cb_create(&key_cb);
+
+ if (!key_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_key_event_cb_set_port(key_cb, callback_port);
+ rpc_port_parcel_read(parcel, &key_cb->parcelable, key_cb);
+ rpc_port_mmifw_gesture_event_cb_create(&gesture_cb);
+
+ if (!gesture_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_gesture_event_cb_set_port(gesture_cb, callback_port);
+ rpc_port_parcel_read(parcel, &gesture_cb->parcelable, gesture_cb);
+ rpc_port_mmifw_voice_event_cb_create(&voice_cb);
+
+ if (!voice_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_voice_event_cb_set_port(voice_cb, callback_port);
+ rpc_port_parcel_read(parcel, &voice_cb->parcelable, voice_cb);
+ rpc_port_mmifw_action_event_cb_create(&action_cb);
+
+ if (!action_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_action_event_cb_set_port(action_cb, callback_port);
+ rpc_port_parcel_read(parcel, &action_cb->parcelable, action_cb);
+ rpc_port_mmifw_feedback_event_cb_create(&feedback_cb);
+
+ if (!feedback_cb) {
+ _E("Failed to create handle");
+ return -1;
+ }
+
+ rpc_port_mmifw_feedback_event_cb_set_port(feedback_cb, callback_port);
+ rpc_port_parcel_read(parcel, &feedback_cb->parcelable, feedback_cb);
+
+ int ret = context->callback.register_cb(context, focus_cb, state_cb, wakeup_cb, key_cb, gesture_cb, voice_cb, action_cb, feedback_cb, context->user_data);
+ do {
+ rpc_port_parcel_h result;
+
+ rpc_port_parcel_create(&result);
+ rpc_port_parcel_write_int32(result, mmifw_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_mmifw_focus_event_cb_destroy(focus_cb);
+ rpc_port_mmifw_state_change_event_cb_destroy(state_cb);
+ rpc_port_mmifw_wakeup_event_cb_destroy(wakeup_cb);
+ rpc_port_mmifw_key_event_cb_destroy(key_cb);
+ rpc_port_mmifw_gesture_event_cb_destroy(gesture_cb);
+ rpc_port_mmifw_voice_event_cb_destroy(voice_cb);
+ rpc_port_mmifw_action_event_cb_destroy(action_cb);
+ rpc_port_mmifw_feedback_event_cb_destroy(feedback_cb);
+ return r;
+}
+
+static int __mmifw_method_deregister_cb(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_stub_mmifw_context_h context = data;
+ rpc_port_h callback_port;
+ int r;
+
+ r = rpc_port_stub_get_port(__mmifw_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+ if (r != 0) {
+ _E("Failed to get callback port");
+ return -1;
+ }
+
+ context->callback.deregister_cb(context, context->user_data);
+
+ return r;
+}
+
+static int __mmifw_method_get_focus(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_stub_mmifw_context_h context = data;
+ rpc_port_h callback_port;
+ int r;
+
+ r = rpc_port_stub_get_port(__mmifw_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+ if (r != 0) {
+ _E("Failed to get callback port");
+ return -1;
+ }
+
+ char *sender;
+
+ rpc_port_parcel_read_string(parcel, &sender);
+
+ context->callback.get_focus(context, sender, context->user_data);
+
+ free(sender);
+ return r;
+}
+
+static int __mmifw_method_set_state(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+ rpc_port_stub_mmifw_context_h context = data;
+ rpc_port_h callback_port;
+ int r;
+
+ r = rpc_port_stub_get_port(__mmifw_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+ if (r != 0) {
+ _E("Failed to get callback port");
+ return -1;
+ }
+
+ char *sender;
+ int state;
+
+ rpc_port_parcel_read_string(parcel, &sender);
+ rpc_port_parcel_read_int32(parcel, &state);
+
+ context->callback.set_state(context, sender, state, context->user_data);
+
+ free(sender);
+
+ return r;
+}
+
+static stub_method __mmifw_method_table[] = {
+ [mmifw_METHOD_register_cb] = __mmifw_method_register_cb,
+ [mmifw_METHOD_deregister_cb] = __mmifw_method_deregister_cb,
+ [mmifw_METHOD_get_focus] = __mmifw_method_get_focus,
+ [mmifw_METHOD_set_state] = __mmifw_method_set_state,
+};
+
+static void __mmifw_on_connected(const char *sender, const char *instance, void *data)
+{
+ rpc_port_stub_mmifw_context_h context;
+
+ _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+ context = __create_mmifw_context(sender, instance);
+ if (!context)
+ return;
+
+ if (context->callback.create)
+ context->callback.create(context, context->user_data);
+ __mmifw_contexts = g_list_append(__mmifw_contexts, context);
+}
+
+static void __mmifw_on_disconnected(const char *sender, const char *instance, void *data)
+{
+ rpc_port_stub_mmifw_context_h context;
+
+ _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+ context = __find_mmifw_context(instance);
+ if (!context)
+ return;
+
+ if (context->callback.terminate)
+ context->callback.terminate(context, context->user_data);
+ __mmifw_contexts = g_list_remove(__mmifw_contexts, context);
+ __destroy_mmifw_context(context);
+}
+
+static int __mmifw_on_received(const char *sender, const char *instance, rpc_port_h port, void *data)
+{
+ rpc_port_stub_mmifw_context_h context;
+ rpc_port_parcel_h parcel;
+ int cmd = -1;
+ int r;
+
+ _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+ context = __find_mmifw_context(instance);
+ if (!context) {
+ _E("Failed to find mmifw 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(__mmifw_method_table) / sizeof(__mmifw_method_table[0]))) {
+ if (__mmifw_method_table[cmd])
+ r = __mmifw_method_table[cmd](port, parcel, context);
+ } else {
+ _E("Unknown Command(%d)", cmd);
+ r = -1;
+ }
+
+ rpc_port_parcel_destroy(parcel);
+
+ return r;
+}
+
+static int __mmifw_add_privileges(void)
+{
+
+ return 0;
+}
+
+int rpc_port_stub_mmifw_register(rpc_port_stub_mmifw_callback_s *callback, void *user_data)
+{
+ int r;
+
+ if (__mmifw_stub) {
+ _W("Already exists");
+ return -1;
+ }
+
+ if (!callback) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ __mmifw_callback = *callback;
+ __mmifw_user_data = user_data;
+ r = rpc_port_stub_create(&__mmifw_stub, "mmifw");
+ if (r != 0) {
+ _E("Failed to create stub handle");
+ return r;
+ }
+
+ r = rpc_port_stub_add_received_event_cb(__mmifw_stub, __mmifw_on_received, NULL);
+ if (r != 0) {
+ _E("Failed to add received event callback");
+ rpc_port_stub_destroy(__mmifw_stub);
+ __mmifw_stub = NULL;
+ return r;
+ }
+
+ r = rpc_port_stub_add_connected_event_cb(__mmifw_stub, __mmifw_on_connected, NULL);
+ if (r != 0) {
+ _E("Failed to add connected event callback");
+ rpc_port_stub_destroy(__mmifw_stub);
+ __mmifw_stub = NULL;
+ return r;
+ }
+
+ r = rpc_port_stub_add_disconnected_event_cb(__mmifw_stub, __mmifw_on_disconnected, NULL);
+ if (r != 0) {
+ _E("Failed to add disconnected event callback");
+ rpc_port_stub_destroy(__mmifw_stub);
+ __mmifw_stub = NULL;
+ return r;
+ }
+
+ r = __mmifw_add_privileges();
+ if (r != 0) {
+ _E("Failed to add privileges");
+ rpc_port_stub_destroy(__mmifw_stub);
+ __mmifw_stub = NULL;
+ return r;
+ }
+
+ r = rpc_port_stub_listen(__mmifw_stub);
+ if (r != 0) {
+ _E("Failed to listen stub");
+ rpc_port_stub_destroy(__mmifw_stub);
+ __mmifw_stub = NULL;
+ return r;
+ }
+
+ return 0;
+}
+
+int rpc_port_stub_mmifw_unregister(void)
+{
+ int r;
+
+ if (!__mmifw_stub)
+ return -1;
+
+ if (__mmifw_contexts) {
+ g_list_free_full(__mmifw_contexts, __destroy_mmifw_context);
+ __mmifw_contexts = NULL;
+ }
+
+ r = rpc_port_stub_destroy(__mmifw_stub);
+ __mmifw_stub = NULL;
+
+ return r;
+}
+
+int rpc_port_stub_mmifw_get_client_number(unsigned int *n)
+{
+ if (!n) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (!__mmifw_stub) {
+ _E("mmifw Stub is not ready");
+ return -1;
+ }
+
+ *n = g_list_length(__mmifw_contexts);
+
+ return 0;
+}