VirtualBox

Changeset 75877 in vbox for trunk


Ignore:
Timestamp:
Dec 2, 2018 5:46:10 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
127081
Message:

GuestControl: Use a map for the session IDs to optimize GstCtrlService::hostProcessCommand a little. bugref:9313

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestControl/service.cpp

    r75876 r75877  
    865865    void *mpvHostData;
    866866    /** Map containing all connected clients, key is HGCM client ID. */
    867     ClientStateMap  mClientStateMap; /**< @todo Use VBOXHGCMSVCFNTABLE::cbClient for this! */
     867    ClientStateMap  m_ClientStateMap;
     868    /** Session ID -> client state. */
     869    ClientStateMap  m_SessionIdMap;
    868870    /** The current master client, NULL if none. */
    869871    ClientState    *m_pMasterClient;
     
    956958    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    957959
    958     AssertMsg(pThis->mClientStateMap.find(idClient) == pThis->mClientStateMap.end(),
     960    AssertMsg(pThis->m_ClientStateMap.find(idClient) == pThis->m_ClientStateMap.end(),
    959961              ("Client with ID=%RU32 already connected when it should not\n", idClient));
    960962
     
    973975    try
    974976    {
    975         pThis->mClientStateMap[idClient] = pClient;
     977        pThis->m_ClientStateMap[idClient] = pClient;
    976978    }
    977979    catch (std::bad_alloc &)
     
    10181020    ClientState *pClient = reinterpret_cast<ClientState *>(pvClient);
    10191021    AssertPtrReturn(pClient, VERR_INVALID_POINTER);
    1020     LogFlowFunc(("[Client %RU32] Disconnected (%zu clients total)\n", idClient, pThis->mClientStateMap.size()));
     1022    LogFlowFunc(("[Client %RU32] Disconnected (%zu clients total)\n", idClient, pThis->m_ClientStateMap.size()));
    10211023
    10221024    /*
     
    10411043     * Delete the client state.
    10421044     */
    1043     pThis->mClientStateMap.erase(idClient);
     1045    pThis->m_ClientStateMap.erase(idClient);
     1046    if (pClient->m_idSession != UINT32_MAX)
     1047        pThis->m_SessionIdMap.erase(pClient->m_idSession);
    10441048    pClient->~ClientState();
    10451049    pClient = NULL;
     
    10641068        Assert(pClient != pThis->m_pMasterClient);
    10651069
    1066     if (pThis->mClientStateMap.empty())
     1070    if (pThis->m_ClientStateMap.empty())
    10671071        pThis->m_fLegacyMode = true;
    10681072
     
    17181722            {
    17191723                /*
    1720                  * We've got a match. Try complete the request and
     1724                 * We've got a match.
     1725                 * Try insert it into the sessio ID map and complete the request.
    17211726                 */
     1727                try
     1728                {
     1729                    m_SessionIdMap[idSession] = pClient;
     1730                }
     1731                catch (std::bad_alloc &)
     1732                {
     1733                    LogFunc(("Out of memory!\n"));
     1734                    return VERR_NO_MEMORY;
     1735                }
     1736
    17221737                int rc = mpHelpers->pfnCallComplete(hCall, VINF_SUCCESS);
    17231738                if (RT_SUCCESS(rc))
     
    17311746                }
    17321747                else
     1748                {
    17331749                    LogFunc(("pfnCallComplete -> %Rrc\n", rc));
     1750                    m_SessionIdMap.erase(idSession);
     1751                }
    17341752                return VINF_HGCM_ASYNC_EXECUTE; /* The caller must not complete it. */
    17351753            }
     
    18291847        ASSERT_GUEST_LOGREL_MSG_RETURN(idSession > 0, ("idSession=%u (%#x)\n", idSession, uValue), VERR_OUT_OF_RANGE);
    18301848
    1831         for (ClientStateMap::iterator It = mClientStateMap.begin(); It != mClientStateMap.end(); ++It)
    1832             ASSERT_GUEST_LOGREL_MSG_RETURN(It->second->m_idSession != idSession,
    1833                                            ("idSession=%u uValue=%#x idClient=%u; conflicting with client %u\n",
    1834                                             idSession, uValue, pClient->m_idClient, It->second->m_idClient),
    1835                                            VERR_DUPLICATE);
     1849        ClientStateMap::iterator ItConflict = m_SessionIdMap.find(idSession);
     1850        ASSERT_GUEST_LOGREL_MSG_RETURN(ItConflict == m_SessionIdMap.end(),
     1851                                       ("idSession=%u uValue=%#x idClient=%u; conflicting with client %u\n",
     1852                                        idSession, uValue, pClient->m_idClient, ItConflict->second->m_idClient),
     1853                                       VERR_DUPLICATE);
     1854
    18361855        /* Commit it. */
     1856        try
     1857        {
     1858            m_SessionIdMap[idSession] = pClient;
     1859        }
     1860        catch (std::bad_alloc &)
     1861        {
     1862            LogFunc(("Out of memory\n"));
     1863            return VERR_NO_MEMORY;
     1864        }
    18371865        pClient->m_idSession = idSession;
    18381866    }
     
    21012129     * the guest is not running/system is messed up somehow.
    21022130     */
    2103     if (mClientStateMap.empty())
     2131    if (m_ClientStateMap.empty())
    21042132    {
    21052133        LogFlow(("GstCtrlService::hostProcessCommand: VERR_NOT_FOUND!\n"));
     
    21322160        {
    21332161            LogFlowFunc(("Handling host command m_idContextAndDst=%#RX64, idFunction=%RU32, cParms=%RU32, paParms=%p, cClients=%zu\n",
    2134                          pHostCmd->m_idContextAndDst, idFunction, cParms, paParms, mClientStateMap.size()));
     2162                         pHostCmd->m_idContextAndDst, idFunction, cParms, paParms, m_ClientStateMap.size()));
    21352163
    21362164            /*
     
    21382166             * session ID doesn't match any particular client it goes to the master.
    21392167             */
    2140             AssertMsg(!mClientStateMap.empty(), ("Client state map is empty when it should not be!\n"));
     2168            AssertMsg(!m_ClientStateMap.empty(), ("Client state map is empty when it should not be!\n"));
    21412169
    21422170            /* Dispatch to the session. */
    21432171            if (fDestinations & VBOX_GUESTCTRL_DST_SESSION)
    21442172            {
    2145                 rc = VWRN_NOT_FOUND;
    21462173                uint32_t const idSession = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pHostCmd->m_idContext);
    2147                 for (ClientStateMap::iterator It = mClientStateMap.begin(); It != mClientStateMap.end(); ++It)
     2174                ClientStateMap::iterator It = m_SessionIdMap.find(idSession);
     2175                if (It != m_SessionIdMap.end())
    21482176                {
    21492177                    ClientState *pClient = It->second;
    2150                     if (pClient->m_idSession == idSession)
    2151                     {
    2152                         RTListAppend(&pClient->m_HostCmdList, &pHostCmd->m_ListEntry);
    2153                         pHostCmd  = pHostCmd2;
    2154                         pHostCmd2 = NULL;
    2155 
    2156                         int rc2 = pClient->Wakeup();
    2157                         LogFlowFunc(("Woke up client ID=%RU32 -> rc=%Rrc\n", pClient->m_idClient, rc2));
    2158                         RT_NOREF(rc2);
    2159                         rc = VINF_SUCCESS;
    2160                         break;
    2161                     }
     2178                    Assert(pClient->m_idSession == idSession);
     2179                    RTListAppend(&pClient->m_HostCmdList, &pHostCmd->m_ListEntry);
     2180                    pHostCmd  = pHostCmd2;
     2181                    pHostCmd2 = NULL;
     2182
     2183                    int rc2 = pClient->Wakeup();
     2184                    LogFlowFunc(("Woke up client ID=%RU32 -> rc=%Rrc\n", pClient->m_idClient, rc2));
     2185                    RT_NOREF(rc2);
     2186                    rc = VINF_SUCCESS;
     2187                }
     2188                else
     2189                {
     2190                    LogFunc(("No client with session ID %u was found! (idFunction=%d %s)\n",
     2191                             idSession, idFunction, GstCtrlHostFnName((eHostFn)idFunction)));
     2192                    rc = !(fDestinations & VBOX_GUESTCTRL_DST_ROOT_SVC) ? VERR_NOT_FOUND : VWRN_NOT_FOUND;
    21622193                }
    21632194            }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette