wsc: Use macros to simplify reply code a bit

This commit is contained in:
Denis Kenzior 2020-01-17 12:05:47 -06:00
parent 30ec06edcc
commit b00d4f4ce6
1 changed files with 26 additions and 50 deletions

View File

@ -461,6 +461,16 @@ struct wsc_station_dbus {
uint32_t station_state_watch; uint32_t station_state_watch;
}; };
#define CONNECT_REPLY(wsc, message) \
if ((wsc)->super.pending_connect) \
dbus_pending_reply(&(wsc)->super.pending_connect, \
message((wsc)->super.pending_connect)) \
#define CANCEL_REPLY(wsc, message) \
if ((wsc)->super.pending_cancel) \
dbus_pending_reply(&(wsc)->super.pending_cancel, \
message((wsc)->super.pending_cancel)) \
static void wsc_try_credentials(struct wsc_station_dbus *wsc, static void wsc_try_credentials(struct wsc_station_dbus *wsc,
struct wsc_credentials_info *creds, struct wsc_credentials_info *creds,
unsigned int n_creds) unsigned int n_creds)
@ -509,8 +519,7 @@ static void wsc_try_credentials(struct wsc_station_dbus *wsc,
return; return;
} }
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, wsc_error_not_reachable);
wsc_error_not_reachable(wsc->super.pending_connect));
station_set_autoconnect(wsc->station, true); station_set_autoconnect(wsc->station, true);
} }
@ -560,31 +569,17 @@ static void wsc_dbus_done_cb(int err, struct wsc_credentials_info *creds,
break; break;
case -ECANCELED: case -ECANCELED:
/* Send reply if we haven't already sent one e.g. in Cancel() */ /* Send reply if we haven't already sent one e.g. in Cancel() */
if (wsc->super.pending_connect) CONNECT_REPLY(wsc, dbus_error_aborted);
dbus_pending_reply(&wsc->super.pending_connect, CANCEL_REPLY(wsc, l_dbus_message_new_method_return);
dbus_error_aborted(
wsc->super.pending_connect));
if (wsc->super.pending_cancel)
dbus_pending_reply(&wsc->super.pending_cancel,
l_dbus_message_new_method_return(
wsc->super.pending_cancel));
return; return;
case -ENOKEY: case -ENOKEY:
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, wsc_error_no_credentials);
wsc_error_no_credentials(
wsc->super.pending_connect));
return; return;
case -EBUSY: case -EBUSY:
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_busy);
dbus_error_busy(
wsc->super.pending_connect));
return; return;
default: default:
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_failed);
dbus_error_failed(
wsc->super.pending_connect));
return; return;
} }
@ -660,8 +655,7 @@ static void wsc_check_can_connect(struct wsc_station_dbus *wsc,
} }
error: error:
wsc->target = NULL; wsc->target = NULL;
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_failed);
dbus_error_failed(wsc->super.pending_connect));
} }
static void wsc_cancel_scan(struct wsc_station_dbus *wsc) static void wsc_cancel_scan(struct wsc_station_dbus *wsc)
@ -685,11 +679,7 @@ static void walk_timeout(struct l_timeout *timeout, void *user_data)
struct wsc_station_dbus *wsc = user_data; struct wsc_station_dbus *wsc = user_data;
wsc_cancel_scan(wsc); wsc_cancel_scan(wsc);
CONNECT_REPLY(wsc, wsc_error_walk_time_expired);
if (wsc->super.pending_connect)
dbus_pending_reply(&wsc->super.pending_connect,
wsc_error_walk_time_expired(
wsc->super.pending_connect));
} }
static void pin_timeout(struct l_timeout *timeout, void *user_data) static void pin_timeout(struct l_timeout *timeout, void *user_data)
@ -697,11 +687,7 @@ static void pin_timeout(struct l_timeout *timeout, void *user_data)
struct wsc_station_dbus *wsc = user_data; struct wsc_station_dbus *wsc = user_data;
wsc_cancel_scan(wsc); wsc_cancel_scan(wsc);
CONNECT_REPLY(wsc, wsc_error_time_expired);
if (wsc->super.pending_connect)
dbus_pending_reply(&wsc->super.pending_connect,
wsc_error_time_expired(
wsc->super.pending_connect));
} }
static bool push_button_scan_results(int err, struct l_queue *bss_list, static bool push_button_scan_results(int err, struct l_queue *bss_list,
@ -718,8 +704,7 @@ static bool push_button_scan_results(int err, struct l_queue *bss_list,
if (err) { if (err) {
wsc_cancel_scan(wsc); wsc_cancel_scan(wsc);
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_failed);
dbus_error_failed(wsc->super.pending_connect));
return false; return false;
} }
@ -820,8 +805,7 @@ static bool push_button_scan_results(int err, struct l_queue *bss_list,
session_overlap: session_overlap:
wsc_cancel_scan(wsc); wsc_cancel_scan(wsc);
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, wsc_error_session_overlap);
wsc_error_session_overlap(wsc->super.pending_connect));
return false; return false;
} }
@ -872,8 +856,7 @@ static bool pin_scan_results(int err, struct l_queue *bss_list, void *userdata)
if (err) { if (err) {
wsc_cancel_scan(wsc); wsc_cancel_scan(wsc);
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_failed);
dbus_error_failed(wsc->super.pending_connect));
return false; return false;
} }
@ -1047,9 +1030,7 @@ static void wsc_station_dbus_connect(struct wsc_dbus *super,
wsc->station = station_find(netdev_get_ifindex(wsc->netdev)); wsc->station = station_find(netdev_get_ifindex(wsc->netdev));
if (!wsc->station) { if (!wsc->station) {
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_not_available);
dbus_error_not_available(
wsc->super.pending_connect));
return; return;
} }
@ -1066,9 +1047,7 @@ static void wsc_station_dbus_connect(struct wsc_dbus *super,
} }
if (!wsc_initiate_scan(wsc, dpid, scan_callback)) { if (!wsc_initiate_scan(wsc, dpid, scan_callback)) {
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_failed);
dbus_error_failed(
wsc->super.pending_connect));
return; return;
} }
@ -1094,15 +1073,12 @@ static void wsc_station_dbus_cancel(struct wsc_dbus *super)
wsc->target = NULL; wsc->target = NULL;
} }
dbus_pending_reply(&wsc->super.pending_connect, CONNECT_REPLY(wsc, dbus_error_aborted);
dbus_error_aborted(wsc->super.pending_connect));
if (wsc->enrollee) if (wsc->enrollee)
wsc_enrollee_cancel(wsc->enrollee, true); wsc_enrollee_cancel(wsc->enrollee, true);
else else
dbus_pending_reply(&wsc->super.pending_cancel, CANCEL_REPLY(wsc, l_dbus_message_new_method_return);
l_dbus_message_new_method_return(
wsc->super.pending_cancel));
} }
static void wsc_station_dbus_remove(struct wsc_dbus *super) static void wsc_station_dbus_remove(struct wsc_dbus *super)