summaryrefslogtreecommitdiff
path: root/source3/lib/messages.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-09-12 00:47:11 +0000
committerAndrew Tridgell <tridge@samba.org>2000-09-12 00:47:11 +0000
commit06eeb3c45803bcf26ee586103a974fd852de21b9 (patch)
treef6dedcae3ebee3d75186987bb38ea315fa1ad5b9 /source3/lib/messages.c
parentd836024b2816f37abd523afb3b2d4f2bfb130f0a (diff)
downloadsamba-06eeb3c45803bcf26ee586103a974fd852de21b9.tar.gz
samba-06eeb3c45803bcf26ee586103a974fd852de21b9.tar.bz2
samba-06eeb3c45803bcf26ee586103a974fd852de21b9.zip
much nicer message interface. We now register dispatch functions,
allowing new bits of code or vfs modules to register functions without impacting on the messaging code itself. Also note that multiple registrations for the same message type are possible allowing the same message to be delivered to multiple parts of the code (possibly useful for reload messages). (This used to be commit c3350c77f52cade48d2945574e09cb630af85b92)
Diffstat (limited to 'source3/lib/messages.c')
-rw-r--r--source3/lib/messages.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 30eef40ec9..bbda5d71ed 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -19,7 +19,18 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* this module is used for internal messaging between Samba daemons. */
+/* this module is used for internal messaging between Samba daemons.
+
+ The idea is that if a part of Samba wants to do communication with
+ another Samba process then it will do a message_register() of a
+ dispatch function, and use message_send_pid() to send messages to
+ that process.
+
+ This system doesn't have any inherent size limitations but is not
+ very efficient for large messages or when messages are sent in very
+ quick succession.
+
+*/
#include "includes.h"
@@ -38,6 +49,13 @@ struct message_rec {
size_t len;
};
+/* we have a linked list of dispatch handlers */
+static struct dispatch_fns {
+ struct dispatch_fns *next, *prev;
+ enum message_type msg_type;
+ void (*fn)(enum message_type msg_type, pid_t pid, void *buf, size_t len);
+} *dispatch_fns;
+
/****************************************************************************
notifications come in as signals
****************************************************************************/
@@ -213,6 +231,8 @@ static BOOL message_recv(enum message_type *msg_type, pid_t *src, void **buf, si
/****************************************************************************
receive and dispatch any messages pending for this process
+notice that all dispatch handlers for a particular msg_type get called,
+so you can register multiple handlers for a message
****************************************************************************/
void message_dispatch(void)
{
@@ -220,18 +240,35 @@ void message_dispatch(void)
pid_t src;
void *buf;
size_t len;
+ struct dispatch_fns *dfn;
if (!received_signal) return;
received_signal = 0;
while (message_recv(&msg_type, &src, &buf, &len)) {
- switch (msg_type) {
- case MSG_DEBUG:
- debug_message(src, buf, len);
- break;
- default:
- DEBUG(0,("Unknown message type %d from %d\n", msg_type, (int)src));
- break;
+ for (dfn = dispatch_fns; dfn; dfn = dfn->next) {
+ if (dfn->msg_type == msg_type) {
+ dfn->fn(msg_type, src, buf, len);
+ }
}
}
}
+
+
+/****************************************************************************
+register a dispatch function for a particular message type
+****************************************************************************/
+void message_register(enum message_type msg_type,
+ void (*fn)(enum message_type msg_type, pid_t pid, void *buf, size_t len))
+{
+ struct dispatch_fns *dfn;
+
+ dfn = (struct dispatch_fns *)malloc(sizeof(*dfn));
+
+ ZERO_STRUCTP(dfn);
+
+ dfn->msg_type = msg_type;
+ dfn->fn = fn;
+
+ DLIST_ADD(dispatch_fns, dfn);
+}