Change return type of contacts_sim_import_progress_cb() 91/87191/2 accepted/tizen/common/20160912.180959 accepted/tizen/ivi/20160912.093353 accepted/tizen/mobile/20160912.093315 accepted/tizen/wearable/20160912.093336 submit/tizen/20160912.021532
authorJongkyu Koo <jk.koo@samsung.com>
Wed, 7 Sep 2016 01:39:41 +0000 (10:39 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Thu, 8 Sep 2016 03:52:30 +0000 (20:52 -0700)
Change-Id: I9ae6812d0fab4eae668116f27865ce14f9d7682a
Signed-off-by: Jongkyu Koo <jk.koo@samsung.com>
common/ctsvc_socket.c
common/ctsvc_socket.h
include/mobile/contacts_sim.h
include/wearable/contacts_sim.h
packaging/contacts-service.spec
server/ctsvc_server_sim.c
server/ctsvc_server_sim.h
server/ctsvc_server_socket.c

index d837ba9..c1c9039 100644 (file)
@@ -134,6 +134,21 @@ static int __ctsvc_socket_handle_return(int fd, ctsvc_socket_msg_s *msg)
        return CONTACTS_ERROR_NONE;
 }
 
+static int __ctsvc_cancel_sim_import(int fd)
+{
+       int ret;
+       ctsvc_socket_msg_s msg = {0};
+
+       RETVM_IF(-1 == fd, CONTACTS_ERROR_IPC, "socket is not connected");
+
+       msg.type = CTSVC_SOCKET_MSG_TYPE_CANCEL_IMPORT_SIM;
+
+       ret = __ctsvc_safe_write(fd, (char *)&msg, sizeof(msg));
+       RETVM_IF(-1 == ret, CONTACTS_ERROR_IPC, "__ctsvc_safe_write() Fail(errno = %d)", errno);
+
+       return CONTACTS_ERROR_NONE;
+}
+
 static int __ctsvc_client_socket_response_handler(int fd, ctsvc_socket_msg_s *msg, contacts_sim_import_progress_cb callback, void *user_data)
 {
        CTS_FN_CALL;
@@ -151,10 +166,12 @@ static int __ctsvc_client_socket_response_handler(int fd, ctsvc_socket_msg_s *ms
 
                case CTSVC_SOCKET_MSG_TYPE_REQUEST_INVOKE_CB:
                        DBG("total[%d], index[%d]", msg->val, msg->data);
-                       if (callback)
-                               callback(msg->val, msg->data, user_data);
-                       else
+                       if (callback) {
+                               if (false == callback(msg->val, msg->data, user_data))
+                                       __ctsvc_cancel_sim_import(fd);
+                       } else {
                                WARN("No callback");
+                       }
                        break;
 
                /* LCOV_EXCL_START */
index a4b4fd8..7253a69 100644 (file)
@@ -32,6 +32,7 @@ enum {
        CTSVC_SOCKET_MSG_TYPE_REQUEST_IMPORT_SIM,
        CTSVC_SOCKET_MSG_TYPE_REQUEST_SIM_INIT_COMPLETE,
        CTSVC_SOCKET_MSG_TYPE_REQUEST_INVOKE_CB,
+       CTSVC_SOCKET_MSG_TYPE_CANCEL_IMPORT_SIM,
 };
 
 #define CTSVC_SOCKET_MSG_REQUEST_MAX_ATTACH 5
index becdddf..0bbbaf2 100644 (file)
@@ -117,11 +117,14 @@ int contacts_sim_get_initialization_status(bool *completed) TIZEN_DEPRECATED_API
  * @param[in]   imported_cnt      The number of already imported contacts
  * @param[in]   user_data         The user data passed from the callback registration function
  *
+ * @return  @c true to continue with the import of contacts
+ *          otherwise @c false to stop the import of contacts
+ *
  * @pre contacts_sim_import_all_contacts_by_sim_slot_no() will invoke this callback.
  *
  * @see contacts_sim_import_all_contacts_by_sim_slot_no()
  */
-typedef void (*contacts_sim_import_progress_cb)(int total, int imported_cnt, void *user_data);
+typedef bool (*contacts_sim_import_progress_cb)(int total, int imported_cnt, void *user_data);
 
 /**
  * @brief Imports all contacts from SIM of the given SIM slot number to the Contacts Database.
index 0a5fab9..143fa05 100644 (file)
@@ -62,11 +62,14 @@ extern "C"
  * @param[in]   imported_cnt      The number of already imported contacts
  * @param[in]   user_data         The user data passed from the callback registration function
  *
+ * @return  @c true to continue with the import of contacts
+ *          otherwise @c false to stop the import of contacts
+ *
  * @pre contacts_sim_import_all_contacts_by_sim_slot_no() will invoke this callback.
  *
  * @see contacts_sim_import_all_contacts_by_sim_slot_no()
  */
-typedef void (*contacts_sim_import_progress_cb)(int total, int imported_cnt, void *user_data);
+typedef bool (*contacts_sim_import_progress_cb)(int total, int imported_cnt, void *user_data);
 
 /**
  * @brief Imports all contacts from SIM of the given SIM slot number to the Contacts Database.
index e795c6d..3d806e6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       contacts-service
 Summary:    Contacts Service
-Version:    0.13.58
+Version:    0.13.59
 Release:    0
 Group:      Social & Content/Service
 License:    Apache-2.0
index 13dbeb2..2e71d5e 100644 (file)
@@ -102,6 +102,7 @@ typedef struct {
 static GSList *__ctsvc_sim_info = NULL;
 static void *greturn_data = NULL;
 static bool __ctsvc_tapi_cb = false;
+static bool sim_import_cancel = false;
 
 static TapiHandle* __ctsvc_server_sim_get_tapi_handle(ctsvc_sim_info_s *info)
 {
@@ -395,6 +396,15 @@ static void __ctsvc_server_sim_import_contact_cb(TapiHandle *handle, int result,
        sim_contact_s *record = NULL;
        ctsvc_sim_info_s *info;
 
+       if (sim_import_cancel) {
+               DBG("SIM contacts import is canceled");
+               ret = ctsvc_server_socket_return(__ctsvc_server_sim_get_return_data(), CONTACTS_ERROR_NONE, 0, NULL);
+               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_server_socket_return() Fail(%d)", ret);
+               __ctsvc_server_sim_set_return_data(NULL);
+               sim_import_cancel = false;
+               return;
+       }
+
        if (NULL == sim_info) {
                /* LCOV_EXCL_START */
                ERR("sim_info is NULL, result = %d", access_rt);
@@ -548,6 +558,11 @@ int ctsvc_server_sim_import_contact(void *data, int sim_slot_no)
        return CONTACTS_ERROR_NONE;
 }
 
+void ctsvc_server_sim_cancel_import()
+{
+       sim_import_cancel = true;
+}
+
 int ctsvc_server_socket_get_sim_init_status(void *data, int sim_slot_no)
 {
        CTS_FN_CALL;
index 9bfe604..7adca01 100644 (file)
@@ -40,6 +40,7 @@ int ctsvc_server_sim_init(void);
 int ctsvc_server_sim_final(void);
 
 int ctsvc_server_sim_import_contact(void *data, int sim_slot_no);
+void ctsvc_server_sim_cancel_import();
 int ctsvc_server_sim_get_info_id_by_sim_slot_no(int sim_slot_no);
 int ctsvc_server_sim_get_sim_slot_no_by_info_id(int sim_info_id);
 int ctsvc_server_socket_get_sim_init_status(void *data, int sim_slot_no);
index 8429f8c..58adbd5 100644 (file)
@@ -378,6 +378,10 @@ static gboolean __ctsvc_server_socket_request_handler(GIOChannel *src, GIOCondit
                }
                __ctsvc_server_socket_get_sim_init_status(src, msg.attach_sizes[0]);
                break;
+       case CTSVC_SOCKET_MSG_TYPE_CANCEL_IMPORT_SIM:
+               ctsvc_server_sim_cancel_import();
+               break;
+
        default:
                /* LCOV_EXCL_START */
                ERR("Unknown request type(%d)", msg.type);