ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/callback.C
Revision: 1.1
Committed: Thu Jul 19 08:24:56 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# User Rev Content
1 pippijn 1.1 /**
2     * callback.C: C++ callback mechanism
3     * Rights to this code are documented in doc/LICENSE.
4     *
5     * Copyright © 2007 Pippijn van Steenhoven
6     */
7    
8     static char const rcsid[] = "$Id";
9    
10     #include "svsconfig.h"
11     #include "ipc/callback.h"
12    
13     has_callbacks::callbacks has_callbacks::callback;
14    
15     has_callbacks::has_callbacks ()
16     {
17     callback.created (this);
18     }
19    
20     has_callbacks::~has_callbacks ()
21     {
22     callback.destroyed (this);
23     }
24    
25     namespace callback
26     {
27     has_listeners::has_listeners ()
28     {
29     }
30    
31     has_listeners::~has_listeners ()
32     {
33     disconnect_all ();
34     }
35    
36     has_listeners::sender_set &
37     has_listeners::invokers ()
38     {
39     return this->m_senders;
40     }
41    
42     const has_listeners::sender_set &
43     has_listeners::invokers () const
44     {
45     return this->m_senders;
46     }
47    
48    
49     has_listeners::has_listeners (const has_listeners &rhs)
50     {
51     this->copy_invokers (rhs);
52     }
53    
54     has_listeners &
55     has_listeners::operator = (const has_listeners &rhs)
56     {
57     this->disconnect_all ();
58     this->copy_invokers (rhs);
59     return *this;
60     }
61    
62     void
63     has_listeners::add_invoker (event_base * sender)
64     {
65     this->invokers ().insert (sender);
66     }
67    
68     void
69     has_listeners::remove_invoker (event_base * sender)
70     {
71     this->invokers ().erase (sender);
72     }
73    
74     void
75     has_listeners::copy_invokers (const has_listeners &rhs)
76     {
77     if (&rhs == this)
78     return;
79    
80     const_iterator it;
81     const_iterator itEnd = rhs.invokers ().end ();
82    
83     for (it = rhs.invokers ().begin (); it != itEnd; ++it)
84     {
85     (*it)->listener_duplicate (&rhs, this);
86     this->invokers ().insert (*it);
87     }
88     }
89    
90     void
91     has_listeners::disconnect_all ()
92     {
93     iterator it;
94     iterator et = this->invokers ().end ();
95    
96     for (it = this->invokers ().begin (); et != it; ++it)
97     (*it)->detach (this);
98    
99     this->invokers ().clear ();
100     }
101     } // namespace callback