[ACR-249] Change retval 70/47470/1
authorGukhwan Cho <gh78.cho@samsung.com>
Thu, 21 May 2015 02:04:23 +0000 (11:04 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Thu, 3 Sep 2015 13:58:11 +0000 (22:58 +0900)
Change-Id: If95877b213e4ab52ab5279a803ad52aabf1858b4
Signed-off-by: Gukhwan Cho <gh78.cho@samsung.com>
client/ctsvc_client_handle.c
client/ctsvc_client_ipc.c
client/ctsvc_client_service.c
client/ctsvc_client_service_helper.c
common/ctsvc_handle.c
include/contacts_service.h

index 2354765..5e3f18b 100644 (file)
@@ -57,6 +57,12 @@ int ctsvc_client_handle_get_p_with_id(unsigned int id, contacts_h *p_contact)
        contact = g_hash_table_lookup(_ctsvc_handle_table, key);
        ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
 
+       if (NULL == contact)
+       {
+               CTS_ERR("g_hash_table_lookup() return NULL");
+               return CONTACTS_ERROR_NO_DATA;
+       }
+
        *p_contact = contact;
        return CONTACTS_ERROR_NONE;
 }
index 23ca6f2..e42bed2 100644 (file)
@@ -171,6 +171,11 @@ int ctsvc_ipc_connect(contacts_h contact, unsigned int handle_id)
 
        if (NULL == ipc_data) {
                ipc_data = calloc(1, sizeof(struct ctsvc_ipc_s));
+               if (NULL == ipc_data)
+               {
+                       CTS_ERR("calloc() Fail");
+                       return CONTACTS_ERROR_OUT_OF_MEMORY;
+               }
                ret = _ctsvc_ipc_create(&(ipc_data->ipc));
                if (CONTACTS_ERROR_NONE != ret) {
                        _ctsvc_ipc_data_free(ipc_data);
index 3a2ef5f..fa5eee5 100644 (file)
@@ -35,9 +35,15 @@ 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);
+               if (CONTACTS_ERROR_NONE != ret)
+               {
+                       CTS_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) {
                CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
@@ -45,6 +51,9 @@ API int contacts_connect_with_flags(unsigned int flags)
        }
 
        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 +66,24 @@ 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);
+               if (CONTACTS_ERROR_NONE != ret)
+               {
+                       CTS_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) {
                CTS_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;
 }
@@ -78,12 +96,13 @@ API int contacts_disconnect(void)
        unsigned int id = ctsvc_client_get_pid();
 
        ret = ctsvc_client_handle_get_p_with_id(id, &contact);
-       RETV_IF(NULL == contact, CONTACTS_ERROR_NONE);
        RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
        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;
 
        if (0 == ((ctsvc_base_s *)contact)->connection_count) {
                ret = ctsvc_client_handle_remove(id, contact);
@@ -101,9 +120,15 @@ 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);
+               if (CONTACTS_ERROR_NONE != ret)
+               {
+                       CTS_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) {
                CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
@@ -112,6 +137,9 @@ API int contacts_connect_on_thread(void)
 
        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;
 }
@@ -124,12 +152,13 @@ API int contacts_disconnect_on_thread(void)
        unsigned int id = ctsvc_client_get_tid();
 
        ret = ctsvc_client_handle_get_p_with_id(id, &contact);
-       RETV_IF(NULL == contact, CONTACTS_ERROR_NONE);
        RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
        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;
 
        if (0 == ((ctsvc_base_s *)contact)->connection_count) {
                ret = ctsvc_client_handle_remove(id, contact);
index 62fdd44..529846b 100644 (file)
@@ -166,7 +166,7 @@ int ctsvc_client_disconnect(contacts_h contact)
        else {
                CTS_DBG("System : please call contacts_connect(), connection count is (%d)", _ctsvc_connection);
                ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               return CONTACTS_ERROR_DB;
        }
 
        _ctsvc_connection--;
@@ -234,7 +234,7 @@ int ctsvc_client_disconnect_on_thread(contacts_h contact)
        if (1 == base->connection_count) {
                ret = ctsvc_ipc_disconnect(contact, ctsvc_client_get_tid(), _ctsvc_connection_on_thread);
                if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_ipc_disconnect_on_thread() Fail(%d)", ret);
+                       CTS_ERR("ctsvc_ipc_disconnect() Fail(%d)", ret);
                        ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
                        return ret;
                }
@@ -256,7 +256,7 @@ int ctsvc_client_disconnect_on_thread(contacts_h contact)
        else {
                CTS_DBG("System : please call contacts_connect_on_thread(), connection count is (%d)", _ctsvc_connection_on_thread);
                ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               return CONTACTS_ERROR_DB;
        }
 
        _ctsvc_connection_on_thread--;
index a10a420..75d7d51 100644 (file)
@@ -24,6 +24,11 @@ int ctsvc_handle_create(contacts_h *contact)
 {
        RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
        ctsvc_base_s *base = calloc(1, sizeof(ctsvc_base_s));
+       if (NULL == base)
+       {
+               CTS_ERR("calloc() Fail");
+               return CONTACTS_ERROR_OUT_OF_MEMORY;
+       }
        *contact = (contacts_h)base;
        return CONTACTS_ERROR_NONE;
 }
index db8e2d7..42b2891 100644 (file)
@@ -57,11 +57,10 @@ extern "C"
  *          otherwise a negative error value
  *
  * @retval  #CONTACTS_ERROR_NONE                Successful
- * @retval  #CONTACTS_ERROR_DB                  Database operation failure
- * @retval  #CONTACTS_ERROR_IPC_NOT_AVALIABLE   IPC server is not available
  * @retval  #CONTACTS_ERROR_IPC                 IPC error
+ * @retval  #CONTACTS_ERROR_OUT_OF_MEMORY       Out of memory
  * @retval  #CONTACTS_ERROR_SYSTEM              System error
- * @retval  #CONTACTS_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CONTACTS_ERROR_INTERNAL            Internal error
  *
  * @see contacts_disconnect()
  */
@@ -78,9 +77,10 @@ int contacts_connect(void);
  *          otherwise a negative error value
  *
  * @retval  #CONTACTS_ERROR_NONE                  Successful
- * @retval  #CONTACTS_ERROR_INVALID_PARAMETER     Invalid parameter
- * @retval  #CONTACTS_ERROR_DB                    Database operation failure
  * @retval  #CONTACTS_ERROR_IPC                   IPC error
+ * @retval  #CONTACTS_ERROR_OUT_OF_MEMORY         Out of memory
+ * @retval  #CONTACTS_ERROR_SYSTEM                System error
+ * @retval  #CONTACTS_ERROR_DB                    Database operation failure
  *
  * @see contacts_connect()
  */
@@ -99,10 +99,8 @@ int contacts_disconnect(void);
  *          otherwise a negative error value
  *
  * @retval  #CONTACTS_ERROR_NONE                Successful
- * @retval  #CONTACTS_ERROR_OUT_OF_MEMORY       Out of memory
- * @retval  #CONTACTS_ERROR_DB                  Database operation failure
- * @retval  #CONTACTS_ERROR_IPC_NOT_AVALIABLE   IPC server is not available
  * @retval  #CONTACTS_ERROR_IPC                 IPC error
+ * @retval  #CONTACTS_ERROR_OUT_OF_MEMORY       Out of memory
  * @retval  #CONTACTS_ERROR_SYSTEM              System error
  * @retval  #CONTACTS_ERROR_INTERNAL            Internal error
  * @retval  #CONTACTS_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
@@ -116,13 +114,16 @@ int contacts_connect_on_thread(void);
  *
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.4 @endif
  *
+ * @remarks If there is no opened connection, this function returns #CONTACTS_ERROR_DB.
+ *
  * @return  @c 0 on success,
  *          otherwise a negative error value
  *
  * @retval  #CONTACTS_ERROR_NONE                  Successful
- * @retval  #CONTACTS_ERROR_INVALID_PARAMETER     Invalid parameter
- * @retval  #CONTACTS_ERROR_DB                    Database operation failure
  * @retval  #CONTACTS_ERROR_IPC                   IPC error
+ * @retval  #CONTACTS_ERROR_OUT_OF_MEMORY         Out of memory
+ * @retval  #CONTACTS_ERROR_SYSTEM                System error
+ * @retval  #CONTACTS_ERROR_DB                    Database operation failure
  *
  * @see contacts_connect_on_thread()
  */
@@ -163,11 +164,10 @@ int contacts_disconnect_on_thread(void);
  *          otherwise a negative error value
  *
  * @retval  #CONTACTS_ERROR_NONE                Successful
- * @retval  #CONTACTS_ERROR_DB                  Database operation failure
- * @retval  #CONTACTS_ERROR_IPC_NOT_AVALIABLE   IPC server is not available
  * @retval  #CONTACTS_ERROR_IPC                 IPC error
+ * @retval  #CONTACTS_ERROR_OUT_OF_MEMORY       Out of memory
  * @retval  #CONTACTS_ERROR_SYSTEM              System error
- * @retval  #CONTACTS_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CONTACTS_ERROR_INTERNAL            Internal error
  *
  * @see  contacts_disconnect()
  */