I'm working on a plugin with LIRC support. The LIRC stuff is placed in its own
class. To detect incomming data, I'm using gdk_input_add().
However, I've been unsuccessfull to get this to compile. The callback is setup
in the class constructor and the function that needs to be 'called' is a
member function of the same class. The sourcecode of the class is posted below.
When compiling I'm getting the following error(s);
input_lirc.cpp: In constructor `InputLirc::InputLirc()':
input_lirc.cpp:67: error: argument of type `void (InputLirc:
(void*, int,
GdkInputCondition)' does not match `void (*)(void*, int,
GdkInputCondition)'
or this one;
input_lirc.cpp: In constructor `InputLirc::InputLirc()':
input_lirc.cpp:67: error: cannot convert `void (InputLirc::*)(void*, int,
GdkInputCondition)' to `void (*)(void*, int, GdkInputCondition)' for
argument `3' to `gint gdk_input_add(int, GdkInputCondition, void (*)(void*,
int, GdkInputCondition), void*)'
Any help would be appreciated as I'm completely stuck atm...
Header:
Code:
class InputLirc : public InputInterface {
public:
/**
* @brief Sets up a connection to the LIRC server and reads the config.
*/
InputLirc();
/**
* @brief Cleans up LIRC config stuff and disconnects from server.
*/
~InputLirc();
private:
/**
* @brief GDK callback to process incomming data from the LIRC daemon
*/
void ProcessLircInput( gpointer data, gint source, GdkInputCondition condition );
struct lirc_config *config; /**< LIRC config */
int tag; /**< GDK callback tag */
};
cpp file:
Code:
// system includes
#include <lirc/lirc_client.h>
#include <gdk/gdk.h>
#include <fcntl.h>
// liquid-mp3 includes
#include "inputinterface.h"
#include "input_lirc.h"
#include "defines.h"
#include "plugin.h"
extern PlayerPlugin * Plugin;
/**
* Sets up a connection to the LIRC server and reads the config.
*/
InputLirc :: InputLirc()
{
Plugin->OutputMessage( LIQ_DEBUG, "Initialising LIRC input", "InputLirc::InputLirc" );
int sock; // file descriptor of the socket that is connected to lircd
int flags; // flags used for fcntl
// init lirc
sock = lirc_init( "liquidmp3", 1 );
if ( sock == -1)
Plugin->OutputMessage( LIQ_ERROR, "Error initialising LIRC library", "InputLirc::InputLirc" );
// read config
if (lirc_readconfig(
NULL, // config file (pass NULL to use the default config)
&config, // pointer to the config file data structure (needed for lirc_code2char())
NULL // call-back function that can be used for syntax checks with the config strings
) == -1)
Plugin->OutputMessage( LIQ_ERROR, "Error loading LIRC config", "InputLirc::InputLirc" );
// prevent lirc_nextcode() from blocking the socket
fcntl( sock, F_SETOWN, getpid() );
flags = fcntl( sock, F_GETFL, 0 );
if (flags != -1)
fcntl( sock, F_SETFL, flags | O_NONBLOCK );
// setup callback that responds to input on the lirc socket
void (InputLirc::*pFunc) ( gpointer data, gint source, GdkInputCondition condition );
pFunc = &InputLirc::ProcessLircInput;
tag = gdk_input_add( sock,
GDK_INPUT_READ,
(pFunc),
//this->ProcessLircInput,
//ProcessLircInput,
NULL );
}
/**
* Cleans up LIRC config stuff and disconnects from server.
*/
InputLirc :: ~InputLirc()
{
// stop monitoring
gdk_input_remove( tag ); // GDK
// free data structures associated with config
lirc_freeconfig( config );
// close connection with LIRC
lirc_deinit();
}
/**
* Monitor userinput received through the LIRC server.
*/
void InputLirc :: ProcessLircInput( gpointer data, gint source, GdkInputCondition condition )
{
char *code; // code transmitted to your application on the lircd socket
char *configString; //
int ret;
while((ret=lirc_nextcode(&code))==0 && code!=NULL)
{
// get the config string(s) that the user has provided in the config file
while ((ret = lirc_code2char(config, code, &configString)) == 0 && configString != NULL)
{
Plugin->OutputMessage( LIQ_DEBUG, configString, "LIRC command received" );
}
free( code );
if (ret == -1)
break;
}
}