int methodCallback()

in docker_images/c/wrapper/glue/InternalGlue.cpp [254:295]


int methodCallback(const char *method_name, const unsigned char *payload, const size_t size, unsigned char **response, size_t *response_size, void *userContextCallback)
{
    std::cout << "methodCallback called" << std::endl;
    int result;

    method_callback_struct *cb_data = (method_callback_struct *)userContextCallback;
    cb_data->actual_method_name = std::string(reinterpret_cast<const char *>(method_name));
    cb_data->actual_request_payload = std::string(reinterpret_cast<const char *>(payload), size);

    if (cb_data->actual_method_name.compare(cb_data->expected_method_name) == 0)
    {
        if (cb_data->expected_request_payload.compare(cb_data->actual_request_payload) == 0)
        {
            std::cout << "method and payload matched.  returning response" << std::endl;
            *response_size = cb_data->response.length();
            *response = (unsigned char *)malloc(*response_size);
            if (response == NULL)
            {
                throw new std::runtime_error("failed to allocate memory for response");
            };
            (void)memcpy(*response, cb_data->response.c_str(), *response_size);
            result = cb_data->status_code;
        }
        else
        {
            std::cout << "request payload doesn't match" << std::endl;
            std::cout << "expected: " << cb_data->expected_request_payload << std::endl;
            std::cout << "received: " << cb_data->actual_request_payload << std::endl;
            result = 500;
        }
    }
    else
    {
        std::cout << "method name doesn't match" << std::endl;
        std::cout << "expected: " << cb_data->expected_method_name << std::endl;
        std::cout << "received: " << cb_data->actual_method_name << std::endl;
        result = 404;
    }

    cb_data->cv.notify_one();
    return result;
}