Annotation of libaitrpc/inc/aitrpc_cli.h, revision 1.4
1.2 misho 1: /*************************************************************************
2: * (C) 2015 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.4 ! misho 6: * $Id: aitrpc_cli.h,v 1.3.4.1 2024/12/09 13:41:57 misho Exp $
1.2 misho 7: *
8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
1.3 misho 15: Copyright 2004 - 2024
1.2 misho 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
46: #ifndef __AITRPC_CLI_H
47: #define __AITRPC_CLI_H
48:
49:
50: #include <aitrpc_pkt.h>
51:
52:
53: /* Network RPC client elements */
54:
55: typedef struct {
56: int cli_id; /* slot id */
57: int cli_sock; /* socket fd */
58: sockaddr_t cli_sa; /* host address */
59: ait_val_t cli_buf; /* network buffer */
60:
61: array_t *cli_vars; /* function return variables */
62:
63: void *cli_parent; /* pointer to parent rpc_srv_t for server or to rpc_sess_t for client */
64: } rpc_cli_t;
65: #define RPC_RETVARS(x) ((x)->cli_vars)
66: #define RPC_SRV_SERVER(x) ((rpc_srv_t*) (x)->cli_parent)
67: #define RPC_CLI_SESSION(x) ((rpc_sess_t*) (x)->cli_parent)
68:
69: /* ----------------------------------------------------------------------- */
70:
1.4 ! misho 71: #ifdef __cplusplus
! 72: extern "C" {
! 73: #endif
! 74:
1.2 misho 75: /* Error support functions */
76:
77: // rpc_GetErrno() Get error code of last operation
78: int rpc_GetErrno();
79: // rpc_GetError() Get error text of last operation
80: const char *rpc_GetError();
81: // rpc_SetErr() Set error to variables for internal use!!!
82: void rpc_SetErr(int eno, char *estr, ...);
83:
84:
85: /*
86: * rpc_Read() - RPC read operation
87: *
88: * @sock = socket
89: * @type = type of socket
90: * @flags = receive flags
91: * @sa = check client address, if you use udp protocol
92: * @pkt = RPC packet
93: * return: -1 error, 0 EOF or or >0 readed bytes into buffer
94: */
95: ssize_t rpc_Read(int sock, int type, int flags, sockaddr_t * __restrict sa,
96: ait_val_t * __restrict pkt);
97: /*
98: * rpc_Write() - RPC write operation
99: *
100: * @sock = socket
101: * @type = type of socket
102: * @flags = send flags
103: * @sa = send to client address, if you use udp protocol
104: * @pkt = RPC packet
105: * @blen = write length
106: * return: -1 error, 0 EOF or >0 written bytes into buffer
107: */
108: ssize_t rpc_Write(int sock, int type, int flags, sockaddr_t * __restrict sa,
109: ait_val_t * __restrict pkt, size_t blen);
110:
111: /*
112: * rpc_pktFreeSpace() - Get free space for payload into RPC packet
113: *
114: * @c = RPC client
115: * return: remains free bytes from packet
116: */
117: size_t rpc_pktFreeSpace(rpc_cli_t * __restrict c);
118: /*
119: * rpc_chkPktSession() - Check RPC session
120: *
121: * @p = packet session
122: * @s = active session
123: * return: -1, 1, 2, 3 are errors or 0 ok
124: */
125: int rpc_chkPktSession(rpc_sess_t *p, rpc_sess_t *s);
126: /*
127: * rpc_addPktSession() - Prepare session into network format
128: *
129: * @p = packet session
130: * @s = host session
131: * return: -1 error or 0 ok
132: */
133: int rpc_addPktSession(rpc_sess_t *p, rpc_sess_t *s);
134:
135: /* CLIENT part of functions */
136:
137: /*
138: * rpc_cli_sendBLOB() - Send BLOB to server
139: *
140: * @cli = Client instance
141: * @var = BLOB variable
142: * @data = BLOB data
143: * @tout = BLOB live on server timeout in seconds, if =0 default timeout
144: * return: -1 error, 0 ok, 1 remote error
145: */
146: int rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var,
147: void * __restrict data, int tout);
148: /*
149: * rpc_cli_recvBLOB() - Receive BLOB from server
150: *
151: * @cli = Client instance
152: * @var = BLOB variable
153: * @data = BLOB data, must be e_free after use!
154: * return: -1 error, 0 ok, 1 remote error
155: */
156: int rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** __restrict data);
157: /*
158: * rpc_cli_delBLOB() - Delete BLOB from server
159: *
160: * @cli = Client instance
161: * @var = BLOB variable
162: * return: -1 error, 0 ok, 1 remote error
163: */
164: int rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var);
165: /*
166: * rpc_cli_getBLOB() - Receive BLOB from server and Delete after that.
167: *
168: * @cli = Client instance
169: * @var = BLOB variable
170: * @data = BLOB data, must be e_free after use!
171: * return: -1 error, 0 ok, >0 remote error
172: */
173: int rpc_cli_getBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var,
174: void ** __restrict data);
175:
176:
177: /* RPC Client side functions */
178:
179: /*
180: * rpc_cli_openClient() - Connect to RPC Server
181: *
182: * @InstID = InstID for RPC session request
183: * @netBuf = Network buffer length (min:512 bytes), if =0 == BUFSIZ (also meaning max RPC packet)
184: * @csHost = Host name or IP address for bind server
185: * @Port = Port for bind server, if Port == 0 default port is selected
186: * @proto = Protocol, if == 0 choose SOCK_STREAM
187: * return: NULL == error or !=NULL connection to RPC server established
188: */
189: rpc_cli_t *rpc_cli_openClient(unsigned char InstID, int netBuf,
190: const char *csHost, unsigned short Port, int proto);
191: /*
192: * rpc_cli_reconnectClient() - Reconnecting client to RPC server
193: *
194: * @cli = RPC Client session
195: * return: -1 error or 0 ok
196: */
197: int rpc_cli_reconnectClient(rpc_cli_t * __restrict cli);
198: /*
199: * rpc_cli_closeClient() - Close connection to RPC server and free resources
200: *
201: * @cli = RPC Client session
202: * return: none
203: */
204: void rpc_cli_closeClient(rpc_cli_t ** __restrict cli);
205: /*
206: * rpc_pkt_Send() - Send RPC packet
207: *
208: * @sock = Socket
209: * @type = Type of socket
210: * @sa = Server address
211: * @pkt = RPC packet
212: * @len = Length of packet
213: * return: -1 error, 0 EOF or >0 sended bytes
214: */
215: int rpc_pkt_Send(int sock, int type, sockaddr_t * __restrict sa,
216: ait_val_t * __restrict pkt, int len);
217: /*
218: * rpc_pkt_Receive() - Receive RPC packet
219: *
220: * @sock = Socket
221: * @type = Type of socket
222: * @sa = Server address
223: * @pkt = RPC packet
224: * @seq = Signed packet with seq.no
225: * return: -1 error, 0 EOF or >0 received bytes
226: */
227: int rpc_pkt_Receive(int sock, int type, sockaddr_t * __restrict sa,
228: ait_val_t * __restrict pkt, int seq);
229: /*
230: * rpc_pkt_Request() - Build RPC Request packet
231: *
232: * @pkt = Packet buffer
233: * @sess = RPC session info
234: * @tag = Function tag for execution
235: * @vars = Function argument array of values, may be NULL
1.3 misho 236: * @noreply = >0 We not want RPC reply, -1 IPC request with reply
1.2 misho 237: * @nocrc = Without CRC calculation
238: * @seq = Sign packet with seq.no
239: * return: -1 error or != -1 prepared bytes into packet
240: */
241: int rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t * __restrict sess,
242: unsigned short tag, array_t * __restrict vars, int noreply, int nocrc, int seq);
243: /*
244: * rpc_pkt_Replay() - Decode RPC Replay packet
245: *
246: * @pkt = Packet buffer
247: * @sess = RPC session info, if =NULL don't check session
248: * @tag = Function tag, if =CALL_TAG_MAX don't check tag
249: * @vars = Function argument array of values, may be NULL
250: * @nocrc = Without CRC calculation
251: * return: -1 error or != -1 return value from function
252: */
253: int rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t * __restrict sess,
254: unsigned short tag, array_t ** __restrict vars, int nocrc);
255: /*
256: * rpc_cli_execCall() - Execute RPC call
257: *
258: * @cli = RPC Client session
1.3 misho 259: * @noreply = >0 We not want RPC reply, -1 IPC request with reply
1.2 misho 260: * @tag = Function tag for execution
261: * @in_vars = IN function argument array of values, may be NULL
262: * @out_vars = OUT returned array of rpc values, if !=NULL must be free after use with ait_freeVars()
263: * return: -1 error, 0 ok result or 1 closed rpc connection
264: */
265: int rpc_cli_execCall(rpc_cli_t *cli, int noreply, unsigned short tag,
266: array_t * __restrict in_vars, array_t ** __restrict out_vars);
267: /*
268: * rpc_cli_freeCall() - Free resouce allocated by RPC call
269: *
270: * @out_vars = Returned array with variables from RPC call
271: * return: none
272: */
273: void rpc_cli_freeCall(array_t ** __restrict out_vars);
274: /*
275: * rpc_cli_ping() - Ping RPC server
276: *
277: * @cli = connected client
278: * return: -1 error or !=-1 ping seq id
279: */
280: int rpc_cli_ping(rpc_cli_t *cli);
281:
282:
283: /*
284: * rpc_cli_openBLOBClient() - Connect to BLOB Server
285: *
286: * @rpccli = RPC Client session
287: * @Port = Port for bind server, if Port == 0 default port is selected
288: * return: NULL == error or !=NULL connection to BLOB server established
289: */
290: rpc_cli_t *rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, unsigned short Port);
291: /*
292: * rpc_cli_closeBLOBClient() - Close connection to BLOB server and free resources
293: *
294: * @cli = BLOB Client session
295: * return: none
296: */
297: void rpc_cli_closeBLOBClient(rpc_cli_t ** __restrict cli);
298:
299:
300: /*
301: * rpc_cli_openClient2() - Connect to layer2 RPC Server
302: *
303: * @InstID = InstID for RPC session request
304: * @netBuf = Network buffer length (min:512 bytes), if =0 == BUFSIZ (also meaning max RPC packet)
305: * @csIface = Interface name for bind client, if NULL first interface on host
306: * @csHost = Host ethernet address
307: * return: NULL == error or !=NULL connection to RPC server established
308: */
309: rpc_cli_t *rpc_cli_openClient2(u_char InstID, int netBuf,
310: const char *csIface, const char *csHost);
311: /*
312: * rpc_cli_closeClient2() - Close layer2 connection to RPC server and free resources
313: *
314: * @cli = RPC Client session
315: * return: none
316: */
317: void rpc_cli_closeClient2(rpc_cli_t ** __restrict cli);
318:
319:
320: /*
321: * rpc_cli_openClientExt() - Connect to pipe RPC Server
322: *
323: * @InstID = InstID for RPC session request
324: * @netBuf = Network buffer length (min:512 bytes), if =0 == BUFSIZ (also meaning max RPC packet)
325: * @fd = File descriptor
326: * return: NULL == error or !=NULL connection to RPC server established
327: */
328: rpc_cli_t *rpc_cli_openClientExt(u_char InstID, int netBuf, int fd);
329: /*
330: * rpc_cli_closeClientExt() - Close pipe connection to RPC server and free resources
331: *
332: * @cli = RPC Client session
333: * return: none
334: */
335: void rpc_cli_closeClientExt(rpc_cli_t ** __restrict cli);
336:
1.4 ! misho 337: #ifdef __cplusplus
! 338: }
! 339: #endif
1.2 misho 340:
341: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>