Re: reg: callbacks



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, Dec 13, 2006 at 12:43:00PM +0530, Prasad Achar wrote:
Hi

I have a situation where in have to catch 2 different callbacks on 2
different events from single fuction.

Then how can i manage the below function..

whether i have to add one more gpointer       func_data1 ?


gint gtk_signal_connect( GtkObject     *object,
                         gchar         *name,
                         GtkSignalFunc  func,
                         gpointer       func_data );


Quite probably you are not being called from *both* places *at the same
time* ;-)

So when you are being called from place A you point with func_data to
func_data, else you point to func_data1. Now you just have to
differentiate both cases whithin your callback. May be a struct member
in the struct pointed to by func_data is all is needed.

E.g.:

 | typedef struct func_data { /* generic */
 |   int whence; /* 0 for A, 1 for B; better use enum! */
 |   union {
 |     struct {
 |       blah blah
 |     } A;
 |     struct {
 |       bloh bloh
 |     } B;
 |   } stuff;
 | } fundata;

Then on place A:

 | fundata *f1 = g_new(fundata, 1);
 | f1->whence = 0; /* called from A */
 | f1->stuff.A.foo = 2;
 | ...
 | gtk_signal_connect(obj, "foobar from A", fun, f1);

Likewise on place B

HTH
- -- tomÃs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFf8c9Bcgs9XrR2kYRAtGdAJ0aTJtY28xsXn/GBswufUMP0+9ABwCeNf1b
/0hhs6jwYnJ/jJJeMtK1cD8=
=r6JY
-----END PGP SIGNATURE-----




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]