resource-manager: Add convenient macro SYSCOMMON_RESOURCE_ID() 44/297044/2
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 9 Aug 2023 08:45:23 +0000 (17:45 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 9 Aug 2023 09:13:25 +0000 (18:13 +0900)
 The resource-manage APIs are working on top of the resource_id. Thus
an API user must get resource_id in advance to access resource instance.
Currently resource-manager provides syscommon_resman_get_resource_id()
for this purpose, however, it gets resource_id via parameter. Therefore,
it cannot pass resource_id directly to a function parameter.
 On the other hand, the convenient macro returns resource_id on success,
-1 on failure. As it returns reosurce_id, it can be used as an inline
parameter.

Change-Id: I45426096144c2a47de2554cbf2856b9f78d5b51d
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
include/libsyscommon/resource-manager.h

index ddf70b4..c7bb435 100644 (file)
@@ -191,6 +191,15 @@ int syscommon_resman_monitor_get_resource_attr_json(int resource_id, u_int64_t a
 int syscommon_resman_get_resource_list_json(char **json_string);
 int syscommon_resman_get_number_of_resource_instance(int resource_type, int *n_instance);
 int syscommon_resman_get_resource_id(int resource_type, int *resource_id);
+#define SYSCOMMON_RESOURCE_ID(resource_type) ({                                \
+       int _id;                                                        \
+       int _ret;                                                       \
+       if (syscommon_resman_get_resource_id(resource_type, &_id) >= 0) \
+               _ret = _id;                                             \
+       else                                                            \
+               _ret = -1;                                              \
+       _ret;                                                           \
+       })
 
 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);