VirtualBox

Ignore:
Timestamp:
Mar 3, 2018 12:53:44 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121088
Message:

VirtualBoxClientListImpl.cpp: Fixed invalid LogRel format string (%\n); did some cleanups, left a bunch of r=bird comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/VirtualBoxClientListImpl.cpp

    r71160 r71183  
    11/* $Id$ */
    22/** @file
    3 * VBox Global COM Class implementation.
    4 */
     3 * VBox Global COM Class implementation.
     4 *
     5 * @todo r=bird: Why is this file in src-all? Shouldn't it be in src-global/win/?!?
     6 */
    57
    68/*
     
    1618 */
    1719
     20
    1821#include "Logging.h"
    1922#include "VirtualBoxClientListImpl.h"
     
    2528////////////////// CClientListWatcher implementation /////////////////
    2629
    27 /*
    28 * Helper class that tracks existance of registered client processes.
    29 * It removes the client process from client list if it shutdowned unexpectedly,
    30 * without calling DeRegisterClient().
    31 * Also it notifies VBoxSVC and VBoxSDS that this client process finished.
    32 */
     30/**
     31 * Helper class that tracks existance of registered client processes.
     32 *
     33 * It removes the client process from client list if it shutdowned unexpectedly,
     34 * without calling DeRegisterClient().
     35 *
     36 * It also notifies VBoxSVC and VBoxSDS that this client process finished.
     37 */
    3338class CClientListWatcher
    3439{
     
    4853};
    4954
    50 volatile RTTHREAD CClientListWatcher::m_WatcherThread = NULL;
     55volatile RTTHREAD CClientListWatcher::m_WatcherThread = NULL; /** @todo r=bird: Wrong prefix for a static variable (s_)*/
    5156
    5257CClientListWatcher::CClientListWatcher(TClientSet& list, RTCRITSECTRW& clientListCritSect)
     
    5762    if (ASMAtomicReadPtr((void* volatile*)&CClientListWatcher::m_WatcherThread) != NULL)
    5863    {
    59         LogRelFunc(("Error: watcher thread already created.\n"));
     64        LogRelFunc(("Error: Watcher thread already created!\n"));
    6065        return;
    6166    }
     
    6469    if (RT_FAILURE(rc))
    6570    {
    66         LogRelFunc(("Error: failed to create wake up event for watcher thread. %Rrs \n", rc));
     71        LogRelFunc(("Error: Failed to create wake up event for watcher thread: %Rrs\n", rc));
    6772        return;
    6873    }
    6974
     75    /** @todo r=bird: Hanging indent on '(', please. */
    7076    RTTHREAD watcherThread;
    7177    rc = RTThreadCreate(&watcherThread,
     
    8288    }
    8389    else
    84         LogRelFunc(("Failed to create client list watcher thread %Rrs \n", rc));
     90        LogRelFunc(("Failed to create client list watcher thread: %Rrs\n", rc));
    8591}
    8692
     
    99105    rc = RTThreadWait(CClientListWatcher::m_WatcherThread, RT_INDEFINITE_WAIT, NULL);
    100106    if (RT_FAILURE(rc))
    101         LogRelFunc(("Error: watcher thread didn't finished. Possible thread leak. %Rrs \n", rc));
     107        LogRelFunc(("Error: watcher thread didn't finished. Possible thread leak. %Rrs\n", rc));
    102108    else
    103         LogRelFunc(("Watcher thread finished. %\n"));
     109        LogRelFunc(("Watcher thread finished.\n"));
    104110
    105111    ASMAtomicWriteNullPtr((void* volatile*)&CClientListWatcher::m_WatcherThread);
     
    108114}
    109115
     116/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
     117/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
     118/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
    110119
    111120/*
     
    123132    */
    124133    HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxSDS, NULL, CLSCTX_LOCAL_SERVER, IID_IVirtualBoxSDS,
    125         (void **)ptrVirtualBoxSDS.asOutParam());
     134                                   (void **)ptrVirtualBoxSDS.asOutParam());
    126135    if (SUCCEEDED(hrc))
    127136    {
    128         LogRelFunc(("Notify SDS that all API clients finished\n"));
     137        LogRelFunc(("Notifying SDS that all API clients finished...\n"));
    129138        ptrVirtualBoxSDS->NotifyClientsFinished();
    130139    }
     
    132141
    133142
     143/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
     144/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
     145/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
    134146/*
    135147* Deregister all staled VBoxSVC through VBoxSDS and forcebly close VBoxSVC process
     
    143155    LogRelFunc(("Enter watcher thread\n"));
    144156
    145     CClientListWatcher* pThis = (CClientListWatcher*)pvUser;
     157    CClientListWatcher *pThis = (CClientListWatcher *)pvUser;
    146158    Assert(pThis);
    147159
     
    159171        for (; it != end; ++it)
    160172        {
     173/** @todo r=bird: this is a bit inefficient because RTProcWait will try open
     174 * all the process each time.  Would be better have registerClient open the
     175 * process and just to a WaitForSingleObject here (if you want to be really
     176 * performant, you could keep wait arrays of 64 objects each and use
     177 * WaitForMultipleObjects on each of them).
     178 *
     179 * And please, don't give me the portability argument here, because this
     180 * RTProcWait call only works on windows.  We're not the parent of any of these
     181 * clients and can't wait on them.
     182 */
    161183            // check status of client process by his pid
    162184            int rc = RTProcWait(*it, RTPROCWAIT_FLAGS_NOBLOCK, NULL);
     
    186208         * Destructor will wake up it immidietely.
    187209         */
     210/** @todo r=bird: This is where wait for multiple objects would be really nice, as
     211 * you could wait on the first 63 client processes here in addition to the event.
     212 * That would speed up the response time. */
    188213        RTSemEventWait(pThis->m_wakeUpWatcherEvent, 2000);
    189214    }
     
    197222{
    198223    int rc = RTCritSectRwInit(&m_MapCritSect);
    199     Assert(RT_SUCCESS(rc));
    200     if (RT_FAILURE(rc))
    201     {
    202         LogRelFunc(("Error: creating client list critical section. %Rrs\n", rc));
    203         return E_FAIL;
    204     }
    205 
    206     m_pWatcher = new CClientListWatcher(m_ClientSet, m_MapCritSect);
     224    AssertLogRelRCReturn(rc, E_FAIL);
     225
     226    try
     227    {
     228        m_pWatcher = new CClientListWatcher(m_ClientSet, m_MapCritSect);
     229    }
     230    catch (std::bad_alloc)
     231    {
     232        AssertLogRelFailedReturn(E_OUTOFMEMORY);
     233    }
    207234    Assert(m_pWatcher);
    208235
     
    225252
    226253    int rc = RTCritSectRwDelete(&m_MapCritSect);
    227     Assert(RT_SUCCESS(rc));
    228     NOREF(rc);
     254    AssertRC(rc);
    229255
    230256    BaseFinalRelease();
    231     LogRelFunc(("VirtualBoxClientList released. res=%d\n", rc));
    232 }
    233 
     257    LogRelFunc(("VirtualBoxClientList released.\n"));
     258}
     259
     260/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
     261/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
     262/** @todo r=bird: DOXYGEN COMMENTS! DON'T FORGET IT!! */
    234263/*
    235264* Deregister API client to add it to API client list
     
    240269{
    241270    int rc = RTCritSectRwEnterExcl(&m_MapCritSect);
    242     Assert(RT_SUCCESS(rc));
    243     NOREF(rc);
     271    AssertRCReturn(rc, E_FAIL);
    244272    Assert(m_pWatcher);
    245273
    246     m_ClientSet.insert(aPid);
     274    try
     275    {
     276        m_ClientSet.insert(aPid);
     277    }
     278    catch (std::bad_alloc)
     279    {
     280        RTCritSectRwLeaveExcl(&m_MapCritSect);
     281        AssertLogRelFailedReturn(E_OUTOFMEMORY);
     282    }
    247283
    248284    rc = RTCritSectRwLeaveExcl(&m_MapCritSect);
    249     Assert(RT_SUCCESS(rc));
    250     LogRelFunc(("VirtualBoxClientList client registered. pid: %d res=%d\n", aPid, rc));
     285    AssertRC(rc);
     286    LogRelFunc(("VirtualBoxClientList client registered. pid: %d\n", aPid, rc));
    251287    return S_OK;
    252288}
    253289
    254290
    255 /*
    256 * Returns list of api client processes.
    257 * Result list contains PID of all clients exept VBoxSDS and VBoxSVC
    258 *   aEnvironment - reference to clients list that should be filled here
    259 *
    260 */
     291/**
     292 * Returns PIDs of the API client processes.
     293 *
     294 * @returns COM status code.
     295 * @param   aEnvironment    Reference to vector that is to receive the PID list.
     296 *
     297 * @todo r=bird: There is no obvious reason why this is called 'aEnvironment', a
     298 *               more natural name would be 'aPids'.
     299 */
    261300HRESULT VirtualBoxClientList::getClients(std::vector<LONG> &aEnvironment)
    262301{
    263302    int rc = RTCritSectRwEnterShared(&m_MapCritSect);
    264     Assert(RT_SUCCESS(rc));
    265     NOREF(rc);
    266     if (RT_SUCCESS(rc))
    267     {
    268         if (!m_ClientSet.empty())
     303    AssertLogRelRCReturn(rc, E_FAIL);
     304    if (!m_ClientSet.empty())
     305    {
     306        Assert(aEnvironment.empty());
     307        size_t const cClients = m_ClientSet.size();
     308        try
    269309        {
    270             Assert(aEnvironment.empty());
    271             aEnvironment.reserve(m_ClientSet.size());
     310            aEnvironment.reserve(cClients);
    272311            aEnvironment.assign(m_ClientSet.begin(), m_ClientSet.end());
    273             Assert(aEnvironment.size());
    274312        }
    275         else
     313        catch (std::bad_alloc)
    276314        {
    277             LogFunc(("Client list is empty\n"));
     315            RTCritSectRwLeaveShared(&m_MapCritSect);
     316            AssertLogRelMsgFailedReturn(("cClients=%zu\n", cClients), E_OUTOFMEMORY);
    278317        }
    279 
    280         rc = RTCritSectRwLeaveShared(&m_MapCritSect);
    281         Assert(RT_SUCCESS(rc));
    282     }
    283     LogRelFunc(("VirtualBoxClientList client list requested. res=%d\n", rc));
     318        Assert(aEnvironment.size() == cClients);
     319    }
     320    else
     321    {
     322        LogFunc(("Client list is empty\n"));
     323    }
     324
     325    rc = RTCritSectRwLeaveShared(&m_MapCritSect);
     326    AssertRC(rc);
     327
     328    LogRelFunc(("VirtualBoxClientList client list requested.\n"));
    284329    return S_OK;
    285330}
     331
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