resource-manager: Introduce attribute listener operations 78/287478/4
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 12 Jan 2023 01:01:22 +0000 (10:01 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 13 Feb 2023 06:40:35 +0000 (15:40 +0900)
Now each attribute can have 'listener_ops' which consists 'init',
'exit', and 'action', to watch changes for underlying state. Each
operation has a role as below:

 - init: allocate resources and register listeners
 - exit: deallocate resources and unregister listeners
 - action: change attribute values as following listener parameters

'init'/'exit' is called automatically when each attribute interest is
set/unset each, on the other hand, 'action' should be called by each
listener.

Change-Id: I076f41f751b18f4c39d7548e4d78ddc02e8e26a2
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
CMakeLists.txt
src/resource-manager/resource-listener.h [new file with mode: 0644]
src/resource-manager/resource-manager.c
src/resource-manager/resource-manager.h

index d9d7f07..50dabeb 100644 (file)
@@ -31,6 +31,7 @@ SET(HEADERS
        src/resource-manager/resource-manager.h
        src/resource-manager/resource-type.h
        src/resource-manager/resource-device.h
+       src/resource-manager/resource-listener.h
 )
 
 # CHECK PKG
diff --git a/src/resource-manager/resource-listener.h b/src/resource-manager/resource-listener.h
new file mode 100644 (file)
index 0000000..980cf00
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __RESOURCE_LISTENER_H__
+#define __RESOURCE_LISTENER_H__
+
+enum syscommon_resman_listener_type {
+       SYSCOMMON_RESMAN_LISTENER_TYPE_UNKNOWN,
+       SYSCOMMON_RESMAN_LISTENER_TYPE_EPOLL,
+       SYSCOMMON_RESMAN_LISTENER_TYPE_UEVENT,
+       SYSCOMMON_RESMAN_LISTENER_TYPE_TIMER,
+       SYSCOMMON_RESMAN_LISTENER_TYPE_MAX,
+};
+
+#endif
index 7167ca2..92d87ee 100644 (file)
@@ -1066,6 +1066,12 @@ syscommon_resman_set_resource_attr_interest(int resource_id, u_int64_t interest_
                        goto err;
                }
 
+               if (resource->attrs[i].listener_ops.init) {
+                       ret = resource->attrs[i].listener_ops.init(resource_id, &resource->attrs[i]);
+                       if (ret < 0)
+                               goto err;
+               }
+
                /*
                 * In resource monitor, each resource has a lot of attributes, but
                 * only updated attributes are selected by clients on demand. So,
@@ -1116,6 +1122,9 @@ err:
                if (!(resource->attrs[i].id & interest_mask))
                        continue;
 
+               if (resource->attrs[i].listener_ops.exit)
+                       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)
                        continue;
@@ -1145,6 +1154,9 @@ unset_resource_attr_interest(struct syscommon_resman_resource *resource, u_int64
                if (!(resource->attrs[i].id & interest_mask))
                        continue;
 
+               if (resource->attrs[i].listener_ops.exit)
+                       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)
                        return -EINVAL;
index e838b8b..0f2ea53 100644 (file)
@@ -26,6 +26,8 @@
 
 #define SYSCOMMON_RESMAN_BUFF_MAX      255
 
+enum syscommon_resman_listener_type;
+
 struct syscommon_resman_resource_attribute;
 struct syscommon_resman_resource_control;
 
@@ -55,12 +57,20 @@ struct syscommon_resman_resource_attribute_ops {
                   const struct syscommon_resman_resource_attribute *attr);
 };
 
+struct syscommon_resman_resource_attribute_listener_ops {
+       int (*init)(int resource_id, const struct syscommon_resman_resource_attribute *attr);
+       void (*exit)(int resource_id, const struct syscommon_resman_resource_attribute *attr);
+       void (*action)(int resource_id, const struct syscommon_resman_resource_attribute *attr,
+                      void *param, enum syscommon_resman_listener_type listener_type);
+};
+
 struct syscommon_resman_resource_attribute {
        const char name[SYSCOMMON_RESMAN_BUFF_MAX];
        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_listener_ops listener_ops;
 };
 
 struct syscommon_resman_resource_control_ops {