2013-11-28 06:23:12 +00:00
|
|
|
#ifndef __SERVALD_MSP_CLIENT_H
|
|
|
|
#define __SERVALD_MSP_CLIENT_H
|
|
|
|
|
|
|
|
#define MSP_STATE_UNINITIALISED 0
|
|
|
|
#define MSP_STATE_LISTENING (1<<0)
|
|
|
|
|
2013-12-05 00:55:47 +00:00
|
|
|
#define MSP_STATE_RECEIVED_DATA (1<<1)
|
|
|
|
#define MSP_STATE_RECEIVED_PACKET (1<<2)
|
2013-11-28 06:23:12 +00:00
|
|
|
|
|
|
|
#define MSP_STATE_SHUTDOWN_LOCAL (1<<3)
|
|
|
|
#define MSP_STATE_SHUTDOWN_REMOTE (1<<4)
|
|
|
|
|
|
|
|
// this connection is about to be free'd, release any other resources or references to the state
|
|
|
|
#define MSP_STATE_CLOSED (1<<5)
|
|
|
|
|
2013-12-05 00:55:47 +00:00
|
|
|
// something has gone wrong somewhere
|
2013-11-28 06:23:12 +00:00
|
|
|
#define MSP_STATE_ERROR (1<<6)
|
|
|
|
|
|
|
|
// is there space for sending more data?
|
2013-12-05 06:07:19 +00:00
|
|
|
#define MSP_STATE_DATAOUT (1<<7)
|
2013-11-28 06:23:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct msp_sock;
|
|
|
|
typedef uint16_t msp_state_t;
|
|
|
|
|
|
|
|
// allocate a new socket
|
|
|
|
struct msp_sock * msp_socket(int mdp_sock);
|
|
|
|
void msp_close(struct msp_sock *sock);
|
2013-12-05 00:55:47 +00:00
|
|
|
void msp_close_all(int mdp_sock);
|
2013-12-18 04:07:46 +00:00
|
|
|
unsigned msp_socket_count();
|
2013-11-28 06:23:12 +00:00
|
|
|
|
2013-12-19 04:15:58 +00:00
|
|
|
void msp_debug();
|
|
|
|
|
2013-11-28 06:23:12 +00:00
|
|
|
int msp_set_handler(struct msp_sock *sock,
|
|
|
|
int (*handler)(struct msp_sock *sock, msp_state_t state, const uint8_t *payload, size_t len, void *context),
|
|
|
|
void *context);
|
|
|
|
|
|
|
|
// the local address is only set when calling msp_listen or msp_send
|
|
|
|
int msp_set_local(struct msp_sock *sock, struct mdp_sockaddr local);
|
|
|
|
int msp_set_remote(struct msp_sock *sock, struct mdp_sockaddr remote);
|
|
|
|
|
|
|
|
int msp_listen(struct msp_sock *sock);
|
|
|
|
|
|
|
|
int msp_get_remote_adr(struct msp_sock *sock, struct mdp_sockaddr *remote);
|
|
|
|
msp_state_t msp_get_state(struct msp_sock *sock);
|
|
|
|
|
|
|
|
// bind, send data, and potentially shutdown this end of the connection
|
|
|
|
int msp_send(struct msp_sock *sock, const uint8_t *payload, size_t len);
|
|
|
|
int msp_shutdown(struct msp_sock *sock);
|
|
|
|
|
|
|
|
// receive and process an incoming packet
|
|
|
|
int msp_recv(int mdp_sock);
|
|
|
|
|
|
|
|
// next_action indicates the next time that msp_processing should be called
|
|
|
|
int msp_processing(time_ms_t *next_action);
|
|
|
|
|
|
|
|
#endif
|