change ipc connection as sync and add registering in result cb
[platform/core/uifw/mmi-framework.git] / src / mmi-client.c
index eb047e6..6c4088a 100644 (file)
@@ -54,6 +54,7 @@ int mmi_client_destroy(void)
        }
 
        mmi_ipc_deinitialize();
+       mmi_h->rpc_h = NULL;
 
        GList *iter = NULL;
        mmi_result_cb_s *data = NULL;
@@ -81,6 +82,24 @@ int mmi_client_destroy(void)
        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);
@@ -90,6 +109,11 @@ int mmi_client_set_result_cb(int input_event_type, mmi_result_cb callback, void*
                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");
@@ -100,6 +124,13 @@ int mmi_client_set_result_cb(int input_event_type, mmi_result_cb callback, void*
        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;
 }