Closed larrylisky closed 8 years ago
It is certainly possible though not in the way of C style "void *" user data pointer.
The current callback mechanism uses C++ function model and not traditional C style function pointer. So the following are possible -
There are more things possible. See example code given in http://en.cppreference.com/w/cpp/utility/functional/function
"void *" is a C style of doing this which is outdated and requires explicit casting which is not recommended in C++.
An example code for Voxel SDK using std::bind():
using namespace Voxel;
void callback(DepthCamera &camera, const Frame &frame, FrameType callBackType, UserDataType &userData) { // Do whatever is needed.... }
int main() { . . . UserDataType userData;
using namespace std::placeholders;
auto callback1 = std::bind(callback, _1, _2, _3, std::ref(userData));
depthCamera->registerCallback(..., callback1); . . . }
Hope this solves the problem of passing user data.
The current frame callback mechanism does not permit user to pass user data through arguments. This forces use of globals/share data. To better support structured C++ programming, please provide a (void*) user pointer as an argument in the call back function, and allow the callback registration to pass the user pointer.