Callback function inside typedef?

I'm porting a C++ program to a graphical language (LabVIEW). For this, I have to import all of the functions inside the necessary DLLs, and so I have to be very specific about data types in each function.

For isntance, one of the function uses an argument of type HDSchedulerCallback. I looked inside the headers and one of the headers has this typedef:

1
2
/* Callback to scheduler operations. */       
typedef HDCallbackCode (HDCALLBACK *HDSchedulerCallback)(void *pUserData);


What does that mean?
some sort of "HDSchedulerCallback is a pointer to HDCallbackCode type, but a function with a void argument"?


There's another header with
1
2
3
4
5
6
7
8
9
#if defined(WIN32)
#  ifdef HD_EXPORTS
#     define HDAPI __declspec(dllexport)
#  else
#     define HDAPI __declspec(dllimport)
#  endif
#  define HDAPIENTRY  __stdcall
#  define HDCALLBACK  __stdcall
#endif /* WIN32 */ 

Which I understand is some way of saying that HDCALLBACK is a function.




The particular function I'm importing is defined in the API reference as
hdScheduleAsynchronous Description: Schedules an operation to be executed by the scheduler in the servo loop, and does not
wait for its completion. Scheduler callbacks submitted from the servo loop thread are run
immediately regardless of priority.
Syntax:
1
2
3
4
HDSchedulerHandle
hdScheduleAsynchronous(HDSchedulerCallback pCallback,
void *pUserData,
HDushort nPriority)

Argument Definition pCallback The function callback.
pUserData The data to be used by the function.
nPriority The priority of the operation. Callbacks are
processed once per scheduler tick, in order of
decreasing priority.
Returns: Handle for the operation.
Usage: Typically used for scheduling callbacks that run every tick of the servo loop. For example,
one can run a dynamic simulation within an asynchronous callback and set forces within
that simulation.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
HDCallbackCode HDCALLBACK mySchedulerCallback(void *pUserData)
{
HDint buttons;
hdGetIntegerv(HD_CURRENT_BUTTONS,&buttons);
if (buttons == 0)
return HD_CALLBACK_CONTINUE;
return HD_CALLBACK_DONE;
}
...
HDSchedulerHandle hHandle =
hdScheduleAsynchronous(mySchedulerCallback,
(void*)0, HD_DEFAULT_SCHEDULER_PRIORITY);



More details on the whole program I'm porting can be seen at the end of:
http://brl.ee.washington.edu/Education/EE589/AIIT/NotesPack/OmniProgramming1.pdf
It means "HDSchedulerCallback is a typedef for 'a pointer to a function that takes a generic pointer and returns an HDCallbackCode, and uses the __stdcall calling convention'".
Last edited on
Oh, and I also found this in the API reefrence:
HDSchedulerCallback Type Description: Scheduler operation function type, used to define operations to be run in the scheduler
thread.
Syntax:
1
2
typedef HDCallbackCode (HDCALLBACK *HDSchedulerCallabck)
(void *pUserData)

Argument Definition pUserData Data used by the operation, created when the
operation is scheduled.
Returns: HD_CALLBACK_DONE or HD_CALLBACK_CONTINUE depending on whether the
operation is complete or should be executed again the next tick of the scheduler.
Usage: Scheduled by hdSchedulerSynchronous() or hdScheduleAsynchronous(), the operation
is then run during the next scheduler tick, or immediately for synchronous operations if
the scheduler has not been started. The return value controls whether the operation
terminates after being run or runs again in the next scheduler tick. A periodic operation,
i.e. one that is executed indefinitely, should return HD_CALLBACK_DONE when it is
finally to be unscheduled.
Example:
1
2
3
4
5
6
7
8
9
10
11
HDCallbackCode HDCALLBACK renderForceCallback(void *pUserData)
{
HDdouble beginTime = hdGetSchedulerTimeStamp();
HHD hHD = hdGetCurrentDevice();
hdBeginFrame(hHD);
computeForce();
hdEndFrame(hHD);
HDdouble endTime = hdGetSchedulerTimeStamp();
/* Compute the elasped time within this callback */
HDdouble callbackTime = endTime - beginTime;
}


but this doesn't help me understand what fundamental type should I tell LabVIEW the argument is.


HDCallbackCode is an integer;0 and 1 are the values mentioned above.
And yes, the typo came in the API ref
Oh, so it's a pointer... thanks a lot!
Topic archived. No new replies allowed.