Added Shutdown() call to D-Bus interface, properly catch SIGINT and SIGTERM in Daemon
This commit is contained in:
parent
6bb8a4dc8e
commit
bb10adb20d
7 changed files with 82 additions and 20 deletions
|
@ -15,5 +15,11 @@
|
||||||
<method name="SetConfig">
|
<method name="SetConfig">
|
||||||
<arg name="config" type="i" direction="in" />
|
<arg name="config" type="i" direction="in" />
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
rumble_enable SLOT
|
||||||
|
rumble_disable SLOT
|
||||||
|
set_rumble_gain SLOT GAIN
|
||||||
|
-->
|
||||||
</interface>
|
</interface>
|
||||||
</node>
|
</node>
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include "xboxdrv_daemon_glue.hpp"
|
#include "xboxdrv_daemon_glue.hpp"
|
||||||
#include "xboxdrv_controller_glue.hpp"
|
#include "xboxdrv_controller_glue.hpp"
|
||||||
|
|
||||||
|
XboxdrvDaemon* XboxdrvDaemon::s_current = 0;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool get_usb_id(udev_device* device, uint16_t* vendor_id, uint16_t* product_id)
|
bool get_usb_id(udev_device* device, uint16_t* vendor_id, uint16_t* product_id)
|
||||||
|
@ -100,12 +102,18 @@ XboxdrvDaemon::XboxdrvDaemon(const Options& opts) :
|
||||||
m_monitor(0),
|
m_monitor(0),
|
||||||
m_controller_slots(),
|
m_controller_slots(),
|
||||||
m_inactive_threads(),
|
m_inactive_threads(),
|
||||||
m_uinput()
|
m_uinput(),
|
||||||
|
m_gmain()
|
||||||
{
|
{
|
||||||
|
assert(!s_current);
|
||||||
|
s_current = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
XboxdrvDaemon::~XboxdrvDaemon()
|
XboxdrvDaemon::~XboxdrvDaemon()
|
||||||
{
|
{
|
||||||
|
assert(s_current);
|
||||||
|
s_current = 0;
|
||||||
|
|
||||||
for(ControllerSlots::iterator i = m_controller_slots.begin(); i != m_controller_slots.end(); ++i)
|
for(ControllerSlots::iterator i = m_controller_slots.begin(); i != m_controller_slots.end(); ++i)
|
||||||
{
|
{
|
||||||
(*i)->disconnect();
|
(*i)->disconnect();
|
||||||
|
@ -377,17 +385,19 @@ XboxdrvDaemon::run(const Options& opts)
|
||||||
// we don't use glib threads, but we still need to init the thread
|
// we don't use glib threads, but we still need to init the thread
|
||||||
// system to make glib thread safe
|
// system to make glib thread safe
|
||||||
g_thread_init(NULL);
|
g_thread_init(NULL);
|
||||||
|
|
||||||
GMainLoop* gmain = g_main_loop_new(NULL, false);
|
signal(SIGINT, &XboxdrvDaemon::on_sigint);
|
||||||
|
signal(SIGTERM, &XboxdrvDaemon::on_sigint);
|
||||||
|
m_gmain = g_main_loop_new(NULL, false);
|
||||||
|
|
||||||
init_g_udev();
|
init_g_udev();
|
||||||
init_g_dbus();
|
init_g_dbus();
|
||||||
|
|
||||||
log_info("launching into glib main loop");
|
log_info("launching into glib main loop");
|
||||||
g_main_loop_run(gmain);
|
g_main_loop_run(m_gmain);
|
||||||
log_info("glib main loop finished");
|
log_info("glib main loop finished");
|
||||||
|
signal(SIGINT, 0);
|
||||||
g_main_loop_unref(gmain);
|
g_main_loop_unref(m_gmain);
|
||||||
}
|
}
|
||||||
catch(const std::exception& err)
|
catch(const std::exception& err)
|
||||||
{
|
{
|
||||||
|
@ -908,4 +918,17 @@ XboxdrvDaemon::status()
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
XboxdrvDaemon::shutdown()
|
||||||
|
{
|
||||||
|
assert(m_gmain);
|
||||||
|
g_main_loop_quit(m_gmain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
XboxdrvDaemon::on_sigint(int)
|
||||||
|
{
|
||||||
|
XboxdrvDaemon::current()->shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -34,6 +34,8 @@ struct XPadDevice;
|
||||||
class XboxdrvDaemon
|
class XboxdrvDaemon
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
static XboxdrvDaemon* s_current;
|
||||||
|
|
||||||
const Options& m_opts;
|
const Options& m_opts;
|
||||||
struct udev* m_udev;
|
struct udev* m_udev;
|
||||||
struct udev_monitor* m_monitor;
|
struct udev_monitor* m_monitor;
|
||||||
|
@ -45,6 +47,11 @@ private:
|
||||||
Threads m_inactive_threads;
|
Threads m_inactive_threads;
|
||||||
|
|
||||||
std::auto_ptr<UInput> m_uinput;
|
std::auto_ptr<UInput> m_uinput;
|
||||||
|
GMainLoop* m_gmain;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void on_sigint(int);
|
||||||
|
static XboxdrvDaemon* current() { return s_current; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XboxdrvDaemon(const Options& opts);
|
XboxdrvDaemon(const Options& opts);
|
||||||
|
@ -53,6 +60,7 @@ public:
|
||||||
void run(const Options& opts);
|
void run(const Options& opts);
|
||||||
|
|
||||||
std::string status();
|
std::string status();
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void create_pid_file(const Options& opts);
|
void create_pid_file(const Options& opts);
|
||||||
|
|
|
@ -6,22 +6,11 @@
|
||||||
<method name="Status">
|
<method name="Status">
|
||||||
<arg type="s" direction="out" />
|
<arg type="s" direction="out" />
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
<method name="Shutdown" />
|
||||||
<!--
|
<!--
|
||||||
<method name="SetLed">
|
|
||||||
<arg name="status" type="i" direction="in" />
|
|
||||||
</method>
|
|
||||||
|
|
||||||
<method name="SetRumble">
|
|
||||||
<arg name="strong" type="i" direction="in" />
|
|
||||||
<arg name="weak" type="i" direction="in" />
|
|
||||||
</method>
|
|
||||||
|
|
||||||
reset_leds
|
reset_leds
|
||||||
shutdown, quit, exit
|
|
||||||
disconnect SLOT
|
disconnect SLOT
|
||||||
rumble_enable SLOT
|
|
||||||
rumble_disable SLOT
|
|
||||||
set_rumble_gain SLOT GAIN
|
|
||||||
-->
|
-->
|
||||||
</interface>
|
</interface>
|
||||||
</node>
|
</node>
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "xboxdrv_g_daemon.hpp"
|
#include "xboxdrv_g_daemon.hpp"
|
||||||
|
|
||||||
|
#include "log.hpp"
|
||||||
#include "xboxdrv_daemon.hpp"
|
#include "xboxdrv_daemon.hpp"
|
||||||
|
|
||||||
/* will create xboxdrv_g_daemon_get_type and set xboxdrv_g_daemon_parent_class */
|
/* will create xboxdrv_g_daemon_get_type and set xboxdrv_g_daemon_parent_class */
|
||||||
|
@ -57,8 +58,18 @@ xboxdrv_g_daemon_new(XboxdrvDaemon* daemon)
|
||||||
gboolean
|
gboolean
|
||||||
xboxdrv_g_daemon_status(XboxdrvGDaemon* self, gchar** ret, GError** error)
|
xboxdrv_g_daemon_status(XboxdrvGDaemon* self, gchar** ret, GError** error)
|
||||||
{
|
{
|
||||||
|
log_info("D-Bus: xboxdrv_g_daemon_status(" << self << ")");
|
||||||
|
|
||||||
*ret = g_strdup(self->daemon->status().c_str());
|
*ret = g_strdup(self->daemon->status().c_str());
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean xboxdrv_g_daemon_shutdown(XboxdrvGDaemon* self, GError** error)
|
||||||
|
{
|
||||||
|
log_info("D-Bus: xboxdrv_g_daemon_shutdown(" << self << ")");
|
||||||
|
|
||||||
|
self->daemon->shutdown();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -51,6 +51,7 @@ GType xboxdrv_g_daemon_get_type();
|
||||||
XboxdrvGDaemon* xboxdrv_g_daemon_new(XboxdrvDaemon* daemon);
|
XboxdrvGDaemon* xboxdrv_g_daemon_new(XboxdrvDaemon* daemon);
|
||||||
|
|
||||||
gboolean xboxdrv_g_daemon_status(XboxdrvGDaemon* self, gchar** ret, GError** error);
|
gboolean xboxdrv_g_daemon_status(XboxdrvGDaemon* self, gchar** ret, GError** error);
|
||||||
|
gboolean xboxdrv_g_daemon_shutdown(XboxdrvGDaemon* self, GError** error);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
26
xboxdrvctl
26
xboxdrvctl
|
@ -1,11 +1,28 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
## Xbox360 USB Gamepad Userspace Driver
|
||||||
|
## Copyright (C) 2011 Ingo Ruhnke <grumbel@gmx.de>
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
from optparse import OptionParser, OptionGroup
|
from optparse import OptionParser, OptionGroup
|
||||||
|
|
||||||
parser = OptionParser("Usage: %prog [OPTIONS]")
|
parser = OptionParser("Usage: %prog [OPTIONS]\n"
|
||||||
|
"Remote control application for the xboxdrv daemon")
|
||||||
|
|
||||||
group = OptionGroup(parser, "D-Bus Options")
|
group = OptionGroup(parser, "D-Bus Options")
|
||||||
group.add_option("-b", "--bus", metavar="BUS",
|
group.add_option("-b", "--bus", metavar="BUS",
|
||||||
|
@ -38,6 +55,10 @@ group.add_option("-c", "--config", metavar="NUM", type="int",
|
||||||
dest="config",
|
dest="config",
|
||||||
help="switches to controller configuration NUM")
|
help="switches to controller configuration NUM")
|
||||||
|
|
||||||
|
group.add_option("--shutdown", action="store_true",
|
||||||
|
dest="shutdown",
|
||||||
|
help="shuts down the daemon")
|
||||||
|
|
||||||
parser.add_option_group(group)
|
parser.add_option_group(group)
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
@ -47,6 +68,9 @@ bus = dbus.SessionBus()
|
||||||
if options.status:
|
if options.status:
|
||||||
daemon = bus.get_object("org.seul.Xboxdrv", '/org/seul/Xboxdrv/Daemon')
|
daemon = bus.get_object("org.seul.Xboxdrv", '/org/seul/Xboxdrv/Daemon')
|
||||||
sys.stdout.write(daemon.Status())
|
sys.stdout.write(daemon.Status())
|
||||||
|
elif options.shutdown:
|
||||||
|
daemon = bus.get_object("org.seul.Xboxdrv", '/org/seul/Xboxdrv/Daemon')
|
||||||
|
daemon.Shutdown()
|
||||||
else:
|
else:
|
||||||
if (options.led or options.rumble or options.config) and options.slot == None:
|
if (options.led or options.rumble or options.config) and options.slot == None:
|
||||||
print "Error: --slot argument required"
|
print "Error: --slot argument required"
|
||||||
|
|
Loading…
Add table
Reference in a new issue