1 | #include <svsconfig.h> |
1 | #include <svsconfig.h> |
2 | #include <common.h> |
2 | #include <common.h> |
3 | #include <ermyth/module.h> |
3 | #include <ermyth/module.h> |
4 | |
4 | |
5 | modules::modules (srcinf const &si, char const * const name, bool norestart, bool (*init)(module *), void (*fini)(), |
5 | modules::modules (impl::srcinf const &si, char const * const name, bool norestart, bool (*init)(module *), void (*fini)(), |
6 | char const * const vendor, char const * const modversion) |
6 | char const * const vendor, char const * const modversion) |
7 | { |
7 | { |
8 | if (provides (name)) |
8 | if (provides (name)) |
9 | throw module_exception (si, "Trying to register two modules with the same name: %s", name); |
9 | throw module_exception (si, "Trying to register two modules with the same name: %s", name); |
10 | module *mod = new module (name, norestart, init, fini, vendor, modversion); |
10 | module *mod = new module (name, norestart, init, fini, vendor, modversion); |
… | |
… | |
18 | if (find (name) != NULL) |
18 | if (find (name) != NULL) |
19 | return true; |
19 | return true; |
20 | return false; |
20 | return false; |
21 | } |
21 | } |
22 | |
22 | |
23 | faultcode_t |
23 | fault::code |
24 | modules::enable (char const * const name) |
24 | modules::enable (char const * const name) |
25 | { |
25 | { |
26 | module *m = find (name); |
26 | module *m = find (name); |
27 | |
27 | |
28 | if (!m) |
28 | if (!m) |
29 | return fault_nosuch_target; |
29 | return fault::nosuch_target; |
30 | |
30 | |
31 | if (m->enabled) |
31 | if (m->enabled) |
32 | return fault_nochange; |
32 | return fault::nochange; |
33 | |
33 | |
34 | m->enabled = m->init (m); |
34 | m->enabled = m->init (m); |
35 | |
35 | |
36 | return m->enabled ? fault_ok : fault_failed; |
36 | return m->enabled ? fault::ok : fault::failed; |
37 | } |
37 | } |
38 | |
38 | |
39 | faultcode_t |
39 | fault::code |
40 | modules::disable (char const * const name) |
40 | modules::disable (char const * const name) |
41 | { |
41 | { |
42 | module *m = find (name); |
42 | module *m = find (name); |
43 | |
43 | |
44 | if (!m) |
44 | if (!m) |
45 | return fault_nosuch_target; |
45 | return fault::nosuch_target; |
46 | |
46 | |
47 | if (m->norestart) |
47 | if (m->norestart) |
48 | return fault_noprivs; |
48 | return fault::noprivs; |
49 | |
49 | |
50 | if (m->enabled) |
50 | if (m->enabled) |
51 | m->fini (); |
51 | m->fini (); |
52 | else |
52 | else |
53 | return fault_nochange; |
53 | return fault::nochange; |
54 | |
54 | |
55 | m->enabled = false; |
55 | m->enabled = false; |
56 | |
56 | |
57 | return fault_ok; |
57 | return fault::ok; |
58 | } |
58 | } |
59 | |
59 | |
60 | module * |
60 | module * |
61 | modules::find (char const * const name) |
61 | modules::find (char const * const name) |
62 | { |
62 | { |