LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2005, 12:12 PM   #1
Zotty
LQ Newbie
 
Registered: Sep 2004
Location: Netherlands
Distribution: Debian testing
Posts: 25

Rep: Reputation: 15
gdk_input_add callback in C++ problem


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;
	}
}
 
Old 03-16-2005, 07:22 PM   #2
YetAnotherDave
Member
 
Registered: Feb 2005
Posts: 95

Rep: Reputation: 17
The problem you describe should go away if you declare "ProcessLircInput()" as static as shown below.


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
	 */
	static void ProcessLircInput( gpointer data, gint source, GdkInputCondition condition );

	struct lirc_config *config;				/**< LIRC config */
	int					tag;				/**< GDK callback tag */
};
 
Old 03-17-2005, 09:24 AM   #3
Zotty
LQ Newbie
 
Registered: Sep 2004
Location: Netherlands
Distribution: Debian testing
Posts: 25

Original Poster
Rep: Reputation: 15
Solved it by using a dispath function. Works like a charm

Code:
class InputLirc
{
public:
   static void DispatchProcessLircInput (gpointer aInputLirc, gint source, GdkInputCondition condition)
   {
        InputLirc *obj = static_cast<InputLirc*>(aInputLirc);
        return obj->ProcessLircInput (NULL, source, condition);
   }

InputLirc :: InputLirc()
{
  ...

  tag = gdk_input_add( sock,
      GDK_INPUT_READ,
      DispatchProcessLircInput,
      this );

  ...
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gtk callback problem elyk Programming 4 07-12-2005 01:28 AM
Callback with pppd problem simanyay Linux - Networking 0 08-07-2004 04:30 AM
Problem with Callback! Linuxnewbie Linux - Networking 1 02-24-2004 01:55 AM
C++, GTK, Classes and "gdk_input_add" Ohmu Programming 1 01-23-2004 02:22 PM
ISDN + callback zeky Linux - General 0 12-25-2002 07:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration