std::string InternalGlue::Connect()

in docker_images/c/wrapper/glue/InternalGlue.cpp [53:87]


std::string InternalGlue::Connect(const char *transportType, std::string connectionString, std::string caCertificate)
{
    // NOTE: Currently not using the caCertificate. The TLS Handshake between the module and edgeHub will fail
    // unless this cert is in the trusted certificate store.

    std::cout << "InternalGlue::Connect for " << transportType << std::endl;
    IOTHUB_CLIENT_CORE_HANDLE client;
    IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol = protocolFromTransportName(transportType);
    if ((client = IoTHubClientCore_CreateFromConnectionString(connectionString.c_str(), protocol)) == NULL)
    {
        throw new std::runtime_error("failed to create client");
    }
    else
    {
        char address[32];

        sprintf(address, "%p", client);
        std::cout << "InternalGlue::Connect Client Pointer: " << address << std::endl;
        bool traceOn = true;
        bool rawTraceOn = true;
        size_t sasTokenLifetime = 3600;
        IoTHubClientCore_SetOption(client, "logtrace", &traceOn);
        IoTHubClientCore_SetOption(client, "rawlogtrace", &rawTraceOn);
        IoTHubClientCore_SetOption(client, "sas_token_lifetime", &sasTokenLifetime);
        
        std::string clientId = getNextClientId();
        this->clientMap[clientId] = (void *)client;

        setConnectionStatusCallback(client);

        std::string ret = "{ \"connectionId\" : \"" + clientId + "\"}";
        std::cout << "returning " << ret << std::endl;
        return ret;
    }
}