That's better

This commit is contained in:
XANTRONIX Development 2015-07-21 01:01:41 -05:00
parent f4e290229b
commit 86f5dd44b9
2 changed files with 28 additions and 23 deletions

View file

@ -40,6 +40,7 @@ typedef struct _patty_ax25_link {
} patty_ax25_link; } patty_ax25_link;
typedef struct _patty_ax25_if { typedef struct _patty_ax25_if {
enum patty_ax25_if_type type;
patty_kiss_tnc * tnc; patty_kiss_tnc * tnc;
patty_ax25_stats stats; patty_ax25_stats stats;
patty_dict * ports; patty_dict * ports;
@ -53,35 +54,37 @@ typedef struct _patty_ax25 {
int patty_ax25_init(patty_ax25 *ax25); int patty_ax25_init(patty_ax25 *ax25);
void patty_ax25_finish(patty_ax25 *ax25); void patty_ax25_stop(patty_ax25 *ax25);
int patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info); patty_ax25_if *patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info);
int patty_ax25_each_if(patty_ax25 *ax25, int patty_ax25_each_if(patty_ax25 *ax25,
int (*callback)(patty_ax25_if *, void *), void *ctx); int (*callback)(patty_ax25_if *, void *), void *ctx);
int patty_ax25_get_if(patty_ax25 *ax25, const char *name); patty_ax25_if *patty_ax25_get_if(patty_ax25 *ax25, const char *name);
int patty_ax25_destroy_if(patty_ax25 *ax25, int iface); int patty_ax25_destroy_if(patty_ax25 *ax25, patty_ax25_if *iface);
int patty_ax25_listen(patty_ax25 *ax25, int iface, patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface,
const char *callsign, int ssid); const char *callsign, int ssid);
int patty_ax25_shutdown(patty_ax25 *ax25, int port); int patty_ax25_shutdown(patty_ax25 *ax25, patty_ax25_port *port);
int patty_ax25_connect(patty_ax25 *ax25, int port, patty_ax25_link *patty_ax25_connect(patty_ax25 *ax25, patty_ax25_port *port,
const char *callsign, int ssid); const char *callsign, int ssid);
int patty_ax25_close(patty_ax25 *ax25, int link); int patty_ax25_close(patty_ax25 *ax25, patty_ax25_link *link);
int patty_ax25_recv(patty_ax25 *ax25, int iface, patty_ax25_frame *frame); int patty_ax25_recv(patty_ax25 *ax25,
patty_ax25_if *iface, patty_ax25_frame *frame);
int patty_ax25_send(patty_ax25 *ax25, int iface, int patty_ax25_send(patty_ax25 *ax25,
const patty_ax25_frame *frame); patty_ax25_if *iface, const patty_ax25_frame *frame);
ssize_t patty_ax25_read(patty_ax25 *ax25, int link, void *data, size_t len); ssize_t patty_ax25_read(patty_ax25 *ax25,
patty_ax25_link *link, void *data, size_t len);
ssize_t patty_ax25_write(patty_ax25 *ax25, int link, ssize_t patty_ax25_write(patty_ax25 *ax25,
const void *data, size_t len); patty_ax25_link *link, const void *data, size_t len);
#endif /* _PATTY_AX25_IF */ #endif /* _PATTY_AX25_IF */

View file

@ -33,13 +33,13 @@ error_dict_new_ifaces:
return -1; return -1;
} }
void patty_ax25_finish(patty_ax25 *ax25) { void patty_ax25_stop(patty_ax25 *ax25) {
patty_dict_destroy(ax25->links); patty_dict_destroy(ax25->links);
patty_dict_destroy(ax25->ports); patty_dict_destroy(ax25->ports);
patty_dict_destroy(ax25->ifaces); patty_dict_destroy(ax25->ifaces);
} }
static int create_if_tnc(patty_ax25 *ax25, const char *device) { static patty_ax25_if *create_if_tnc(patty_ax25 *ax25, const char *device) {
patty_ax25_if *iface; patty_ax25_if *iface;
if ((iface = malloc(sizeof(*iface))) == NULL) { if ((iface = malloc(sizeof(*iface))) == NULL) {
@ -56,11 +56,13 @@ static int create_if_tnc(patty_ax25 *ax25, const char *device) {
goto error_kiss_tnc_open; goto error_kiss_tnc_open;
} }
iface->type = PATTY_AX25_IF_KISS_TNC_TTY;
if (patty_dict_set(ax25->ifaces, (void *)device, strlen(device), iface) == NULL) { if (patty_dict_set(ax25->ifaces, (void *)device, strlen(device), iface) == NULL) {
goto error_dict_set_iface; goto error_dict_set_iface;
} }
return 0; return iface;
error_dict_set_iface: error_dict_set_iface:
patty_kiss_tnc_close(iface->tnc); patty_kiss_tnc_close(iface->tnc);
@ -72,10 +74,10 @@ error_dict_new_ports:
free(iface); free(iface);
error_malloc_iface: error_malloc_iface:
return -1; return NULL;
} }
int patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) { patty_ax25_if *patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) {
switch (PATTY_AX25_IF_OPT_TYPE(opts)) { switch (PATTY_AX25_IF_OPT_TYPE(opts)) {
case PATTY_AX25_IF_KISS_TNC_TTY: { case PATTY_AX25_IF_KISS_TNC_TTY: {
return create_if_tnc(ax25, (const char *)info); return create_if_tnc(ax25, (const char *)info);
@ -86,5 +88,5 @@ int patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) {
errno = EINVAL; errno = EINVAL;
return -1; return NULL;
} }