r15049: for really efficient oplock handling with thousands of open files we
[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 typedef void (*msg_callback_t)(struct messaging_context *msg, void *private, 
80                                uint32_t msg_type, uint32_t server_id, DATA_BLOB *data);
81
82 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, uint32_t server_id, 
83                                          struct event_context *ev);
84 NTSTATUS messaging_send(struct messaging_context *msg, uint32_t server, 
85                         uint32_t msg_type, DATA_BLOB *data);
86 NTSTATUS messaging_register(struct messaging_context *msg, void *private,
87                             uint32_t msg_type, 
88                             msg_callback_t fn);
89 NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private,
90                                 msg_callback_t fn, uint32_t *msg_type);
91 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, uint32_t server_id, 
92                                          struct event_context *ev);
93 struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, 
94                                          struct event_context *ev);
95 NTSTATUS messaging_send_ptr(struct messaging_context *msg, uint32_t server, 
96                             uint32_t msg_type, void *ptr);
97 void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private);
98
99
100
101
102 NTSTATUS irpc_register(struct messaging_context *msg_ctx, 
103                        const struct dcerpc_interface_table *table, 
104                        int call, irpc_function_t fn, void *private);
105 struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, 
106                                     uint32_t server_id, 
107                                     const struct dcerpc_interface_table *table, 
108                                     int callnum, void *r, TALLOC_CTX *ctx);
109 NTSTATUS irpc_call_recv(struct irpc_request *irpc);
110 NTSTATUS irpc_call(struct messaging_context *msg_ctx, 
111                    uint32_t server_id, 
112                    const struct dcerpc_interface_table *table, 
113                    int callnum, void *r, TALLOC_CTX *ctx);
114
115 NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name);
116 uint32_t *irpc_servers_byname(struct messaging_context *msg_ctx, const char *name);
117 void irpc_remove_name(struct messaging_context *msg_ctx, const char *name);
118 NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status);
119
120