r7294: implemented the irpc messaging system. This is the core of the
[samba.git] / source4 / lib / messaging / irpc.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Samba internal rpc code - header
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 /*
24   an incoming irpc message
25 */
26 struct irpc_message {
27         uint32_t from;
28 };
29
30 /* don't allow calls to take too long */
31 #define IRPC_CALL_TIMEOUT 10
32
33
34 /* the server function type */
35 typedef NTSTATUS (*irpc_function_t)(struct irpc_message *, void *r);
36
37 /* register a server function with the irpc messaging system */
38 #define IRPC_REGISTER(msg_ctx, pipename, funcname, function) \
39    irpc_register(msg_ctx, &dcerpc_table_ ## pipename, \
40                           DCERPC_ ## funcname, \
41                           (irpc_function_t)function)
42
43 /* make a irpc call */
44 #define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr) \
45    irpc_call(msg_ctx, server_id, &dcerpc_table_ ## pipename, DCERPC_ ## funcname, ptr)
46
47
48 /*
49   a pending irpc call
50 */
51 struct irpc_request {
52         struct messaging_context *msg_ctx;
53         const struct dcerpc_interface_table *table;
54         int callnum;
55         int callid;
56         void *r;
57         NTSTATUS status;
58         BOOL done;
59         struct {
60                 void (*fn)(struct irpc_request *);
61                 void *private;
62         } async;
63 };
64
65
66 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, uint32_t server_id, 
67                                          struct event_context *ev);
68 NTSTATUS messaging_send(struct messaging_context *msg, uint32_t server, 
69                         uint32_t msg_type, DATA_BLOB *data);
70 void messaging_register(struct messaging_context *msg, void *private,
71                         uint32_t msg_type, 
72                         void (*fn)(struct messaging_context *, void *, uint32_t, uint32_t, DATA_BLOB *));
73 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, uint32_t server_id, 
74                                          struct event_context *ev);
75 NTSTATUS messaging_send_ptr(struct messaging_context *msg, uint32_t server, 
76                             uint32_t msg_type, void *ptr);
77 void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private);
78
79
80
81
82 NTSTATUS irpc_register(struct messaging_context *msg_ctx, 
83                        const struct dcerpc_interface_table *table, 
84                        int call, irpc_function_t fn);
85 struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, 
86                                     uint32_t server_id, 
87                                     const struct dcerpc_interface_table *table, 
88                                     int callnum, void *r);
89 NTSTATUS irpc_call_recv(struct irpc_request *irpc);
90 NTSTATUS irpc_call(struct messaging_context *msg_ctx, 
91                    uint32_t server_id, 
92                    const struct dcerpc_interface_table *table, 
93                    int callnum, void *r);
94