// ---------------------------------------------------------------------------
// Name:        GraphicsServerCommunication::ConnectProcess
// Description: Connect to Graphics server's specific process
// Arguments:   strPid - Process ID to connect to and update current PID, (optional) can be "", function will then connect to known process
// Return Val:  bool  - Success / failure
// ---------------------------------------------------------------------------
bool GraphicsServerCommunication::ConnectProcess(const gtASCIIString strPid, const gtASCIIString& apiType)
{
    gtASCIIString strWebResponse;

    bool retVal = false;

    if ((0 < strPid.length()) && (true == strPid.isIntegerNumber()))
    {
        m_strPid = strPid;
    }

    if (apiType.isEmpty() == false)
    {
        if (apiType == GP_GRAPHICS_SERVER_DX12_API_TYPE || apiType == GP_GRAPHICS_SERVER_VULKAN_API_TYPE)
        {
            m_strApiHttpCommand = "/";
            m_strApiHttpCommand.append(apiType);
        }
        else
        {
            gtString msg = L"Wrong API given : ";
            msg.append(gtString().fromASCIIString(apiType.asCharArray()));
            GT_ASSERT_EX(false, msg.asCharArray());
            m_strApiHttpCommand = "";
        }
    }
    if (m_strPid.isEmpty() == false && m_strApiHttpCommand.isEmpty() == false)
    {
        // Connect
        gtASCIIString showStack = m_strApiHttpCommand;
        retVal = SendCommandPid(showStack.append("/ShowStack"), strWebResponse, "");

        if (retVal)
        {
            gtASCIIString timeControl = m_strApiHttpCommand;
            retVal = SendCommandPid(timeControl.append("/PushLayer=TimeControl") , strWebResponse, "");
        }

        if (retVal)
        {
            gtASCIIString tcSettings = m_strApiHttpCommand;
            retVal = SendCommandPid(tcSettings.append("/TC/Settings.xml"), strWebResponse, "");
        }
    }

    return retVal;
}
// ---------------------------------------------------------------------------
// Name:        GraphicsServerCommunication::SendCommandPid
// Description: locate available Graphics server
// Arguments:   strWebResponse(return) - web string returned.
//              strCommand - URL command to send to server
//              strPid - optional Process ID string, leave empty, "", to use existing Process ID
// Return Val:  bool  - Success / failure
// ---------------------------------------------------------------------------
bool GraphicsServerCommunication::SendCommandPid(const gtASCIIString& strCommand, gtASCIIString& strWebResponse, const gtASCIIString& strPid, bool isResendAllowed)
{
    bool retVal = false;
    gtASCIIString strConnectPid;
    gtASCIIString strQueryUrl;

    if ((0 < strPid.length()) && (true == strPid.isIntegerNumber()))
    {
        strConnectPid = strPid;
    }
    else if ((0 < m_strPid.length()) && (true == m_strPid.isIntegerNumber()))
    {
        strConnectPid = m_strPid;
    }

    strQueryUrl = "/";
    strQueryUrl.append(strConnectPid);
    strQueryUrl.append(strCommand);

    retVal = RequestData(strQueryUrl, strWebResponse, isResendAllowed);

    return retVal;
}