r13317: Create a new function messaging_client_init() which can be used when
[kai/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 #include "librpc/gen_ndr/irpc.h"
24
25 /*
26   an incoming irpc message
27 */
28 struct irpc_message {
29         uint32_t from;
30         void *private;
31         struct irpc_header header;
32         struct ndr_pull *ndr;
33         BOOL defer_reply;
34         struct messaging_context *msg_ctx;
35         struct irpc_list *irpc;
36         void *data;
37         struct event_context *ev;
38 };
39
40 /* don't allow calls to take too long */
41 #define IRPC_CALL_TIMEOUT 10
42
43
44 /* the server function type */
45 typedef NTSTATUS (*irpc_function_t)(struct irpc_message *, void *r);
46
47 /* register a server function with the irpc messaging system */
48 #define IRPC_REGISTER(msg_ctx, pipename, funcname, function, private) \
49    irpc_register(msg_ctx, &dcerpc_table_ ## pipename, \
50                           DCERPC_ ## funcname, \
51                           (irpc_function_t)function, private)
52
53 /* make a irpc call */
54 #define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
55    irpc_call(msg_ctx, server_id, &dcerpc_table_ ## pipename, DCERPC_ ## funcname, ptr, ctx)
56
57 #define IRPC_CALL_SEND(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
58    irpc_call_send(msg_ctx, server_id, &dcerpc_table_ ## pipename, DCERPC_ ## funcname, ptr, ctx)
59
60
61 /*
62   a pending irpc call
63 */
64 struct irpc_request {
65         struct messaging_context *msg_ctx;
66         const struct dcerpc_interface_table *table;
67         int callnum;
68         int callid;
69         void *r;
70         NTSTATUS status;
71         BOOL done;
72         TALLOC_CTX *mem_ctx;
73         struct {
74                 void (*fn)(struct irpc_request *);
75                 void *private;
76         } async;
77 };
78
79
80 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, uint32_t server_id, 
81                                          struct event_context *ev);
82 NTSTATUS messaging_send(struct messaging_context *msg, uint32_t server, 
83                         uint32_t msg_type, DATA_BLOB *data);
84 void messaging_register(struct messaging_context *msg, void *private,
85                         uint32_t msg_type, 
86                         void (*fn)(struct messaging_context *, void *, uint32_t, uint32_t, DATA_BLOB *));
87 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, uint32_t server_id, 
88                                          struct event_context *ev);
89 struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, 
90                                          struct event_context *ev);
91 NTSTATUS messaging_send_ptr(struct messaging_context *msg, uint32_t server, 
92                             uint32_t msg_type, void *ptr);
93 void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private);
94
95
96
97
98 NTSTATUS irpc_register(struct messaging_context *msg_ctx, 
99                        const struct dcerpc_interface_table *table, 
100                        int call, irpc_function_t fn, void *private);
101 struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, 
102                                     uint32_t server_id, 
103                                     const struct dcerpc_interface_table *table, 
104                                     int callnum, void *r, TALLOC_CTX *ctx);
105 NTSTATUS irpc_call_recv(struct irpc_request *irpc);
106 NTSTATUS irpc_call(struct messaging_context *msg_ctx, 
107                    uint32_t server_id, 
108                    const struct dcerpc_interface_table *table, 
109                    int callnum, void *r, TALLOC_CTX *ctx);
110
111 NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name);
112 uint32_t *irpc_servers_byname(struct messaging_context *msg_ctx, const char *name);
113 void irpc_remove_name(struct messaging_context *msg_ctx, const char *name);
114 NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status);
115
116