diff options
Diffstat (limited to 'src/power_commands.c')
-rw-r--r-- | src/power_commands.c | 80 |
1 files changed, 3 insertions, 77 deletions
diff --git a/src/power_commands.c b/src/power_commands.c index 33f1366..4000733 100644 --- a/src/power_commands.c +++ b/src/power_commands.c @@ -2,9 +2,8 @@ #include <string.h> #include <errno.h> -#include<d_bus.h> +#include "d_bus_commands.h" -#include "utils.h" #include "power_commands.h" static const string_quadruple_t chassis_dbus = { @@ -25,17 +24,6 @@ static const string_quadruple_t policy_dbus = { "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy"}; -typedef struct -{ - int command; - const string_quadruple_t * path; -}command_dbus_path_t; - -typedef struct -{ - int command; - const char* value; -}command_dbus_value_t; typedef enum { @@ -58,7 +46,7 @@ const command_dbus_path_t power_command_paths[] = { { 0, NULL } }; -const command_dbus_value_t power_command_values[] = { +const command_dbus_member_t power_command_values[] = { { POWER_ON_GRACEFUL, "xyz.openbmc_project.State.Host.Transition.On" }, { POWER_ON_FORCE, "xyz.openbmc_project.State.Host.Transition.On" }, { POWER_OFF_GRACEFUL, "xyz.openbmc_project.State.Host.Transition.Off" }, @@ -77,12 +65,6 @@ typedef enum }power_policy_command_t; -typedef struct -{ - const char* name; - int command; - const char* help; -}universal_command_t; universal_command_t power_commands[] = { { "on-graceful", POWER_ON_GRACEFUL, "Graceful Power On" }, @@ -111,69 +93,13 @@ const command_dbus_path_t power_command_policy_paths[] = { { 0, NULL } }; -const command_dbus_value_t power_command_policy_values[] = { +const command_dbus_member_t power_command_policy_values[] = { { POWER_POLICY_ON, "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn" }, { POWER_POLICY_OFF, "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff" }, { POWER_POLICY_RESTORE, "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore" }, { 0, NULL } }; -static void print_power_help(const universal_command_t* cmds) -{ - printf("Power commands list: \n"); - for(const universal_command_t* current=cmds;current->name!=NULL;current++) - { - printf("\t %s - %s \n", current->name, current->help); - } -} - -static power_command_t parse_power_command(const char* command, const universal_command_t* cmds) -{ - power_command_t result = POWER_UNKNOWN; - for(const universal_command_t* current=cmds;current->name!=NULL;current++) - { - if(strcmp(command, current->name)==0) - result = current->command; - } - return result; -} - -const string_quadruple_t* get_dbus_interface(power_command_t cmd, const command_dbus_path_t* pathes) -{ - for(const command_dbus_path_t* current = pathes; current->path!=NULL; current++) - { - if(current->command == cmd)return current->path; - } - return NULL; -} - -const char* get_dbus_value(power_command_t cmd, const command_dbus_value_t* values) -{ - for(const command_dbus_value_t* current = values; current->value!=NULL; current++) - { - if(current->command == cmd)return current->value; - } - return NULL; -} - - -int com_dbus_property( char *arg, const universal_command_t* commands, const command_dbus_path_t* paths, const command_dbus_value_t* values) -{ - power_command_t cmd = parse_power_command(arg, commands); - if(cmd==POWER_UNKNOWN) { - fprintf(stderr, "Unknown command: %s\n", arg); - print_power_help(commands); - return -EOPNOTSUPP; - } - const string_quadruple_t* dbus_power_interface = get_dbus_interface(cmd, paths); - if(!dbus_power_interface) - return -EOPNOTSUPP; - const char* property_val = get_dbus_value(cmd, values); - if(!property_val) - return -EOPNOTSUPP; - return dbus_set_property_string(dbus_power_interface, property_val); - return 0; -} int com_power( char *arg ) { return com_dbus_property(arg, power_commands, power_command_paths, power_command_values); |