std::string ModuleGlue::ConnectFromEnvironment()

in docker_images/c/wrapper/glue/ModuleGlue.cpp [26:55]


std::string ModuleGlue::ConnectFromEnvironment(const char *transportType)
{
    std::cout << "ModuleGlue::ConnectFromEnvironment for " << transportType << std::endl;
    IOTHUB_MODULE_CLIENT_HANDLE client;
    IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol = protocolFromTransportName(transportType);
    if ((client = IoTHubModuleClient_CreateFromEnvironment(protocol)) == NULL)
    {
        throw new std::runtime_error("failed to create client");
    }
    else
    {
        bool traceOn = true;
        bool rawTraceOn = true;
        size_t sasTokenLifetime = 3600;
        IoTHubModuleClient_SetOption(client, "logtrace", &traceOn);
        IoTHubModuleClient_SetOption(client, "rawlogtrace", &rawTraceOn);
        IoTHubModuleClient_SetOption(client, "sas_token_lifetime", &sasTokenLifetime);
        std::cout << "Module client(" << (void*)client << ") created" << std::endl;
        

        std::string clientId = getNextClientId();
        this->clientMap[clientId] = (void *)client;

        setConnectionStatusCallback(client);

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