|
1 /* |
|
2 * Copyright 2004-2006 Intel Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifndef DTN_IPC_H |
|
18 #define DTN_IPC_H |
|
19 |
|
20 #include <rpc/rpc.h> |
|
21 |
|
22 #ifdef __CYGWIN__ |
|
23 #include <stdio.h> |
|
24 #include <string.h> |
|
25 #include <cygwin/socket.h> |
|
26 #endif |
|
27 |
|
28 #ifdef __cplusplus |
|
29 extern "C" { |
|
30 #endif |
|
31 |
|
32 /************************************************************* |
|
33 * |
|
34 * Internal structures and functions that implement the DTN |
|
35 * IPC layer. Generally, this is not exposed to applications. |
|
36 * |
|
37 *************************************************************/ |
|
38 |
|
39 /** |
|
40 * DTN IPC version. Just a simple number for now; we can refine it to |
|
41 * a major/minor version later if desired. |
|
42 * |
|
43 * This currently cannot exceed 16 bits in width. |
|
44 * |
|
45 * Make sure to bump this when changing any data structures, message |
|
46 * types, adding functions, etc. |
|
47 */ |
|
48 #define DTN_IPC_VERSION 7 |
|
49 |
|
50 /** |
|
51 * Default api ports. The handshake port is used for initial contact |
|
52 * with the daemon to establish a session, and the latter is used for |
|
53 * individual sessions. |
|
54 */ |
|
55 #define DTN_IPC_PORT 5010 |
|
56 |
|
57 /** |
|
58 * The maximum IPC message size (in bytes). Used primarily for |
|
59 * efficiency in buffer allocation since the transport uses TCP. |
|
60 */ |
|
61 #define DTN_MAX_API_MSG 65536 |
|
62 |
|
63 /** |
|
64 * State of a DTN IPC channel. |
|
65 */ |
|
66 struct dtnipc_handle { |
|
67 int sock; ///< Socket file descriptor |
|
68 int err; ///< Error code |
|
69 int in_poll; ///< Flag to register a call to poll() |
|
70 int debug; ///< Debug flag for channel |
|
71 char buf[DTN_MAX_API_MSG]; ///< send/recv buffer |
|
72 XDR xdr_encode; ///< XDR encoder |
|
73 XDR xdr_decode; ///< XDR decoder |
|
74 unsigned int total_sent; ///< Counter for debugging |
|
75 unsigned int total_rcvd; ///< Counter for debugging |
|
76 }; |
|
77 |
|
78 typedef struct dtnipc_handle dtnipc_handle_t; |
|
79 |
|
80 /** |
|
81 * Type codes for api messages. |
|
82 */ |
|
83 typedef enum { |
|
84 DTN_OPEN = 1, |
|
85 DTN_CLOSE = 2, |
|
86 DTN_LOCAL_EID = 3, |
|
87 DTN_REGISTER = 4, |
|
88 DTN_UNREGISTER = 5, |
|
89 DTN_FIND_REGISTRATION = 6, |
|
90 DTN_CHANGE_REGISTRATION = 7, |
|
91 DTN_BIND = 8, |
|
92 DTN_UNBIND = 9, |
|
93 DTN_SEND = 10, |
|
94 DTN_RECV = 11, |
|
95 DTN_BEGIN_POLL = 12, |
|
96 DTN_CANCEL_POLL = 13, |
|
97 DTN_CANCEL = 14, |
|
98 DTN_SESSION_UPDATE = 15 |
|
99 } dtnapi_message_type_t; |
|
100 |
|
101 /** |
|
102 * Type code to string conversion routine. |
|
103 */ |
|
104 const char* dtnipc_msgtoa(u_int8_t type); |
|
105 |
|
106 /* |
|
107 * Initialize the handle structure and a new ipc session with the |
|
108 * daemon. |
|
109 * |
|
110 * Returns 0 on success, -1 on error. |
|
111 */ |
|
112 int dtnipc_open(dtnipc_handle_t* handle); |
|
113 |
|
114 /* |
|
115 * Clean up the handle. dtnipc_open must have already been called on |
|
116 * the handle. |
|
117 * |
|
118 * Returns 0 on success, -1 on error. |
|
119 */ |
|
120 int dtnipc_close(dtnipc_handle_t* handle); |
|
121 |
|
122 /* |
|
123 * Send a message over the dtn ipc protocol. |
|
124 * |
|
125 * Returns 0 on success, -1 on error. |
|
126 */ |
|
127 int dtnipc_send(dtnipc_handle_t* handle, dtnapi_message_type_t type); |
|
128 |
|
129 /* |
|
130 * Receive a message response on the ipc channel. May block if there |
|
131 * is no pending message. |
|
132 * |
|
133 * Sets status to the server-returned status code and returns the |
|
134 * length of any reply message on success, returns -1 on internal |
|
135 * error. |
|
136 */ |
|
137 int dtnipc_recv(dtnipc_handle_t* handle, int* status); |
|
138 |
|
139 /** |
|
140 * Send a message and wait for a response over the dtn ipc protocol. |
|
141 * |
|
142 * Returns 0 on success, -1 on error. |
|
143 */ |
|
144 int dtnipc_send_recv(dtnipc_handle_t* handle, dtnapi_message_type_t type); |
|
145 |
|
146 |
|
147 #ifdef __cplusplus |
|
148 } |
|
149 #endif |
|
150 |
|
151 #endif /* DTN_IPC_H */ |