Line data Source code
1 : /* SPDX-License-Identifier: Apache-2.0 */
2 : /**
3 : * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
4 : *
5 : * @file modules.c
6 : * @date 25 June 2022
7 : * @brief Internal module utility header of Machine Learning agent daemon
8 : * @see https://github.com/nnstreamer/deviceMLOps.MLAgent
9 : * @author Sangjung Woo <sangjung.woo@samsung.com>
10 : * @bug No known bugs except for NYI items
11 : */
12 :
13 : #include <glib.h>
14 : #include <stdio.h>
15 :
16 : #include "common.h"
17 : #include "modules.h"
18 : #include "log.h"
19 :
20 : static GList *module_head = NULL;
21 :
22 : /**
23 : * @brief Add the specific DBus interface into the Machine Learning agent daemon.
24 : */
25 : void
26 72 : add_module (const struct module_ops *module)
27 : {
28 72 : module_head = g_list_append (module_head, (gpointer) module);
29 72 : }
30 :
31 : /**
32 : * @brief Remove the specific DBus interface from the Machine Learning agent daemon.
33 : */
34 : void
35 72 : remove_module (const struct module_ops *module)
36 : {
37 72 : module_head = g_list_remove (module_head, (gconstpointer) module);
38 72 : }
39 :
40 : /**
41 : * @brief Initialize all added modules by calling probe and init callback functions.
42 : */
43 : void
44 19 : init_modules (void *data)
45 : {
46 : GList *elem, *elem_n;
47 : const struct module_ops *module;
48 :
49 19 : elem = module_head;
50 76 : while (elem != NULL) {
51 57 : module = elem->data;
52 57 : elem_n = elem->next;
53 :
54 57 : if (module->probe && module->probe (data) != 0) {
55 0 : ml_loge ("[%s] probe fail", module->name);
56 0 : module_head = g_list_remove (module_head, (gconstpointer) module);
57 0 : elem = elem_n;
58 0 : continue;
59 : }
60 :
61 57 : if (module->init)
62 57 : module->init (data);
63 57 : elem = elem_n;
64 : }
65 19 : }
66 :
67 : /**
68 : * @brief Clean up all added modules by calling the exit callback function.
69 : */
70 : void
71 19 : exit_modules (void *data)
72 : {
73 : GList *elem;
74 : const struct module_ops *module;
75 :
76 76 : for (elem = module_head; elem != NULL; elem = elem->next) {
77 57 : module = elem->data;
78 57 : if (module->exit)
79 57 : module->exit (data);
80 : }
81 19 : }
|