VirtualBox

Ignore:
Timestamp:
Apr 3, 2019 3:11:36 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
129765
Message:

Main/HostDnsService: Some more cleanup and renaming.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/HostDnsService.cpp

    r77984 r77993  
    131131}
    132132
     133/* static */
    133134HostDnsServiceBase *HostDnsServiceBase::createHostDnsMonitor(void)
    134135{
     
    154155}
    155156
    156 void HostDnsServiceBase::shutdown(void)
    157 {
    158     monitorThreadShutdown();
    159     int rc = RTThreadWait(m->hMonitorThread, 5000, NULL);
    160     AssertRCSuccess(rc);
    161 }
    162 
    163 
    164 void HostDnsServiceBase::setInfo(const HostDnsInformation &info)
    165 {
    166     if (m->pProxy != NULL)
    167         m->pProxy->notify(info);
    168 }
    169 
    170157HRESULT HostDnsServiceBase::init(HostDnsMonitorProxy *pProxy)
    171158{
     159    LogRel(("HostDnsMonitor: initializing\n"));
     160
     161    AssertPtrReturn(pProxy, E_POINTER);
    172162    m->pProxy = pProxy;
    173163
    174164    if (m->fThreaded)
    175165    {
     166        LogRel2(("HostDnsMonitor: starting thread ...\n"));
     167
    176168        int rc = RTSemEventCreate(&m->hMonitorThreadEvent);
    177169        AssertRCReturn(rc, E_FAIL);
    178170
    179171        rc = RTThreadCreate(&m->hMonitorThread,
    180                             HostDnsServiceBase::threadMonitoringRoutine,
     172                            HostDnsServiceBase::threadMonitorProc,
    181173                            this, 128 * _1K, RTTHREADTYPE_IO,
    182174                            RTTHREADFLAGS_WAITABLE, "dns-monitor");
     
    184176
    185177        RTSemEventWait(m->hMonitorThreadEvent, RT_INDEFINITE_WAIT);
    186     }
     178
     179        LogRel2(("HostDnsMonitor: thread started\n"));
     180    }
     181
    187182    return S_OK;
     183}
     184
     185void HostDnsServiceBase::uninit(void)
     186{
     187    LogRel(("HostDnsMonitor: shutting down ...\n"));
     188
     189    if (m->fThreaded)
     190    {
     191        LogRel2(("HostDnsMonitor: waiting for thread ...\n"));
     192
     193        const RTMSINTERVAL uTimeoutMs = 30 * 1000; /* 30s */
     194
     195        monitorThreadShutdown(uTimeoutMs);
     196
     197        int rc = RTThreadWait(m->hMonitorThread, uTimeoutMs, NULL);
     198        if (RT_FAILURE(rc))
     199            LogRel(("HostDnsMonitor: waiting for thread failed with rc=%Rrc\n", rc));
     200    }
     201
     202    LogRel(("HostDnsMonitor: shut down\n"));
     203}
     204
     205void HostDnsServiceBase::setInfo(const HostDnsInformation &info)
     206{
     207    if (m->pProxy != NULL)
     208        m->pProxy->notify(info);
    188209}
    189210
     
    247268}
    248269
    249 void HostDnsServiceBase::monitorThreadInitializationDone(void)
    250 {
     270void HostDnsServiceBase::onMonitorThreadInitDone(void)
     271{
     272    if (!m->fThreaded) /* If non-threaded, bail out, nothing to do here. */
     273        return;
     274
    251275    RTSemEventSignal(m->hMonitorThreadEvent);
    252276}
    253277
    254 DECLCALLBACK(int) HostDnsServiceBase::threadMonitoringRoutine(RTTHREAD, void *pvUser)
     278DECLCALLBACK(int) HostDnsServiceBase::threadMonitorProc(RTTHREAD, void *pvUser)
    255279{
    256280    HostDnsServiceBase *pThis = static_cast<HostDnsServiceBase *>(pvUser);
    257     return pThis->monitorWorker();
     281    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     282    return pThis->monitorThreadProc();
    258283}
    259284
    260285/* HostDnsMonitorProxy */
    261286HostDnsMonitorProxy::HostDnsMonitorProxy()
    262   : m(NULL)
     287    : m(NULL)
    263288{
    264289}
     
    266291HostDnsMonitorProxy::~HostDnsMonitorProxy()
    267292{
    268     Assert(!m);
    269 }
    270 
    271 void HostDnsMonitorProxy::init(VirtualBox* aParent)
    272 {
    273     HostDnsServiceBase *pMonitor = HostDnsServiceBase::createHostDnsMonitor();
    274     m = new HostDnsMonitorProxy::Data(pMonitor, aParent);
    275     m->pMonitorImpl->init(this);
     293    uninit();
     294}
     295
     296HRESULT HostDnsMonitorProxy::init(VirtualBox* aParent)
     297{
     298    AssertMsgReturn(m == NULL, ("DNS monitor proxy already initialized\n"), E_FAIL);
     299
     300    HostDnsServiceBase *pMonitorImpl = HostDnsServiceBase::createHostDnsMonitor();
     301    AssertPtrReturn(pMonitorImpl, E_OUTOFMEMORY);
     302
     303    Assert(m == NULL); /* Paranoia. */
     304    m = new HostDnsMonitorProxy::Data(pMonitorImpl, aParent);
     305    AssertPtrReturn(m, E_OUTOFMEMORY);
     306
     307    return m->pMonitorImpl->init(this);
    276308}
    277309
     
    280312    if (m)
    281313    {
    282         m->pMonitorImpl->shutdown();
     314        m->pMonitorImpl->uninit();
     315
    283316        delete m;
    284317        m = NULL;
     
    288321void HostDnsMonitorProxy::notify(const HostDnsInformation &info)
    289322{
    290     bool fNotify = updateInfo(info);
     323    const bool fNotify = updateInfo(info);
    291324    if (fNotify)
    292325        m->pVirtualBox->i_onHostNameResolutionConfigurationChange();
     
    334367bool HostDnsMonitorProxy::updateInfo(const HostDnsInformation &info)
    335368{
    336     LogRel(("HostDnsMonitor::updateInfo\n"));
     369    LogRel(("HostDnsMonitor: updating information\n"));
    337370    RTCLock grab(m_LockMtx);
    338371
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