Having second thoughts about the old pointer approach; fds might actually make more sense on bare metal, too

This commit is contained in:
XANTRONIX Development 2015-07-22 23:05:00 -05:00 committed by XANTRONIX Industrial
parent bbf3db7466
commit 7fc4bf7e9d
2 changed files with 21 additions and 21 deletions

View file

@ -16,6 +16,13 @@
#define PATTY_AX25_IF_OPT_TYPE(n) \
((n) & PATTY_AX25_IF_OPT_TYPE_MASK)
enum patty_ax25_obj_type {
PATTY_AX25_OBJ_UNKNOWN,
PATTY_AX25_OBJ_IFACE,
PATTY_AX25_OBJ_PORT,
PATTY_AX25_OBJ_LINK
};
enum patty_ax25_if_type {
PATTY_AX25_IF_UNKNOWN = 0x00,
PATTY_AX25_IF_KISS_TNC_TTY = 0x01,
@ -48,9 +55,10 @@ typedef struct _patty_ax25_link {
} patty_ax25_link;
typedef struct _patty_ax25 {
patty_dict * ifaces; /* Key: AX.25 interface name */
patty_dict * ports; /* Key: Integer port descriptor */
patty_dict * links; /* Key: Integer link descriptor */
patty_list * ifaces;
patty_list * ports;
patty_dict * iface_table; /* address => iface */
patty_dict * links; /* remote => local */
} patty_ax25;
int patty_ax25_init(patty_ax25 *ax25);

View file

@ -92,19 +92,18 @@ patty_ax25_if *patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) {
return NULL;
}
static uint32_t address_hash(patty_ax25_address *address) {
char key[10];
if (snprintf(key, sizeof(key), "%s/%d", address->callsign, address->ssid) < 0) {
goto error_snprintf_key;
static inline void *dict_get_by_address(patty_dict *dict, patty_ax25_address *address) {
return patty_dict_get(dict, address,
sizeof(address->callsign) + sizeof(address->ssid));
}
return patty_hash(key, strlen(key));
static inline void *dict_set_for_address(patty_dict *dict, patty_ax25_address *address, void *value) {
return patty_dict_set(dict, address,
sizeof(address->callsign) + sizeof(address->ssid), value);
}
patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const char *callsign, int ssid) {
patty_ax25_port *port;
char key[10];
if ((port = malloc(sizeof(*port))) == NULL) {
goto error_malloc_port;
@ -117,7 +116,7 @@ patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const
port->ssid = ssid;
port->repeated = 0;
if (patty_dict_set(iface->ports, (void *)key, strlen(key), port) == NULL) {
if (dict_set_with_address(iface->ports, (patty_ax25_address *)port, port) == NULL) {
goto error_dict_set_port;
}
@ -129,7 +128,6 @@ patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const
error_dict_set_port:
error_strncpy_callsign:
error_snprintf_key:
free(port);
error_malloc_port:
@ -137,15 +135,9 @@ error_malloc_port:
}
int patty_ax25_shutdown(patty_ax25 *ax25, patty_ax25_port *port) {
int ret = 0;
if (patty_dict_delete(iface->ports, (void *)key, strlen(key)) == NULL) {
ret = -1;
}
if (patty_dict_delete(ax25->ports, (void *)key, strlen(key)) == NULL) {
ret = -1;
return -1;
}
return ret;
return 0;
}