ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/rpc.h
Revision: 1.3
Committed: 2008-01-01T09:40:33Z (16 years, 10 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * rpc.h - Remote Procedure Calls
3 *
4 * Basilisk II (C) 1997-2008 Christian Bauer
5 * Contributed by Gwenole Beauchesne
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #ifndef RPC_H
23 #define RPC_H
24
25 // Error Types
26 enum {
27 RPC_ERROR_NO_ERROR = 0,
28 RPC_ERROR_GENERIC = -1000,
29 RPC_ERROR_ERRNO_SET = -1001,
30 RPC_ERROR_NO_MEMORY = -1002,
31 RPC_ERROR_CONNECTION_NULL = -1003,
32 RPC_ERROR_CONNECTION_TYPE_MISMATCH = -1004,
33 RPC_ERROR_MESSAGE_TRUNCATED = -1005,
34 RPC_ERROR_MESSAGE_ARGUMENT_MISMATCH = -1006,
35 RPC_ERROR_MESSAGE_ARGUMENT_UNKNOWN = -1007,
36 };
37
38 // Connection Handling
39 typedef struct rpc_connection_t rpc_connection_t;
40 extern rpc_connection_t *rpc_init_server(const char *ident);
41 extern rpc_connection_t *rpc_init_client(const char *ident);
42 extern int rpc_exit(rpc_connection_t *connection);
43 extern int rpc_listen_socket(rpc_connection_t *connection);
44 extern int rpc_listen(rpc_connection_t *connection);
45 extern int rpc_dispatch(rpc_connection_t *connection);
46 extern int rpc_wait_dispatch(rpc_connection_t *connection, int timeout);
47 extern int rpc_connection_busy(rpc_connection_t *connection);
48
49 // Message Passing
50 enum {
51 RPC_TYPE_INVALID = 0,
52 RPC_TYPE_CHAR = -2000,
53 RPC_TYPE_BOOLEAN = -2001,
54 RPC_TYPE_INT32 = -2002,
55 RPC_TYPE_UINT32 = -2003,
56 RPC_TYPE_STRING = -2004,
57 RPC_TYPE_ARRAY = -2005,
58 };
59 typedef struct rpc_message_t rpc_message_t;
60 extern int rpc_message_send_char(rpc_message_t *message, char c);
61 extern int rpc_message_send_int32(rpc_message_t *message, int32_t value);
62 extern int rpc_message_send_uint32(rpc_message_t *message, uint32_t value);
63 extern int rpc_message_send_string(rpc_message_t *message, const char *str);
64 extern int rpc_message_send_bytes(rpc_message_t *message, unsigned char *bytes, int count);
65 extern int rpc_message_recv_char(rpc_message_t *message, char *ret);
66 extern int rpc_message_recv_int32(rpc_message_t *message, int32_t *ret);
67 extern int rpc_message_recv_uint32(rpc_message_t *message, uint32_t *ret);
68 extern int rpc_message_recv_string(rpc_message_t *message, char **ret);
69 extern int rpc_message_recv_bytes(rpc_message_t *message, unsigned char *bytes, int count);
70 typedef int (*rpc_message_callback_t)(rpc_message_t *message, void *p_value);
71 typedef struct {
72 int id;
73 int size;
74 rpc_message_callback_t send_callback;
75 rpc_message_callback_t recv_callback;
76 } rpc_message_descriptor_t;
77 extern int rpc_message_add_callbacks(const rpc_message_descriptor_t *descs, int n_descs);
78
79 // Method Callbacks Handling
80 typedef int (*rpc_method_callback_t)(rpc_connection_t *connection);
81 typedef struct {
82 int id;
83 rpc_method_callback_t callback;
84 } rpc_method_descriptor_t;
85 extern int rpc_method_add_callbacks(rpc_connection_t *connection, const rpc_method_descriptor_t *descs, int n_descs);
86 extern int rpc_method_remove_callback_id(rpc_connection_t *connection, int id);
87 extern int rpc_method_remove_callbacks(rpc_connection_t *connection, const rpc_method_descriptor_t *descs, int n_descs);
88
89 // Remote Procedure Call (method invocation)
90 extern int rpc_method_invoke(rpc_connection_t *connection, int method, ...);
91 extern int rpc_method_wait_for_reply(rpc_connection_t *connection, ...);
92 extern int rpc_method_get_args(rpc_connection_t *connection, ...);
93 extern int rpc_method_send_reply(rpc_connection_t *connection, ...);
94
95 // Message Protocol
96 enum {
97 RPC_METHOD_ERROR_ALERT = 1,
98 RPC_METHOD_WARNING_ALERT,
99 RPC_METHOD_EXIT
100 };
101
102 #endif /* RPC_H */