ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/module.C
Revision: 1.5
Committed: Thu Aug 30 19:56:26 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +10 -10 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

File Contents

# Content
1 #include <svsconfig.h>
2 #include <common.h>
3 #include <ermyth/module.h>
4
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)
7 {
8 if (provides (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);
11 modlist ().push_back (mod);
12 provides (name);
13 }
14
15 bool
16 modules::provides (char const * const name)
17 {
18 if (find (name) != NULL)
19 return true;
20 return false;
21 }
22
23 fault::code
24 modules::enable (char const * const name)
25 {
26 module *m = find (name);
27
28 if (!m)
29 return fault::nosuch_target;
30
31 if (m->enabled)
32 return fault::nochange;
33
34 m->enabled = m->init (m);
35
36 return m->enabled ? fault::ok : fault::failed;
37 }
38
39 fault::code
40 modules::disable (char const * const name)
41 {
42 module *m = find (name);
43
44 if (!m)
45 return fault::nosuch_target;
46
47 if (m->norestart)
48 return fault::noprivs;
49
50 if (m->enabled)
51 m->fini ();
52 else
53 return fault::nochange;
54
55 m->enabled = false;
56
57 return fault::ok;
58 }
59
60 module *
61 modules::find (char const * const name)
62 {
63 foreach (module *m, modlist ())
64 if (!strcmp (m->name, name))
65 return m;
66
67 return NULL;
68 }
69
70 void
71 modules::cleanup ()
72 {
73 list_type::iterator it = modlist().begin ();
74 list_type::iterator et = modlist().end ();
75
76 while (--et != it)
77 {
78 module *m = *et;
79 if (m->enabled)
80 m->fini ();
81 delete m;
82 }
83 }