From: Chanwoo Choi Date: Tue, 8 Mar 2022 07:34:49 +0000 (+0900) Subject: lib: tmonitor: Replace the initial tmonitor API to enhanced declaration X-Git-Tag: submit/tizen/20220311.083421~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8d5058bc951c9da88df6063ebb1eb5b946713c8c;p=platform%2Fcore%2Fsystem%2Fpass.git lib: tmonitor: Replace the initial tmonitor API to enhanced declaration Replace the initial tmonitor API to enhanced declaration and add the declaration of missing tmonitor API. Change-Id: I8845f9a17e325e13118767943536c5c313828fd9 Signed-off-by: Chanwoo Choi --- diff --git a/include/util/request.h b/include/util/request.h index c60793c..a0bb183 100644 --- a/include/util/request.h +++ b/include/util/request.h @@ -25,21 +25,21 @@ enum { REQUEST_CREATE_RESOURCE, + REQUEST_DELETE_RESOURCE, REQUEST_UPDATE_RESOURCE, - REQUEST_REMOVE_RESOURCE, - REQUEST_SET_ATTR_INTEREST, - REQUEST_UNSET_ATTR_INTEREST, - REQUEST_SET_RESOURCE_CONTROL, + REQUEST_UPDATE_RESOURCE_ALL, + REQUEST_GET_RESOURCE_COUNT, + REQUEST_SET_RESOURCE_CTRL, + REQUEST_SET_RESOURCE_ATTR, + REQUEST_UNSET_RESOURCE_ATTR, + REQUEST_IS_RESOURCE_ATTR_SUPPORTED, REQUEST_GET_VALUE_INT, REQUEST_GET_VALUE_INT64, REQUEST_GET_VALUE_UINT, REQUEST_GET_VALUE_UINT64, REQUEST_GET_VALUE_DOUBLE, REQUEST_GET_VALUE_STRING, - REQUEST_GET_RESOURCE_NUM, - REQUEST_GET_AVAILABLE_ATTRS, REQUEST_MAX, }; #endif /* __REQUEST_H__ */ - diff --git a/lib/tmonitor/tmonitor.c b/lib/tmonitor/tmonitor.c index 6e28ce6..2e74090 100644 --- a/lib/tmonitor/tmonitor.c +++ b/lib/tmonitor/tmonitor.c @@ -95,7 +95,7 @@ static struct tmonitor_client *find_client_by_id(int id) } EXPORT -int tmonitor_init(int period, int (*func)(void *data, void* user_data), void *user_data) +int tmonitor_init(void) { struct tmonitor_client *client; struct sockaddr_in server_addr; @@ -107,14 +107,6 @@ int tmonitor_init(int period, int (*func)(void *data, void* user_data), void *us return -ENOMEM; } - /* the minimum period is 100ms */ - if (period > 0 || period < 100) - period = 100; - - client->period = period; - client->func = func; - client->user_data = user_data; - /* open socket to server */ client->id = socket(AF_INET, SOCK_STREAM, 0); if (client->id < 0) { @@ -148,12 +140,6 @@ err_out_free: return ret; } -EXPORT -int tmonitor_connect(void) -{ - return tmonitor_init(0, NULL, NULL); -} - EXPORT int tmonitor_exit(int id) { @@ -172,6 +158,12 @@ int tmonitor_exit(int id) return 0; } +EXPORT +int tmonitor_get_resource_count(int id, int resource_type) +{ + return 0; +} + EXPORT int tmonitor_create_resource(int id, int resource_type) { @@ -206,15 +198,21 @@ int tmonitor_create_resource(int id, int resource_type) } EXPORT -int tmonitor_set_attr_interest(int id, int resource_id, u_int64_t attr_mask) +int tmonitor_delete_resource(int id, int resource_id) +{ + return 0; +} + +EXPORT +int tmonitor_set_resource_ctrl(int id, int resource_id, u_int64_t ctrl_id, int value) { char buffer[MAX_BUF_SIZE + 1]; int buffer_len; int response_req; int ret; - buffer_len = sprintf(buffer, "%d:%d:%"PRIu64, - REQUEST_SET_ATTR_INTEREST, resource_id, attr_mask); + buffer_len = sprintf(buffer, "%d:%d:%"PRIu64":%d", + REQUEST_SET_RESOURCE_CTRL, resource_id, ctrl_id, value); if (send(id, buffer, buffer_len, 0) < 0) { _E("[libpass] error occurred while sending buffer"); return -EIO; @@ -231,7 +229,7 @@ int tmonitor_set_attr_interest(int id, int resource_id, u_int64_t attr_mask) if (sscanf(buffer, "%d:%d", &response_req, &ret) < 2) return -EINVAL; - if (response_req != REQUEST_SET_ATTR_INTEREST) { + if (response_req != REQUEST_SET_RESOURCE_CTRL) { _E("[libpass] wrong response"); return -EINVAL; } @@ -240,15 +238,15 @@ int tmonitor_set_attr_interest(int id, int resource_id, u_int64_t attr_mask) } EXPORT -int tmonitor_set_resource_control(int id, int resource_id, u_int64_t ctrl_id, int value) +int tmonitor_set_resource_attr(int id, int resource_id, u_int64_t attr_mask) { char buffer[MAX_BUF_SIZE + 1]; int buffer_len; int response_req; int ret; - buffer_len = sprintf(buffer, "%d:%d:%"PRIu64":%d", - REQUEST_SET_RESOURCE_CONTROL, resource_id, ctrl_id, value); + buffer_len = sprintf(buffer, "%d:%d:%"PRIu64, + REQUEST_SET_RESOURCE_ATTR, resource_id, attr_mask); if (send(id, buffer, buffer_len, 0) < 0) { _E("[libpass] error occurred while sending buffer"); return -EIO; @@ -265,29 +263,22 @@ int tmonitor_set_resource_control(int id, int resource_id, u_int64_t ctrl_id, in if (sscanf(buffer, "%d:%d", &response_req, &ret) < 2) return -EINVAL; - if (response_req != REQUEST_SET_RESOURCE_CONTROL) { + if (response_req != REQUEST_SET_RESOURCE_ATTR) { _E("[libpass] wrong response"); return -EINVAL; } return ret; } -EXPORT -int tmonitor_get_available_attrs(int id, int resource_type, - int *available_attrs[], int *num_attrs) -{ - /* TODO */ - return 0; -} EXPORT -int tmonitor_start(int id) +int tmonitor_unset_resource_attr(int id, int resource_id, u_int64_t attr_mask) { return 0; } EXPORT -int tmonitor_stop(int id) +bool tmonitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id) { return 0; } @@ -534,10 +525,3 @@ int tmonitor_get_value_string(int id, int resource_id, u_int64_t attr_id, char * return ret; } - - -EXPORT -int tmonitor_get_resource_num(int id, int resource_type) -{ - return 0; -} diff --git a/lib/tmonitor/tmonitor.h b/lib/tmonitor/tmonitor.h index 8d61152..98ce0d8 100644 --- a/lib/tmonitor/tmonitor.h +++ b/lib/tmonitor/tmonitor.h @@ -19,6 +19,9 @@ #ifndef __TMONITOR__ #define __TMONITOR__ +#include +#include + #ifdef __cplusplus extern "C" { #endif @@ -115,93 +118,98 @@ extern "C" { /** * @brief Initialize the tizen monitor - * @param[in] Timer period (unit: millisecond, minimum value is 100ms) - * @param[in] Timer callback function - * @param[in] User data be passed to timer callback function - * @return @c positive integer on success, otherwise a negative error value + * @return @c positive integer as tizen monitor id on success, otherwise a negative error value */ -int tmonitor_init(int period, int (*func)(void *data, void* user_data), void *user_data); - -/** - * @brief Initialize the tizen monitor quickly - * @return @c positive integer on success, otherwise a negative error value - */ -int tmonitor_connect(void); +int tmonitor_init(void); /** * @brief Exit the tizem monitor - * @param[in] Unique id of tizen monitor which be returnted by tmonitor_init + * @param[in] Id of tizen monitor which be returnted by tmonitor_init * @return @c 0 on success, otherwise a negative error value */ int tmonitor_exit(int id); /** - * @brief Alias of tmonitor_exit to provide pair with tmonitor_connect - * @param[in] Unique id of tizen monitor which be returnted by tmonitor_connect - * @return @c 0 on success, otherwise a negative error value + * @brief Get the count of supported resources according to resource type + * @param[in] Tizen monitor id + * @param[in] Resource type + * @return @c positive integer as resource count on success, otherwise a negative error value */ -#define tmonitor_disconnect tmonitor_exit +int tmonitor_get_resource_count(int id, int resource_type); /** * @brief Create resource for given resource_type - * @param[in] Unique id of tizen monitor which be returnted by tmonitor_init/connect + * @param[in] Tizen monitor id which be returnted by tmonitor_init * @param[in] Resource type - * @return @c positive integer as resource handler id on success, otherwise a negative error value + * @return @c positive integer as resource id on success, otherwise a negative error value */ int tmonitor_create_resource(int id, int resource_type); /** - * @brief Set the interested attributes for monitoring - * @param[in] Unique id of tizen monitor - * @param[in] Unique id of resource - * @param[in] Attribute mask including the various attributes + * @brief Delete resource of given resource id + * @param[in] Tizen monitor id which be returnted by tmonitor_init + * @param[in] Resource id * @return @c 0 on success, otherwise a negative error value */ -int tmonitor_set_attr_interest(int id, int resource_id, u_int64_t attr_mask); +int tmonitor_delete_resource(int id, int resource_id); + +/** + * @brief Set the resource control with value which is diffierential according to resource control id + * @param[in] Tizen monitor id + * @param[in] Resource id + * @param[in] Resource control id + * @param[in] Value for resource control id + * @return @c 0 on success, otherwise a negative error value + */ +int tmonitor_set_resource_ctrl(int id, int resource_id, u_int64_t ctrl_id, int value); /** * @brief Set the interested attributes for monitoring - * @param[in] Unique id of tizen monitor - * @param[in] Unique id of resource + * @param[in] Tizen monitor id + * @param[in] Resource id * @param[in] Attribute mask including the various attributes * @return @c 0 on success, otherwise a negative error value */ -int tmonitor_set_resource_control(int id, int resource_id, u_int64_t ctrl_id, int value); +int tmonitor_set_resource_attr(int id, int resource_id, u_int64_t attr_mask); /** - * @brief Start tizen monitor with asynchronous method - * @param[in] Unique id of tizen monitor + * @brief Unset the interested attributes for monitoring + * @param[in] Tizen monitor id + * @param[in] Resource id + * @param[in] Attribute mask including the various attributes * @return @c 0 on success, otherwise a negative error value */ -int tmonitor_start(int id); +int tmonitor_unset_resource_attr(int id, int resource_id, u_int64_t attr_mask); /** - * @brief Stop tizen monitor - * @param[in] Unique id of tizen monitor + * @brief Check whether a resouce attribute is supported or not + * @param[in] Tizen monitor id + * @param[in] Resource id + * @param[in] Resource attribute id * @return @c 0 on success, otherwise a negative error value */ -int tmonitor_stop(int id); +bool tmonitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id); /** - * @brief Update value of the interested attributes by tmonitor_set_attrs() - * @param[in] Unique id of tizen monitor + * @brief Update value of the interested attributes for all created resource + * @param[in] Tizen monitor id * @return @c 0 on success, otherwise a negative error value */ int tmonitor_update(int id); /** - * @brief Update value of the interested attributes by tmonitor_set_attrs() - * @param[in] Unique id of tizen monitor - * @param[in] Unique id of resource + * @brief Update value of the interested attributes for a resource + * @param[in] Tizen monitor id + * @param[in] Resource id * @return @c 0 on success, otherwise a negative error value */ int tmonitor_update_resource(int id, int resource_id); /** * @brief Get [int/int64/uint/uint64/double/string] value of resource attribute - * @param[in] Unique id of tizen monitor - * @param[in] Unique id of resource - * @param[in] Resoruce attribute id + * @param[in] Tizen monitor id + * @param[in] Resource id + * @param[in] Resource attribute id * @param[out] Value retrieved from resource attribute * @return @ 0 on success, otherwise a negative error value */ @@ -212,14 +220,6 @@ int tmonitor_get_value_uint64(int id, int resource_id, u_int64_t attr, u_int64_t int tmonitor_get_value_double(int id, int resource_id, u_int64_t attr, double *value); int tmonitor_get_value_string(int id, int resource_id, u_int64_t attr, char *value); -/** - * @brief Get the supported resource number - * @param[in] Unique id of tizen monitor - * @param[in] Resource type - * @return @c positive integer value, otherwise a negative error value - */ -int tmonitor_get_resource_num(int id, int resource_type); - #ifdef __cplusplus } #endif diff --git a/src/monitor/request-handler.c b/src/monitor/request-handler.c index 92a5b23..2d01ad0 100644 --- a/src/monitor/request-handler.c +++ b/src/monitor/request-handler.c @@ -117,7 +117,7 @@ static int handle_request_update_resource(struct request_client *client, char *a return update_resource_attrs(res); } -static int handle_request_set_attr_interest(struct request_client *client, char *args) +static int handle_request_set_resource_attr(struct request_client *client, char *args) { struct resource *res; int resource_id; @@ -127,7 +127,7 @@ static int handle_request_set_attr_interest(struct request_client *client, char return -ENOENT; /** - * Format of REQUEST_SET_ATTR_INTEREST args: + * Format of REQUEST_SET_RESOURCE_ATTR args: * - */ if (sscanf(args, "%d:%"PRIu64, &resource_id, &interest_masks) < 2) @@ -142,7 +142,7 @@ static int handle_request_set_attr_interest(struct request_client *client, char return 0; } -static int handle_request_set_resource_control(struct request_client *client, char *args) +static int handle_request_set_resource_ctrl(struct request_client *client, char *args) { struct resource *res; int resource_id, value; @@ -152,7 +152,7 @@ static int handle_request_set_resource_control(struct request_client *client, ch return -ENOENT; /** - * Format of REQUEST_SET_RESOURCE_CONTROL args: + * Format of REQUEST_SET_RESOURCE_CTRL args: * - */ if (sscanf(args, "%d:%"PRIu64":%d", &resource_id, &ctrl_id, &value) < 3) @@ -346,15 +346,15 @@ static void handle_request(struct request_client *client, char *buffer) if (ret < 0) _D("failed to update resource"); break; - case REQUEST_SET_ATTR_INTEREST: - ret = handle_request_set_attr_interest(client, args); + case REQUEST_SET_RESOURCE_CTRL: + ret = handle_request_set_resource_ctrl(client, args); if (ret < 0) - _D("failed to set attr interest"); + _D("failed to set resource control"); break; - case REQUEST_SET_RESOURCE_CONTROL: - ret = handle_request_set_resource_control(client, args); + case REQUEST_SET_RESOURCE_ATTR: + ret = handle_request_set_resource_attr(client, args); if (ret < 0) - _D("failed to set resource control"); + _D("failed to set attr interest"); break; case REQUEST_GET_VALUE_INT: {