3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

client: Introduce cmd execution status

This commit is contained in:
Tim Kourt 2017-04-25 18:13:58 -07:00 committed by Denis Kenzior
parent 7a9f72018a
commit e0117febd5
4 changed files with 72 additions and 18 deletions

View File

@ -33,16 +33,20 @@
static struct l_queue *command_families;
static void cmd_version(const char *entity, char *arg)
static enum cmd_status cmd_version(const char *entity, char *arg)
{
display("IWD version %s\n", VERSION);
return CMD_STATUS_OK;
}
static void cmd_quit(const char *entity, char *arg)
static enum cmd_status cmd_quit(const char *entity, char *arg)
{
display_quit();
l_main_quit();
return CMD_STATUS_OK;
}
static const struct command command_list[] = {
@ -281,12 +285,40 @@ char *command_entity_arg_completion(const char *text, int state,
static void execute_cmd(const char *family, const char *entity,
const struct command *cmd, char *args)
{
enum cmd_status status;
display_refresh_set_cmd(family, entity, cmd, args);
cmd->function(entity, args);
status = cmd->function(entity, args);
if (status != CMD_STATUS_OK)
goto error;
if (cmd->refreshable)
display_refresh_timeout_set();
return;
error:
switch (status) {
case CMD_STATUS_INVALID_ARGS:
display("Invalid command. Use the following pattern:\n");
display_command_line(family, cmd);
break;
case CMD_STATUS_UNSUPPORTED:
display_refresh_reset();
display("Unsupported command\n");
break;
case CMD_STATUS_FAILED:
l_main_quit();
break;
default:
l_error("Unknown command status.");
}
}
static bool match_cmd(const char *family, const char *entity, const char *cmd,

View File

@ -22,11 +22,18 @@
typedef char *(*command_completion_func_t) (const char *text, int state);
enum cmd_status {
CMD_STATUS_OK,
CMD_STATUS_INVALID_ARGS,
CMD_STATUS_UNSUPPORTED,
CMD_STATUS_FAILED,
};
struct command {
const char *entity;
const char *cmd;
const char *arg;
void (*function)(const char *entity, char *arg);
enum cmd_status (*function)(const char *entity, char *arg);
const char *desc;
const bool refreshable;
command_completion_func_t completion;

View File

@ -369,18 +369,20 @@ static const struct proxy_interface *get_device_proxy_by_name(
return proxy;
}
static void cmd_show(const char *device_name, char *args)
static enum cmd_status cmd_show(const char *device_name, char *args)
{
struct device *device;
const struct proxy_interface *proxy =
get_device_proxy_by_name(device_name);
if (!proxy)
return;
return CMD_STATUS_INVALID_ARGS;
device = proxy_interface_get_data(proxy);
display_device(device);
return CMD_STATUS_OK;
}
static void check_errors_method_callback(struct l_dbus_message *message,
@ -389,43 +391,49 @@ static void check_errors_method_callback(struct l_dbus_message *message,
dbus_message_has_error(message);
}
static void cmd_scan(const char *device_name, char *args)
static enum cmd_status cmd_scan(const char *device_name, char *args)
{
const struct proxy_interface *proxy =
get_device_proxy_by_name(device_name);
if (!proxy)
return;
return CMD_STATUS_INVALID_ARGS;
proxy_interface_method_call(proxy, "Scan", "",
check_errors_method_callback);
return CMD_STATUS_OK;
}
static void cmd_disconnect(const char *device_name, char *args)
static enum cmd_status cmd_disconnect(const char *device_name, char *args)
{
const struct proxy_interface *proxy =
get_device_proxy_by_name(device_name);
if (!proxy)
return;
return CMD_STATUS_INVALID_ARGS;
proxy_interface_method_call(proxy, "Disconnect", "",
check_errors_method_callback);
return CMD_STATUS_OK;
}
static void cmd_get_networks(const char *device_name, char *args)
static enum cmd_status cmd_get_networks(const char *device_name, char *args)
{
const struct proxy_interface *proxy =
get_device_proxy_by_name(device_name);
if (!proxy)
return;
return CMD_STATUS_INVALID_ARGS;
proxy_interface_method_call(proxy, "GetOrderedNetworks", "",
ordered_networks_callback);
return CMD_STATUS_OK;
}
static void cmd_list(const char *device_name, char *args)
static enum cmd_status cmd_list(const char *device_name, char *args)
{
display_table_header("Devices", MARGIN "%-*s%-*s%-*s%-*s", 20, "Name",
20, "Address", 15, "State", 10, "Adapter");
@ -433,14 +441,18 @@ static void cmd_list(const char *device_name, char *args)
proxy_interface_display_list(device_interface_type.interface);
display_table_footer();
return CMD_STATUS_OK;
}
static void cmd_set_property(const char *device_name, char *args)
static enum cmd_status cmd_set_property(const char *device_name, char *args)
{
return CMD_STATUS_UNSUPPORTED;
}
static void cmd_connect(const char *device_name, char *args)
static enum cmd_status cmd_connect(const char *device_name, char *args)
{
return CMD_STATUS_UNSUPPORTED;
}
static const struct command device_commands[] = {

View File

@ -244,21 +244,24 @@ static struct proxy_interface_type known_networks_interface_type = {
.ops = &known_networks_ops,
};
static void cmd_list(const char *entity, char *args)
static enum cmd_status cmd_list(const char *entity, char *args)
{
struct proxy_interface *proxy =
proxy_interface_find(IWD_KNOWN_NETWORKS_INTREFACE,
IWD_KNOWN_NETWORKS_PATH);
if (!proxy)
return;
return CMD_STATUS_FAILED;
proxy_interface_method_call(proxy, "ListKnownNetworks", "",
list_networks_callback);
return CMD_STATUS_OK;
}
static void cmd_forget(const char *entity, char *args)
static enum cmd_status cmd_forget(const char *entity, char *args)
{
return CMD_STATUS_UNSUPPORTED;
}
static const struct command known_networks_commands[] = {