ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/src/module.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +52 -341 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

# Content
1 #include <svsconfig.h>
2 #include <common.h>
3 #include <ermyth/module.h>
4
5 modules::modules (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 faultcode_t
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 faultcode_t
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 }