1
0
Fork 0

event input for Linux: substitude dbus+hal by udev

This commit is contained in:
Torsten Dreyer 2011-12-03 22:59:20 +01:00
parent 61e60484c8
commit ded106fe31
2 changed files with 23 additions and 81 deletions

View file

@ -25,15 +25,11 @@
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <poll.h>
#include <linux/input.h>
#include <dbus/dbus.h>
#include <fcntl.h>
#include "FGLinuxEventInput.hxx"
#include <libudev.h>
#include <poll.h>
#include <linux/input.h>
#include <dbus/dbus.h>
#include <fcntl.h>
#include <string.h>
@ -445,92 +441,42 @@ void FGLinuxInputDevice::SetDevname( std::string name )
this->devname = name;
}
FGLinuxEventInput::FGLinuxEventInput() :
halcontext(NULL)
FGLinuxEventInput::FGLinuxEventInput()
{
}
FGLinuxEventInput::~FGLinuxEventInput()
{
if( halcontext != NULL ) {
libhal_ctx_shutdown( halcontext, NULL);
libhal_ctx_free( halcontext );
halcontext = NULL;
}
}
#if 0
//TODO: enable hotplug support
static void DeviceAddedCallback (LibHalContext *ctx, const char *udi)
{
FGLinuxEventInput * linuxEventInput = (FGLinuxEventInput*)libhal_ctx_get_user_data (ctx);
linuxEventInput->AddHalDevice( udi );
}
static void DeviceRemovedCallback (LibHalContext *ctx, const char *udi)
{
}
#endif
void FGLinuxEventInput::postinit()
{
FGEventInput::postinit();
DBusConnection * connection;
DBusError dbus_error;
struct udev * udev = udev_new();
dbus_error_init(&dbus_error);
connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
if (dbus_error_is_set(&dbus_error)) {
SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to system bus " << dbus_error.message);
dbus_error_free (&dbus_error);
return;
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(enumerate, "input");
udev_enumerate_scan_devices(enumerate);
struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate);
struct udev_list_entry *dev_list_entry;
udev_list_entry_foreach(dev_list_entry, devices) {
const char * path = udev_list_entry_get_name(dev_list_entry);
struct udev_device *dev = udev_device_new_from_syspath(udev, path);
const char * node = udev_device_get_devnode(dev);
dev = udev_device_get_parent( dev );
const char * name = udev_device_get_sysattr_value(dev,"name");
SG_LOG(SG_INPUT,SG_ALERT, "name=" << (name?name:"<null>") << ", node=" << (node?node:"<null>"));
if( name && node )
AddDevice( new FGLinuxInputDevice(name, node) );
udev_device_unref(dev);
}
halcontext = libhal_ctx_new();
libhal_ctx_set_dbus_connection (halcontext, connection );
dbus_error_init (&dbus_error);
if( libhal_ctx_init( halcontext, &dbus_error )) {
int num_devices = 0;
char ** devices = libhal_find_device_by_capability(halcontext, "input", &num_devices, NULL);
for ( int i = 0; i < num_devices; i++)
AddHalDevice( devices[i] );
libhal_free_string_array (devices);
//TODO: enable hotplug support
// libhal_ctx_set_user_data( halcontext, this );
// libhal_ctx_set_device_added( halcontext, DeviceAddedCallback );
// libhal_ctx_set_device_removed( halcontext, DeviceRemovedCallback );
} else {
if(dbus_error_is_set (&dbus_error) ) {
SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to hald: " << dbus_error.message);
dbus_error_free (&dbus_error);
} else {
SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to hald." );
}
libhal_ctx_free (halcontext);
halcontext = NULL;
}
}
void FGLinuxEventInput::AddHalDevice( const char * udi )
{
char * device = libhal_device_get_property_string( halcontext, udi, "input.device", NULL);
char * product = libhal_device_get_property_string( halcontext, udi, "input.product", NULL);
if( product != NULL && device != NULL )
AddDevice( new FGLinuxInputDevice(product, device) );
else
SG_LOG( SG_INPUT, SG_ALERT, "Can't get device or product property of " << udi );
if( device != NULL ) libhal_free_string( device );
if( product != NULL ) libhal_free_string( product );
udev_unref(udev);
}

View file

@ -25,7 +25,6 @@
#include "FGEventInput.hxx"
#include <linux/input.h>
#include <hal/libhal.h>
struct FGLinuxEventData : public FGEventData {
FGLinuxEventData( struct input_event & event, double dt, int modifiers ) :
@ -71,10 +70,7 @@ public:
virtual void update (double dt);
virtual void postinit();
void AddHalDevice( const char * udi );
protected:
LibHalContext *halcontext;
};
#endif