#endif
#include <cstring>
+#include <cstdio>
#include <sys/types.h>
#include <sys/stat.h>
#include "FGLinuxEventInput.hxx"
-#include <libudev.h>
+extern "C" {
+ #include <libudev.h>
+}
+
#include <poll.h>
#include <linux/input.h>
#include <fcntl.h>
return (unsigned long)type << 16 | (unsigned long)code;
}
- bool operator < ( const TypeCode other) const {
+ bool operator < ( const TypeCode & other) const {
return hashCode() < other.hashCode();
}
};
evt.value = (long)value;
evt.time.tv_sec = 0;
evt.time.tv_usec = 0;
- write( fd, &evt, sizeof(evt) );
- SG_LOG( SG_INPUT, SG_DEBUG, "Written event " << eventName
- << " as type=" << evt.type << ", code=" << evt.code << " value=" << evt.value );
+ size_t bytes_written = write(fd, &evt, sizeof(evt));
+
+ if( bytes_written == sizeof(evt) )
+ SG_LOG( SG_INPUT,
+ SG_DEBUG,
+ "Written event " << eventName << " as type=" << evt.type
+ << ", code=" << evt.code
+ << " value=" << evt.value );
+ else
+ SG_LOG( SG_INPUT,
+ SG_WARN,
+ "Failed to write event: written = " << bytes_written );
}
static char ugly_buffer[128];
return EVENT_NAME_BY_TYPE[typeCode];
}
-void FGLinuxInputDevice::SetDevname( std::string name )
+void FGLinuxInputDevice::SetDevname( const std::string & name )
{
this->devname = name;
}