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 ea2675a..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.
@@ -35,16 +32,23 @@ API int contacts_connect_with_flags(unsigned int flags)
        unsigned int id = ctsvc_client_get_pid();
 
        ret = ctsvc_client_handle_get_p_with_id(id, &contact);
-       if (NULL == contact) {
+       if (CONTACTS_ERROR_NO_DATA == ret) {
                ret = ctsvc_client_handle_create(id, &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_p_with_id() Fail(%d)", ret);
+               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;
 }
@@ -57,15 +61,22 @@ API int contacts_connect(void)
        unsigned int id = ctsvc_client_get_pid();
 
        ret = ctsvc_client_handle_get_p_with_id(id, &contact);
-       if (NULL == contact) {
+       if (CONTACTS_ERROR_NO_DATA == ret) {
                ret = ctsvc_client_handle_create(id, &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_p_with_id() Fail(%d)", ret);
+               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;
 }
@@ -83,11 +94,8 @@ API int contacts_disconnect(void)
 
        ret = ctsvc_client_disconnect(contact);
        WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
-
-       if (0 == ((ctsvc_base_s *)contact)->connection_count) {
-               ret = ctsvc_client_handle_remove(id, contact);
-               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);
-       }
+       if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
+               ret = CONTACTS_ERROR_IPC;
 
        return ret;
 }
@@ -100,17 +108,24 @@ API int contacts_connect_on_thread(void)
        unsigned int id = ctsvc_client_get_tid();
 
        ret = ctsvc_client_handle_get_p_with_id(id, &contact);
-       if (NULL == contact) {
+       if (CONTACTS_ERROR_NO_DATA == ret) {
                ret = ctsvc_client_handle_create(id, &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_p_with_id() Fail(%d)", ret);
+               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;
 }
@@ -128,11 +143,8 @@ API int contacts_disconnect_on_thread(void)
 
        ret = ctsvc_client_disconnect_on_thread(contact);
        WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
-
-       if (0 == ((ctsvc_base_s *)contact)->connection_count) {
-               ret = ctsvc_client_handle_remove(id, contact);
-               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);
-       }
+       if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
+               ret = CONTACTS_ERROR_IPC;
 
        return ret;
 }