ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/module.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (16 years, 9 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

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