common : module : define module_foreach_func 95/141495/4
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 1 Aug 2017 01:10:07 +0000 (10:10 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 2 Aug 2017 02:06:43 +0000 (11:06 +0900)
- To use module_foreach, we had to convert gpointer to struct module
- It is because of using g_slist_foreach which needs GFunc
- For convenience, call func directly with using struct module

Change-Id: I9efced0e82860d6c7de068c1853d8dc3ae058b90
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/common/event.c
src/common/module.c
src/common/module.h

index cb8654dd0b747cab5e3aaee023f25b3e932050a0..813fb2e2ff11815222be7448f8e0a84cb811183a 100644 (file)
@@ -63,9 +63,8 @@ API int event_send(char *dest, enum event_type type, void *data)
 /**
  * @brief  Push an event and wake up module's event worker
  */
-static void event_push(gpointer data, gpointer user_data)
+static void event_push(struct module *module, void *user_data)
 {
-       struct module *module = data;
        struct event *event = user_data;
 
        if (!module || !event) {
index 3dc11275b79eb4d08843842720475f8c8c3da9ce..94e51ed4b74523d818bd24ddaeb8f0ab5a74d76d 100644 (file)
@@ -57,14 +57,21 @@ API struct module *module_find(const char *name)
        return NULL;
 }
 
-API void module_foreach(GFunc func, gpointer user_data)
+API void module_foreach(module_foreach_func func, void *user_data)
 {
-       g_slist_foreach(module_list, func, user_data);
+       struct module *module;
+
+       if (!func) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       G_SLIST_FOREACH(module_list, module)
+               func(module, user_data);
 }
 
-static void module_init(gpointer data, gpointer user_data)
+static void module_init(struct module *module, void *user_data)
 {
-       struct module *module = data;
        int *num_successful = (int *)user_data;
        int ret;
 
@@ -110,9 +117,8 @@ API int module_register(void)
        return num_successful;
 }
 
-static void module_exit(gpointer data, gpointer user_data)
+static void module_exit(struct module *module, void *user_data)
 {
-       struct module *module = data;
        int ret;
 
        if (module->event_handler) {
index b3089e37d681f68ca71b2890d9acb5d34ca2b0be..2385f6e7273ffafec0ded05044b05b70208602f0 100644 (file)
@@ -56,6 +56,8 @@ struct module {
        struct event_worker *event_worker;
 };
 
+typedef void (*module_foreach_func) (struct module *module, void *user_data);
+
 /**
  * @brief  Attach module to the module list
  * @param[in] module  Module structure
@@ -76,7 +78,7 @@ struct module *module_find(const char *name);
  * @param[in] func  Function to call with each module
  * @param[in] user_data  Argument to pass to the func
  */
-void module_foreach(GFunc func, gpointer user_data);
+void module_foreach(module_foreach_func func, void *user_data);
 
 /**
  * @brief  Initialize all modules in the module list