From b05b507adde3ea5433b444afa9449508741250b2 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 21 Feb 2023 10:25:29 +0900 Subject: [PATCH 01/16] resource-manager: Change variable name There will be another type, instance_type, which denotes how an resource instance operates. To clearly distinguish role of those variables, change variable name type to resource_type. Change-Id: I2b5dd012d86cc7869da7206feea4ffad7f1dd8c3 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index 83532ea..5f3fa1e 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -41,7 +41,7 @@ struct syscommon_resman_resource { char *name; int id; const struct syscommon_resman_resource_driver *driver; - int type; + int resource_type; /* which type of resource */ int num_attrs; const struct syscommon_resman_resource_attribute *attrs; @@ -221,7 +221,7 @@ syscommon_resman_create_resource(int *resource_id, int resource_type) return -ENOMEM; resource->id = alloc_resource_id(); - resource->type = resource_type; + resource->resource_type = resource_type; resource->name = g_strdup(driver->name); resource->driver = driver; resource->num_attrs = driver->num_attrs; @@ -340,7 +340,7 @@ syscommon_resman_monitor_update_resource_attrs(int resource_id) int i, ret; struct syscommon_resman_resource *resource = find_resource(resource_id); - if (!resource || !resource->type) + if (!resource || !resource->resource_type) return -EINVAL; if (resource->driver && resource->driver->ops.prepare_update) { @@ -593,13 +593,13 @@ syscommon_resman_monitor_get_resource_attrs_json(int resource_id, char **json_st struct syscommon_resman_resource *resource = find_resource(resource_id); int i; - if (!resource || !resource->type) + if (!resource || !resource->resource_type) return -EINVAL; jobj_root = json_object_new_object(); jobj_res_name = json_object_new_string(resource->name); - jobj_res_type = json_object_new_int(resource->type); + jobj_res_type = json_object_new_int(resource->resource_type); jobj_res_attrs = json_object_new_array(); for (i = 0; i < resource->num_attrs; i++) { @@ -1117,7 +1117,7 @@ syscommon_resman_get_resource_type(int resource_id) { struct syscommon_resman_resource *resource = find_resource(resource_id); - return resource ? resource->type : -EINVAL; + return resource ? resource->resource_type : -EINVAL; } int -- 2.7.4 From f1a21857ca4275d218cf8bbb7ef9e3bc3780e5eb Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 21 Feb 2023 10:41:58 +0900 Subject: [PATCH 02/16] resource-manager: Introduce resource instance type To clearly partition the way how resource works, added instance_type to resource, INSTANCE_TYPE_NORMAL and INSTANCE_TYPE_MONITOR. Resource instance of each type can be created by the below functions: - INSTANCE_TYPE_NORMAL: syscommon_resman_create_resource() - INSTANCE_TYPE_MONITOR: syscommon_resman_monitor_create_resource() Instance type of NORMAL sets all interest bits by default. Therefore, it doesn't need to set interest bit additionally. On the other hand, instance type of MONITOR clears all interest bits by default. Therefore, it should set bit manually in which a monitor interest before it starts monitoring. In addition, instance type of NORMAL always invoke its attribute getter for every access to attribute value. That is, it always fetches the latest value. On the other hand, instance type of MONITOR fetches attribute value on a specific time that must have been synchronized by syscommon_resman_monitor_update_resource_attrs(). Change-Id: I39b2089a21d5b5d7b59704a7835e2646939a20c2 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 68 +++++++++++++++++++++++++++++---- src/resource-manager/resource-manager.h | 1 + 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index 5f3fa1e..953ed85 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -20,6 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include #include #include #include @@ -37,11 +38,15 @@ #define RESOURCE_ATTR_FLAG_VISIBILITY_MASK (SYSCOMMON_RESMAN_RESOURCE_ATTR_FLAG_PRIVATE \ | SYSCOMMON_RESMAN_RESOURCE_ATTR_FLAG_PUBLIC) +#define INSTANCE_TYPE_NORMAL 0 +#define INSTANCE_TYPE_MONITOR 1 + struct syscommon_resman_resource { char *name; int id; const struct syscommon_resman_resource_driver *driver; int resource_type; /* which type of resource */ + int instance_type; /* how resource instance operates */ int num_attrs; const struct syscommon_resman_resource_attribute *attrs; @@ -57,6 +62,7 @@ struct syscommon_resman_resource { u_int64_t attr_supported; }; +static int set_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64_t interest_mask); static int unset_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64_t interest_mask); static bool is_resource_attr_interested(struct syscommon_resman_resource *resource, u_int64_t interest_mask); @@ -202,8 +208,8 @@ void syscommon_resman_delete_resource(int resource_id) g_hash_table_remove(g_resource_hash_table, GINT_TO_POINTER(resource_id)); } -int -syscommon_resman_create_resource(int *resource_id, int resource_type) +static int +create_resource(int *resource_id, int resource_type, int instance_type) { const struct syscommon_resman_resource_driver *driver = NULL; struct syscommon_resman_resource *resource = NULL; @@ -222,6 +228,7 @@ syscommon_resman_create_resource(int *resource_id, int resource_type) resource->id = alloc_resource_id(); resource->resource_type = resource_type; + resource->instance_type = instance_type; resource->name = g_strdup(driver->name); resource->driver = driver; resource->num_attrs = driver->num_attrs; @@ -259,6 +266,46 @@ syscommon_resman_create_resource(int *resource_id, int resource_type) return 0; } +static int set_resource_attr_interest_all(struct syscommon_resman_resource *resource) +{ + u_int64_t all; + + if (!resource || !resource->num_attrs) + return -EINVAL; + + all = (1ULL << resource->num_attrs) - 1; + + return set_resource_attr_interest(resource, all); +} + +int +syscommon_resman_create_resource(int *resource_id, int resource_type) +{ + int ret; + struct syscommon_resman_resource *resource = NULL; + + ret = create_resource(resource_id, resource_type, INSTANCE_TYPE_NORMAL); + if (ret < 0) + return ret; + + resource = find_resource(*resource_id); + assert(resource); + + ret = set_resource_attr_interest_all(resource); + if (ret < 0) { + free_resource(resource); + return ret; + } + + return 0; +} + +int +syscommon_resman_monitor_create_resource(int *resource_id, int resource_type) +{ + return create_resource(resource_id, resource_type, INSTANCE_TYPE_MONITOR); +} + int syscommon_resman_set_resource_flag(int resource_id, u_int64_t flag_mask) { @@ -891,13 +938,12 @@ is_resource_attr_visible(struct syscommon_resman_resource *resource, return true; } -int -syscommon_resman_set_resource_attr_interest(int resource_id, u_int64_t interest_mask) +static int +set_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64_t interest_mask) { struct syscommon_resman_resource_attribute_value *attr_value; int i, ret; bool supported; - struct syscommon_resman_resource *resource = find_resource(resource_id); if (!resource) return -EINVAL; @@ -928,7 +974,7 @@ syscommon_resman_set_resource_attr_interest(int resource_id, u_int64_t interest_ } if (resource->attrs[i].listener_ops.init) { - ret = resource->attrs[i].listener_ops.init(resource_id, &resource->attrs[i]); + ret = resource->attrs[i].listener_ops.init(resource->id, &resource->attrs[i]); if (ret < 0) goto err; } @@ -984,7 +1030,7 @@ err: continue; if (resource->attrs[i].listener_ops.exit) - resource->attrs[i].listener_ops.exit(resource_id, &resource->attrs[i]); + resource->attrs[i].listener_ops.exit(resource->id, &resource->attrs[i]); attr_value = get_resource_attr_value(resource, resource->attrs[i].id); if (!attr_value) @@ -999,6 +1045,14 @@ err: return ret; } +int +syscommon_resman_set_resource_attr_interest(int resource_id, u_int64_t interest_mask) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + return set_resource_attr_interest(resource, interest_mask); +} + static int unset_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64_t interest_mask) { diff --git a/src/resource-manager/resource-manager.h b/src/resource-manager/resource-manager.h index 8c7b006..5086cf4 100644 --- a/src/resource-manager/resource-manager.h +++ b/src/resource-manager/resource-manager.h @@ -132,6 +132,7 @@ void syscommon_resman_remove_resource_driver(const struct syscommon_resman_resou /* Create/delete resource instance */ int syscommon_resman_create_resource(int *resource_id, int resource_type); +int syscommon_resman_monitor_create_resource(int *resource_id, int resource_type); void syscommon_resman_delete_resource(int resource_id); /* Set flag of the resource to given flag mask */ -- 2.7.4 From 45efc07414e3234c6bc4ef94ed4da68a44a471c7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 21 Feb 2023 12:10:00 +0900 Subject: [PATCH 03/16] resource-manager: Reimplement attribute_ops attribute_ops is in charge of operations for resource instance type of INSTANCE_TYPE_NORMAL. As the is_resource_attr_supported() works based on instance type, API for NORMAL instance has been added. - syscommon_resman_is_resource_attr_supported() Change-Id: Ia9078f9d4639f6ce3812a4749aaf0ada87af22f2 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 65 ++++++++++++++++++++++++++++----- src/resource-manager/resource-manager.h | 17 +++++++++ 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index 953ed85..f9eb0e3 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -62,6 +62,14 @@ struct syscommon_resman_resource { u_int64_t attr_supported; }; +struct attribute_is_supported_ops { + bool (*is_supported)(int resource_id, + const struct syscommon_resman_resource_attribute *attr); + int (*get)(int resource_id, + const struct syscommon_resman_resource_attribute *attr, + void *data); +}; + static int set_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64_t interest_mask); static int unset_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64_t interest_mask); static bool is_resource_attr_interested(struct syscommon_resman_resource *resource, u_int64_t interest_mask); @@ -444,12 +452,35 @@ syscommon_resman_get_resource_attr_value(int resource_id, u_int64_t attr_id) return get_resource_attr_value(resource, attr_id); } -static int monitor_is_resource_attr_supported(struct syscommon_resman_resource *resource, u_int64_t attr_id, bool *supported) +static int select_attribute_is_supported_ops(int instance_type, + const struct syscommon_resman_resource_attribute *attr, struct attribute_is_supported_ops *ops) +{ + assert(attr); + assert(ops); + + switch (instance_type) { + case INSTANCE_TYPE_NORMAL: + ops->is_supported = attr->ops.is_supported; + ops->get = attr->ops.get; + return 0; + case INSTANCE_TYPE_MONITOR: + ops->is_supported = attr->monitor_ops.is_supported; + ops->get = attr->monitor_ops.get; + return 0; + default: + assert(0); // unreachable + } + + return -EINVAL; +} + +static int is_resource_attr_supported(struct syscommon_resman_resource *resource, u_int64_t attr_id, bool *supported) { const struct syscommon_resman_resource_attribute *attr = NULL; int attr_index = RESOURCE_ATTR_INDEX(attr_id); int ret; bool is_supported = false; + struct attribute_is_supported_ops ops = { 0 , }; if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) { *supported = false; @@ -458,11 +489,18 @@ static int monitor_is_resource_attr_supported(struct syscommon_resman_resource * attr = &resource->attrs[attr_index]; + /* Select ops for testing support by instance type */ + ret = select_attribute_is_supported_ops(resource->instance_type, attr, &ops); + if (ret < 0) { + *supported = false; + return ret; + } + if (attr->id & resource->attr_supported) { is_supported = true; - } else if (attr->monitor_ops.is_supported) { - is_supported = attr->monitor_ops.is_supported(resource->id, attr); - } else if (attr->monitor_ops.get) { + } else if (ops.is_supported) { + is_supported = ops.is_supported(resource->id, attr); + } else if (ops.get) { /* * Optionally, if .is_supported ops is not implemented, * use .get ops in order to check whether the resource attribute @@ -470,7 +508,7 @@ static int monitor_is_resource_attr_supported(struct syscommon_resman_resource * */ char data[SYSCOMMON_RESMAN_BUFF_MAX] = {0, }; - ret = attr->monitor_ops.get(resource->id, attr, (void *)data); + ret = ops.get(resource->id, attr, (void *)data); is_supported = (ret < 0) ? false : true; } @@ -483,11 +521,22 @@ static int monitor_is_resource_attr_supported(struct syscommon_resman_resource * } int +syscommon_resman_is_resource_attr_supported(int resource_id, u_int64_t attr_id, bool *supported) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!resource || resource->instance_type != INSTANCE_TYPE_NORMAL) + return -EINVAL; + + return is_resource_attr_supported(resource, attr_id, supported); +} + +int syscommon_resman_monitor_is_resource_attr_supported(int resource_id, u_int64_t attr_id, bool *supported) { struct syscommon_resman_resource *resource = find_resource(resource_id); - return monitor_is_resource_attr_supported(resource, attr_id, supported); + return is_resource_attr_supported(resource, attr_id, supported); } static bool @@ -952,9 +1001,7 @@ set_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64_t if (!(resource->attrs[i].id & interest_mask)) continue; - ret = monitor_is_resource_attr_supported(resource, - resource->attrs[i].id, - &supported); + ret = is_resource_attr_supported(resource, resource->attrs[i].id, &supported); if (ret < 0) { goto err; } else if (!supported) { diff --git a/src/resource-manager/resource-manager.h b/src/resource-manager/resource-manager.h index 5086cf4..cc6d886 100644 --- a/src/resource-manager/resource-manager.h +++ b/src/resource-manager/resource-manager.h @@ -48,6 +48,21 @@ struct syscommon_resman_resource_attribute_value { void *data; }; +struct syscommon_resman_resource_attribute_ops { + int (*set)(int resource_id, + const struct syscommon_resman_resource_attribute *attr, + const void *data, int count); + int (*get)(int resource_id, + const struct syscommon_resman_resource_attribute *attr, + void *data); + /* + * If .is_supported ops is not implemented, use .get ops in order to + * check whether the resource attribute is supported or not. + */ + bool (*is_supported)(int resource_id, + const struct syscommon_resman_resource_attribute *attr); +}; + struct syscommon_resman_resource_attribute_monitor_ops { int (*get)(int resource_id, const struct syscommon_resman_resource_attribute *attr, @@ -72,6 +87,7 @@ struct syscommon_resman_resource_attribute { const u_int64_t id; const int type; const u_int64_t flag; + const struct syscommon_resman_resource_attribute_ops ops; const struct syscommon_resman_resource_attribute_monitor_ops monitor_ops; const struct syscommon_resman_resource_attribute_listener_ops listener_ops; }; @@ -148,6 +164,7 @@ const struct syscommon_resman_resource_attribute * syscommon_resman_get_resource_attr(int resource_id, u_int64_t attr_id); struct syscommon_resman_resource_attribute_value * syscommon_resman_get_resource_attr_value(int resource_id, u_int64_t attr_id); +int syscommon_resman_is_resource_attr_supported(int resource_id, u_int64_t attr_id, bool *supported); int syscommon_resman_monitor_is_resource_attr_supported(int resource_id, u_int64_t attr_id, bool *supported); static inline bool -- 2.7.4 From b0334c47546043c8818a2fb6f8fe3d251fb6bac8 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 21 Feb 2023 17:06:22 +0900 Subject: [PATCH 04/16] resource-manager: Make monitor API be exclusive for INSTANCE_TYPE_MONITOR The APIs for monitor instance has changed to return error when it is used on instance type other than INSTANCE_TYPE_MONITOR. Change-Id: Ifa1ce8924e60cb3a08ab467bf6f112421bd0abb7 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 76 +++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index f9eb0e3..d100e8e 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -389,13 +389,18 @@ monitor_update_resource_attr(struct syscommon_resman_resource *resource, return 0; } +static bool is_valid_resource(struct syscommon_resman_resource *resource, int instance_type) +{ + return (resource && resource->instance_type == instance_type); +} + int syscommon_resman_monitor_update_resource_attrs(int resource_id) { int i, ret; struct syscommon_resman_resource *resource = find_resource(resource_id); - if (!resource || !resource->resource_type) + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) return -EINVAL; if (resource->driver && resource->driver->ops.prepare_update) { @@ -525,7 +530,7 @@ syscommon_resman_is_resource_attr_supported(int resource_id, u_int64_t attr_id, { struct syscommon_resman_resource *resource = find_resource(resource_id); - if (!resource || resource->instance_type != INSTANCE_TYPE_NORMAL) + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) return -EINVAL; return is_resource_attr_supported(resource, attr_id, supported); @@ -536,6 +541,9 @@ syscommon_resman_monitor_is_resource_attr_supported(int resource_id, u_int64_t a { struct syscommon_resman_resource *resource = find_resource(resource_id); + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + return is_resource_attr_supported(resource, attr_id, supported); } @@ -689,7 +697,7 @@ syscommon_resman_monitor_get_resource_attrs_json(int resource_id, char **json_st struct syscommon_resman_resource *resource = find_resource(resource_id); int i; - if (!resource || !resource->resource_type) + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) return -EINVAL; jobj_root = json_object_new_object(); @@ -738,6 +746,9 @@ syscommon_resman_monitor_get_resource_attr_json(int resource_id, u_int64_t attr_ json_object *jobj_attr; struct syscommon_resman_resource *resource = find_resource(resource_id); + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + attr = get_resource_attr(resource, attr_id); attr_value = get_resource_attr_value(resource, attr_id); @@ -877,10 +888,9 @@ int syscommon_resman_get_resource_list_json(char **json_string) } static int -get_resource_attr_value_data(int resource_id, u_int64_t attr_id, enum syscommon_resman_data_type type, void *data) +get_resource_attr_value_data(struct syscommon_resman_resource *resource, u_int64_t attr_id, enum syscommon_resman_data_type type, void *data) { struct syscommon_resman_resource_attribute_value *attr_value = NULL; - struct syscommon_resman_resource *resource = find_resource(resource_id); if (!check_attr_validate(resource, attr_id, type)) return -EINVAL; @@ -926,49 +936,89 @@ get_resource_attr_value_data(int resource_id, u_int64_t attr_id, enum syscommon_ int syscommon_resman_monitor_get_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t *data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT, data); } int syscommon_resman_monitor_get_resource_attr_int64(int resource_id, u_int64_t attr_id, int64_t *data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT64, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT64, data); } int syscommon_resman_monitor_get_resource_attr_uint(int resource_id, u_int64_t attr_id, u_int32_t *data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT, data); } int syscommon_resman_monitor_get_resource_attr_uint64(int resource_id, u_int64_t attr_id, u_int64_t *data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT64, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT64, data); } int syscommon_resman_monitor_get_resource_attr_double(int resource_id, u_int64_t attr_id, double *data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_DOUBLE, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_DOUBLE, data); } int syscommon_resman_monitor_get_resource_attr_string(int resource_id, u_int64_t attr_id, char *data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_STRING, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_STRING, data); } int syscommon_resman_monitor_get_resource_attr_array(int resource_id, u_int64_t attr_id, struct syscommon_resman_array_value **data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_ARRAY, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_ARRAY, data); } int syscommon_resman_monitor_get_resource_attr_ptr(int resource_id, u_int64_t attr_id, void **data) { - return get_resource_attr_value_data(resource_id, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_PTR, data); + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_MONITOR)) + return -EINVAL; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_PTR, data); } static inline bool -- 2.7.4 From 3b0e69d23249a757e8eacfc4a5cc228e5b7938fe Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 15 Feb 2023 17:37:17 +0900 Subject: [PATCH 05/16] resource-manager: Add get API for INSTANCE_TYPE_NORMAL Resource instance type of INSTANCE_TYPE_NORMAL fetches its attribute value by calling attribute_ops.get(). - syscommon_resman_get_resource_attr_int() - syscommon_resman_get_resource_attr_int64() - syscommon_resman_get_resource_attr_uint() - syscommon_resman_get_resource_attr_uint64() - syscommon_resman_get_resource_attr_double() - syscommon_resman_get_resource_attr_string() - syscommon_resman_get_resource_attr_array() - syscommon_resman_get_resource_attr_ptr() Change-Id: Ib3482ff685b0c3e4783cd8a3ce7dc5e6ab1e9699 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 156 +++++++++++++++++++++++++++++++- src/resource-manager/resource-manager.h | 9 ++ 2 files changed, 163 insertions(+), 2 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index d100e8e..00c1dca 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -364,8 +364,32 @@ syscommon_resman_get_resource_control_name(int resource_id, u_int64_t ctrl_id) } static int -monitor_update_resource_attr(struct syscommon_resman_resource *resource, - u_int64_t attr_id) +update_resource_attr(struct syscommon_resman_resource *resource, u_int64_t attr_id) +{ + int attr_index = RESOURCE_ATTR_INDEX(attr_id); + const struct syscommon_resman_resource_attribute *attr = NULL; + struct syscommon_resman_resource_attribute_value *attr_value = NULL; + int ret; + + if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) + return -EINVAL; + + attr = &resource->attrs[attr_index]; + + if (!attr->ops.get) + return -EINVAL; + + attr_value = &resource->attrs_value[attr_index]; + + ret = attr->ops.get(resource->id, attr, attr_value->data); + if (ret < 0) + return ret; + + return 0; +} + +static int +monitor_update_resource_attr(struct syscommon_resman_resource *resource, u_int64_t attr_id) { int attr_index = RESOURCE_ATTR_INDEX(attr_id); const struct syscommon_resman_resource_attribute *attr = NULL; @@ -934,6 +958,134 @@ get_resource_attr_value_data(struct syscommon_resman_resource *resource, u_int64 } int +syscommon_resman_get_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t *data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT, data); +} + +int +syscommon_resman_get_resource_attr_int64(int resource_id, u_int64_t attr_id, int64_t *data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT64, data); +} + +int +syscommon_resman_get_resource_attr_uint(int resource_id, u_int64_t attr_id, u_int32_t *data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT, data); +} + +int +syscommon_resman_get_resource_attr_uint64(int resource_id, u_int64_t attr_id, u_int64_t *data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT64, data); +} + +int +syscommon_resman_get_resource_attr_double(int resource_id, u_int64_t attr_id, double *data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_DOUBLE, data); +} + +int +syscommon_resman_get_resource_attr_string(int resource_id, u_int64_t attr_id, char *data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_STRING, data); +} + +int +syscommon_resman_get_resource_attr_array(int resource_id, u_int64_t attr_id, struct syscommon_resman_array_value **data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_ARRAY, data); +} + +int +syscommon_resman_get_resource_attr_ptr(int resource_id, u_int64_t attr_id, void **data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + int ret; + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + ret = update_resource_attr(resource, attr_id); + if (ret < 0) + return ret; + + return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_PTR, data); +} + +int syscommon_resman_monitor_get_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t *data) { struct syscommon_resman_resource *resource = find_resource(resource_id); diff --git a/src/resource-manager/resource-manager.h b/src/resource-manager/resource-manager.h index cc6d886..045d980 100644 --- a/src/resource-manager/resource-manager.h +++ b/src/resource-manager/resource-manager.h @@ -178,6 +178,15 @@ int syscommon_resman_monitor_get_resource_attrs_json(int resource_id, char **jso int syscommon_resman_monitor_get_resource_attr_json(int resource_id, u_int64_t attr_id, char **json_string); int syscommon_resman_get_resource_list_json(char **json_string); +int syscommon_resman_get_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t *data); +int syscommon_resman_get_resource_attr_int64(int resource_id, u_int64_t attr_id, int64_t *data); +int syscommon_resman_get_resource_attr_uint(int resource_id, u_int64_t attr_id, u_int32_t *data); +int syscommon_resman_get_resource_attr_uint64(int resource_id, u_int64_t attr_id, u_int64_t *data); +int syscommon_resman_get_resource_attr_double(int resource_id, u_int64_t attr_id, double *data); +int syscommon_resman_get_resource_attr_string(int resource_id, u_int64_t attr_id, char *data); +int syscommon_resman_get_resource_attr_array(int resource_id, u_int64_t attr_id, struct syscommon_resman_array_value **data); +int syscommon_resman_get_resource_attr_ptr(int resource_id, u_int64_t attr_id, void **data); + int syscommon_resman_monitor_get_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t *data); int syscommon_resman_monitor_get_resource_attr_int64(int resource_id, u_int64_t attr_id, int64_t *data); int syscommon_resman_monitor_get_resource_attr_uint(int resource_id, u_int64_t attr_id, u_int32_t *data); -- 2.7.4 From a2168a482945760ac86060304aac7b1d8bfcd6f8 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Feb 2023 13:44:03 +0900 Subject: [PATCH 06/16] resource-manager: Introduce attribute setter The setter is only allowed for resource type of INSTANCE_TYPE_NORMAL. - syscommon_resman_set_resource_attr_int() - syscommon_resman_set_resource_attr_int64() - syscommon_resman_set_resource_attr_uint() - syscommon_resman_set_resource_attr_uint64() - syscommon_resman_set_resource_attr_double() - syscommon_resman_set_resource_attr_string() - syscommon_resman_set_resource_attr_array() - syscommon_resman_set_resource_attr_ptr() Change-Id: I0e30425c35ec6df9660ef3c57a5ecd6a5769e1dd Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 149 ++++++++++++++++++++++++++++++++ src/resource-manager/resource-manager.h | 9 ++ 2 files changed, 158 insertions(+) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index 00c1dca..b3f3b9d 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -1173,6 +1173,155 @@ syscommon_resman_monitor_get_resource_attr_ptr(int resource_id, u_int64_t attr_i return get_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_PTR, data); } +static int +set_resource_attr_value_data(struct syscommon_resman_resource *resource, + u_int64_t attr_id, enum syscommon_resman_data_type type, const void *data, int count) +{ + const struct syscommon_resman_resource_attribute *attr = NULL; + struct syscommon_resman_resource_attribute_value *attr_value = NULL; + int ret; + + if (!data) + return -EINVAL; + + if (!check_attr_validate(resource, attr_id, type)) + return -EINVAL; + + attr = get_resource_attr(resource, attr_id); + if (!attr || !attr->ops.get) + return -EINVAL; + + attr_value = get_resource_attr_value(resource, attr_id); + if (!attr_value) + return -EINVAL; + + ret = attr->ops.set(resource->id, attr, data, count); + if (ret < 0) + return ret; + + /* TODO: We need to discuss about updating attr_value->data after ops.set() */ + switch (type) { + case SYSCOMMON_RESMAN_DATA_TYPE_INT: + *((int32_t *) attr_value->data) = *(int32_t *) data; + break; + case SYSCOMMON_RESMAN_DATA_TYPE_INT64: + *((int64_t *) attr_value->data) = *(int64_t *) data; + break; + case SYSCOMMON_RESMAN_DATA_TYPE_UINT: + *((u_int32_t *) attr_value->data) = *(u_int32_t *) data; + break; + case SYSCOMMON_RESMAN_DATA_TYPE_UINT64: + *((u_int64_t *) attr_value->data) = *(u_int64_t *) data; + break; + case SYSCOMMON_RESMAN_DATA_TYPE_DOUBLE: + *((double *) attr_value->data) = *(double *) data; + break; + case SYSCOMMON_RESMAN_DATA_TYPE_STRING: + strncpy((char *) attr_value->data, data, SYSCOMMON_RESMAN_BUFF_MAX); + break; + case SYSCOMMON_RESMAN_DATA_TYPE_ARRAY: + attr_value->data = *(struct syscommon_resman_array_value **) data; + break; + case SYSCOMMON_RESMAN_DATA_TYPE_PTR: + attr_value->data = *(void **) data; + break; + case SYSCOMMON_RESMAN_DATA_TYPE_BOOLEAN: + case SYSCOMMON_RESMAN_DATA_TYPE_NUM: + default: + return -EINVAL; + } + + return 0; +} + +int +syscommon_resman_set_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT, &data, 1); +} + +int +syscommon_resman_set_resource_attr_int64(int resource_id, u_int64_t attr_id, int64_t data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_INT64, &data, 1); +} + +int +syscommon_resman_set_resource_attr_uint(int resource_id, u_int64_t attr_id, u_int32_t data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT, &data, 1); +} + +int +syscommon_resman_set_resource_attr_uint64(int resource_id, u_int64_t attr_id, u_int64_t data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_UINT64, &data, 1); +} + +int +syscommon_resman_set_resource_attr_double(int resource_id, u_int64_t attr_id, double data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_DOUBLE, &data, 1); +} + +int +syscommon_resman_set_resource_attr_string(int resource_id, u_int64_t attr_id, char data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_STRING, &data, 1); +} + +int +syscommon_resman_set_resource_attr_array(int resource_id, u_int64_t attr_id, void *data, int count) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_ARRAY, &data, count); +} + +int +syscommon_resman_set_resource_attr_ptr(int resource_id, u_int64_t attr_id, void *data) +{ + struct syscommon_resman_resource *resource = find_resource(resource_id); + + if (!is_valid_resource(resource, INSTANCE_TYPE_NORMAL)) + return -EINVAL; + + return set_resource_attr_value_data(resource, attr_id, SYSCOMMON_RESMAN_DATA_TYPE_PTR, &data, 1); +} + static inline bool is_resource_attr_visible(struct syscommon_resman_resource *resource, const struct syscommon_resman_resource_attribute *attr) diff --git a/src/resource-manager/resource-manager.h b/src/resource-manager/resource-manager.h index 045d980..d89f08b 100644 --- a/src/resource-manager/resource-manager.h +++ b/src/resource-manager/resource-manager.h @@ -196,6 +196,15 @@ int syscommon_resman_monitor_get_resource_attr_string(int resource_id, u_int64_t int syscommon_resman_monitor_get_resource_attr_array(int resource_id, u_int64_t attr_id, struct syscommon_resman_array_value **data); int syscommon_resman_monitor_get_resource_attr_ptr(int resource_id, u_int64_t attr_id, void **data); +int syscommon_resman_set_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t data); +int syscommon_resman_set_resource_attr_int64(int resource_id, u_int64_t attr_id, int64_t data); +int syscommon_resman_set_resource_attr_uint(int resource_id, u_int64_t attr_id, u_int32_t data); +int syscommon_resman_set_resource_attr_uint64(int resource_id, u_int64_t attr_id, u_int64_t data); +int syscommon_resman_set_resource_attr_double(int resource_id, u_int64_t attr_id, double data); +int syscommon_resman_set_resource_attr_string(int resource_id, u_int64_t attr_id, char data); +int syscommon_resman_set_resource_attr_array(int resource_id, u_int64_t attr_id, void *data, int count); +int syscommon_resman_set_resource_attr_ptr(int resource_id, u_int64_t attr_id, void *data); + int syscommon_resman_set_resource_attr_interest(int resource_id, u_int64_t interest_mask); int syscommon_resman_unset_resource_attr_interest(int resource_id, u_int64_t interest_mask); bool syscommon_resman_is_resource_attr_interested(int resource_id, u_int64_t interest_mask); -- 2.7.4 From 5880b22f3e55b60c7b9326c51012b95f05416145 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 9 Mar 2023 09:23:06 +0900 Subject: [PATCH 07/16] resource-manager: Relocate add_resource() in create_resource() If operations following the add_resource() fail, then it is necessary to cleanup resource instance from hashtable that has been added by add_resource(). Instead of impelementing cleanup, move add_resource() to the end of create_resource() so that nothing follow add_resource(). Change-Id: I705a3dc3487c8ebf9e80cff51b7e89069a6a4f1a Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index b3f3b9d..a870a0b 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -248,12 +248,6 @@ create_resource(int *resource_id, int resource_type, int instance_type) return -ENOMEM; } - ret = add_resource(resource); - if (ret < 0) { - free_resource(resource); - return ret; - } - for (i = 0; i < resource->num_attrs; i++) resource->attrs_value[i].type = driver->attrs[i].type; @@ -271,6 +265,14 @@ create_resource(int *resource_id, int resource_type, int instance_type) *resource_id = resource->id; + ret = add_resource(resource); + if (ret < 0) { + if (driver->ops.delete) + driver->ops.delete(resource->id); + free_resource(resource); + return ret; + } + return 0; } -- 2.7.4 From 0823f4e0eccc27a381c966290f99bd6213a05f12 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Tue, 7 Feb 2023 15:53:24 +0900 Subject: [PATCH 08/16] plugin-api: common: Add plugin-api-common plugin-api was added to provide plugin feature. Plugin separates target-specific code to plugin-backend from common Tizen codes such as deviced or resourced. The structure of plugin-api is based on the hal-api. The files newly created during build due to this patch are as follows: (arch=armv7l) plugin-api-common-0.1.0-0.armv7l.rpm * /usr/lib/: libplugin-api-common.so.0 -> libplugin-api-common.so.0.1.0 * /usr/lib/: libplugin-api-common.so.0.1.0 * /usr/share/licenses/plugin-api-common: LICENSE.MIT plugin-api-common-debuginfo-0.1.0-0.armv7l * /usr/lib/debug/usr/lib: libplugin-api-common.so.0.1.0.debug libsyscommon-debugsource-5.0.0-0.armv7l.rpm * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/common/include: plugin-common.h * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/common/include: plugin-common-interface.h * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/common/src: plugin-api-list.h * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/common/src: plugin-api-conf.c * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/common/src: plugin-api-conf.h * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/common/src: common.h * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/common/src: plugin-api-common.c plugin-api-common-devel-0.1.0-0.armv7l * /usr/include/plugin: plugin-common.h * /usr/include/plugin: plugin-common-interface.h * /usr/lib/: libplugin-api-common.so -> libplugin-api-common.so.0 * /usr/lib/pkgconfig/plugin-api-common.pc * /usr/share/licenses/plugin-api-common: LICENSE.MIT Change-Id: I3c0b385d7bd76b82db8db73beb189b78009b8774 Signed-off-by: SangYoun Kwak --- CMakeLists.txt | 1 + packaging/libsyscommon.spec | 47 +- src/plugin-api/common/CMakeLists.txt | 62 ++ .../common/include/plugin-common-interface.h | 56 ++ src/plugin-api/common/include/plugin-common.h | 153 +++++ src/plugin-api/common/plugin-api-common.pc.in | 16 + src/plugin-api/common/src/common.h | 127 ++++ src/plugin-api/common/src/plugin-api-common.c | 724 +++++++++++++++++++++ src/plugin-api/common/src/plugin-api-conf.c | 181 ++++++ src/plugin-api/common/src/plugin-api-conf.h | 48 ++ src/plugin-api/common/src/plugin-api-list.h | 60 ++ 11 files changed, 1474 insertions(+), 1 deletion(-) create mode 100644 src/plugin-api/common/CMakeLists.txt create mode 100644 src/plugin-api/common/include/plugin-common-interface.h create mode 100644 src/plugin-api/common/include/plugin-common.h create mode 100644 src/plugin-api/common/plugin-api-common.pc.in create mode 100644 src/plugin-api/common/src/common.h create mode 100644 src/plugin-api/common/src/plugin-api-common.c create mode 100644 src/plugin-api/common/src/plugin-api-conf.c create mode 100644 src/plugin-api/common/src/plugin-api-conf.h create mode 100644 src/plugin-api/common/src/plugin-api-list.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ce20dbf..3e46332 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ PROJECT(libsyscommon C) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared) +ADD_SUBDIRECTORY(src/plugin-api/common) # ADD_SUBDIRECTORY(src/libgdbus) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 41bf65c..c46cffa 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,3 +1,5 @@ +%define plugin_api_common_version 0.1.0 + Name: libsyscommon Summary: System Libraries Version: 5.0.0 @@ -41,7 +43,11 @@ Development header files for system common library. cp %{SOURCE1001} . %build -%cmake . -DFULLVER=%{version} +PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) +%cmake . -DFULLVER=%{version} \ + -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ + -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ + -DPLUGIN_API_COMMON_ENABLE_DLOG=1 make %{?_smp_mflags} %install @@ -69,3 +75,42 @@ touch debugsources.list %{_libdir}/libsyscommon.so %{_includedir}/libsyscommon/*.h %{_libdir}/pkgconfig/libsyscommon.pc + +# Packages for plugin-api +%package -n plugin-api-common +Summary: Common plugin APIs +Version: %{plugin_api_common_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-common +Common plugin APIs to load another APIs from backend. + +%files -n plugin-api-common +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_libdir}/libplugin-api-common.so.* + +%post -n plugin-api-common +pushd %{_libdir} +chsmack -a "_" libplugin-api-common.so.%{plugin_api_common_version} +popd +/sbin/ldconfig + +%package -n plugin-api-common-devel +Summary: Header files for common plugin APIs +Version: %{plugin_api_common_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-common-devel +Development header files for common plugin APIs. + +%files -n plugin-api-common-devel +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_includedir}/plugin/plugin-common*.h +%{_libdir}/pkgconfig/plugin-api-common.pc +%{_libdir}/libplugin-api-common.so diff --git a/src/plugin-api/common/CMakeLists.txt b/src/plugin-api/common/CMakeLists.txt new file mode 100644 index 0000000..326139c --- /dev/null +++ b/src/plugin-api/common/CMakeLists.txt @@ -0,0 +1,62 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(plugin-api-common) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(VERSION ${PLUGIN_API_COMMON_VERSION}) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) + +if (${PLUGIN_API_COMMON_ENABLE_DLOG}) + ADD_DEFINITIONS("-DENABLE_DLOG=1") + ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_COMMON\"") + SET(PKG_MODULES + dlog + gio-2.0 + glib-2.0 + ) +else() + SET(PKG_MODULES + gio-2.0 + glib-2.0 + ) +endif() + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") +SET(CMAKE_EXE_LINKER_FLAGS "-pie") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +SET(SRCS + src/plugin-api-common.c + src/plugin-api-conf.c) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} + -ldl -Wl,-z,nodelete,--no-undefined) + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PLUGIN_API_COMMON_MAJORVER}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${INCLUDEDIR} + FILES_MATCHING PATTERN "*.h") + +# CONFIGURE .pc FILE +FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) + SET(PLUGIN_COMMON_INCLUDEDIR "${PLUGIN_COMMON_INCLUDEDIR} -I${include_dirs}") +ENDFOREACH(include_dirs) +FOREACH(libraries ${pkgs_LIBRARIES}) + SET(PLUGIN_COMMON_LIBS "${PLUGIN_COMMON_LIBS} -l${libraries}") +ENDFOREACH(libraries) +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/common/include/plugin-common-interface.h b/src/plugin-api/common/include/plugin-common-interface.h new file mode 100644 index 0000000..37f201a --- /dev/null +++ b/src/plugin-api/common/include/plugin-common-interface.h @@ -0,0 +1,56 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_COMMON_INTERFACE__ +#define __PLUGIN_COMMON_INTERFACE__ + +#ifdef __cplusplus +extern "C" { +#endif + +enum plugin_abi_version { + PLUGIN_ABI_VERSION_UNKNOWN = 0, + PLUGIN_ABI_VERSION_TIZEN_7_0, + PLUGIN_ABI_VERSION_TIZEN_7_5, + PLUGIN_ABI_VERSION_END, +}; + +static const char *const plugin_abi_version_str[] = { + [PLUGIN_ABI_VERSION_UNKNOWN] = "Unknown PLUGIN ABI Version", + [PLUGIN_ABI_VERSION_TIZEN_7_0] = "PLUGIN_ABI_VERSION_TIZEN_7_0", + [PLUGIN_ABI_VERSION_TIZEN_7_5] = "PLUGIN_ABI_VERSION_TIZEN_7_5", +}; + +typedef struct __plugin_backend { + const char *name; + const char *vendor; + const unsigned int abi_version; + int (*init) (void **data); + int (*exit) (void *data); +} plugin_backend; + +#ifdef __cplusplus +} +#endif +#endif /* __PLUGIN_COMMON_INTERFACE__ */ diff --git a/src/plugin-api/common/include/plugin-common.h b/src/plugin-api/common/include/plugin-common.h new file mode 100644 index 0000000..d7856bc --- /dev/null +++ b/src/plugin-api/common/include/plugin-common.h @@ -0,0 +1,153 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_COMMON__ +#define __PLUGIN_COMMON__ + +#include "plugin-common-interface.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum plugin_module { + PLUGIN_MODULE_UNKNOWN = 0, + PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + PLUGIN_MODULE_END, +}; + +/** + * @brief Get the backend library name according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[out] Backend Library name of PLUGIN module + * @param[in] Arrary size of name[] + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_get_backend_library_name(enum plugin_module module, char *name, int size); + +/** + * @brief Get the backend symbol name according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[out] Backend symbol name of PLUGIN module + * @param[in] Arrary size of name[] + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int size); + +/** + * @brief Get the backend data according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[out] Data pointer where 'plugin_backend_[module]_funcs' instance + * should be stored from PLUGIN backend binary. + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_get_backend(enum plugin_module module, void **data); + +/** + * @brief Put the backend data according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[in] Data pointer where 'plugin_backend_[module]_funcs' instance + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_put_backend(enum plugin_module module, void *data); + +/** + * @brief Get the backend data with the specific library name according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[out] Data pointer where 'plugin_backend_[module]_funcs' instance + * should be stored from PLUGIN backend binary. + * @param[in] PLUGIN backend library name which is not default library name + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_get_backend_with_library_name(enum plugin_module module, + void **data, const char *library_name); + +/** + * @brief Put the backend data with the specific library name according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[in] Data pointer where 'plugin_backend_[module]_funcs' instance + * @param[in] PLUGIN backend library name which is not default library name + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_put_backend_with_library_name(enum plugin_module module, + void *data, const char *library_name); + +/** + * @brief Check PLUGIN ABI version whehter is suppored or not on current platform + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[in] PLUGIN ABI version of backend module among enum plugin_abi_version + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_check_backend_abi_version(enum plugin_module module, + enum plugin_abi_version abi_version); + +/** + * @brief Get the backend PLUGIN ABI version according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @return @c positive integer value on success, otherwise a zero error value + */ +unsigned int plugin_common_get_backend_abi_version(enum plugin_module module); + +/** + * @brief Get the backend name according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[out] Backend name of PLUGIN module + * @param[in] Arrary size of name[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int plugin_common_get_backend_name(enum plugin_module module, char *name, int size); + +/** + * @brief Get the backend vendor description according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[out] Backend vendor description of PLUGIN module + * @param[in] Arrary size of vendor[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int plugin_common_get_backend_vendor(enum plugin_module module, char *vendor, int size); + +/** + * @brief Get the number of the backend libraries according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_get_backend_count(enum plugin_module module); + +/** + * @brief Get the backend library names according to the type of PLUGIN module + * @param[in] PLUGIN module id among enum plugin_moudle + * @param[out] Data pointer should be filled by backend library names + * @param[in] Number of backend library of specific PLUGIN module + * @param[in] Maximum length of the library name + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_common_get_backend_library_names(enum plugin_module module, + char **library_names, + int library_count, + int library_name_size); + +#ifdef __cplusplus +} +#endif +#endif /* __PLUGIN_COMMON__ */ diff --git a/src/plugin-api/common/plugin-api-common.pc.in b/src/plugin-api/common/plugin-api-common.pc.in new file mode 100644 index 0000000..4738a7f --- /dev/null +++ b/src/plugin-api/common/plugin-api-common.pc.in @@ -0,0 +1,16 @@ +# Package Information for pkg-config +# +# Copyright (c) 2023 Samsung Electronics Co., Ltd. +# All rights reserved. +# + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: plugin-api-common +Description: Common plugin APIs +Version: @VERSION@ +Cflags: -I${includedir} @PLUGIN_COMMON_INCLUDEDIR@ +Libs: -L${libdir} -lplugin-api-common @PLUGIN_COMMON_LIBS@ diff --git a/src/plugin-api/common/src/common.h b/src/plugin-api/common/src/common.h new file mode 100644 index 0000000..33e4560 --- /dev/null +++ b/src/plugin-api/common/src/common.h @@ -0,0 +1,127 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#include + +#include "plugin-common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef ENABLE_DLOG +#include + +#define _D(fmt, args...) SLOGD(fmt, ##args) +#define _I(fmt, args...) SLOGI(fmt, ##args) +#define _W(fmt, args...) SLOGW(fmt, ##args) +#define _E(fmt, args...) SLOGE(fmt, ##args) +#else +#define _D(fmt, args...) do { } while(0) +#define _I(fmt, args...) do { } while(0) +#define _W(fmt, args...) do { } while(0) +#define _E(fmt, args...) do { } while(0) +#endif + +#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) + +enum plugin_license { + PLUGIN_LICENSE_UNKNOWN = 0, + PLUGIN_LICENSE_APACHE_2_0, + PLUGIN_LICENSE_FLORA, + PLUGIN_LICENSE_MIT, + PLUGIN_LICENSE_END, +}; + +enum plugin_group { + PLUGIN_GROUP_UNKNOWN = 0, + PLUGIN_GROUP_RESOURCED, + PLUGIN_GROUP_DEVICED, + PLUGIN_GROUP_END, +}; + +static const char *const plugin_group_string[] = { + [PLUGIN_GROUP_UNKNOWN] = "PLUGIN_GROUP_UNKNOWN", + [PLUGIN_GROUP_RESOURCED] = "PLUGIN_GROUP_RESOURCED", + [PLUGIN_GROUP_DEVICED] = "PLUGIN_GROUP_DEVICED", +}; + +/** + * plugin-api-common provides the PLUGIN ABI * (Application Binary Interface) + * version check feature which is used to check the ABI compatibility between + * PLUGIN API package and PLUGIN backend package. + * In order to compare ABI version between two binary, Tizen core platform + * always must maintain the current PLUGIN ABI version. + * So that, define the below global variable (g_platform_curr_abi_version). + * + * 'g_platform_curr_abi_version' will be used for all PLUGIN API modules, + * to check whether PLUGIN backend ABI version of each module is supported + * or not with current PLUGIN ABI version. + * + * 'g_platform_curr_abi_version' must be updated when Tizen platform will be + * released officially. + */ +struct plugin_abi_version_match { + enum plugin_abi_version platform_abi_version; + enum plugin_abi_version backend_min_abi_version; +}; + +struct __plugin_module_info { + int usage_count; + + enum plugin_group group; + enum plugin_module module; + enum plugin_license license; + char *module_name; + char *backend_module_name; + + char *library_name; + char *library_name_64bit; + void *handle; + plugin_backend *backend; + char *symbol_name; + + unsigned int num_abi_versions; + struct plugin_abi_version_match *abi_versions; +}; + +static inline const char* get_backend_library_name(struct __plugin_module_info *info) +{ + if (!info) + return NULL; + +#if defined(__aarch64__) || defined(__x86_64__) + return info->library_name_64bit; +#else + return info->library_name; +#endif +} + +#ifdef __cplusplus +} +#endif +#endif /* __COMMON_H__ */ diff --git a/src/plugin-api/common/src/plugin-api-common.c b/src/plugin-api/common/src/plugin-api-common.c new file mode 100644 index 0000000..0f5dcc6 --- /dev/null +++ b/src/plugin-api/common/src/plugin-api-common.c @@ -0,0 +1,724 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define _GNU_SOURCE +#include + +#include + +#include "common.h" +#include "plugin-api-conf.h" + +extern char *program_invocation_name; + +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility("default"))) +#endif + +static enum plugin_abi_version g_platform_curr_abi_version; +G_LOCK_DEFINE_STATIC(plugin_common_lock); + +EXPORT +int plugin_common_get_backend_library_name(enum plugin_module module, char *name, int size) +{ + const char *library_name = NULL; + struct __plugin_module_info *info = NULL; + int ret; + int len_library_name; + + /* Check parameter whether is valid or not */ + if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + _E("Invalid parameter of PLUGIN module (%d)\n", module); + return -EINVAL; + } + + if (_plugin_api_conf_init()) + return -EINVAL; + + info = _plugin_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get PLUGIN module(%d) information\n", module); + ret = -EINVAL; + goto out; + } + + library_name = get_backend_library_name(info); + if (!library_name) { + _E("%s backend library name is NULL\n", info->module_name); + ret = 0; + goto out; + } + + len_library_name = strlen(library_name); + if (!name || (len_library_name + 1 > size)) { + ret = -EINVAL; + name = NULL; + goto out; + } + strncpy(name, library_name, size); + + ret = 0; +out: + _plugin_api_conf_exit(); + + return ret; +} + +EXPORT +int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int size) +{ + struct __plugin_module_info *info = NULL; + char *symbol_name = NULL; + int ret; + int len_symbol_name; + + /* Check parameter whether is valid or not */ + if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + _E("Invalid paramer of PLUGIN module (%d)\n", module); + return -EINVAL; + } + + if (_plugin_api_conf_init()) + return -EINVAL; + + info = _plugin_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get PLUGIN module(%d) information\n", module); + ret = -EINVAL; + goto out; + } + symbol_name = info->symbol_name; + if (!symbol_name) { + _E("%s backend symbol name is NULL\n", info->module_name); + ret = 0; + goto out; + } + + len_symbol_name = strlen(symbol_name); + if (!name || (len_symbol_name + 1 > size)) { + ret = -EINVAL; + name = NULL; + goto out; + } + strncpy(name, symbol_name, size); + + ret = 0; +out: + _plugin_api_conf_exit(); + + return ret; +} + +static int __open_backend(struct __plugin_module_info *info) +{ + const char *backend_library_name = NULL; + int ret; + + if (info->backend && info->handle) + return 0; + + backend_library_name = get_backend_library_name(info); + if (!backend_library_name) { + _E("%s: Failed to get backend library name\n", + info->module_name); + ret = -EINVAL; + goto err; + } + + if (access(backend_library_name, F_OK) == -1) { + _I("%s: There is no backend library\n", + info->module_name); + ret = -ENOENT; + goto err; + } + + if (!info->symbol_name) { + _E("%s: Failed to get backend symbol name\n", + info->module_name); + ret = -EINVAL; + goto err; + } + + info->handle = dlopen(backend_library_name, RTLD_LAZY); + if (!info->handle) { + _E("%s: Failed to load backend library (%s)\n", + info->module_name, dlerror()); + ret = -EINVAL; + goto err; + } + + info->backend = dlsym(info->handle, info->symbol_name); + if (!info->backend) { + _E("%s: Failed to find backend data (%s)\n", + info->module_name, dlerror()); + ret = -EINVAL; + goto err_dlclose; + } + + _I("%s: Open PLUGIN backend: name(%s)|vendor(%s)|library(%s)|count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + backend_library_name, info->usage_count, + program_invocation_name); + + return 0; + +err_dlclose: + dlclose(info->handle); +err: + info->backend = NULL; + info->handle = NULL; + + return ret; +} + +static void __close_backend(struct __plugin_module_info *info) +{ + if (!info->backend || !info->handle) + return; + + _I("%s: Close PLUGIN backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + get_backend_library_name(info), info->usage_count, + program_invocation_name); + + if (info->handle) + dlclose(info->handle); + + info->backend = NULL; + info->handle = NULL; +} + +static int __init_backend(struct __plugin_module_info *info, void **data, + const char *library_name) +{ + int ret; + + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + return 0; + } + + if (!info->backend->init) { + _E("%s: plugin_backend->init() is NULL\n", info->module_name); + return -EINVAL; + } + + /* Check PLUGIN ABI Version */ + ret = plugin_common_check_backend_abi_version(info->module, + info->backend->abi_version); + if (ret < 0) { + _E("%s: Failed to check ABI version\n", info->module_name); + return -EINVAL; + } + + /* Initialize backend */ + ret = info->backend->init(data); + if (ret < 0) { + _E("%s: Failed to initialize backend: name(%s)/vendor(%s)\n", + info->module_name, info->backend->name, + info->backend->vendor); + return -EINVAL; + } + + return 0; +} + +static int __exit_backend(struct __plugin_module_info *info, void *data, + const char *library_name) +{ + int ret; + + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + return 0; + } + + /* Exit backend */ + if (info->backend->exit) { + ret = info->backend->exit(data); + if (ret < 0) { + _E("%s: Failed to exit backend: name(%s)/vendor(%s)\n", + info->module_name, info->backend->name, + info->backend->vendor); + return -EINVAL; + } + } + + return 0; +} + +static int __get_backend(enum plugin_module module, void **data, + const char *library_name) +{ + struct __plugin_module_info *info = NULL; + int ret; + + if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + _E("Invalid parameter of PLUGIN module (%d)\n", module); + return -EINVAL; + } + + G_LOCK(plugin_common_lock); + if (_plugin_api_conf_init()) { + ret = -EINVAL; + goto err; + } + + info = _plugin_api_conf_get_module_info(module, library_name); + if (info == NULL) { + if (!library_name) + _E("Failed to get PLUGIN module(%d) information\n", module); + else + _E("Failed to get PLUGIN module(%d) information (%s)\n", + module, library_name); + ret = -EINVAL; + goto err; + } + + ret = __open_backend(info); + if (ret < 0) + goto err; + + ret = __init_backend(info, data, NULL); + if (ret < 0) { + _E("%s: Failed to initialize the backend library\n", + info->module_name); + ret = -EINVAL; + goto err_dlclose; + } + + info->usage_count++; + + _I("%s: Get PLUGIN backend: name(%s)|vendor(%s)|library(%s)|count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + get_backend_library_name(info), info->usage_count, + program_invocation_name); + + G_UNLOCK(plugin_common_lock); + return 0; + +err_dlclose: + __close_backend(info); + _plugin_api_conf_exit(); +err: + G_UNLOCK(plugin_common_lock); + return ret; +} + +static int __put_backend(enum plugin_module module, void *data, + const char *library_name) +{ + struct __plugin_module_info *info = NULL; + int ret; + + /* Check parameter whether is valid or not */ + if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + _E("Invalid parameter of PLUGIN module (%d)\n", module); + return -EINVAL; + } + + G_LOCK(plugin_common_lock); + + info = _plugin_api_conf_get_module_info(module, library_name); + if (info == NULL) { + _E("Failed to get PLUGIN module(%d) information\n", module); + ret = -EINVAL; + goto out; + } + + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + ret = 0; + goto out; + } + + if (!info->usage_count) { + _I("%s: Already fully put for PLUGIN module\n", info->module_name); + ret = 0; + goto out; + } + + ret = __exit_backend(info, data, NULL); + if (ret < 0) { + _E("%s: Failed to exit the backend library\n", + info->module_name); + ret = -EINVAL; + goto out; + } + + info->usage_count--; + + _I("%s: Put PLUGIN backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + get_backend_library_name(info), info->usage_count, + program_invocation_name); + + if (info->usage_count > 0) { + ret = 0; + goto out; + } + + __close_backend(info); + _plugin_api_conf_exit(); + + ret = 0; + +out: + G_UNLOCK(plugin_common_lock); + return ret; +} + +static int __get_backend_data(enum plugin_module module, unsigned int *abi_version, + char *name, int name_size, char *vendor, int vendor_size) +{ + struct __plugin_module_info *info = NULL; + int ret, len; + + if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + _E("Invalid parameter of PLUGIN module (%d)\n", module); + return 0; + } + + G_LOCK(plugin_common_lock); + + if (_plugin_api_conf_init()) { + ret = PLUGIN_ABI_VERSION_UNKNOWN; + goto err_unlock; + } + + info = _plugin_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get PLUGIN module(%d) information\n", module); + ret = PLUGIN_ABI_VERSION_UNKNOWN; + goto err_conf_exit; + } + + ret = __open_backend(info); + if (ret < 0) + goto err_conf_exit; + + /* Return abi_verion of plugin_backend structure */ + if (!name_size && !vendor_size) { + *abi_version = info->backend->abi_version; + + /* Return name of plugin_backend structure */ + } else if (info->backend->name && name_size && !vendor_size) { + len = strlen(info->backend->name); + + if (!info->backend->name || (len + 1 > name_size)) { + _E("%s: Invalid size of name[] array\n", info->module_name); + ret = -EINVAL; + goto err_conf_exit; + } + + strncpy(name, info->backend->name, name_size); + + /* Return vendor of plugin_backend structure */ + } else if (info->backend->vendor && !name_size && vendor_size) { + len = strlen(info->backend->vendor); + + if (!info->backend->vendor || (len + 1 > vendor_size)) { + _E("%s: Invalid size of vendor[] array\n", info->module_name); + ret = -EINVAL; + goto err_conf_exit; + } + + strncpy(vendor, info->backend->vendor, vendor_size); + } else { + _E("%s: Failed to get backend data\n", info->module_name); + ret = -EINVAL; + goto err_conf_exit; + } + ret = 0; + +err_conf_exit: + _plugin_api_conf_exit(); +err_unlock: + G_UNLOCK(plugin_common_lock); + return ret; +} + +EXPORT +int plugin_common_get_backend(enum plugin_module module, void **data) +{ + return __get_backend(module, data, NULL); +} + +EXPORT +int plugin_common_put_backend(enum plugin_module module, void *data) +{ + return __put_backend(module, data, NULL); +} + +EXPORT +int plugin_common_get_backend_with_library_name(enum plugin_module module, + void **data, const char *library_name) +{ + return __get_backend(module, data, library_name); +} + +EXPORT +int plugin_common_put_backend_with_library_name(enum plugin_module module, + void *data, const char *library_name) +{ + return __put_backend(module, data, library_name); +} + +EXPORT +int plugin_common_check_backend_abi_version(enum plugin_module module, + enum plugin_abi_version abi_version) +{ + struct __plugin_module_info *info = NULL; + int i; + int ret; + + /* Check parameter whether is valid or not */ + if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + _E("Invalid paramer of PLUGIN module(%d)\n", module); + return -EINVAL; + } + + if (abi_version <= PLUGIN_ABI_VERSION_UNKNOWN + || abi_version >= PLUGIN_ABI_VERSION_END) { + _E("Invalid paramer of PLUGIN ABI version(%d) for PLUGIN module(%d)\n", + abi_version, module); + return -EINVAL; + } + + if (_plugin_api_conf_init()) + return -EINVAL; + + info = _plugin_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get PLUGIN module(%d) information\n", module); + ret = -EINVAL; + goto out; + } + + if (!info->num_abi_versions + || !info->abi_versions) { + _E("%s: Doesn't have the ABI version information\n", + info->module_name); + ret = -EINVAL; + goto out; + } + + g_platform_curr_abi_version = _plugin_api_conf_get_platform_abi_version(); + + if (g_platform_curr_abi_version <= PLUGIN_ABI_VERSION_UNKNOWN + || g_platform_curr_abi_version >= PLUGIN_ABI_VERSION_END) { + _E("Invalid paramer of current PLUGIN ABI version(%d)(%d)\n", + g_platform_curr_abi_version, module); + ret = -EINVAL; + goto out; + } + + for (i = 0; i < info->num_abi_versions; i++) { + struct plugin_abi_version_match *data + = &info->abi_versions[i]; + + if (g_platform_curr_abi_version != data->platform_abi_version) + continue; + + if (data->backend_min_abi_version <= PLUGIN_ABI_VERSION_UNKNOWN || + data->backend_min_abi_version >= PLUGIN_ABI_VERSION_END) { + _E("%s: abi_versions[%d].backend_min_abi_version(%d) is invalid\n", + info->module_name, i, data->backend_min_abi_version); + ret = -EINVAL; + goto out; + } + + if (abi_version <= data->platform_abi_version + && abi_version >= data->backend_min_abi_version) { + ret = 0; + goto out; + } + + _E("%s: \'%s\' doesn't support \'%s\'\n", + info->module_name, + plugin_abi_version_str[g_platform_curr_abi_version], + plugin_abi_version_str[abi_version]); + _E("%s: Must use ABI versions from \'%s\' to \'%s\'\n", + info->module_name, + plugin_abi_version_str[data->backend_min_abi_version], + plugin_abi_version_str[data->platform_abi_version]); + } + ret = -EINVAL; + +out: + _plugin_api_conf_exit(); + return ret; +} + +EXPORT +unsigned int plugin_common_get_backend_abi_version(enum plugin_module module) +{ + unsigned int abi_version; + int ret; + + ret = __get_backend_data(module, &abi_version, NULL, 0, NULL, 0); + if (ret < 0) + return PLUGIN_ABI_VERSION_UNKNOWN; + + return abi_version; +} + +EXPORT +int plugin_common_get_backend_name(enum plugin_module module, char *name, int size) +{ + return __get_backend_data(module, NULL, name, size, NULL, 0); +} + +EXPORT +int plugin_common_get_backend_vendor(enum plugin_module module, char *vendor, int size) +{ + return __get_backend_data(module, NULL, NULL, 0, vendor, size); +} + + +static int __get_backend_library_data(enum plugin_module module, + char **lib_names, + int lib_count, + int lib_name_size) +{ + struct __plugin_module_info *info = NULL; + struct dirent *de; + DIR *dir; + char *backend_module_name = NULL; + int count, i, ret; +#if defined(__aarch64__) || defined(__x86_64__) + const char plugin_backend_path[] = "/usr/lib64/plugin"; +#else + const char plugin_backend_path[] = "/usr/lib/plugin"; +#endif + + /* Check if lib_names and lib_count are valid */ + assert(!(lib_names == NULL && lib_count != 0)); + + /* Check parameter whether is valid or not */ + if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + _E("Invalid parameter of PLUGIN module (%d)\n", module); + return -EINVAL; + } + + if (_plugin_api_conf_init()) + return -EINVAL; + + info = _plugin_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get PLUGIN module(%d) information\n", module); + ret = -EINVAL; + goto err; + } + + if (info->backend_module_name == NULL) { + _E("Don't support PLUGIN backend of PLUGIN module(%s)\n", + info->module_name); + ret = -EINVAL; + goto err; + } + backend_module_name = g_strdup_printf("libplugin-backend-%s", + info->backend_module_name); + if (!backend_module_name) { + _E("Failed to allocate the backend_module_name of PLUGIN module(%s)\n", + info->module_name); + ret = -EINVAL; + goto err; + } + + /* Find PLUGIN backend libraries */ + dir = opendir(plugin_backend_path); + if (!dir) { + _E("Failed to find PLUGIN backend path(%s) for PLUGIN module(%s)\n", + plugin_backend_path, info->module_name); + ret = -EINVAL; + goto err_free_backend_module_name; + } + + count = 0; + while ((de = readdir(dir)) != NULL) { + if (!g_str_has_prefix(de->d_name, backend_module_name)) + continue; + + if (lib_count == 0) { + ++count; + continue; + } + + if (lib_count > 0) { + strncpy(lib_names[count], de->d_name, lib_name_size - 1); + lib_names[count][lib_name_size - 1] = '\0'; + + ++count; + continue; + } + } + + if (lib_count > 0 && count != lib_count) { + ret = -EINVAL; + goto err_mismatch_count; + } + + closedir(dir); + _plugin_api_conf_exit(); + g_free(backend_module_name); + + return count; + +err_mismatch_count: + for (i = count - 1; i >= 0; i--) + memset(lib_names[i], 0, strlen(lib_names[i])); + + closedir(dir); +err_free_backend_module_name: + g_free(backend_module_name); +err: + _plugin_api_conf_exit(); + return ret; +} + +EXPORT +int plugin_common_get_backend_count(enum plugin_module module) +{ + return __get_backend_library_data(module, NULL, 0, 0); +} + +EXPORT +int plugin_common_get_backend_library_names(enum plugin_module module, + char **library_names, + int library_count, + int library_name_size) +{ + int ret = __get_backend_library_data(module, library_names, + library_count, library_name_size); + return (ret < 0) ? ret : 0; +} diff --git a/src/plugin-api/common/src/plugin-api-conf.c b/src/plugin-api/common/src/plugin-api-conf.c new file mode 100644 index 0000000..bb560a2 --- /dev/null +++ b/src/plugin-api/common/src/plugin-api-conf.c @@ -0,0 +1,181 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include +#include + +#include "plugin-common.h" +#include "plugin-common-interface.h" + +#include "common.h" +#include "plugin-api-conf.h" +#include "plugin-api-list.h" + +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility("default"))) +#endif + +static GHashTable *_module_hash = NULL; + +static int _usage_count = 0; + +EXPORT +void _destroy_module_info(gpointer data) +{ + struct __plugin_module_info *info = (struct __plugin_module_info *)data; + + if (info) { + free(info->module_name); + free(info->backend_module_name); + free(info->library_name); + free(info->library_name_64bit); + free(info->symbol_name); + free(info); + } +} + +static struct __plugin_module_info* _get_module_info(enum plugin_module module) +{ + return &g_plugin_module_info[module]; +} + +static struct __plugin_module_info* _get_module_info_with_library_name(enum plugin_module module, + const char *library_name) +{ + struct __plugin_module_info *info = NULL, *new_info = NULL, *tmp_info = NULL; + char *library_name_prefix = NULL; + + if (!_module_hash || !library_name) + return NULL; + + tmp_info = _get_module_info(module); + if (tmp_info == NULL) { + _E("Failed to get PLUGIN module(%d) information\n", module); + return NULL; + } + + if (tmp_info->backend_module_name == NULL) { + _E("Don't support PLUGIN backend of PLUGIN module(%s)\n", + tmp_info->module_name); + return NULL; + } + library_name_prefix = g_strdup_printf("libplugin-backend-%s", + tmp_info->backend_module_name); + if (!library_name_prefix) { + _E("Failed to allocate library_name_prefix of PLUGIN module(%s)\n", + tmp_info->module_name); + return NULL; + } + + if (!g_str_has_prefix(library_name, library_name_prefix)) { + _E("Invalid library name(%s) of PLUGIN module(%s)\n", + library_name, tmp_info->module_name); + goto out; + } + + /* Find module info with the passed library name */ + info = (struct __plugin_module_info*)g_hash_table_lookup(_module_hash, + (gpointer)library_name); + if (info) { + g_free(library_name_prefix); + return info; + } + + /* Create new module info with the passed library name */ + info = tmp_info; + + new_info = (struct __plugin_module_info *)calloc(1, + sizeof(struct __plugin_module_info)); + if (new_info == NULL) { + _E("Failed to allocate the memory\n"); + goto out; + } + + new_info->usage_count = 0; + new_info->group = info->group; + new_info->module = info->module; + new_info->license = info->license; + new_info->module_name = g_strdup(info->module_name); +#if defined(__aarch64__) || defined(__x86_64__) + new_info->library_name_64bit = g_strdup_printf("/usr/lib64/plugin/%s", library_name); +#else + new_info->library_name = g_strdup_printf("/usr/lib/plugin/%s", library_name); +#endif + new_info->symbol_name = g_strdup(info->symbol_name); + new_info->num_abi_versions = info->num_abi_versions; + new_info->abi_versions = info->abi_versions; + + g_hash_table_insert(_module_hash, (gpointer)library_name, new_info); + +out: + g_free(library_name_prefix); + + return new_info; +} + +EXPORT +struct __plugin_module_info* _plugin_api_conf_get_module_info(enum plugin_module module, + const char *library_name) +{ + if (!_module_hash) + return NULL; + + if (!library_name) + return _get_module_info(module); + else + return _get_module_info_with_library_name(module, library_name); +} + + +enum plugin_abi_version _plugin_api_conf_get_platform_abi_version(void) +{ + return g_platform_curr_abi_version; +} + +EXPORT +int _plugin_api_conf_init(void) +{ + if (_usage_count++ > 0) + return 0; + + _module_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _destroy_module_info); + + return 0; +} + +EXPORT +void _plugin_api_conf_exit(void) +{ + _usage_count--; + if (_usage_count != 0) + return; + + if (_module_hash) { + g_hash_table_remove_all(_module_hash); + g_hash_table_unref(_module_hash); + _module_hash = NULL; + } +} diff --git a/src/plugin-api/common/src/plugin-api-conf.h b/src/plugin-api/common/src/plugin-api-conf.h new file mode 100644 index 0000000..2d59713 --- /dev/null +++ b/src/plugin-api/common/src/plugin-api-conf.h @@ -0,0 +1,48 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_API_CONF__ +#define __PLUGIN_API_CONF__ + +#include +#include + +#include "plugin-common-interface.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +int _plugin_api_conf_init(void); +void _plugin_api_conf_exit(void); + +struct __plugin_module_info *_plugin_api_conf_get_module_info(enum plugin_module module, + const char *library_name); + +enum plugin_abi_version _plugin_api_conf_get_platform_abi_version(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __PLUGIN_API_CONF__ */ diff --git a/src/plugin-api/common/src/plugin-api-list.h b/src/plugin-api/common/src/plugin-api-list.h new file mode 100644 index 0000000..79439fb --- /dev/null +++ b/src/plugin-api/common/src/plugin-api-list.h @@ -0,0 +1,60 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_API_LIST_H__ +#define __PLUGIN_API_LIST_H__ + +#include "plugin-common.h" + +#include "common.h" + +#define PLUGIN_ABI_VERSION_MAX 10 + +enum plugin_abi_version g_platform_curr_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5; + +static struct plugin_abi_version_match abi_version_match_data[PLUGIN_MODULE_END][PLUGIN_ABI_VERSION_MAX] = { + [PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { + [0] = { + .platform_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, + .backend_min_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, + }, + }, +}; + +static struct __plugin_module_info g_plugin_module_info[] = { + [PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { + .group = PLUGIN_GROUP_RESOURCED, + .module = PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + .license = PLUGIN_LICENSE_APACHE_2_0, + .module_name = "PLUGIN_MODULE_RESOURCED_MEMORY_LMK", + .backend_module_name = "resourced-memory-lmk", + .library_name = "/usr/lib/plugin/libplugin-backend-resourced-memory-lmk.so", + .library_name_64bit = "/usr/lib64/plugin/libplugin-backend-resourced-memory-lmk.so", + .symbol_name = "plugin_backend_resourced_memory_lmk_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[PLUGIN_MODULE_RESOURCED_MEMORY_LMK]), + .abi_versions = abi_version_match_data[PLUGIN_MODULE_RESOURCED_MEMORY_LMK], + }, +}; + +#endif /* __PLUGIN_API_LIST_H__ */ -- 2.7.4 From c6c3558f85a54dc978f45a715cb2cb681a0fff2f Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Wed, 8 Feb 2023 19:59:30 +0900 Subject: [PATCH 09/16] plugin-api: resourced: Add plugin-api-resourced This plugin api provides functions for resourced. Provided functions: * plugin_resourced_low_memory_killer_get_backend: get backend library * plugin_resourced_low_memory_killer_put_backend: put backend library * plugin_resourced_low_memory_killer_get_kill_candidates: choose kill candidates from procs/apps list. The files newly created during build due to this patch are as follows: (arch=armv7l) plugin-api-resourced-0.1.0-0.armv7l.rpm * /usr/lib: libplugin-api-resourced.so.0 -> libplugin-api-resourced.so.0.1.0 * /usr/lib: libplugin-api-resourced.so.0.1.0 * /usr/share/licenses/plugin-api/resourced: LICENSE.MIT plugin-api-resourced-debuginfo-0.1.0-0.armv7l.rpm * /usr/lib/debug/usr/lib/libplugin-api-resourced.so.0.1.0.debug libsyscommon-debugsource-5.0.0-0.armv7l.rpm * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/resourced/include: plugin-resourced-memory-lmk-interface.h * /usr/src/debug/libsyscommon-5.0.0-0.arm/src/plugin-api/resourced/src: plugin-resourced-memory-lmk.c plugin-api-resourced-devel-0.1.0-0.armv7l.rpm * /usr/include/plugin: plugin-resourced-memory-lmk.h * /usr/include/plugin: plugin-resourced-memory-lmk-interface.h * /usr/lib: libplugin-api-resourced.so -> libplugin-api-resourced.so.0 * /usr/lib/pkgconfig: plugin-api-resourced.pc * /usr/share/licenses/plugin-api/resourced: LICENSE.MIT Change-Id: I3f9c2deac1220131df5bb8a3db502b40dc1bdd72 Signed-off-by: SangYoun Kwak --- CMakeLists.txt | 1 + packaging/libsyscommon.spec | 45 ++++++++- src/plugin-api/resourced/CMakeLists.txt | 67 ++++++++++++++ .../plugin-resourced-memory-lmk-interface.h | 46 +++++++++ .../include/plugin-resourced-memory-lmk.h | 94 +++++++++++++++++++ .../resourced/plugin-api-resourced.pc.in | 17 ++++ src/plugin-api/resourced/src/common.h | 42 +++++++++ .../resourced/src/plugin-resourced-memory-lmk.c | 103 +++++++++++++++++++++ 8 files changed, 414 insertions(+), 1 deletion(-) create mode 100644 src/plugin-api/resourced/CMakeLists.txt create mode 100644 src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h create mode 100644 src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h create mode 100644 src/plugin-api/resourced/plugin-api-resourced.pc.in create mode 100644 src/plugin-api/resourced/src/common.h create mode 100644 src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e46332..c6a6b54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(libsyscommon C) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared) ADD_SUBDIRECTORY(src/plugin-api/common) +ADD_SUBDIRECTORY(src/plugin-api/resourced) # ADD_SUBDIRECTORY(src/libgdbus) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index c46cffa..415db65 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,4 +1,5 @@ %define plugin_api_common_version 0.1.0 +%define plugin_api_resourced_version 0.1.0 Name: libsyscommon Summary: System Libraries @@ -44,10 +45,14 @@ cp %{SOURCE1001} . %build PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) +PLUGIN_API_RESOURCED_MAJORVER=$(echo %{plugin_api_resourced_version} | cut -d'.' -f1) %cmake . -DFULLVER=%{version} \ -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ - -DPLUGIN_API_COMMON_ENABLE_DLOG=1 + -DPLUGIN_API_RESOURCED_VERSION=%{plugin_api_resourced_version} \ + -DPLUGIN_API_RESOURCED_MAJORVER=${PLUGIN_API_RESOURCED_MAJORVER} \ + -DPLUGIN_API_COMMON_ENABLE_DLOG=1 \ + -DPLUGIN_API_RESOURCED_ENABLE_DLOG=1 make %{?_smp_mflags} %install @@ -114,3 +119,41 @@ Development header files for common plugin APIs. %{_includedir}/plugin/plugin-common*.h %{_libdir}/pkgconfig/plugin-api-common.pc %{_libdir}/libplugin-api-common.so + +%package -n plugin-api-resourced +Summary: Plugin APIs for the resourced +Version: %{plugin_api_resourced_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-resourced +Plugin APIs for the resourced. + +%files -n plugin-api-resourced +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_libdir}/libplugin-api-resourced.so.* + +%post -n plugin-api-resourced +pushd %{_libdir} +chsmack -a "_" libplugin-api-resourced.so.%{plugin_api_resourced_version} +popd +/sbin/ldconfig + +%package -n plugin-api-resourced-devel +Summary: Header files for plugin APIs for the resourced +Version: %{plugin_api_resourced_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-resourced-devel +Development header files for plugin APIs for the resourced. + +%files -n plugin-api-resourced-devel +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_includedir}/plugin/plugin-resourced*.h +%{_libdir}/pkgconfig/plugin-api-resourced.pc +%{_libdir}/libplugin-api-resourced.so diff --git a/src/plugin-api/resourced/CMakeLists.txt b/src/plugin-api/resourced/CMakeLists.txt new file mode 100644 index 0000000..c428dd1 --- /dev/null +++ b/src/plugin-api/resourced/CMakeLists.txt @@ -0,0 +1,67 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(plugin-api-resourced) + + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(VERSION ${PLUGIN_API_RESOURCED_VERSION}) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +# Including below should be removed if the repository of plugin-api-common is +# separated. +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) + +if (${PLUGIN_API_RESOURCED_ENABLE_DLOG}) + SET(PKG_MODULES + glib-2.0 + dlog) + ADD_DEFINITIONS("-DENABLE_DLOG") + ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_RESOURCED\"") +else() + SET(PKG_MODULES + glib-2.0) +endif() + +INCLUDE(FindPkgConfig) +pkg_check_modules(${PROJECT_NAME} REQUIRED ${PKG_MODULES}) +FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +# plugin-api-common.c and plugin-api-conf.c are unnecessary if the repository of +# plugin-api-common is separated. +# Please remove them from SRCS and add 'plugin-api-common' to PKG_MODULES. +SET(SRCS src/plugin-resourced-memory-lmk.c + ../common/src/plugin-api-common.c + ../common/src/plugin-api-conf.c) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} + -ldl -Wl,-z,nodelete,--no-undefined) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${PLUGIN_API_RESOURCED_VERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PLUGIN_API_RESOURCED_MAJORVER}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${INCLUDEDIR} + FILES_MATCHING PATTERN "*.h" +) + +# CONFIGURE .pc FILE +FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) + SET(PLUGIN_RESOURCED_INCLUDEDIR "${PLUGIN_RESOURCED_INCLUDEDIR} -I${include_dirs}") +ENDFOREACH(include_dirs) +FOREACH(libraries ${pkgs_LIBRARIES}) + SET(PLUGIN_RESOURCED_LIBS "${PLUGIN_RESOURCED_LIBS} -l${libraries}") +ENDFOREACH(libraries) +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h b/src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h new file mode 100644 index 0000000..e936fc0 --- /dev/null +++ b/src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h @@ -0,0 +1,46 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ +#define __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _plugin_backend_resourced_memory_lmk_funcs { + int (*get_kill_candidates)(GArray *candidates, + GArray *task_info_app_array, + GArray *task_info_proc_array, + unsigned long totalram_kb); + +} plugin_backend_resourced_memory_lmk_funcs; + +#ifdef __cplusplus +} +#endif + +#endif /* __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ */ diff --git a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h b/src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h new file mode 100644 index 0000000..9d58ca5 --- /dev/null +++ b/src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h @@ -0,0 +1,94 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_RESOURCED_MEMORY_LMK_H__ +#define __PLUGIN_RESOURCED_MEMORY_LMK_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct task_info { + /* + * Mostly, there are not multiple processes with the same pgid. + * So, for the frequent case, we use pid variable to avoid + * allocating arrays. + */ + pid_t pid; + GArray *pids; + pid_t pgid; + /* oom_score_adj is smae as /proc//oom_score_adj */ + int oom_score_adj; + /* + * oom_score_lru is same as oom_score_adj or adjusted by + * proc_app_info lru_state for apps that are marked as favourite. + * + * oom_score_lru is the main value used in comparison for LMK. + */ + int oom_score_lru; + int size; + /** + * proc_app_info_oom_killed and proc_app_info_flags + * are not used if task is not an app. + * Especially, proc_app_info_oom_killed is NULL when this task + * is not an app. + */ + bool *proc_app_info_oom_killed; + int proc_app_info_flags; +}; + +/** + * @brief Get the backend data of resourced-memory-lmk module + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_resourced_memory_lmk_get_backend(void); + +/** + * @brief Put the backend data of resourced-memory-lmk module + * @return @c 0 on success, otherwise a negative error value + */ +int plugin_resourced_memory_lmk_put_backend(void); + +/** + * @brief Call the get_kill_candidates function of resourced-memory-lmk module + * @param[in] candidates is an an GArray to return kill candidates + * @param[in] task_info_app_array is a GArray that contains app info + * @param[in] task_info_proc_array is a GArray that contains process info + * @param[in] totalram_kb is the total amount of memory in kibibytes + * @return @c the number of kill candidates on success, + * otherwise a negative error value + */ +int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, + GArray *task_info_app_array, + GArray *task_info_proc_array, + unsigned long totalram_kb); + +#ifdef __cplusplus +} +#endif + +#endif /* __PLUGIN_RESOURCED_MEMORY_LMK_H__ */ diff --git a/src/plugin-api/resourced/plugin-api-resourced.pc.in b/src/plugin-api/resourced/plugin-api-resourced.pc.in new file mode 100644 index 0000000..6b406aa --- /dev/null +++ b/src/plugin-api/resourced/plugin-api-resourced.pc.in @@ -0,0 +1,17 @@ +# Package Information for pkg-config +# +# Copyright (c) 2023 Samsung Electronics Co., Ltd. +# All rights reserved. +# + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: plugin-api-resourced +Description: Plugin APIs for the resourced +Version: @VERSION@ +Requires.private: plugin-api-common +Cflags: -I${includedir} @PLUGIN_RESOURCED_INCLUDEDIR@ +Libs: -L${libdir} -lplugin-api-resourced @PLUGIN_RESOURCED_LIBS@ diff --git a/src/plugin-api/resourced/src/common.h b/src/plugin-api/resourced/src/common.h new file mode 100644 index 0000000..236c616 --- /dev/null +++ b/src/plugin-api/resourced/src/common.h @@ -0,0 +1,42 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#ifdef ENABLE_DLOG +#include + +#define _D(fmt, args...) SLOGD(fmt, ##args) +#define _I(fmt, args...) SLOGI(fmt, ##args) +#define _W(fmt, args...) SLOGW(fmt, ##args) +#define _E(fmt, args...) SLOGE(fmt, ##args) +#else +#define _D(fmt, args...) do { } while(0) +#define _I(fmt, args...) do { } while(0) +#define _W(fmt, args...) do { } while(0) +#define _E(fmt, args...) do { } while(0) +#endif + +#endif /* __COMMON_H__ */ diff --git a/src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c b/src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c new file mode 100644 index 0000000..f1aed5b --- /dev/null +++ b/src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c @@ -0,0 +1,103 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "plugin-common.h" + +#include "common.h" +#include "plugin-resourced-memory-lmk.h" +#include "plugin-resourced-memory-lmk-interface.h" + +#ifndef EXPORT +#define EXPORT __attribute__((visibility("default"))) +#endif + +static plugin_backend_resourced_memory_lmk_funcs *funcs = NULL; + +EXPORT +int plugin_resourced_memory_lmk_get_backend(void) +{ + int ret = 0; + + if (funcs) + return 0; + + ret = plugin_common_get_backend( + PLUGIN_MODULE_RESOURCED_MEMORY_LMK, (void **)&funcs); + if (ret < 0) { + _E("Failed to get resourced_memory_lmk backend: %d", ret); + return ret; + } + + _I("Success to get resourced_memory_lmk backend: %d", ret); + + return 0; +} + +EXPORT +int plugin_resourced_memory_lmk_put_backend(void) +{ + int ret = 0; + + if (!funcs) + return 0; + + ret = plugin_common_put_backend( + PLUGIN_MODULE_RESOURCED_MEMORY_LMK, (void *)funcs); + if (ret < 0) { + _E("Failed to put resourced_memory_lmk backend: %d", ret); + return ret; + } + funcs = NULL; + + _I("Success to put resourced_memory_lmk backend: %d", ret); + + return 0; +} + +EXPORT +int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, + GArray *task_info_app_array, + GArray *task_info_proc_array, + unsigned long totalram_kb) +{ + int ret = 0; + + if (!funcs) { + ret = plugin_resourced_memory_lmk_get_backend(); + if (ret < 0) + return ret; + } + + if (!funcs || !funcs->get_kill_candidates) { + _E("No backend or no \"get_kill_candidates\" function"); + return -ENOTSUP; + } + + return funcs->get_kill_candidates(candidates, + task_info_app_array, + task_info_proc_array, + totalram_kb); +} -- 2.7.4 From 449dacb8dc4ee7692ad5336e126d187a10736a08 Mon Sep 17 00:00:00 2001 From: TaeminYeom Date: Thu, 23 Feb 2023 16:51:13 +0900 Subject: [PATCH 10/16] ini-parser: Fix size_t to ssize_t Variable "n_read" brings the return of getline, but return type of getline is ssize_t. Also, fseek's second parameter is long type, so it is proper to use signed data type. Change-Id: I87f01a986a9b7fa68d7a675a1e31a0afe0c1f4bf Signed-off-by: TaeminYeom --- src/libcommon/ini-parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcommon/ini-parser.c b/src/libcommon/ini-parser.c index e7d7605..e8e2bce 100644 --- a/src/libcommon/ini-parser.c +++ b/src/libcommon/ini-parser.c @@ -162,7 +162,7 @@ int libsys_config_parse_by_section(const char *fname, int cb(const struct parse_ FILE *fp = NULL; char *line = NULL; size_t len = 0; - size_t n_read; + ssize_t n_read; int ret = 0; int retval; struct parse_result result = { 0, }; -- 2.7.4 From ba823a0294b55f2eefa317a069578c6c64a26f8d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Mar 2023 12:54:51 +0900 Subject: [PATCH 11/16] Revert "resource-manager: Relocate add_resource() in create_resource()" This reverts commit 5880b22f3e55b60c7b9326c51012b95f05416145. The resource instance must be added to hashtable prior to the operation driver->ops.create(resource->id). As this operation passes resource id, it is possible that the operation work based on that resource id, which denotes resource instance and must have been registered to hashtable. Therefore, add_resource() must be followed by driver->ops.create(). Change-Id: I05b8a9f85741313c14201501fe6bbc4a5b8c7233 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index a870a0b..b3f3b9d 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -248,6 +248,12 @@ create_resource(int *resource_id, int resource_type, int instance_type) return -ENOMEM; } + ret = add_resource(resource); + if (ret < 0) { + free_resource(resource); + return ret; + } + for (i = 0; i < resource->num_attrs; i++) resource->attrs_value[i].type = driver->attrs[i].type; @@ -265,14 +271,6 @@ create_resource(int *resource_id, int resource_type, int instance_type) *resource_id = resource->id; - ret = add_resource(resource); - if (ret < 0) { - if (driver->ops.delete) - driver->ops.delete(resource->id); - free_resource(resource); - return ret; - } - return 0; } -- 2.7.4 From 92ee2e600ff54f91f2ba38c0261153dfe12b5bf3 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Mar 2023 13:07:42 +0900 Subject: [PATCH 12/16] resource-manager: cleanup resource instance correctly On failure during create_resource(), remove resource instance from hashtable if it has been registered hashtable via add_resource(). Change-Id: I124add4633b06be0e3a2bc2786f1eee8b69acce0 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index b3f3b9d..6fd1f5e 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -264,7 +264,7 @@ create_resource(int *resource_id, int resource_type, int instance_type) if (driver->ops.create) { ret = driver->ops.create(resource->id); if (ret < 0) { - free_resource(resource); + g_hash_table_remove(g_resource_hash_table, GINT_TO_POINTER(resource->id)); return ret; } } -- 2.7.4 From 22b8578535821c5c0b5354b1f20554a14c1a4238 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 17 Mar 2023 09:40:27 +0900 Subject: [PATCH 13/16] packaging: Rearrange %package directive As those relocated %packages overwrite the %{version} of libsyscommon, define %{libsyscommon_version} to maintain its value. Change-Id: I0049a45fdd343515e09c97a4abf0f8aa6ea9704a Signed-off-by: Youngjae Cho --- packaging/libsyscommon.spec | 81 +++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 415db65..be70866 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,9 +1,10 @@ +%define libsyscommon_version 5.0.0 %define plugin_api_common_version 0.1.0 %define plugin_api_resourced_version 0.1.0 Name: libsyscommon Summary: System Libraries -Version: 5.0.0 +Version: %{libsyscommon_version} Release: 0%{?release_flags} License: MIT Group: System/Libraries @@ -39,6 +40,44 @@ Requires: pkgconfig(capi-system-info) %description -n libsyscommon-devel Development header files for system common library. +# Packages for plugin-api +%package -n plugin-api-common +Summary: Common plugin APIs +Version: %{plugin_api_common_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%package -n plugin-api-common-devel +Summary: Header files for common plugin APIs +Version: %{plugin_api_common_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-common-devel +Development header files for common plugin APIs. + +%package -n plugin-api-resourced +Summary: Plugin APIs for the resourced +Version: %{plugin_api_resourced_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-resourced +Plugin APIs for the resourced. + +%package -n plugin-api-resourced-devel +Summary: Header files for plugin APIs for the resourced +Version: %{plugin_api_resourced_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-resourced-devel +Development header files for plugin APIs for the resourced. + %prep %setup -q cp %{SOURCE1001} . @@ -46,7 +85,7 @@ cp %{SOURCE1001} . %build PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) PLUGIN_API_RESOURCED_MAJORVER=$(echo %{plugin_api_resourced_version} | cut -d'.' -f1) -%cmake . -DFULLVER=%{version} \ +%cmake . -DFULLVER=%{libsyscommon_version} \ -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ -DPLUGIN_API_RESOURCED_VERSION=%{plugin_api_resourced_version} \ @@ -81,14 +120,6 @@ touch debugsources.list %{_includedir}/libsyscommon/*.h %{_libdir}/pkgconfig/libsyscommon.pc -# Packages for plugin-api -%package -n plugin-api-common -Summary: Common plugin APIs -Version: %{plugin_api_common_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - %description -n plugin-api-common Common plugin APIs to load another APIs from backend. @@ -103,16 +134,6 @@ chsmack -a "_" libplugin-api-common.so.%{plugin_api_common_version} popd /sbin/ldconfig -%package -n plugin-api-common-devel -Summary: Header files for common plugin APIs -Version: %{plugin_api_common_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - -%description -n plugin-api-common-devel -Development header files for common plugin APIs. - %files -n plugin-api-common-devel %defattr(-,root,root,-) %license LICENSE.MIT @@ -120,16 +141,6 @@ Development header files for common plugin APIs. %{_libdir}/pkgconfig/plugin-api-common.pc %{_libdir}/libplugin-api-common.so -%package -n plugin-api-resourced -Summary: Plugin APIs for the resourced -Version: %{plugin_api_resourced_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - -%description -n plugin-api-resourced -Plugin APIs for the resourced. - %files -n plugin-api-resourced %defattr(-,root,root,-) %license LICENSE.MIT @@ -141,16 +152,6 @@ chsmack -a "_" libplugin-api-resourced.so.%{plugin_api_resourced_version} popd /sbin/ldconfig -%package -n plugin-api-resourced-devel -Summary: Header files for plugin APIs for the resourced -Version: %{plugin_api_resourced_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - -%description -n plugin-api-resourced-devel -Development header files for plugin APIs for the resourced. - %files -n plugin-api-resourced-devel %defattr(-,root,root,-) %license LICENSE.MIT -- 2.7.4 From 35ae84e72bf86544d55841a3fda9ed5e8707e0e2 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 17 Mar 2023 09:57:59 +0900 Subject: [PATCH 14/16] plugin-api: deviced: Add plugin-api-deviced Initialize plugin-api for deviced. It creates package plugin-api-deviced and the package contains empty library. Change-Id: I2a91b9185e4b9f0ffbe61c4d71801d20a15b0df2 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 + packaging/libsyscommon.spec | 39 ++++++++++++- src/plugin-api/deviced/CMakeLists.txt | 66 ++++++++++++++++++++++ .../include/plugin-deviced-display-interface.h | 36 ++++++++++++ .../deviced/include/plugin-deviced-display.h | 36 ++++++++++++ src/plugin-api/deviced/plugin-api-deviced.pc.in | 17 ++++++ .../deviced/src/plugin-deviced-display.c | 23 ++++++++ 7 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 src/plugin-api/deviced/CMakeLists.txt create mode 100644 src/plugin-api/deviced/include/plugin-deviced-display-interface.h create mode 100644 src/plugin-api/deviced/include/plugin-deviced-display.h create mode 100644 src/plugin-api/deviced/plugin-api-deviced.pc.in create mode 100644 src/plugin-api/deviced/src/plugin-deviced-display.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a6b54..d28713b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared) ADD_SUBDIRECTORY(src/plugin-api/common) ADD_SUBDIRECTORY(src/plugin-api/resourced) +ADD_SUBDIRECTORY(src/plugin-api/deviced) # ADD_SUBDIRECTORY(src/libgdbus) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index be70866..a7c8cb5 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,6 +1,7 @@ %define libsyscommon_version 5.0.0 %define plugin_api_common_version 0.1.0 %define plugin_api_resourced_version 0.1.0 +%define plugin_api_deviced_version 0.1.0 Name: libsyscommon Summary: System Libraries @@ -78,6 +79,26 @@ Requires: pkgconfig(dlog) %description -n plugin-api-resourced-devel Development header files for plugin APIs for the resourced. +%package -n plugin-api-deviced +Summary: Plugin APIs for the deviced +Version: %{plugin_api_deviced_version} +License: MIT + +%description -n plugin-api-deviced +Plugin APIs for the deviced. + +%package -n plugin-api-deviced-devel +Summary: Header files for plugin APIs for the deviced +Version: %{plugin_api_deviced_version} +License: MIT + +%description -n plugin-api-deviced-devel +Development header files for plugin APIs for the deviced. + + +###### + + %prep %setup -q cp %{SOURCE1001} . @@ -85,13 +106,17 @@ cp %{SOURCE1001} . %build PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) PLUGIN_API_RESOURCED_MAJORVER=$(echo %{plugin_api_resourced_version} | cut -d'.' -f1) +PLUGIN_API_DEVICED_MAJORVER=$(echo %{plugin_api_deviced_version} | cut -d'.' -f1) %cmake . -DFULLVER=%{libsyscommon_version} \ -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ -DPLUGIN_API_RESOURCED_VERSION=%{plugin_api_resourced_version} \ -DPLUGIN_API_RESOURCED_MAJORVER=${PLUGIN_API_RESOURCED_MAJORVER} \ + -DPLUGIN_API_DEVICED_VERSION=%{plugin_api_deviced_version} \ + -DPLUGIN_API_DEVICED_MAJORVER=${PLUGIN_API_DEVICED_MAJORVER} \ -DPLUGIN_API_COMMON_ENABLE_DLOG=1 \ - -DPLUGIN_API_RESOURCED_ENABLE_DLOG=1 + -DPLUGIN_API_RESOURCED_ENABLE_DLOG=1 \ + -DPLUGIN_API_DEVICEDD_ENABLE_DLOG=1 make %{?_smp_mflags} %install @@ -158,3 +183,15 @@ popd %{_includedir}/plugin/plugin-resourced*.h %{_libdir}/pkgconfig/plugin-api-resourced.pc %{_libdir}/libplugin-api-resourced.so + +%files -n plugin-api-deviced +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_libdir}/libplugin-api-deviced.so.* + +%files -n plugin-api-deviced-devel +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_includedir}/plugin/plugin-deviced*.h +%{_libdir}/pkgconfig/plugin-api-deviced.pc +%{_libdir}/libplugin-api-deviced.so diff --git a/src/plugin-api/deviced/CMakeLists.txt b/src/plugin-api/deviced/CMakeLists.txt new file mode 100644 index 0000000..89ed42d --- /dev/null +++ b/src/plugin-api/deviced/CMakeLists.txt @@ -0,0 +1,66 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(plugin-api-deviced) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(VERSION ${PLUGIN_API_DEVICED_VERSION}) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +# Including below should be removed if the repository of plugin-api-common is +# separated. +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) + +if (${PLUGIN_API_DEVICED_ENABLE_DLOG}) + SET(PKG_MODULES + glib-2.0 + dlog) + ADD_DEFINITIONS("-DENABLE_DLOG") + ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_DEVICED\"") +else() + SET(PKG_MODULES + glib-2.0) +endif() + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +# plugin-api-common.c and plugin-api-conf.c are unnecessary if the repository of +# plugin-api-common is separated. +# Please remove them from SRCS and add 'plugin-api-common' to PKG_MODULES. +SET(SRCS src/plugin-deviced-display.c + ../common/src/plugin-api-common.c + ../common/src/plugin-api-conf.c) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} + -ldl -Wl,-z,nodelete,--no-undefined) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${PLUGIN_API_DEVICED_VERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PLUGIN_API_DEVICED_MAJORVER}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${INCLUDEDIR} + FILES_MATCHING PATTERN "*.h" +) + +# CONFIGURE .pc FILE +FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) + SET(PLUGIN_DEVICED_INCLUDEDIR "${PLUGIN_DEVICED_INCLUDEDIR} -I${include_dirs}") +ENDFOREACH(include_dirs) +FOREACH(libraries ${pkgs_LIBRARIES}) + SET(PLUGIN_DEVICED_LIBS "${PLUGIN_DEVICED_LIBS} -l${libraries}") +ENDFOREACH(libraries) +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/deviced/include/plugin-deviced-display-interface.h b/src/plugin-api/deviced/include/plugin-deviced-display-interface.h new file mode 100644 index 0000000..2a0c909 --- /dev/null +++ b/src/plugin-api/deviced/include/plugin-deviced-display-interface.h @@ -0,0 +1,36 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#define __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif //__PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ diff --git a/src/plugin-api/deviced/include/plugin-deviced-display.h b/src/plugin-api/deviced/include/plugin-deviced-display.h new file mode 100644 index 0000000..14e5c6c --- /dev/null +++ b/src/plugin-api/deviced/include/plugin-deviced-display.h @@ -0,0 +1,36 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __PLUGIN_DEVICED_DISPLAY_H__ +#define __PLUGIN_DEVICED_DISPLAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif //__PLUGIN_DEVICED_DISPLAY_H__ diff --git a/src/plugin-api/deviced/plugin-api-deviced.pc.in b/src/plugin-api/deviced/plugin-api-deviced.pc.in new file mode 100644 index 0000000..a328de4 --- /dev/null +++ b/src/plugin-api/deviced/plugin-api-deviced.pc.in @@ -0,0 +1,17 @@ +# Package Information for pkg-config +# +# Copyright (c) 2023 Samsung Electronics Co., Ltd. +# All rights reserved. +# + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: plugin-api-deviced +Description: Plugin APIs for the deviced +Version: @VERSION@ +Requires.private: plugin-api-common +Cflags: -I${includedir} @PLUGIN_DEVICED_INCLUDEDIR@ +Libs: -L${libdir} -lplugin-api-deviced @PLUGIN_DEVICED_LIBS@ diff --git a/src/plugin-api/deviced/src/plugin-deviced-display.c b/src/plugin-api/deviced/src/plugin-deviced-display.c new file mode 100644 index 0000000..f07bd13 --- /dev/null +++ b/src/plugin-api/deviced/src/plugin-deviced-display.c @@ -0,0 +1,23 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ -- 2.7.4 From 5c5c7f315c8d675eb98abc53dd9c6170c30cfaba Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 16 Mar 2023 20:45:18 +0900 Subject: [PATCH 15/16] plugin-api: Fix the prefix for pkg_check_modules of CMakeLists.txt The command pkg_check_modules in CMakeLists.txt checks modules and sets variables about these modules. The names of these variables have their prefix designated by the command pkg_check_modules like below: pkg_check_modules( REQUIRED ) Previously, in plugin-api-common, prefix was "pkgs", which is not a unique name. In plugin-api-resourced, prefix was ${PROJECT_NAME} but when calling variables, "pkgs" was used for prefix, which is not correct usage. This fault was fixed by replacing their prefix as their ${PROJECT_NAME}. Change-Id: Ide1db4b707f2c6e9f632c0cc36ab4ec654383887 Signed-off-by: SangYoun Kwak --- src/plugin-api/common/CMakeLists.txt | 10 +++++----- src/plugin-api/resourced/CMakeLists.txt | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugin-api/common/CMakeLists.txt b/src/plugin-api/common/CMakeLists.txt index 326139c..8f0e0fe 100644 --- a/src/plugin-api/common/CMakeLists.txt +++ b/src/plugin-api/common/CMakeLists.txt @@ -25,8 +25,8 @@ else() endif() INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) -FOREACH(flag ${pkgs_CFLAGS}) +pkg_check_modules(${PROJECT_NAME} REQUIRED ${PKG_MODULES}) +FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -41,7 +41,7 @@ SET(SRCS src/plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} -ldl -Wl,-z,nodelete,--no-undefined) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PLUGIN_API_COMMON_MAJORVER}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) @@ -52,10 +52,10 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ FILES_MATCHING PATTERN "*.h") # CONFIGURE .pc FILE -FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) +FOREACH(include_dirs ${${PROJECT_NAME}_INCLUDE_DIRS}) SET(PLUGIN_COMMON_INCLUDEDIR "${PLUGIN_COMMON_INCLUDEDIR} -I${include_dirs}") ENDFOREACH(include_dirs) -FOREACH(libraries ${pkgs_LIBRARIES}) +FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_COMMON_LIBS "${PLUGIN_COMMON_LIBS} -l${libraries}") ENDFOREACH(libraries) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) diff --git a/src/plugin-api/resourced/CMakeLists.txt b/src/plugin-api/resourced/CMakeLists.txt index c428dd1..114cbcb 100644 --- a/src/plugin-api/resourced/CMakeLists.txt +++ b/src/plugin-api/resourced/CMakeLists.txt @@ -44,7 +44,7 @@ SET(SRCS src/plugin-resourced-memory-lmk.c ../common/src/plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} -ldl -Wl,-z,nodelete,--no-undefined) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${PLUGIN_API_RESOURCED_VERSION}) @@ -57,10 +57,10 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ ) # CONFIGURE .pc FILE -FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) +FOREACH(include_dirs ${${PROJECT_NAME}_INCLUDE_DIRS}) SET(PLUGIN_RESOURCED_INCLUDEDIR "${PLUGIN_RESOURCED_INCLUDEDIR} -I${include_dirs}") ENDFOREACH(include_dirs) -FOREACH(libraries ${pkgs_LIBRARIES}) +FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_RESOURCED_LIBS "${PLUGIN_RESOURCED_LIBS} -l${libraries}") ENDFOREACH(libraries) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -- 2.7.4 From 13584c15d345712dfbddb20ae6440fdfb4cd883d Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 27 Apr 2023 14:13:39 +0900 Subject: [PATCH 16/16] plugin-api: Rename 'plugin' to 'syscommon-plugin' Since the plugin-api is the plugin feature which is only used in system scope and it is located in libsyscommon, plugin was changed to syscommon-plugin to indicate its usage and location. Change rule: * Basically, plugin becomes syscommon-plugin to indicate it is from the libsyscommon repository * Symbols which are used internally can omit the prefix 'syscommon'. Changed: * Package name: plugin-api... -> libsyscommon-plugin-api... * Package config file name: plugin-api-....pc -> libsyscommon-plugin-api....pc * .so name: libplugin-api-....so -> libsyscommon-plugin-api....so Change-Id: Ia56c935ebf97a93cad7efd0235508c540ee0348d Signed-off-by: SangYoun Kwak --- packaging/libsyscommon.spec | 124 ++++++++++----------- src/plugin-api/common/CMakeLists.txt | 15 +-- ...rface.h => syscommon-plugin-common-interface.h} | 28 ++--- .../{plugin-common.h => syscommon-plugin-common.h} | 57 ++++++---- ....pc.in => libsyscommon-plugin-api-common.pc.in} | 6 +- src/plugin-api/common/src/common.h | 12 +- ...-api-common.c => syscommon-plugin-api-common.c} | 87 ++++++++------- ...ugin-api-conf.c => syscommon-plugin-api-conf.c} | 25 +++-- ...ugin-api-conf.h => syscommon-plugin-api-conf.h} | 15 +-- ...ugin-api-list.h => syscommon-plugin-api-list.h} | 33 +++--- src/plugin-api/deviced/CMakeLists.txt | 28 ++--- ...> syscommon-plugin-deviced-display-interface.h} | 6 +- ...isplay.h => syscommon-plugin-deviced-display.h} | 6 +- ...pc.in => libsyscommon-plugin-api-deviced.pc.in} | 8 +- ...isplay.c => syscommon-plugin-deviced-display.c} | 0 src/plugin-api/resourced/CMakeLists.txt | 28 ++--- ...common-plugin-resourced-memory-lmk-interface.h} | 10 +- ...k.h => syscommon-plugin-resourced-memory-lmk.h} | 13 ++- ....in => libsyscommon-plugin-api-resourced.pc.in} | 8 +- ...k.c => syscommon-plugin-resourced-memory-lmk.c} | 27 +++-- 20 files changed, 282 insertions(+), 254 deletions(-) rename src/plugin-api/common/include/{plugin-common-interface.h => syscommon-plugin-common-interface.h} (66%) rename src/plugin-api/common/include/{plugin-common.h => syscommon-plugin-common.h} (76%) rename src/plugin-api/common/{plugin-api-common.pc.in => libsyscommon-plugin-api-common.pc.in} (64%) rename src/plugin-api/common/src/{plugin-api-common.c => syscommon-plugin-api-common.c} (81%) rename src/plugin-api/common/src/{plugin-api-conf.c => syscommon-plugin-api-conf.c} (86%) rename src/plugin-api/common/src/{plugin-api-conf.h => syscommon-plugin-api-conf.h} (78%) rename src/plugin-api/common/src/{plugin-api-list.h => syscommon-plugin-api-list.h} (56%) rename src/plugin-api/deviced/include/{plugin-deviced-display-interface.h => syscommon-plugin-deviced-display-interface.h} (87%) rename src/plugin-api/deviced/include/{plugin-deviced-display.h => syscommon-plugin-deviced-display.h} (89%) rename src/plugin-api/deviced/{plugin-api-deviced.pc.in => libsyscommon-plugin-api-deviced.pc.in} (56%) rename src/plugin-api/deviced/src/{plugin-deviced-display.c => syscommon-plugin-deviced-display.c} (100%) rename src/plugin-api/resourced/include/{plugin-resourced-memory-lmk-interface.h => syscommon-plugin-resourced-memory-lmk-interface.h} (81%) rename src/plugin-api/resourced/include/{plugin-resourced-memory-lmk.h => syscommon-plugin-resourced-memory-lmk.h} (88%) rename src/plugin-api/resourced/{plugin-api-resourced.pc.in => libsyscommon-plugin-api-resourced.pc.in} (55%) rename src/plugin-api/resourced/src/{plugin-resourced-memory-lmk.c => syscommon-plugin-resourced-memory-lmk.c} (74%) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index a7c8cb5..0ce2272 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,7 +1,7 @@ %define libsyscommon_version 5.0.0 -%define plugin_api_common_version 0.1.0 -%define plugin_api_resourced_version 0.1.0 -%define plugin_api_deviced_version 0.1.0 +%define libsyscommon_plugin_api_common_version 0.1.0 +%define libsyscommon_plugin_api_resourced_version 0.1.0 +%define libsyscommon_plugin_api_deviced_version 0.1.0 Name: libsyscommon Summary: System Libraries @@ -41,59 +41,59 @@ Requires: pkgconfig(capi-system-info) %description -n libsyscommon-devel Development header files for system common library. -# Packages for plugin-api -%package -n plugin-api-common -Summary: Common plugin APIs -Version: %{plugin_api_common_version} +# Packages for system plugin api +%package -n libsyscommon-plugin-api-common +Summary: Common system plugin APIs +Version: %{libsyscommon_plugin_api_common_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%package -n plugin-api-common-devel -Summary: Header files for common plugin APIs -Version: %{plugin_api_common_version} +%package -n libsyscommon-plugin-api-common-devel +Summary: Header files for common system plugin APIs +Version: %{libsyscommon_plugin_api_common_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%description -n plugin-api-common-devel -Development header files for common plugin APIs. +%description -n libsyscommon-plugin-api-common-devel +Development header files for common system plugin APIs. -%package -n plugin-api-resourced -Summary: Plugin APIs for the resourced -Version: %{plugin_api_resourced_version} +%package -n libsyscommon-plugin-api-resourced +Summary: System plugin APIs for the resourced +Version: %{libsyscommon_plugin_api_resourced_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%description -n plugin-api-resourced -Plugin APIs for the resourced. +%description -n libsyscommon-plugin-api-resourced +System plugin APIs for the resourced. -%package -n plugin-api-resourced-devel -Summary: Header files for plugin APIs for the resourced -Version: %{plugin_api_resourced_version} +%package -n libsyscommon-plugin-api-resourced-devel +Summary: Header files for system plugin APIs for the resourced +Version: %{libsyscommon_plugin_api_resourced_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%description -n plugin-api-resourced-devel -Development header files for plugin APIs for the resourced. +%description -n libsyscommon-plugin-api-resourced-devel +Development header files for system plugin APIs for the resourced. -%package -n plugin-api-deviced -Summary: Plugin APIs for the deviced -Version: %{plugin_api_deviced_version} +%package -n libsyscommon-plugin-api-deviced +Summary: System plugin APIs for the deviced +Version: %{libsyscommon_plugin_api_deviced_version} License: MIT -%description -n plugin-api-deviced -Plugin APIs for the deviced. +%description -n libsyscommon-plugin-api-deviced +System plugin APIs for the deviced. -%package -n plugin-api-deviced-devel -Summary: Header files for plugin APIs for the deviced -Version: %{plugin_api_deviced_version} +%package -n libsyscommon-plugin-api-deviced-devel +Summary: Header files for system plugin APIs for the deviced +Version: %{libsyscommon_plugin_api_deviced_version} License: MIT -%description -n plugin-api-deviced-devel -Development header files for plugin APIs for the deviced. +%description -n libsyscommon-plugin-api-deviced-devel +Development header files for system plugin APIs for the deviced. ###### @@ -104,15 +104,15 @@ Development header files for plugin APIs for the deviced. cp %{SOURCE1001} . %build -PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) -PLUGIN_API_RESOURCED_MAJORVER=$(echo %{plugin_api_resourced_version} | cut -d'.' -f1) -PLUGIN_API_DEVICED_MAJORVER=$(echo %{plugin_api_deviced_version} | cut -d'.' -f1) +PLUGIN_API_COMMON_MAJORVER=$(echo %{libsyscommon_plugin_api_common_version} | cut -d'.' -f1) +PLUGIN_API_RESOURCED_MAJORVER=$(echo %{libsyscommon_plugin_api_resourced_version} | cut -d'.' -f1) +PLUGIN_API_DEVICED_MAJORVER=$(echo %{libsyscommon_plugin_api_deviced_version} | cut -d'.' -f1) %cmake . -DFULLVER=%{libsyscommon_version} \ - -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ + -DPLUGIN_API_COMMON_VERSION=%{libsyscommon_plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ - -DPLUGIN_API_RESOURCED_VERSION=%{plugin_api_resourced_version} \ + -DPLUGIN_API_RESOURCED_VERSION=%{libsyscommon_plugin_api_resourced_version} \ -DPLUGIN_API_RESOURCED_MAJORVER=${PLUGIN_API_RESOURCED_MAJORVER} \ - -DPLUGIN_API_DEVICED_VERSION=%{plugin_api_deviced_version} \ + -DPLUGIN_API_DEVICED_VERSION=%{libsyscommon_plugin_api_deviced_version} \ -DPLUGIN_API_DEVICED_MAJORVER=${PLUGIN_API_DEVICED_MAJORVER} \ -DPLUGIN_API_COMMON_ENABLE_DLOG=1 \ -DPLUGIN_API_RESOURCED_ENABLE_DLOG=1 \ @@ -145,53 +145,53 @@ touch debugsources.list %{_includedir}/libsyscommon/*.h %{_libdir}/pkgconfig/libsyscommon.pc -%description -n plugin-api-common -Common plugin APIs to load another APIs from backend. +%description -n libsyscommon-plugin-api-common +Common system plugin APIs to load another APIs from backend. -%files -n plugin-api-common +%files -n libsyscommon-plugin-api-common %defattr(-,root,root,-) %license LICENSE.MIT -%{_libdir}/libplugin-api-common.so.* +%{_libdir}/libsyscommon-plugin-api-common.so.* -%post -n plugin-api-common +%post -n libsyscommon-plugin-api-common pushd %{_libdir} -chsmack -a "_" libplugin-api-common.so.%{plugin_api_common_version} +chsmack -a "_" libsyscommon-plugin-api-common.so.%{libsyscommon_plugin_api_common_version} popd /sbin/ldconfig -%files -n plugin-api-common-devel +%files -n libsyscommon-plugin-api-common-devel %defattr(-,root,root,-) %license LICENSE.MIT -%{_includedir}/plugin/plugin-common*.h -%{_libdir}/pkgconfig/plugin-api-common.pc -%{_libdir}/libplugin-api-common.so +%{_includedir}/system/syscommon-plugin-common*.h +%{_libdir}/pkgconfig/libsyscommon-plugin-api-common.pc +%{_libdir}/libsyscommon-plugin-api-common.so -%files -n plugin-api-resourced +%files -n libsyscommon-plugin-api-resourced %defattr(-,root,root,-) %license LICENSE.MIT -%{_libdir}/libplugin-api-resourced.so.* +%{_libdir}/libsyscommon-plugin-api-resourced.so.* -%post -n plugin-api-resourced +%post -n libsyscommon-plugin-api-resourced pushd %{_libdir} -chsmack -a "_" libplugin-api-resourced.so.%{plugin_api_resourced_version} +chsmack -a "_" libsyscommon-plugin-api-resourced.so.%{libsyscommon_plugin_api_resourced_version} popd /sbin/ldconfig -%files -n plugin-api-resourced-devel +%files -n libsyscommon-plugin-api-resourced-devel %defattr(-,root,root,-) %license LICENSE.MIT -%{_includedir}/plugin/plugin-resourced*.h -%{_libdir}/pkgconfig/plugin-api-resourced.pc -%{_libdir}/libplugin-api-resourced.so +%{_includedir}/system/syscommon-plugin-resourced*.h +%{_libdir}/pkgconfig/libsyscommon-plugin-api-resourced.pc +%{_libdir}/libsyscommon-plugin-api-resourced.so -%files -n plugin-api-deviced +%files -n libsyscommon-plugin-api-deviced %defattr(-,root,root,-) %license LICENSE.MIT -%{_libdir}/libplugin-api-deviced.so.* +%{_libdir}/libsyscommon-plugin-api-deviced.so.* -%files -n plugin-api-deviced-devel +%files -n libsyscommon-plugin-api-deviced-devel %defattr(-,root,root,-) %license LICENSE.MIT -%{_includedir}/plugin/plugin-deviced*.h -%{_libdir}/pkgconfig/plugin-api-deviced.pc -%{_libdir}/libplugin-api-deviced.so +%{_includedir}/system/syscommon-plugin-deviced*.h +%{_libdir}/pkgconfig/libsyscommon-plugin-api-deviced.pc +%{_libdir}/libsyscommon-plugin-api-deviced.so diff --git a/src/plugin-api/common/CMakeLists.txt b/src/plugin-api/common/CMakeLists.txt index 8f0e0fe..666d51f 100644 --- a/src/plugin-api/common/CMakeLists.txt +++ b/src/plugin-api/common/CMakeLists.txt @@ -1,17 +1,17 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(plugin-api-common) +PROJECT(syscommon-plugin-api-common) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}/bin") SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(INCLUDEDIR "${PREFIX}/include/system") SET(VERSION ${PLUGIN_API_COMMON_VERSION}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) if (${PLUGIN_API_COMMON_ENABLE_DLOG}) ADD_DEFINITIONS("-DENABLE_DLOG=1") - ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_COMMON\"") + ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_COMMON\"") SET(PKG_MODULES dlog gio-2.0 @@ -37,8 +37,8 @@ SET(CMAKE_EXE_LINKER_FLAGS "-pie") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(SRCS - src/plugin-api-common.c - src/plugin-api-conf.c) + src/syscommon-plugin-api-common.c + src/syscommon-plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} @@ -58,5 +58,6 @@ ENDFOREACH(include_dirs) FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_COMMON_LIBS "${PLUGIN_COMMON_LIBS} -l${libraries}") ENDFOREACH(libraries) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +SET(PACKAGE_CONFIG_FILE "lib${PROJECT_NAME}.pc") +CONFIGURE_FILE(${PACKAGE_CONFIG_FILE}.in ${PACKAGE_CONFIG_FILE} @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/common/include/plugin-common-interface.h b/src/plugin-api/common/include/syscommon-plugin-common-interface.h similarity index 66% rename from src/plugin-api/common/include/plugin-common-interface.h rename to src/plugin-api/common/include/syscommon-plugin-common-interface.h index 37f201a..1cda550 100644 --- a/src/plugin-api/common/include/plugin-common-interface.h +++ b/src/plugin-api/common/include/syscommon-plugin-common-interface.h @@ -22,35 +22,35 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_COMMON_INTERFACE__ -#define __PLUGIN_COMMON_INTERFACE__ +#ifndef __SYSCOMMON_PLUGIN_COMMON_INTERFACE__ +#define __SYSCOMMON_PLUGIN_COMMON_INTERFACE__ #ifdef __cplusplus extern "C" { #endif -enum plugin_abi_version { - PLUGIN_ABI_VERSION_UNKNOWN = 0, - PLUGIN_ABI_VERSION_TIZEN_7_0, - PLUGIN_ABI_VERSION_TIZEN_7_5, - PLUGIN_ABI_VERSION_END, +enum syscommon_plugin_abi_version { + SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN = 0, + SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_0, + SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5, + SYSCOMMON_PLUGIN_ABI_VERSION_END, }; -static const char *const plugin_abi_version_str[] = { - [PLUGIN_ABI_VERSION_UNKNOWN] = "Unknown PLUGIN ABI Version", - [PLUGIN_ABI_VERSION_TIZEN_7_0] = "PLUGIN_ABI_VERSION_TIZEN_7_0", - [PLUGIN_ABI_VERSION_TIZEN_7_5] = "PLUGIN_ABI_VERSION_TIZEN_7_5", +static const char *const syscommon_plugin_abi_version_str[] = { + [SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN] = "Unknown PLUGIN ABI Version", + [SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_0] = "PLUGIN_ABI_VERSION_TIZEN_7_0", + [SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5] = "PLUGIN_ABI_VERSION_TIZEN_7_5", }; -typedef struct __plugin_backend { +typedef struct __syscommon_plugin_backend { const char *name; const char *vendor; const unsigned int abi_version; int (*init) (void **data); int (*exit) (void *data); -} plugin_backend; +} syscommon_plugin_backend; #ifdef __cplusplus } #endif -#endif /* __PLUGIN_COMMON_INTERFACE__ */ +#endif /* __SYSCOMMON_PLUGIN_COMMON_INTERFACE__ */ diff --git a/src/plugin-api/common/include/plugin-common.h b/src/plugin-api/common/include/syscommon-plugin-common.h similarity index 76% rename from src/plugin-api/common/include/plugin-common.h rename to src/plugin-api/common/include/syscommon-plugin-common.h index d7856bc..d530c0a 100644 --- a/src/plugin-api/common/include/plugin-common.h +++ b/src/plugin-api/common/include/syscommon-plugin-common.h @@ -22,19 +22,19 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_COMMON__ -#define __PLUGIN_COMMON__ +#ifndef __SYSCOMMON_PLUGIN_COMMON__ +#define __SYSCOMMON_PLUGIN_COMMON__ -#include "plugin-common-interface.h" +#include "syscommon-plugin-common-interface.h" #ifdef __cplusplus extern "C" { #endif -enum plugin_module { - PLUGIN_MODULE_UNKNOWN = 0, - PLUGIN_MODULE_RESOURCED_MEMORY_LMK, - PLUGIN_MODULE_END, +enum syscommon_plugin_module { + SYSCOMMON_PLUGIN_MODULE_UNKNOWN = 0, + SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + SYSCOMMON_PLUGIN_MODULE_END, }; /** @@ -44,7 +44,9 @@ enum plugin_module { * @param[in] Arrary size of name[] * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_library_name(enum plugin_module module, char *name, int size); +int syscommon_plugin_common_get_backend_library_name( + enum syscommon_plugin_module module, + char *name, int size); /** * @brief Get the backend symbol name according to the type of PLUGIN module @@ -53,7 +55,8 @@ int plugin_common_get_backend_library_name(enum plugin_module module, char *name * @param[in] Arrary size of name[] * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int size); +int syscommon_plugin_common_get_backend_symbol_name( + enum syscommon_plugin_module module, char *name, int size); /** * @brief Get the backend data according to the type of PLUGIN module @@ -62,7 +65,8 @@ int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, * should be stored from PLUGIN backend binary. * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend(enum plugin_module module, void **data); +int syscommon_plugin_common_get_backend(enum syscommon_plugin_module module, + void **data); /** * @brief Put the backend data according to the type of PLUGIN module @@ -70,7 +74,8 @@ int plugin_common_get_backend(enum plugin_module module, void **data); * @param[in] Data pointer where 'plugin_backend_[module]_funcs' instance * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_put_backend(enum plugin_module module, void *data); +int syscommon_plugin_common_put_backend(enum syscommon_plugin_module module, + void *data); /** * @brief Get the backend data with the specific library name according to the type of PLUGIN module @@ -80,7 +85,8 @@ int plugin_common_put_backend(enum plugin_module module, void *data); * @param[in] PLUGIN backend library name which is not default library name * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_get_backend_with_library_name( + enum syscommon_plugin_module module, void **data, const char *library_name); /** @@ -90,7 +96,8 @@ int plugin_common_get_backend_with_library_name(enum plugin_module module, * @param[in] PLUGIN backend library name which is not default library name * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_put_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_put_backend_with_library_name( + enum syscommon_plugin_module module, void *data, const char *library_name); /** @@ -99,15 +106,17 @@ int plugin_common_put_backend_with_library_name(enum plugin_module module, * @param[in] PLUGIN ABI version of backend module among enum plugin_abi_version * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_check_backend_abi_version(enum plugin_module module, - enum plugin_abi_version abi_version); +int syscommon_plugin_common_check_backend_abi_version( + enum syscommon_plugin_module module, + enum syscommon_plugin_abi_version abi_version); /** * @brief Get the backend PLUGIN ABI version according to the type of PLUGIN module * @param[in] PLUGIN module id among enum plugin_moudle * @return @c positive integer value on success, otherwise a zero error value */ -unsigned int plugin_common_get_backend_abi_version(enum plugin_module module); +unsigned int syscommon_plugin_common_get_backend_abi_version( + enum syscommon_plugin_module module); /** * @brief Get the backend name according to the type of PLUGIN module @@ -116,7 +125,9 @@ unsigned int plugin_common_get_backend_abi_version(enum plugin_module module); * @param[in] Arrary size of name[] * @return @c positive integer value on success, otherwise a zero error value */ -int plugin_common_get_backend_name(enum plugin_module module, char *name, int size); +int syscommon_plugin_common_get_backend_name( + enum syscommon_plugin_module module, + char *name, int size); /** * @brief Get the backend vendor description according to the type of PLUGIN module @@ -125,14 +136,17 @@ int plugin_common_get_backend_name(enum plugin_module module, char *name, int si * @param[in] Arrary size of vendor[] * @return @c positive integer value on success, otherwise a zero error value */ -int plugin_common_get_backend_vendor(enum plugin_module module, char *vendor, int size); +int syscommon_plugin_common_get_backend_vendor( + enum syscommon_plugin_module module, + char *vendor, int size); /** * @brief Get the number of the backend libraries according to the type of PLUGIN module * @param[in] PLUGIN module id among enum plugin_moudle * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_count(enum plugin_module module); +int syscommon_plugin_common_get_backend_count( + enum syscommon_plugin_module module); /** * @brief Get the backend library names according to the type of PLUGIN module @@ -142,7 +156,8 @@ int plugin_common_get_backend_count(enum plugin_module module); * @param[in] Maximum length of the library name * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_library_names(enum plugin_module module, +int syscommon_plugin_common_get_backend_library_names( + enum syscommon_plugin_module module, char **library_names, int library_count, int library_name_size); @@ -150,4 +165,4 @@ int plugin_common_get_backend_library_names(enum plugin_module module, #ifdef __cplusplus } #endif -#endif /* __PLUGIN_COMMON__ */ +#endif /* __SYSCOMMON_PLUGIN_COMMON__ */ diff --git a/src/plugin-api/common/plugin-api-common.pc.in b/src/plugin-api/common/libsyscommon-plugin-api-common.pc.in similarity index 64% rename from src/plugin-api/common/plugin-api-common.pc.in rename to src/plugin-api/common/libsyscommon-plugin-api-common.pc.in index 4738a7f..4271f1b 100644 --- a/src/plugin-api/common/plugin-api-common.pc.in +++ b/src/plugin-api/common/libsyscommon-plugin-api-common.pc.in @@ -9,8 +9,8 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: plugin-api-common -Description: Common plugin APIs +Name: libsyscommon-plugin-api-common +Description: Common system plugin APIs Version: @VERSION@ Cflags: -I${includedir} @PLUGIN_COMMON_INCLUDEDIR@ -Libs: -L${libdir} -lplugin-api-common @PLUGIN_COMMON_LIBS@ +Libs: -L${libdir} -lsyscommon-plugin-api-common @PLUGIN_COMMON_LIBS@ diff --git a/src/plugin-api/common/src/common.h b/src/plugin-api/common/src/common.h index 33e4560..a89fe09 100644 --- a/src/plugin-api/common/src/common.h +++ b/src/plugin-api/common/src/common.h @@ -27,7 +27,7 @@ #include -#include "plugin-common.h" +#include "syscommon-plugin-common.h" #ifdef __cplusplus extern "C" { @@ -71,7 +71,7 @@ static const char *const plugin_group_string[] = { }; /** - * plugin-api-common provides the PLUGIN ABI * (Application Binary Interface) + * syscommon-plugin-api-common provides the PLUGIN ABI * (Application Binary Interface) * version check feature which is used to check the ABI compatibility between * PLUGIN API package and PLUGIN backend package. * In order to compare ABI version between two binary, Tizen core platform @@ -86,15 +86,15 @@ static const char *const plugin_group_string[] = { * released officially. */ struct plugin_abi_version_match { - enum plugin_abi_version platform_abi_version; - enum plugin_abi_version backend_min_abi_version; + enum syscommon_plugin_abi_version platform_abi_version; + enum syscommon_plugin_abi_version backend_min_abi_version; }; struct __plugin_module_info { int usage_count; enum plugin_group group; - enum plugin_module module; + enum syscommon_plugin_module module; enum plugin_license license; char *module_name; char *backend_module_name; @@ -102,7 +102,7 @@ struct __plugin_module_info { char *library_name; char *library_name_64bit; void *handle; - plugin_backend *backend; + syscommon_plugin_backend *backend; char *symbol_name; unsigned int num_abi_versions; diff --git a/src/plugin-api/common/src/plugin-api-common.c b/src/plugin-api/common/src/syscommon-plugin-api-common.c similarity index 81% rename from src/plugin-api/common/src/plugin-api-common.c rename to src/plugin-api/common/src/syscommon-plugin-api-common.c index 0f5dcc6..b6fb3db 100644 --- a/src/plugin-api/common/src/plugin-api-common.c +++ b/src/plugin-api/common/src/syscommon-plugin-api-common.c @@ -36,7 +36,7 @@ #include #include "common.h" -#include "plugin-api-conf.h" +#include "syscommon-plugin-api-conf.h" extern char *program_invocation_name; @@ -44,11 +44,11 @@ extern char *program_invocation_name; #define EXPORT __attribute__ ((visibility("default"))) #endif -static enum plugin_abi_version g_platform_curr_abi_version; +static enum syscommon_plugin_abi_version g_platform_curr_abi_version; G_LOCK_DEFINE_STATIC(plugin_common_lock); EXPORT -int plugin_common_get_backend_library_name(enum plugin_module module, char *name, int size) +int syscommon_plugin_common_get_backend_library_name(enum syscommon_plugin_module module, char *name, int size) { const char *library_name = NULL; struct __plugin_module_info *info = NULL; @@ -56,7 +56,7 @@ int plugin_common_get_backend_library_name(enum plugin_module module, char *name int len_library_name; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -94,7 +94,7 @@ out: } EXPORT -int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int size) +int syscommon_plugin_common_get_backend_symbol_name(enum syscommon_plugin_module module, char *name, int size) { struct __plugin_module_info *info = NULL; char *symbol_name = NULL; @@ -102,7 +102,7 @@ int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int len_symbol_name; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid paramer of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -233,7 +233,7 @@ static int __init_backend(struct __plugin_module_info *info, void **data, } /* Check PLUGIN ABI Version */ - ret = plugin_common_check_backend_abi_version(info->module, + ret = syscommon_plugin_common_check_backend_abi_version(info->module, info->backend->abi_version); if (ret < 0) { _E("%s: Failed to check ABI version\n", info->module_name); @@ -276,13 +276,13 @@ static int __exit_backend(struct __plugin_module_info *info, void *data, return 0; } -static int __get_backend(enum plugin_module module, void **data, +static int __get_backend(enum syscommon_plugin_module module, void **data, const char *library_name) { struct __plugin_module_info *info = NULL; int ret; - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -334,14 +334,14 @@ err: return ret; } -static int __put_backend(enum plugin_module module, void *data, +static int __put_backend(enum syscommon_plugin_module module, void *data, const char *library_name) { struct __plugin_module_info *info = NULL; int ret; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -397,13 +397,13 @@ out: return ret; } -static int __get_backend_data(enum plugin_module module, unsigned int *abi_version, +static int __get_backend_data(enum syscommon_plugin_module module, unsigned int *abi_version, char *name, int name_size, char *vendor, int vendor_size) { struct __plugin_module_info *info = NULL; int ret, len; - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return 0; } @@ -411,14 +411,14 @@ static int __get_backend_data(enum plugin_module module, unsigned int *abi_versi G_LOCK(plugin_common_lock); if (_plugin_api_conf_init()) { - ret = PLUGIN_ABI_VERSION_UNKNOWN; + ret = SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN; goto err_unlock; } info = _plugin_api_conf_get_module_info(module, NULL); if (info == NULL) { _E("Failed to get PLUGIN module(%d) information\n", module); - ret = PLUGIN_ABI_VERSION_UNKNOWN; + ret = SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN; goto err_conf_exit; } @@ -468,47 +468,47 @@ err_unlock: } EXPORT -int plugin_common_get_backend(enum plugin_module module, void **data) +int syscommon_plugin_common_get_backend(enum syscommon_plugin_module module, void **data) { return __get_backend(module, data, NULL); } EXPORT -int plugin_common_put_backend(enum plugin_module module, void *data) +int syscommon_plugin_common_put_backend(enum syscommon_plugin_module module, void *data) { return __put_backend(module, data, NULL); } EXPORT -int plugin_common_get_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_get_backend_with_library_name(enum syscommon_plugin_module module, void **data, const char *library_name) { return __get_backend(module, data, library_name); } EXPORT -int plugin_common_put_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_put_backend_with_library_name(enum syscommon_plugin_module module, void *data, const char *library_name) { return __put_backend(module, data, library_name); } EXPORT -int plugin_common_check_backend_abi_version(enum plugin_module module, - enum plugin_abi_version abi_version) +int syscommon_plugin_common_check_backend_abi_version(enum syscommon_plugin_module module, + enum syscommon_plugin_abi_version abi_version) { struct __plugin_module_info *info = NULL; int i; int ret; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid paramer of PLUGIN module(%d)\n", module); return -EINVAL; } - if (abi_version <= PLUGIN_ABI_VERSION_UNKNOWN - || abi_version >= PLUGIN_ABI_VERSION_END) { + if (abi_version <= SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN + || abi_version >= SYSCOMMON_PLUGIN_ABI_VERSION_END) { _E("Invalid paramer of PLUGIN ABI version(%d) for PLUGIN module(%d)\n", abi_version, module); return -EINVAL; @@ -534,8 +534,8 @@ int plugin_common_check_backend_abi_version(enum plugin_module module, g_platform_curr_abi_version = _plugin_api_conf_get_platform_abi_version(); - if (g_platform_curr_abi_version <= PLUGIN_ABI_VERSION_UNKNOWN - || g_platform_curr_abi_version >= PLUGIN_ABI_VERSION_END) { + if (g_platform_curr_abi_version <= SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN + || g_platform_curr_abi_version >= SYSCOMMON_PLUGIN_ABI_VERSION_END) { _E("Invalid paramer of current PLUGIN ABI version(%d)(%d)\n", g_platform_curr_abi_version, module); ret = -EINVAL; @@ -549,8 +549,8 @@ int plugin_common_check_backend_abi_version(enum plugin_module module, if (g_platform_curr_abi_version != data->platform_abi_version) continue; - if (data->backend_min_abi_version <= PLUGIN_ABI_VERSION_UNKNOWN || - data->backend_min_abi_version >= PLUGIN_ABI_VERSION_END) { + if (data->backend_min_abi_version <= SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN || + data->backend_min_abi_version >= SYSCOMMON_PLUGIN_ABI_VERSION_END) { _E("%s: abi_versions[%d].backend_min_abi_version(%d) is invalid\n", info->module_name, i, data->backend_min_abi_version); ret = -EINVAL; @@ -565,12 +565,12 @@ int plugin_common_check_backend_abi_version(enum plugin_module module, _E("%s: \'%s\' doesn't support \'%s\'\n", info->module_name, - plugin_abi_version_str[g_platform_curr_abi_version], - plugin_abi_version_str[abi_version]); + syscommon_plugin_abi_version_str[g_platform_curr_abi_version], + syscommon_plugin_abi_version_str[abi_version]); _E("%s: Must use ABI versions from \'%s\' to \'%s\'\n", info->module_name, - plugin_abi_version_str[data->backend_min_abi_version], - plugin_abi_version_str[data->platform_abi_version]); + syscommon_plugin_abi_version_str[data->backend_min_abi_version], + syscommon_plugin_abi_version_str[data->platform_abi_version]); } ret = -EINVAL; @@ -580,32 +580,32 @@ out: } EXPORT -unsigned int plugin_common_get_backend_abi_version(enum plugin_module module) +unsigned int syscommon_plugin_common_get_backend_abi_version(enum syscommon_plugin_module module) { unsigned int abi_version; int ret; ret = __get_backend_data(module, &abi_version, NULL, 0, NULL, 0); if (ret < 0) - return PLUGIN_ABI_VERSION_UNKNOWN; + return SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN; return abi_version; } EXPORT -int plugin_common_get_backend_name(enum plugin_module module, char *name, int size) +int syscommon_plugin_common_get_backend_name(enum syscommon_plugin_module module, char *name, int size) { return __get_backend_data(module, NULL, name, size, NULL, 0); } EXPORT -int plugin_common_get_backend_vendor(enum plugin_module module, char *vendor, int size) +int syscommon_plugin_common_get_backend_vendor(enum syscommon_plugin_module module, char *vendor, int size) { return __get_backend_data(module, NULL, NULL, 0, vendor, size); } -static int __get_backend_library_data(enum plugin_module module, +static int __get_backend_library_data(enum syscommon_plugin_module module, char **lib_names, int lib_count, int lib_name_size) @@ -616,16 +616,16 @@ static int __get_backend_library_data(enum plugin_module module, char *backend_module_name = NULL; int count, i, ret; #if defined(__aarch64__) || defined(__x86_64__) - const char plugin_backend_path[] = "/usr/lib64/plugin"; + const char plugin_backend_path[] = "/usr/lib64/system/plugin"; #else - const char plugin_backend_path[] = "/usr/lib/plugin"; + const char plugin_backend_path[] = "/usr/lib/system/plugin"; #endif /* Check if lib_names and lib_count are valid */ assert(!(lib_names == NULL && lib_count != 0)); /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -646,7 +646,7 @@ static int __get_backend_library_data(enum plugin_module module, ret = -EINVAL; goto err; } - backend_module_name = g_strdup_printf("libplugin-backend-%s", + backend_module_name = g_strdup_printf("libplugin-%s", info->backend_module_name); if (!backend_module_name) { _E("Failed to allocate the backend_module_name of PLUGIN module(%s)\n", @@ -707,13 +707,14 @@ err: } EXPORT -int plugin_common_get_backend_count(enum plugin_module module) +int syscommon_plugin_common_get_backend_count(enum syscommon_plugin_module module) { return __get_backend_library_data(module, NULL, 0, 0); } EXPORT -int plugin_common_get_backend_library_names(enum plugin_module module, +int syscommon_plugin_common_get_backend_library_names( + enum syscommon_plugin_module module, char **library_names, int library_count, int library_name_size) diff --git a/src/plugin-api/common/src/plugin-api-conf.c b/src/plugin-api/common/src/syscommon-plugin-api-conf.c similarity index 86% rename from src/plugin-api/common/src/plugin-api-conf.c rename to src/plugin-api/common/src/syscommon-plugin-api-conf.c index bb560a2..19daa1a 100644 --- a/src/plugin-api/common/src/plugin-api-conf.c +++ b/src/plugin-api/common/src/syscommon-plugin-api-conf.c @@ -27,12 +27,12 @@ #include #include -#include "plugin-common.h" -#include "plugin-common-interface.h" +#include "syscommon-plugin-common.h" +#include "syscommon-plugin-common-interface.h" #include "common.h" -#include "plugin-api-conf.h" -#include "plugin-api-list.h" +#include "syscommon-plugin-api-conf.h" +#include "syscommon-plugin-api-list.h" #ifndef EXPORT #define EXPORT __attribute__ ((visibility("default"))) @@ -57,13 +57,14 @@ void _destroy_module_info(gpointer data) } } -static struct __plugin_module_info* _get_module_info(enum plugin_module module) +static struct __plugin_module_info* _get_module_info(enum syscommon_plugin_module module) { return &g_plugin_module_info[module]; } -static struct __plugin_module_info* _get_module_info_with_library_name(enum plugin_module module, - const char *library_name) +static struct __plugin_module_info* _get_module_info_with_library_name( + enum syscommon_plugin_module module, + const char *library_name) { struct __plugin_module_info *info = NULL, *new_info = NULL, *tmp_info = NULL; char *library_name_prefix = NULL; @@ -82,7 +83,7 @@ static struct __plugin_module_info* _get_module_info_with_library_name(enum plug tmp_info->module_name); return NULL; } - library_name_prefix = g_strdup_printf("libplugin-backend-%s", + library_name_prefix = g_strdup_printf("libplugin-%s", tmp_info->backend_module_name); if (!library_name_prefix) { _E("Failed to allocate library_name_prefix of PLUGIN module(%s)\n", @@ -120,9 +121,9 @@ static struct __plugin_module_info* _get_module_info_with_library_name(enum plug new_info->license = info->license; new_info->module_name = g_strdup(info->module_name); #if defined(__aarch64__) || defined(__x86_64__) - new_info->library_name_64bit = g_strdup_printf("/usr/lib64/plugin/%s", library_name); + new_info->library_name_64bit = g_strdup_printf("/usr/lib64/system/plugin/%s", library_name); #else - new_info->library_name = g_strdup_printf("/usr/lib/plugin/%s", library_name); + new_info->library_name = g_strdup_printf("/usr/lib/system/plugin/%s", library_name); #endif new_info->symbol_name = g_strdup(info->symbol_name); new_info->num_abi_versions = info->num_abi_versions; @@ -137,7 +138,7 @@ out: } EXPORT -struct __plugin_module_info* _plugin_api_conf_get_module_info(enum plugin_module module, +struct __plugin_module_info* _plugin_api_conf_get_module_info(enum syscommon_plugin_module module, const char *library_name) { if (!_module_hash) @@ -150,7 +151,7 @@ struct __plugin_module_info* _plugin_api_conf_get_module_info(enum plugin_module } -enum plugin_abi_version _plugin_api_conf_get_platform_abi_version(void) +enum syscommon_plugin_abi_version _plugin_api_conf_get_platform_abi_version(void) { return g_platform_curr_abi_version; } diff --git a/src/plugin-api/common/src/plugin-api-conf.h b/src/plugin-api/common/src/syscommon-plugin-api-conf.h similarity index 78% rename from src/plugin-api/common/src/plugin-api-conf.h rename to src/plugin-api/common/src/syscommon-plugin-api-conf.h index 2d59713..20e8b32 100644 --- a/src/plugin-api/common/src/plugin-api-conf.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-conf.h @@ -22,13 +22,13 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_API_CONF__ -#define __PLUGIN_API_CONF__ +#ifndef __SYSCOMMON_PLUGIN_API_CONF__ +#define __SYSCOMMON_PLUGIN_API_CONF__ #include #include -#include "plugin-common-interface.h" +#include "syscommon-plugin-common-interface.h" #ifdef __cplusplus extern "C" { @@ -37,12 +37,13 @@ extern "C" { int _plugin_api_conf_init(void); void _plugin_api_conf_exit(void); -struct __plugin_module_info *_plugin_api_conf_get_module_info(enum plugin_module module, - const char *library_name); +struct __plugin_module_info *_plugin_api_conf_get_module_info( + enum syscommon_plugin_module module, + const char *library_name); -enum plugin_abi_version _plugin_api_conf_get_platform_abi_version(void); +enum syscommon_plugin_abi_version _plugin_api_conf_get_platform_abi_version(void); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* __PLUGIN_API_CONF__ */ +#endif /* __SYSCOMMON_PLUGIN_API_CONF__ */ diff --git a/src/plugin-api/common/src/plugin-api-list.h b/src/plugin-api/common/src/syscommon-plugin-api-list.h similarity index 56% rename from src/plugin-api/common/src/plugin-api-list.h rename to src/plugin-api/common/src/syscommon-plugin-api-list.h index 79439fb..e7b0ee6 100644 --- a/src/plugin-api/common/src/plugin-api-list.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-list.h @@ -22,38 +22,39 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_API_LIST_H__ -#define __PLUGIN_API_LIST_H__ +#ifndef __SYSCOMMON_PLUGIN_API_LIST_H__ +#define __SYSCOMMON_PLUGIN_API_LIST_H__ -#include "plugin-common.h" +#include "syscommon-plugin-common.h" #include "common.h" #define PLUGIN_ABI_VERSION_MAX 10 -enum plugin_abi_version g_platform_curr_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5; +enum syscommon_plugin_abi_version g_platform_curr_abi_version = + SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5; -static struct plugin_abi_version_match abi_version_match_data[PLUGIN_MODULE_END][PLUGIN_ABI_VERSION_MAX] = { - [PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { +static struct plugin_abi_version_match abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_END][PLUGIN_ABI_VERSION_MAX] = { + [SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { [0] = { - .platform_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, - .backend_min_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, + .platform_abi_version = SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5, + .backend_min_abi_version = SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5, }, }, }; static struct __plugin_module_info g_plugin_module_info[] = { - [PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { + [SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { .group = PLUGIN_GROUP_RESOURCED, - .module = PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + .module = SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, .license = PLUGIN_LICENSE_APACHE_2_0, - .module_name = "PLUGIN_MODULE_RESOURCED_MEMORY_LMK", + .module_name = "SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK", .backend_module_name = "resourced-memory-lmk", - .library_name = "/usr/lib/plugin/libplugin-backend-resourced-memory-lmk.so", - .library_name_64bit = "/usr/lib64/plugin/libplugin-backend-resourced-memory-lmk.so", - .symbol_name = "plugin_backend_resourced_memory_lmk_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[PLUGIN_MODULE_RESOURCED_MEMORY_LMK]), - .abi_versions = abi_version_match_data[PLUGIN_MODULE_RESOURCED_MEMORY_LMK], + .library_name = "/usr/lib/system/plugin/libplugin-resourced-memory-lmk.so", + .library_name_64bit = "/usr/lib64/system/plugin/libplugin-resourced-memory-lmk.so", + .symbol_name = "system_plugin_backend_resourced_memory_lmk_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK]), + .abi_versions = abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK], }, }; diff --git a/src/plugin-api/deviced/CMakeLists.txt b/src/plugin-api/deviced/CMakeLists.txt index 89ed42d..78af80a 100644 --- a/src/plugin-api/deviced/CMakeLists.txt +++ b/src/plugin-api/deviced/CMakeLists.txt @@ -1,15 +1,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(plugin-api-deviced) +PROJECT(syscommon-plugin-api-deviced) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}/bin") SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(INCLUDEDIR "${PREFIX}/include/system") SET(VERSION ${PLUGIN_API_DEVICED_VERSION}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -# Including below should be removed if the repository of plugin-api-common is -# separated. +# Including below should be removed if the repository of +# syscommon-plugin-api-common is separated. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) if (${PLUGIN_API_DEVICED_ENABLE_DLOG}) @@ -17,7 +17,7 @@ if (${PLUGIN_API_DEVICED_ENABLE_DLOG}) glib-2.0 dlog) ADD_DEFINITIONS("-DENABLE_DLOG") - ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_DEVICED\"") + ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_DEVICED\"") else() SET(PKG_MODULES glib-2.0) @@ -35,12 +35,13 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -# plugin-api-common.c and plugin-api-conf.c are unnecessary if the repository of -# plugin-api-common is separated. -# Please remove them from SRCS and add 'plugin-api-common' to PKG_MODULES. -SET(SRCS src/plugin-deviced-display.c - ../common/src/plugin-api-common.c - ../common/src/plugin-api-conf.c) +# syscommon-plugin-api-common.c and syscommon-plugin-api-conf.c are unnecessary +# if the repository of syscommon-plugin-api-common is separated. +# Please remove them from SRCS and add 'syscommon-plugin-api-common' +# to PKG_MODULES. +SET(SRCS src/syscommon-plugin-deviced-display.c + ../common/src/syscommon-plugin-api-common.c + ../common/src/syscommon-plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} @@ -62,5 +63,6 @@ ENDFOREACH(include_dirs) FOREACH(libraries ${pkgs_LIBRARIES}) SET(PLUGIN_DEVICED_LIBS "${PLUGIN_DEVICED_LIBS} -l${libraries}") ENDFOREACH(libraries) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +SET(PACKAGE_CONFIG_FILE "lib${PROJECT_NAME}.pc") +CONFIGURE_FILE(${PACKAGE_CONFIG_FILE}.in ${PACKAGE_CONFIG_FILE} @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/deviced/include/plugin-deviced-display-interface.h b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display-interface.h similarity index 87% rename from src/plugin-api/deviced/include/plugin-deviced-display-interface.h rename to src/plugin-api/deviced/include/syscommon-plugin-deviced-display-interface.h index 2a0c909..6b094a3 100644 --- a/src/plugin-api/deviced/include/plugin-deviced-display-interface.h +++ b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display-interface.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ -#define __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#ifndef __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#define __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ #ifdef __cplusplus extern "C" { @@ -33,4 +33,4 @@ extern "C" { } #endif -#endif //__PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#endif //__SYSCOMMON_PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ diff --git a/src/plugin-api/deviced/include/plugin-deviced-display.h b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display.h similarity index 89% rename from src/plugin-api/deviced/include/plugin-deviced-display.h rename to src/plugin-api/deviced/include/syscommon-plugin-deviced-display.h index 14e5c6c..c0267c3 100644 --- a/src/plugin-api/deviced/include/plugin-deviced-display.h +++ b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_DEVICED_DISPLAY_H__ -#define __PLUGIN_DEVICED_DISPLAY_H__ +#ifndef __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_H__ +#define __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_H__ #ifdef __cplusplus extern "C" { @@ -33,4 +33,4 @@ extern "C" { } #endif -#endif //__PLUGIN_DEVICED_DISPLAY_H__ +#endif //__SYSCOMMON_PLUGIN_DEVICED_DISPLAY_H__ diff --git a/src/plugin-api/deviced/plugin-api-deviced.pc.in b/src/plugin-api/deviced/libsyscommon-plugin-api-deviced.pc.in similarity index 56% rename from src/plugin-api/deviced/plugin-api-deviced.pc.in rename to src/plugin-api/deviced/libsyscommon-plugin-api-deviced.pc.in index a328de4..100d572 100644 --- a/src/plugin-api/deviced/plugin-api-deviced.pc.in +++ b/src/plugin-api/deviced/libsyscommon-plugin-api-deviced.pc.in @@ -9,9 +9,9 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: plugin-api-deviced -Description: Plugin APIs for the deviced +Name: libsyscommon-plugin-api-deviced +Description: System plugin APIs for the deviced Version: @VERSION@ -Requires.private: plugin-api-common +Requires.private: libsyscommon-plugin-api-common Cflags: -I${includedir} @PLUGIN_DEVICED_INCLUDEDIR@ -Libs: -L${libdir} -lplugin-api-deviced @PLUGIN_DEVICED_LIBS@ +Libs: -L${libdir} -lsyscommon-plugin-api-deviced @PLUGIN_DEVICED_LIBS@ diff --git a/src/plugin-api/deviced/src/plugin-deviced-display.c b/src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c similarity index 100% rename from src/plugin-api/deviced/src/plugin-deviced-display.c rename to src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c diff --git a/src/plugin-api/resourced/CMakeLists.txt b/src/plugin-api/resourced/CMakeLists.txt index 114cbcb..9060f8e 100644 --- a/src/plugin-api/resourced/CMakeLists.txt +++ b/src/plugin-api/resourced/CMakeLists.txt @@ -1,16 +1,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(plugin-api-resourced) +PROJECT(syscommon-plugin-api-resourced) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}/bin") SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(INCLUDEDIR "${PREFIX}/include/system") SET(VERSION ${PLUGIN_API_RESOURCED_VERSION}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -# Including below should be removed if the repository of plugin-api-common is -# separated. +# Including below should be removed if the repository of +# syscommon-plugin-api-common is separated. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) if (${PLUGIN_API_RESOURCED_ENABLE_DLOG}) @@ -18,7 +18,7 @@ if (${PLUGIN_API_RESOURCED_ENABLE_DLOG}) glib-2.0 dlog) ADD_DEFINITIONS("-DENABLE_DLOG") - ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_RESOURCED\"") + ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_RESOURCED\"") else() SET(PKG_MODULES glib-2.0) @@ -36,12 +36,13 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -# plugin-api-common.c and plugin-api-conf.c are unnecessary if the repository of -# plugin-api-common is separated. -# Please remove them from SRCS and add 'plugin-api-common' to PKG_MODULES. -SET(SRCS src/plugin-resourced-memory-lmk.c - ../common/src/plugin-api-common.c - ../common/src/plugin-api-conf.c) +# syscommon-plugin-api-common.c and syscommon-plugin-api-conf.c are unnecessary +# if the repository of syscommon-plugin-api-common is separated. +# Please remove them from SRCS and add 'syscommon-plugin-api-common' +# to PKG_MODULES. +SET(SRCS src/syscommon-plugin-resourced-memory-lmk.c + ../common/src/syscommon-plugin-api-common.c + ../common/src/syscommon-plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} @@ -63,5 +64,6 @@ ENDFOREACH(include_dirs) FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_RESOURCED_LIBS "${PLUGIN_RESOURCED_LIBS} -l${libraries}") ENDFOREACH(libraries) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +SET(PACKAGE_CONFIG_FILE "lib${PROJECT_NAME}.pc") +CONFIGURE_FILE(${PACKAGE_CONFIG_FILE}.in ${PACKAGE_CONFIG_FILE} @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk-interface.h similarity index 81% rename from src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h rename to src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk-interface.h index e936fc0..9bfc4ac 100644 --- a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h +++ b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk-interface.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ -#define __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ +#ifndef __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ +#define __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ #include @@ -31,16 +31,16 @@ extern "C" { #endif -typedef struct _plugin_backend_resourced_memory_lmk_funcs { +typedef struct _syscommon_plugin_backend_resourced_memory_lmk_funcs { int (*get_kill_candidates)(GArray *candidates, GArray *task_info_app_array, GArray *task_info_proc_array, unsigned long totalram_kb); -} plugin_backend_resourced_memory_lmk_funcs; +} syscommon_plugin_backend_resourced_memory_lmk_funcs; #ifdef __cplusplus } #endif -#endif /* __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ */ +#endif /* __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ */ diff --git a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk.h similarity index 88% rename from src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h rename to src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk.h index 9d58ca5..49f257b 100644 --- a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h +++ b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_RESOURCED_MEMORY_LMK_H__ -#define __PLUGIN_RESOURCED_MEMORY_LMK_H__ +#ifndef __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__ +#define __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__ #include #include @@ -65,13 +65,13 @@ struct task_info { * @brief Get the backend data of resourced-memory-lmk module * @return @c 0 on success, otherwise a negative error value */ -int plugin_resourced_memory_lmk_get_backend(void); +int syscommon_plugin_resourced_memory_lmk_get_backend(void); /** * @brief Put the backend data of resourced-memory-lmk module * @return @c 0 on success, otherwise a negative error value */ -int plugin_resourced_memory_lmk_put_backend(void); +int syscommon_plugin_resourced_memory_lmk_put_backend(void); /** * @brief Call the get_kill_candidates function of resourced-memory-lmk module @@ -82,7 +82,8 @@ int plugin_resourced_memory_lmk_put_backend(void); * @return @c the number of kill candidates on success, * otherwise a negative error value */ -int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, +int syscommon_plugin_resourced_memory_lmk_get_kill_candidates( + GArray *candidates, GArray *task_info_app_array, GArray *task_info_proc_array, unsigned long totalram_kb); @@ -91,4 +92,4 @@ int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, } #endif -#endif /* __PLUGIN_RESOURCED_MEMORY_LMK_H__ */ +#endif /* __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__ */ diff --git a/src/plugin-api/resourced/plugin-api-resourced.pc.in b/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in similarity index 55% rename from src/plugin-api/resourced/plugin-api-resourced.pc.in rename to src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in index 6b406aa..d1292b6 100644 --- a/src/plugin-api/resourced/plugin-api-resourced.pc.in +++ b/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in @@ -9,9 +9,9 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: plugin-api-resourced -Description: Plugin APIs for the resourced +Name: libsyscommon-plugin-api-resourced +Description: System plugin APIs for the resourced Version: @VERSION@ -Requires.private: plugin-api-common +Requires.private: libsyscommon-plugin-api-common Cflags: -I${includedir} @PLUGIN_RESOURCED_INCLUDEDIR@ -Libs: -L${libdir} -lplugin-api-resourced @PLUGIN_RESOURCED_LIBS@ +Libs: -L${libdir} -lsyscommon-plugin-api-resourced @PLUGIN_RESOURCED_LIBS@ diff --git a/src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c b/src/plugin-api/resourced/src/syscommon-plugin-resourced-memory-lmk.c similarity index 74% rename from src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c rename to src/plugin-api/resourced/src/syscommon-plugin-resourced-memory-lmk.c index f1aed5b..c79eeb0 100644 --- a/src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c +++ b/src/plugin-api/resourced/src/syscommon-plugin-resourced-memory-lmk.c @@ -24,28 +24,29 @@ #include -#include "plugin-common.h" +#include "syscommon-plugin-common.h" #include "common.h" -#include "plugin-resourced-memory-lmk.h" -#include "plugin-resourced-memory-lmk-interface.h" +#include "syscommon-plugin-resourced-memory-lmk.h" +#include "syscommon-plugin-resourced-memory-lmk-interface.h" #ifndef EXPORT #define EXPORT __attribute__((visibility("default"))) #endif -static plugin_backend_resourced_memory_lmk_funcs *funcs = NULL; +static syscommon_plugin_backend_resourced_memory_lmk_funcs *funcs = NULL; EXPORT -int plugin_resourced_memory_lmk_get_backend(void) +int syscommon_plugin_resourced_memory_lmk_get_backend(void) { int ret = 0; if (funcs) return 0; - ret = plugin_common_get_backend( - PLUGIN_MODULE_RESOURCED_MEMORY_LMK, (void **)&funcs); + ret = syscommon_plugin_common_get_backend( + SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + (void **)&funcs); if (ret < 0) { _E("Failed to get resourced_memory_lmk backend: %d", ret); return ret; @@ -57,15 +58,16 @@ int plugin_resourced_memory_lmk_get_backend(void) } EXPORT -int plugin_resourced_memory_lmk_put_backend(void) +int syscommon_plugin_resourced_memory_lmk_put_backend(void) { int ret = 0; if (!funcs) return 0; - ret = plugin_common_put_backend( - PLUGIN_MODULE_RESOURCED_MEMORY_LMK, (void *)funcs); + ret = syscommon_plugin_common_put_backend( + SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + (void *)funcs); if (ret < 0) { _E("Failed to put resourced_memory_lmk backend: %d", ret); return ret; @@ -78,7 +80,8 @@ int plugin_resourced_memory_lmk_put_backend(void) } EXPORT -int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, +int syscommon_plugin_resourced_memory_lmk_get_kill_candidates( + GArray *candidates, GArray *task_info_app_array, GArray *task_info_proc_array, unsigned long totalram_kb) @@ -86,7 +89,7 @@ int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, int ret = 0; if (!funcs) { - ret = plugin_resourced_memory_lmk_get_backend(); + ret = syscommon_plugin_resourced_memory_lmk_get_backend(); if (ret < 0) return ret; } -- 2.7.4