Add User Data

Since libpomelo uses callback between request and response, and in practice the callback will do in a separate thread context, user sometimes needs to save context information between callbacks. For example, in C++, a user can save this pointer into user defined data, during callback this pointer can be retrieved easily.

Below is some example code:

in request:    
    // register this object to pomelo client.
    pc_set_user_data(this->client, 0, (void*)this); 
    ...

in callback:
void on_request_cb(pc_request_t *req, int status, json_t *resp) {
    
    pc_client_t * client = pc_get_client(req);
    if (!client) {
        printf("[ERROR]: client is not available after request.\n");
        return;
    }
    
    void* userData = pc_get_user_data(client, 0);
    WorkDescription* wd = (WorkDescription*)userData;
   ...