Add APIs to support update service functionality accepted/tizen/unified/20191014.005011 submit/tizen/20191011.095843
authorAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 11 Oct 2019 06:24:57 +0000 (15:24 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 11 Oct 2019 07:16:24 +0000 (16:16 +0900)
Update service functionality is required to update service information
like presence threshold and absence threshold.

Change-Id: Ic7e8ab3c4efeef1c33d491bbc848a8e67e0de360
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/ua-api.h
include/ua-internal.h
packaging/ua-manager.spec
ua-api/src/ua-api.c
ua-daemon/include/ua-manager-core.h
ua-daemon/include/ua-manager-database.h
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-request-handler.c
ua-daemon/src/ua-manager-service-db.c

index c40a97e..8cbce1b 100644 (file)
@@ -1019,6 +1019,23 @@ int _uam_get_default_service(uam_service_info_s *service);
 int _uam_register_service(uam_service_info_s *service);
 
 /**
+ * @brief Updates service info.
+ * @since_tizen 5.5
+ *
+ * @param[in] service Service information.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UAM_ERROR_NONE Successful
+ * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters
+ * @retval #UAM_ERROR_INTERNAL Internal error
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+int _uam_update_service(uam_service_info_s *service);
+
+/**
  * @brief Unregisters service info.
  * @since_tizen 5.5
  *
index 1d985f2..c70a401 100644 (file)
@@ -75,6 +75,7 @@ extern "C" {
        REQUEST(UAM_REQUEST_RESET_DB) \
        REQUEST(UAM_REQUEST_GET_DEFAULT_SERVICE) \
        REQUEST(UAM_REQUEST_REGISTER_SERVICE) \
+       REQUEST(UAM_REQUEST_UPDATE_SERVICE) \
        REQUEST(UAM_REQUEST_UNREGISTER_SERVICE) \
        REQUEST(UAM_REQUEST_GET_SERVICE_DEVICES) \
        REQUEST(UAM_REQUEST_GET_SERVICE_USERS) \
index 6c193e2..7c0ea16 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.11.4
+Version:    0.11.5
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 74d7c8d..f66fdf0 100644 (file)
@@ -1185,6 +1185,27 @@ UAM_EXPORT_API int _uam_register_service(uam_service_info_s *service)
        return ret;
 }
 
+UAM_EXPORT_API int _uam_update_service(uam_service_info_s *service)
+{
+       FUNC_ENTRY;
+       int ret;
+
+       UAM_VALIDATE_INPUT_PARAMETER(service);
+       UAM_VALIDATE_INPUT_PARAMETER(service->name);
+
+       UAM_INIT_PARAMS();
+       UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, service, sizeof(uam_service_info_s));
+       ret = _uam_sync_request(UAM_REQUEST_UPDATE_SERVICE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       FUNC_EXIT;
+       return ret;
+}
+
 UAM_EXPORT_API int _uam_unregister_service(uam_service_info_s *service)
 {
        FUNC_ENTRY;
index 93b7bcb..faa3b4b 100644 (file)
@@ -201,6 +201,8 @@ int _uam_core_get_default_service(uam_service_info_s *service_info);
 
 int _uam_core_register_service(uam_service_info_s *svc);
 
+int _uam_core_update_service(uam_service_info_s *svc);
+
 int _uam_core_unregister_service(const char *svc_name);
 
 int _uam_core_get_service_devices(const char *svc_name, int *count, uam_device_info_s **device_list);
index 997c61a..6abdbbd 100644 (file)
@@ -163,6 +163,7 @@ int _uam_db_insert_service_info(
 
 /* update */
 int _uam_db_update_service_cycle(const char *service_name, int cycle);
+int _uam_db_update_service_info(uam_db_service_info_t *service);
 
 
 /* DEVICE_SERVICE QUERIES */
index 1b2c68c..27ef4e5 100644 (file)
@@ -3372,6 +3372,32 @@ int _uam_core_register_service(uam_service_info_s *svc)
        return UAM_ERROR_NONE;
 }
 
+int _uam_core_update_service(uam_service_info_s *svc)
+{
+       FUNC_ENTRY;
+       GSList *l;
+       uam_db_service_info_t *service;
+
+       retv_if(NULL == svc->name, UAM_ERROR_INVALID_PARAMETER);
+
+       /* Retrieve service from list */
+       l = g_slist_find_custom(services, svc->name, __compare_svc_name);
+       retv_if((NULL == l) || (l->data == NULL), UAM_ERROR_NOT_REGISTERED);
+
+       service = l->data;
+       service->presence_threshold = svc->presence_threshold;
+       service->absence_threshold = svc->absence_threshold;
+
+       /* Update service to database */
+       if (UAM_ERROR_NONE != _uam_db_update_service_info(service)) {
+               UAM_ERR("_uam_db_update_service_info failed");
+               return UAM_ERROR_DB_FAILED;
+       }
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
+
 int _uam_core_get_default_service(uam_service_info_s *service_info)
 {
        FUNC_ENTRY;
@@ -3632,6 +3658,8 @@ int _uam_core_get_services(int *count, uam_service_info_s **service_list)
 
                g_strlcpy((*service_list)[*count].name,
                                db_info->name, UAM_SERVICE_MAX_STRING_LEN);
+               (*service_list)[*count].presence_threshold = db_info->presence_threshold;
+               (*service_list)[*count].absence_threshold = db_info->absence_threshold;
                *count += 1;
        }
 
index 7d55469..cef31d7 100644 (file)
@@ -583,6 +583,18 @@ static int __uam_manager_sync_request_handler(
                break;
 
        }
+       case UAM_REQUEST_UPDATE_SERVICE: {
+               uam_service_info_s svc;
+
+               __uam_manager_copy_params(in_param1,
+                               &svc, sizeof(uam_service_info_s));
+               UAM_DBG("Name: [%s] Threshold presence: [%d] absence: [%d]",
+                               svc.name, svc.presence_threshold, svc.absence_threshold);
+
+               result = _uam_core_update_service(&svc);
+               break;
+
+       }
        case UAM_REQUEST_UNREGISTER_SERVICE: {
                const char *svc_name;
 
@@ -822,6 +834,7 @@ static gboolean __uam_manager_is_sync_function(int function)
        case UAM_REQUEST_RESET_DB:
        case UAM_REQUEST_GET_DEFAULT_SERVICE:
        case UAM_REQUEST_REGISTER_SERVICE:
+       case UAM_REQUEST_UPDATE_SERVICE:
        case UAM_REQUEST_UNREGISTER_SERVICE:
        case UAM_REQUEST_GET_SERVICE_DEVICES:
        case UAM_REQUEST_GET_SERVICE_USERS:
index 94f6cba..8539053 100644 (file)
@@ -37,6 +37,9 @@
 
 #define UPDATE_CYCLE "UPDATE services SET cycle = ? WHERE service_name = ?"
 
+#define UPDATE_SERVICE "UPDATE services SET (presence_threshold, absence_threshold) " \
+       "= (?, ?) WHERE service_name = ?"
+
 #define DELETE_ALL_SERVICES "delete from services"
 
 #define DELETE_SERVICE_INFO "delete from services WHERE service_name = ?"
@@ -51,6 +54,7 @@ static sqlite3_stmt *select_service;
 
 /* UPDATE statements */
 static sqlite3_stmt *update_cycle;
+static sqlite3_stmt *update_service_info;
 
 /* INSERT statements */
 static sqlite3_stmt *insert_service_info;
@@ -91,6 +95,7 @@ static void __uam_service_finalize_update(void)
        FUNC_ENTRY;
 
        FINALIZE(update_cycle);
+       FINALIZE(update_service_info);
 
        FUNC_EXIT;
 }
@@ -150,6 +155,8 @@ static int __uam_service_prepare_update(sqlite3 *db)
 
        PREPARE_QUERY(rc, db, update_cycle,
                UPDATE_CYCLE, __uam_service_finalize_update);
+       PREPARE_QUERY(rc, db, update_service_info,
+               UPDATE_SERVICE, __uam_service_finalize_update);
 
        initialized = 1;
        FUNC_EXIT;
@@ -272,6 +279,41 @@ handle_error:
        return error_code;
 }
 
+int _uam_db_update_service_info(uam_db_service_info_t *svc)
+{
+       FUNC_ENTRY;
+       int error_code = UAM_ERROR_NONE;
+       sqlite3_stmt *stmt = update_service_info;
+       int sql_ret = SQLITE_OK;
+
+       retv_if(NULL == svc->name, UAM_ERROR_INVALID_PARAMETER);
+
+       UAM_INFO("%s-%d-%d-%d", svc->name, svc->cycle, svc->presence_threshold,
+                               svc->absence_threshold);
+
+       DB_ACTION(sqlite3_bind_int(stmt, 1, svc->presence_threshold),
+               error_code, handle_error);
+       DB_ACTION(sqlite3_bind_int(stmt, 2, svc->absence_threshold),
+               error_code, handle_error);
+       DB_ACTION(sqlite3_bind_text(stmt, 3, svc->name, -1, SQLITE_TRANSIENT),
+               error_code, handle_error);
+
+       sql_ret = sqlite3_step(stmt);
+       if (sql_ret != SQLITE_DONE) {
+               UAM_ERR("Failed to update service info [%d:%s]",
+                       sql_ret, sqlite3_errmsg(database_handle));
+               error_code = UAM_ERROR_DB_FAILED;
+               goto handle_error;
+       }
+
+       UAM_DBG("Service info updated");
+
+handle_error:
+       sqlite3_reset(stmt);
+       FUNC_EXIT;
+       return error_code;
+}
+
 int _uam_db_delete_service_info(const char *service_name)
 {
        FUNC_ENTRY;