Add API to set light detection threshold
authorAbhay Agarwal <ay.agarwal@samsung.com>
Wed, 25 Sep 2019 04:25:50 +0000 (13:25 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 26 Sep 2019 06:47:39 +0000 (15:47 +0900)
Change-Id: Idef67a2c512af01aa3c14669c9c275a724946777
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness-private.h
include/user-awareness.h
packaging/capi-network-ua.spec
src/user-awareness-service.c
test/uat-service.c

index 41b52d265f3895641f85757a1113015521046631..2ce421e97131013e8cd5d51ac03a3035fd735e0a 100644 (file)
@@ -241,6 +241,8 @@ typedef struct {
 typedef struct {
        ua_service_h service_handle; /**< Service handle */
        char *name; /**< Service name */
+       int presence_threshold;
+       int absence_threshold;
        gboolean isadded; /**< Is the service addition completed? */
        gboolean default_service; /**< Is it a default service? */
        gboolean create_by_app; /**< Did app add this service information? */
index ad5b34cef3e607b6fcfd1d4dffe37d1a50d40e7e..fb1cf5212650dbdb6f6eae6da7a9c1275d54acde 100644 (file)
@@ -1651,6 +1651,29 @@ int ua_service_get_by_name(
                const char *name,
                ua_service_h *service_handle);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Sets detection threshold for service handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] service_handle The service handle
+ * @param[in] presence_threshold The service presence threshold information
+ * @param[in] absence_threshold The service absence threshold information
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+int ua_service_set_detection_threshold(
+               ua_service_h service_handle,
+               unsigned int presence_threshold,
+               unsigned int absence_threshold);
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Sets name info for service handle.
index 56f1ec1eeec01156e7c542c8e6f8c29c52fa6fa7..feb1b73e6cebccb78348a0f44e31f3a380899438 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.10.0
+Version: 0.10.1
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index 7781dc6a1a5c7da72cb46b56052b672baa77f35b..0f3ad117a4099740ce7d601263719bb411dd7453 100644 (file)
@@ -358,6 +358,8 @@ int ua_service_add(ua_service_h service_handle)
 
        memset(&uam_service, 0, sizeof(uam_service_info_s));
        g_strlcpy(uam_service.name, service->name, UAM_SERVICE_MAX_STRING_LEN);
+       uam_service.presence_threshold = service->presence_threshold;
+       uam_service.absence_threshold = service->absence_threshold;
 
        ret = _ua_get_error_code(_uam_register_service(&uam_service));
        if (UA_ERROR_NONE != ret) {
@@ -373,7 +375,6 @@ int ua_service_add(ua_service_h service_handle)
        return UA_ERROR_NONE;
 }
 
-
 int ua_service_remove(ua_service_h service_handle)
 {
        FUNC_ENTRY;
@@ -424,6 +425,26 @@ int ua_service_set_name(ua_service_h service_handle, const char *name)
        return UA_ERROR_NONE;
 }
 
+int ua_service_set_detection_threshold(ua_service_h service_handle,
+       unsigned int presence_threshold, unsigned int absence_threshold)
+{
+       FUNC_ENTRY;
+       ua_service_info_s *service = (ua_service_info_s *)service_handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(service_handle);
+       UA_VALIDATE_HANDLE(service_handle, ua_services_list);
+
+       retv_if(service->isadded, UA_ERROR_NOT_PERMITTED);
+//     retv_if(presence_threshold > UAM_SERVICE_MAX_THRESHOLD), UA_ERROR_INVALID_PARAMETER);
+//     retv_if(absence_threshold < UAM_SERVICE_MIN_THRESHOLD), UA_ERROR_INVALID_PARAMETER);
+
+       service->presence_threshold = presence_threshold;
+       service->absence_threshold = absence_threshold;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
 int ua_service_get_name(ua_service_h service_handle, char **name)
 {
        FUNC_ENTRY;
index 1bf834b45e733b7af5a578647eac3d0066397341..30525bc8964879f02549fe551cb4fe96af553832 100644 (file)
@@ -29,6 +29,8 @@
 ua_service_h g_service_h = NULL; /**< Service handle */
 char g_service_str[MENU_DATA_SIZE + 1] = { "ua.service.default" }; /**< Seletected service name */
 
+static char g_presence_threshold_str[MENU_DATA_SIZE + 1] = {0,}; /**< Seletected service presence threshold */
+static char g_absence_threshold_str[MENU_DATA_SIZE + 1] = {0,}; /**< Seletected service absence threshold */
 static char g_selected_service_id[MENU_DATA_SIZE + 1] = {0,}; /**< Selected service id in the list */
 
 static GSList *g_service_list = NULL; /**< Service List */
@@ -168,6 +170,30 @@ static int run_ua_service_set_name(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
+static int run_ua_service_set_detection_threshold(MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+       unsigned int presence_threshold = 0;
+       unsigned int absence_threshold = 0;
+
+       msg("ua_service_set_threshold");
+
+       check_if(NULL == g_service_h);
+
+       if (strlen(g_presence_threshold_str))
+               presence_threshold = (unsigned int)strtol(g_presence_threshold_str, NULL, 10);
+       if (strlen(g_absence_threshold_str))
+               absence_threshold = (unsigned int)strtol(g_absence_threshold_str, NULL, 10);
+
+       ret = ua_service_set_detection_threshold(g_service_h, presence_threshold,
+                                       absence_threshold);
+
+       msg(" - ua_service_set_name() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
 static int run_ua_service_add(
        MManager *mm, struct menu_data *menu)
 {
@@ -256,6 +282,16 @@ static struct menu_data menu_ua_service_get_by_name[] = {
        { NULL, NULL, },
 };
 
+static struct menu_data menu_ua_service_set_detection_threshold[] = {
+       { "1", "light presence detection threshold",
+               NULL, NULL, g_presence_threshold_str},
+       { "2", "light absence detection threshold",
+               NULL, NULL, g_absence_threshold_str},
+       { "3", "run",
+               NULL, run_ua_service_set_detection_threshold, NULL },
+       { NULL, NULL, },
+};
+
 struct menu_data menu_ua_services[] = {
        { "1", "ua_service_get_default_service",
                NULL, run_ua_service_get_default_service, NULL },
@@ -263,15 +299,17 @@ struct menu_data menu_ua_services[] = {
                NULL, run_ua_service_create, NULL },
        { "3", "ua_service_set_name",
                menu_ua_service_set_name, NULL, g_service_str },
-       { "4", "ua_service_add",
+       { "4", "ua_service_set_detection_threshold",
+               menu_ua_service_set_detection_threshold, NULL, NULL },
+       { "5", "ua_service_add",
                NULL, run_ua_service_add, NULL },
-       { "5", "ua_service_remove",
+       { "6", "ua_service_remove",
                NULL, run_ua_service_remove, NULL},
-       { "6", "ua_service_destroy",
+       { "7", "ua_service_destroy",
                NULL, run_ua_service_destroy, NULL},
-       { "7", "ua_service_get_by_name",
+       { "8", "ua_service_get_by_name",
                menu_ua_service_get_by_name, NULL, NULL },
-       { "8", "ua_service_foreach_added_services",
+       { "9", "ua_service_foreach_added_services",
                NULL, run_ua_service_foreach_added_services, NULL },
        { NULL, NULL, },
 };