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:
parent
7a9f72018a
commit
e0117febd5
@ -33,16 +33,20 @@
|
|||||||
|
|
||||||
static struct l_queue *command_families;
|
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);
|
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();
|
display_quit();
|
||||||
|
|
||||||
l_main_quit();
|
l_main_quit();
|
||||||
|
|
||||||
|
return CMD_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct command command_list[] = {
|
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,
|
static void execute_cmd(const char *family, const char *entity,
|
||||||
const struct command *cmd, char *args)
|
const struct command *cmd, char *args)
|
||||||
{
|
{
|
||||||
|
enum cmd_status status;
|
||||||
|
|
||||||
display_refresh_set_cmd(family, entity, cmd, args);
|
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)
|
if (cmd->refreshable)
|
||||||
display_refresh_timeout_set();
|
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,
|
static bool match_cmd(const char *family, const char *entity, const char *cmd,
|
||||||
|
@ -22,11 +22,18 @@
|
|||||||
|
|
||||||
typedef char *(*command_completion_func_t) (const char *text, int state);
|
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 {
|
struct command {
|
||||||
const char *entity;
|
const char *entity;
|
||||||
const char *cmd;
|
const char *cmd;
|
||||||
const char *arg;
|
const char *arg;
|
||||||
void (*function)(const char *entity, char *arg);
|
enum cmd_status (*function)(const char *entity, char *arg);
|
||||||
const char *desc;
|
const char *desc;
|
||||||
const bool refreshable;
|
const bool refreshable;
|
||||||
command_completion_func_t completion;
|
command_completion_func_t completion;
|
||||||
|
@ -369,18 +369,20 @@ static const struct proxy_interface *get_device_proxy_by_name(
|
|||||||
return proxy;
|
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;
|
struct device *device;
|
||||||
const struct proxy_interface *proxy =
|
const struct proxy_interface *proxy =
|
||||||
get_device_proxy_by_name(device_name);
|
get_device_proxy_by_name(device_name);
|
||||||
|
|
||||||
if (!proxy)
|
if (!proxy)
|
||||||
return;
|
return CMD_STATUS_INVALID_ARGS;
|
||||||
|
|
||||||
device = proxy_interface_get_data(proxy);
|
device = proxy_interface_get_data(proxy);
|
||||||
|
|
||||||
display_device(device);
|
display_device(device);
|
||||||
|
|
||||||
|
return CMD_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_errors_method_callback(struct l_dbus_message *message,
|
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);
|
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 =
|
const struct proxy_interface *proxy =
|
||||||
get_device_proxy_by_name(device_name);
|
get_device_proxy_by_name(device_name);
|
||||||
|
|
||||||
if (!proxy)
|
if (!proxy)
|
||||||
return;
|
return CMD_STATUS_INVALID_ARGS;
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "Scan", "",
|
proxy_interface_method_call(proxy, "Scan", "",
|
||||||
check_errors_method_callback);
|
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 =
|
const struct proxy_interface *proxy =
|
||||||
get_device_proxy_by_name(device_name);
|
get_device_proxy_by_name(device_name);
|
||||||
|
|
||||||
if (!proxy)
|
if (!proxy)
|
||||||
return;
|
return CMD_STATUS_INVALID_ARGS;
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "Disconnect", "",
|
proxy_interface_method_call(proxy, "Disconnect", "",
|
||||||
check_errors_method_callback);
|
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 =
|
const struct proxy_interface *proxy =
|
||||||
get_device_proxy_by_name(device_name);
|
get_device_proxy_by_name(device_name);
|
||||||
|
|
||||||
if (!proxy)
|
if (!proxy)
|
||||||
return;
|
return CMD_STATUS_INVALID_ARGS;
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "GetOrderedNetworks", "",
|
proxy_interface_method_call(proxy, "GetOrderedNetworks", "",
|
||||||
ordered_networks_callback);
|
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",
|
display_table_header("Devices", MARGIN "%-*s%-*s%-*s%-*s", 20, "Name",
|
||||||
20, "Address", 15, "State", 10, "Adapter");
|
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);
|
proxy_interface_display_list(device_interface_type.interface);
|
||||||
|
|
||||||
display_table_footer();
|
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[] = {
|
static const struct command device_commands[] = {
|
||||||
|
@ -244,21 +244,24 @@ static struct proxy_interface_type known_networks_interface_type = {
|
|||||||
.ops = &known_networks_ops,
|
.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 =
|
struct proxy_interface *proxy =
|
||||||
proxy_interface_find(IWD_KNOWN_NETWORKS_INTREFACE,
|
proxy_interface_find(IWD_KNOWN_NETWORKS_INTREFACE,
|
||||||
IWD_KNOWN_NETWORKS_PATH);
|
IWD_KNOWN_NETWORKS_PATH);
|
||||||
|
|
||||||
if (!proxy)
|
if (!proxy)
|
||||||
return;
|
return CMD_STATUS_FAILED;
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "ListKnownNetworks", "",
|
proxy_interface_method_call(proxy, "ListKnownNetworks", "",
|
||||||
list_networks_callback);
|
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[] = {
|
static const struct command known_networks_commands[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user