Cleaned up list_controller()
This commit is contained in:
parent
5440a4f4fc
commit
54db79a889
4 changed files with 40 additions and 25 deletions
|
@ -27,7 +27,8 @@ CommandLineOptions* command_line_options = 0;
|
|||
|
||||
CommandLineOptions::CommandLineOptions()
|
||||
{
|
||||
daemon = false;
|
||||
mode = RUN_DEFAULT;
|
||||
|
||||
verbose = false;
|
||||
silent = false;
|
||||
quiet = false;
|
||||
|
@ -99,7 +100,7 @@ void set_ui_axis_map(AxisEvent* ui_axis_map, const std::string& str)
|
|||
}
|
||||
|
||||
void
|
||||
CommandLineOptions::parse_args(Xboxdrv& xboxdrv, int argc, char** argv)
|
||||
CommandLineOptions::parse_args(int argc, char** argv)
|
||||
{
|
||||
CommandLineOptions& opts = *this;
|
||||
|
||||
|
@ -135,7 +136,7 @@ CommandLineOptions::parse_args(Xboxdrv& xboxdrv, int argc, char** argv)
|
|||
strcmp(argv[i], "-D") == 0)
|
||||
{
|
||||
opts.silent = true;
|
||||
opts.daemon = true;
|
||||
opts.mode = RUN_DAEMON;
|
||||
}
|
||||
else if (strcmp(argv[i], "--test-rumble") == 0 ||
|
||||
strcmp(argv[i], "-R") == 0)
|
||||
|
@ -538,8 +539,7 @@ CommandLineOptions::parse_args(Xboxdrv& xboxdrv, int argc, char** argv)
|
|||
else if (strcmp(argv[i], "--list-controller") == 0 ||
|
||||
strcmp(argv[i], "-L") == 0)
|
||||
{
|
||||
xboxdrv.list_controller();
|
||||
exit(EXIT_SUCCESS);
|
||||
opts.mode = RUN_LIST_CONTROLLER;
|
||||
}
|
||||
else if (strcmp(argv[i], "--help-devices") == 0)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,11 @@ class Xboxdrv;
|
|||
class CommandLineOptions
|
||||
{
|
||||
public:
|
||||
bool daemon;
|
||||
enum { RUN_DEFAULT,
|
||||
RUN_DAEMON,
|
||||
RUN_LIST_CONTROLLER
|
||||
} mode;
|
||||
|
||||
bool verbose;
|
||||
bool silent;
|
||||
bool quiet;
|
||||
|
@ -70,7 +74,7 @@ public:
|
|||
|
||||
public:
|
||||
CommandLineOptions();
|
||||
void parse_args(Xboxdrv& xboxdrv, int argc, char** argv);
|
||||
void parse_args(int argc, char** argv);
|
||||
|
||||
void print_command_line_help(int argc, char** argv) const;
|
||||
void print_led_help() const;
|
||||
|
|
|
@ -630,28 +630,40 @@ Xboxdrv::main(int argc, char** argv)
|
|||
signal(SIGINT, on_sigint);
|
||||
|
||||
CommandLineOptions opts;
|
||||
opts.parse_args(*this, argc, argv);
|
||||
opts.parse_args(argc, argv);
|
||||
command_line_options = &opts;
|
||||
|
||||
if (opts.daemon)
|
||||
switch(opts.mode)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid < 0) exit(EXIT_FAILURE); /* fork error */
|
||||
if (pid > 0) exit(EXIT_SUCCESS); /* parent exits */
|
||||
|
||||
pid_t sid = setsid();
|
||||
std::cout << "Sid: " << sid << std::endl;
|
||||
if (chdir("/") != 0)
|
||||
case CommandLineOptions::RUN_DEFAULT:
|
||||
{
|
||||
throw std::runtime_error(strerror(errno));
|
||||
run_main(opts);
|
||||
}
|
||||
break;
|
||||
|
||||
run_main(opts);
|
||||
}
|
||||
else
|
||||
{
|
||||
run_main(opts);
|
||||
case CommandLineOptions::RUN_DAEMON:
|
||||
{
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid < 0) exit(EXIT_FAILURE); /* fork error */
|
||||
if (pid > 0) exit(EXIT_SUCCESS); /* parent exits */
|
||||
|
||||
pid_t sid = setsid();
|
||||
std::cout << "Sid: " << sid << std::endl;
|
||||
if (chdir("/") != 0)
|
||||
{
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
|
||||
run_main(opts);
|
||||
}
|
||||
break;
|
||||
|
||||
case CommandLineOptions::RUN_LIST_CONTROLLER:
|
||||
{
|
||||
list_controller();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(std::exception& err)
|
||||
|
|
|
@ -35,6 +35,7 @@ private:
|
|||
void controller_loop(GamepadType type, uInput* uinput,
|
||||
XboxGenericController* controller,
|
||||
const CommandLineOptions& opts);
|
||||
void list_controller();
|
||||
|
||||
bool find_controller_by_path(const char* busid, const char* devid,struct usb_device** xbox_device) const;
|
||||
void find_controller(struct usb_device*& dev,
|
||||
|
@ -46,8 +47,6 @@ private:
|
|||
bool find_xbox360_controller(int id, struct usb_device** xbox_device, XPadDevice* type) const;
|
||||
|
||||
public:
|
||||
void list_controller();
|
||||
|
||||
int main(int argc, char** argv);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue