I'm working with a Blue Giga BLE112 usb dongle. They supply an API in the form of several header & *.c files. It all works off of callbacks. For example.int main(){    // defined in a cmd_def.h & implemented in cmd_def.c    ble_cmd_connection_get_status();    // read messages off the usb serial port forever    // At some point, we'll read the message that triggers the connection status event.    while (true) { readMessages(); }}// Call back that we implementvoid ble_evt_connection_status(const struct ble_msg_connection_status_evt_t *msg){    // This is terrible because we could call the command from anywhere     // and have no idea what context the event is firing under     // with no way to pass any information into the callback except from global state.    if (msg->flags & connection_connected)     {        printf(WE'RE CONNECTED!);    }}There are around 100 or so pairs of these Commands and responseEventCallbacks. Now, I'm trying to implement a small C++ console application, but I'm having an extremely hard go of it. I've been trying to wrap this behavior in a C++ class, but am failing miserably. At each and every turn I run into issues trying to use these callbacks to set state in the class. (Obviously, I can't because the callbacks are static and can't access members of the class.) Was this a misguided idea? I thought that if I could introduce an OO anti-corruption layer, I could make it easier to deal with the global state and  callback hell I've found myself in. Does anyone have any insight into how to cleanly implement this kind of C callback API in C++? I'm staring at all these callbacks thinking that this is going to be a nightmare to maintain, but I'm also unable to figure out how to wrap these command/response events into a class.Would it be better to simply forget the classes and implement this as a module of functions?For reference, here's an example of what I'm trying to accomplish.// nice clean OO apibool scanning = false;BLUEGIGA_API bool BlueGiga::IsConnected(){    _isConnected = false;    ble_cmd_connection_get_status(0);    scanning = true;    while (scanning)    {        if (!ReadMessage())        {            return false;        }    }    return _isConnected;}// C callback that should not be part of my C++ api, nor can it be a member because C can't use C++ members as callbacks.void ble_evt_connection_status(const struct ble_msg_connection_status_evt_t *msg){    // _isConnected isn't identified because we don't have a `this` instance in here.    _isConnected = (msg->flags & connection_connected);    scanning = false;}
Blue Giga C++ anti-corruption layer for C callback API?
object oriented;c++;c;callbacks