|
From: Stephen T. <st...@to...> - 2007-01-06 16:28:16
|
I am trying to come up with a method to receive all callback from the
vex_main LibVEX_Translate function. I need to get my hands on the IRSB*
processed in the function. I created a C function object like
instrument1 and instrument2 in the VexTranslateArgs class. The idea was
that this was a minimum invasive way to get a the IRSB pointer without
changing the return type of the function.
Well my C++ class, that calls libVEX_Translate, needs the IRSB pointer
to setup the memory space for the next call to LibVEX_Translate. The
idea is that I will setup my data structures, make a call to
LibVEX_Translate and repeat if necessary. I have had no problems calling
C functions and getting back the results via return types. Where I
struggle is giving a callback function to a C function for use later.
I have seen how examples use static functions but I do not know how to
pass any values returned from a C function to other non-static member
functions in the class.
For example:
--------
code
--------
typedef struct {
void (*handleObject)(int number);
} FruitArgs;
bool pickFruit ( FruitArgs* fa )
{
.. do something ..
fa->handleObject(5);
}
class Apple {
public:
static void handleObject (int number )
{
.. do something ..
}
void doWork ()
{
FruitArgs fa ( &handleObject );
pickFruit (&fa);
.. need the value of 'number' here
}
};
Now I can pass a the address of the C++ handleObject function to the
FruitArgs struct and then give it to the C pickFruit function. This is I
understand but how do I give the result, variable 'number', to
non-static function like doWork? Should the value of number be a member
of FruitArgs? I am thinking that if I want to be able to return a result
of the call to LibVEX_Translate to a non-static C++ function I should
add a variable to VexTranslateArgs to contain it. That way I get the
value back without resorting to a new callback. Do I make sense? I know
I am tired and I am trying to give a good example of my problem without
sending a mound of code.
Stephen
|