add APIs for getting SIM init status and importing SIM contacts by sim slot no
[platform/core/pim/contacts-service.git] / client / ctsvc_client_service.c
index 2336248..ab2ad21 100644 (file)
@@ -3,9 +3,6 @@
  *
  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: Dohyung Jin <dh.jin@samsung.com>
- *                 Jongwon Lee <gogosing.lee@samsung.com>
- *                 Donghee Ye <donghee.ye@samsung.com>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +20,7 @@
 #include "contacts.h"
 #include "ctsvc_internal.h"
 #include "ctsvc_client_ipc.h"
+#include "ctsvc_client_utils.h"
 #include "ctsvc_client_handle.h"
 #include "ctsvc_client_service_helper.h"
 
@@ -31,18 +29,26 @@ API int contacts_connect_with_flags(unsigned int flags)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_pid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        if (CONTACTS_ERROR_NO_DATA == ret) {
-               ret = ctsvc_client_handle_create(&contact);
-               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
-       }
-       else if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               ret = ctsvc_client_handle_create(id, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       ERR("ctsvc_client_handle_create() Fail(%d)", ret);
+                       if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
+                               return CONTACTS_ERROR_INTERNAL;
+                       return ret;
+               }
+       } else if (CONTACTS_ERROR_NONE != ret) {
+               ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
                return ret;
        }
 
        ret = ctsvc_client_connect_with_flags(contact, flags);
+       if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
+                       || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
+               return CONTACTS_ERROR_IPC;
 
        return ret;
 }
@@ -52,17 +58,25 @@ API int contacts_connect(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_pid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        if (CONTACTS_ERROR_NO_DATA == ret) {
-               ret = ctsvc_client_handle_create(&contact);
-               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
-       }
-       else if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               ret = ctsvc_client_handle_create(id, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       ERR("ctsvc_client_handle_create() Fail(%d)", ret);
+                       if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
+                               return CONTACTS_ERROR_INTERNAL;
+                       return ret;
+               }
+       } else if (CONTACTS_ERROR_NONE != ret) {
+               ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
                return ret;
        }
        ret = ctsvc_client_connect(contact);
+       if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
+                       || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
+               return CONTACTS_ERROR_IPC;
 
        return ret;
 }
@@ -72,13 +86,16 @@ API int contacts_disconnect(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_pid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
 
        ret = ctsvc_client_disconnect(contact);
        WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
+       if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
+               ret = CONTACTS_ERROR_IPC;
 
        return ret;
 }
@@ -88,19 +105,27 @@ API int contacts_connect_on_thread(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_tid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        if (CONTACTS_ERROR_NO_DATA == ret) {
-               ret = ctsvc_client_handle_create(&contact);
-               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
-       }
-       else if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               ret = ctsvc_client_handle_create(id, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       ERR("ctsvc_client_handle_create() Fail(%d)", ret);
+                       if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
+                               return CONTACTS_ERROR_INTERNAL;
+                       return ret;
+               }
+       } else if (CONTACTS_ERROR_NONE != ret) {
+               ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
                return ret;
        }
 
        ret = ctsvc_client_connect_on_thread(contact);
        WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
+       if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
+                       || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
+               return CONTACTS_ERROR_IPC;
 
        return ret;
 }
@@ -110,13 +135,16 @@ API int contacts_disconnect_on_thread(void)
        CTS_FN_CALL;
        int ret;
        contacts_h contact = NULL;
+       unsigned int id = ctsvc_client_get_tid();
 
-       ret = ctsvc_client_handle_get_current_p(&contact);
+       ret = ctsvc_client_handle_get_p_with_id(id, &contact);
        RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
 
        ret = ctsvc_client_disconnect_on_thread(contact);
        WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
+       if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
+               ret = CONTACTS_ERROR_IPC;
 
        return ret;
 }