Changed IPC connection as sync.
By sync connection, it can register input event and it's result_cb to mmi service
when mmi_set_result_cb is called.
Change-Id: I987e0cbb891907c12cbbe8219fd5467676d3e31f
}
mmi_ipc_deinitialize();
+ mmi_h->rpc_h = NULL;
GList *iter = NULL;
mmi_result_cb_s *data = NULL;
return MMI_ERROR_NONE;
}
+const char* mmi_client_convert_error_code(int err)
+{
+ switch (err) {
+ case MMI_ERROR_NONE: return "MMI_ERROR_NONE";
+ case MMI_ERROR_OUT_OF_MEMORY: return "MMI_ERROR_OUT_OF_MEMORY";
+ case MMI_ERROR_IO_ERROR: return "MMI_ERROR_IO_ERROR";
+ case MMI_ERROR_INVALID_PARAMETER: return "MMI_ERROR_INVALID_PARAMETER";
+ case MMI_ERROR_OUT_OF_NETWORK: return "MMI_ERROR_OUT_OF_NETWORK";
+ case MMI_ERROR_TIMED_OUT: return "MMI_ERROR_TIMED_OUT";
+ case MMI_ERROR_PERMISSION_DENIED: return "MMI_ERROR_PERMISSION_DENIED";
+ case MMI_ERROR_NOT_SUPPORTED: return "MMI_ERROR_NOT_SUPPORTED";
+ case MMI_ERROR_OPERATION_FAILED: return "MMI_ERROR_OPERATION_FAILED";
+ default:
+ return "Invalid error code";
+ }
+ return NULL;
+}
+
int mmi_client_set_result_cb(int input_event_type, mmi_result_cb callback, void* user_data)
{
LOGI("Set result cb about input event type(%d) to client", input_event_type);
return MMI_ERROR_INVALID_PARAMETER;
}
+ if (mmi_h == NULL) {
+ LOGE("Fail to get client");
+ return MMI_ERROR_INVALID_PARAMETER;
+ }
+
mmi_result_cb_s* input_result_callback = (mmi_result_cb_s*)calloc(1, sizeof(mmi_result_cb_s));
if (input_result_callback == NULL) {
LOGE("[ERROR] Fail to allocate memory");
input_result_callback->result_callback = callback;
mmi_h->result_cb_list = g_list_append(mmi_h->result_cb_list, input_result_callback);
+ int ret = mmi_ipc_register_input_event_result_cb(input_event_type, callback);
+ if (ret != MMI_ERROR_NONE) {
+ LOGE("Fail to register input event's result callback(%d), reason(%s)", ret, mmi_client_convert_error_code(ret));
+ callback(input_event_type, mmi_client_convert_error_code(ret), NULL);
+ return ret;
+ }
+
return MMI_ERROR_NONE;
}
#include "mmi-ipc.h"
#include "mmi-dbg.h"
+#include "mmi-client.h"
#include <tzplatform_config.h>
#include <unistd.h>
goto err;
}
- r = rpc_port_proxy_mmi_connect(_rpc_h);
+ r = rpc_port_proxy_mmi_connect_sync(_rpc_h);
if (r != RPC_PORT_ERROR_NONE)
{
LOGE("Failed to connect to %s ! (error:%d)\n", _stub_appid, r);
goto err;
}
+ LOGI("connect mmi ipc");
+
return 0;
err:
if (_rpc_h)
if (!_rpc_h)
return;
+ LOGI("disconnect mmi ipc");
+
rpc_port_proxy_mmi_destroy(_rpc_h);
rpc_port_deregister_proc_info();
_rpc_h = NULL;
_connected = 0;
}
+
+int mmi_ipc_register_input_event_result_cb(int input_event_type, rpc_port_proxy_mmi_result_cb_cb callback)
+{
+ LOGI("Register input event(%d) result cb to MMI Service", input_event_type);
+
+ if (callback == NULL) {
+ LOGE("Parameter callback is NULL");
+ return MMI_ERROR_INVALID_PARAMETER;
+ }
+
+ mmi_handle client = mmi_client_get();
+ if (client == NULL) {
+ LOGE("Fail to get client");
+ return MMI_ERROR_INVALID_PARAMETER;
+ }
+
+ rpc_port_proxy_mmi_h rpc_h = client->rpc_h;
+ if (rpc_h == NULL) {
+ LOGE("Fail to get tidl rpc info");
+ return MMI_ERROR_INVALID_PARAMETER;
+ }
+
+ rpc_port_proxy_mmi_result_cb_h result_cb_h;
+ int ret = rpc_port_proxy_mmi_result_cb_create(&result_cb_h);
+ if (ret != RPC_PORT_ERROR_NONE) {
+ LOGE("Failed to create result callback handle (error:%d)\n", ret);
+ return MMI_ERROR_OPERATION_FAILED;
+ }
+ rpc_port_proxy_mmi_result_cb_set_callback(result_cb_h, callback, NULL);
+ rpc_port_proxy_mmi_result_cb_set_once(result_cb_h, false);
+ if (result_cb_h == NULL) {
+ LOGE("Failed to create event callbacks");
+ return MMI_ERROR_OPERATION_FAILED;
+ }
+
+ ret = rpc_port_proxy_mmi_invoke_register_input_event(rpc_h, input_event_type, result_cb_h);
+ if (ret != RPC_PORT_ERROR_NONE) {
+ LOGE("Failed to register event callbacks(%d)\n", ret);
+ return MMI_ERROR_OPERATION_FAILED;
+ }
+
+ return MMI_ERROR_NONE;
+}
int mmi_ipc_initialize(void);
void mmi_ipc_deinitialize(void);
+int mmi_ipc_register_input_event_result_cb(int input_event_type, rpc_port_proxy_mmi_result_cb_cb callback);
rpc_port_proxy_mmi_h mmi_ipc_get_rpc_h(void);
int mmi_ipc_get_uid(void);
{
LOGI("Set result cb about input event type(%d)", input_event_type);
- int ret;
-
- ret = mmi_client_set_result_cb(input_event_type, callback, user_data);
+ int ret = mmi_client_set_result_cb(input_event_type, callback, user_data);
if(ret != MMI_ERROR_NONE) {
LOGE("Fail to set result cb(%d)", ret);
return ret;
MMI_RESULT_SUCCESS
} mmi_result_e;
+#define TIZEN_ERROR_MMI -0x030F0000
+
typedef enum {
MMI_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
MMI_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
MMI_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */
MMI_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
MMI_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< MMI NOT supported */
+ MMI_ERROR_OPERATION_FAILED = TIZEN_ERROR_MMI | 0x01, /**< Operation failed */
} mmi_error_e;
typedef void (*mmi_result_cb)(int input_event_type, const char *result_out, void *user_data);
mmi_client_destroy();
}
+
+TEST_F(MMIMainTest, MMISetResultCbFailNoClient)
+{
+ int res = mmi_initialize();
+ mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
+ EXPECT_EQ(res, MMI_ERROR_NONE);
+
+ mmi_client_destroy();
+
+ res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL);
+ EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER);
+
+ mmi_deinitialize();
+}
+
+TEST_F(MMIMainTest, MMISetResultCbFailNoRpcHandle)
+{
+ int res = mmi_initialize();
+ mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
+ EXPECT_EQ(res, MMI_ERROR_NONE);
+
+ mmi_ipc_deinitialize();
+
+ mmi_handle mmi_client = mmi_client_get();
+ mmi_client->rpc_h = NULL;
+
+ res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL);
+ EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER);
+
+ mmi_deinitialize();
+}