Changeset 77984 in vbox for trunk/src/VBox/Main/src-server/HostDnsService.cpp
- Timestamp:
- Apr 2, 2019 2:06:13 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 129752
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/HostDnsService.cpp
r77666 r77984 78 78 } 79 79 80 struct HostDns Monitor::Data80 struct HostDnsServiceBase::Data 81 81 { 82 82 Data(bool aThreaded) 83 : proxy(NULL),84 fThreaded(aThreaded)83 : pProxy(NULL) 84 , fThreaded(aThreaded) 85 85 {} 86 86 87 HostDnsMonitorProxy *proxy; 88 89 const bool fThreaded; 90 RTSEMEVENT hDnsInitEvent; 91 RTTHREAD hMonitoringThread; 92 93 HostDnsInformation info; 87 /** Weak pointer to parent proxy object. */ 88 HostDnsMonitorProxy *pProxy; 89 /** Whether the DNS monitor implementation has a dedicated monitoring thread. Optional. */ 90 const bool fThreaded; 91 /** Event for the monitor thread, if any. */ 92 RTSEMEVENT hMonitorThreadEvent; 93 /** Handle of the monitor thread, if any. */ 94 RTTHREAD hMonitorThread; 95 /** Generic host DNS information. */ 96 HostDnsInformation info; 94 97 }; 95 98 96 99 struct HostDnsMonitorProxy::Data 97 100 { 98 Data(HostDns Monitor*aMonitor, VirtualBox *aParent)99 : virtualbox(aParent),100 monitor(aMonitor),101 uLastExtraDataPoll(0),102 fLaxComparison(0),103 info()101 Data(HostDnsServiceBase *aMonitor, VirtualBox *aParent) 102 : pVirtualBox(aParent) 103 , pMonitorImpl(aMonitor) 104 , uLastExtraDataPoll(0) 105 , fLaxComparison(0) 106 , info() 104 107 {} 105 108 106 VirtualBox * virtualbox;107 HostDns Monitor *monitor;109 VirtualBox *pVirtualBox; 110 HostDnsServiceBase *pMonitorImpl; 108 111 109 112 uint64_t uLastExtraDataPoll; … … 113 116 114 117 115 HostDns Monitor::HostDnsMonitor(bool fThreaded)116 : m(NULL)117 { 118 m = new HostDnsMonitor::Data(fThreaded);119 } 120 121 HostDns Monitor::~HostDnsMonitor()118 HostDnsServiceBase::HostDnsServiceBase(bool fThreaded) 119 : m(NULL) 120 { 121 m = new HostDnsServiceBase::Data(fThreaded); 122 } 123 124 HostDnsServiceBase::~HostDnsServiceBase() 122 125 { 123 126 if (m) … … 128 131 } 129 132 130 HostDns Monitor *HostDnsMonitor::createHostDnsMonitor()131 { 132 HostDns Monitor *monitor = NULL;133 HostDnsServiceBase *HostDnsServiceBase::createHostDnsMonitor(void) 134 { 135 HostDnsServiceBase *pMonitor = NULL; 133 136 134 137 #if defined (RT_OS_DARWIN) 135 monitor = new HostDnsServiceDarwin();138 pMonitor = new HostDnsServiceDarwin(); 136 139 #elif defined(RT_OS_WINDOWS) 137 monitor = new HostDnsServiceWin();140 pMonitor = new HostDnsServiceWin(); 138 141 #elif defined(RT_OS_LINUX) 139 monitor = new HostDnsServiceLinux();142 pMonitor = new HostDnsServiceLinux(); 140 143 #elif defined(RT_OS_SOLARIS) 141 monitor = new HostDnsServiceSolaris();144 pMonitor = new HostDnsServiceSolaris(); 142 145 #elif defined(RT_OS_FREEBSD) 143 monitor = new HostDnsServiceFreebsd();146 pMonitor = new HostDnsServiceFreebsd(); 144 147 #elif defined(RT_OS_OS2) 145 monitor = new HostDnsServiceOs2();148 pMonitor = new HostDnsServiceOs2(); 146 149 #else 147 monitor = new HostDnsService();150 pMonitor = new HostDnsServiceBase(); 148 151 #endif 149 152 150 return monitor; 151 } 152 153 154 void HostDnsMonitor::shutdown() 153 return pMonitor; 154 } 155 156 void HostDnsServiceBase::shutdown(void) 155 157 { 156 158 monitorThreadShutdown(); 157 int rc = RTThreadWait(m->hMonitor ingThread, 5000, NULL);159 int rc = RTThreadWait(m->hMonitorThread, 5000, NULL); 158 160 AssertRCSuccess(rc); 159 161 } 160 162 161 163 162 void HostDns Monitor::setInfo(const HostDnsInformation &info)163 { 164 if (m->p roxy != NULL)165 m->p roxy->notify(info);166 } 167 168 HRESULT HostDns Monitor::init(HostDnsMonitorProxy *proxy)169 { 170 m->p roxy = proxy;164 void HostDnsServiceBase::setInfo(const HostDnsInformation &info) 165 { 166 if (m->pProxy != NULL) 167 m->pProxy->notify(info); 168 } 169 170 HRESULT HostDnsServiceBase::init(HostDnsMonitorProxy *pProxy) 171 { 172 m->pProxy = pProxy; 171 173 172 174 if (m->fThreaded) 173 175 { 174 int rc = RTSemEventCreate(&m->h DnsInitEvent);176 int rc = RTSemEventCreate(&m->hMonitorThreadEvent); 175 177 AssertRCReturn(rc, E_FAIL); 176 178 177 rc = RTThreadCreate(&m->hMonitor ingThread,178 HostDns Monitor::threadMonitoringRoutine,179 rc = RTThreadCreate(&m->hMonitorThread, 180 HostDnsServiceBase::threadMonitoringRoutine, 179 181 this, 128 * _1K, RTTHREADTYPE_IO, 180 182 RTTHREADFLAGS_WAITABLE, "dns-monitor"); 181 183 AssertRCReturn(rc, E_FAIL); 182 184 183 RTSemEventWait(m->h DnsInitEvent, RT_INDEFINITE_WAIT);185 RTSemEventWait(m->hMonitorThreadEvent, RT_INDEFINITE_WAIT); 184 186 } 185 187 return S_OK; 186 188 } 187 189 188 189 void HostDnsMonitorProxy::pollGlobalExtraData() 190 { 191 VirtualBox *virtualbox = m->virtualbox; 192 if (RT_UNLIKELY(virtualbox == NULL)) 190 void HostDnsMonitorProxy::pollGlobalExtraData(void) 191 { 192 VirtualBox *pVirtualBox = m->pVirtualBox; 193 if (RT_UNLIKELY(pVirtualBox == NULL)) 193 194 return; 194 195 … … 203 204 const com::Bstr bstrHostDNSOrderIgnoreKey("VBoxInternal2/HostDNSOrderIgnore"); 204 205 com::Bstr bstrHostDNSOrderIgnore; 205 virtualbox->GetExtraData(bstrHostDNSOrderIgnoreKey.raw(),206 pVirtualBox->GetExtraData(bstrHostDNSOrderIgnoreKey.raw(), 206 207 bstrHostDNSOrderIgnore.asOutParam()); 207 208 uint32_t fDNSOrderIgnore = 0; … … 226 227 const com::Bstr bstrHostDNSSuffixesIgnoreKey("VBoxInternal2/HostDNSSuffixesIgnore"); 227 228 com::Bstr bstrHostDNSSuffixesIgnore; 228 virtualbox->GetExtraData(bstrHostDNSSuffixesIgnoreKey.raw(),229 pVirtualBox->GetExtraData(bstrHostDNSSuffixesIgnoreKey.raw(), 229 230 bstrHostDNSSuffixesIgnore.asOutParam()); 230 231 uint32_t fDNSSuffixesIgnore = 0; … … 246 247 } 247 248 248 void HostDnsMonitor::monitorThreadInitializationDone() 249 { 250 RTSemEventSignal(m->hDnsInitEvent); 251 } 252 253 254 DECLCALLBACK(int) HostDnsMonitor::threadMonitoringRoutine(RTTHREAD, void *pvUser) 255 { 256 HostDnsMonitor *pThis = static_cast<HostDnsMonitor *>(pvUser); 249 void HostDnsServiceBase::monitorThreadInitializationDone(void) 250 { 251 RTSemEventSignal(m->hMonitorThreadEvent); 252 } 253 254 DECLCALLBACK(int) HostDnsServiceBase::threadMonitoringRoutine(RTTHREAD, void *pvUser) 255 { 256 HostDnsServiceBase *pThis = static_cast<HostDnsServiceBase *>(pvUser); 257 257 return pThis->monitorWorker(); 258 258 } … … 271 271 void HostDnsMonitorProxy::init(VirtualBox* aParent) 272 272 { 273 HostDnsMonitor *monitor = HostDnsMonitor::createHostDnsMonitor(); 274 m = new HostDnsMonitorProxy::Data(monitor, aParent); 275 m->monitor->init(this); 276 } 277 278 279 void HostDnsMonitorProxy::uninit() 273 HostDnsServiceBase *pMonitor = HostDnsServiceBase::createHostDnsMonitor(); 274 m = new HostDnsMonitorProxy::Data(pMonitor, aParent); 275 m->pMonitorImpl->init(this); 276 } 277 278 void HostDnsMonitorProxy::uninit(void) 280 279 { 281 280 if (m) 282 281 { 283 m-> monitor->shutdown();282 m->pMonitorImpl->shutdown(); 284 283 delete m; 285 284 m = NULL; … … 291 290 bool fNotify = updateInfo(info); 292 291 if (fNotify) 293 m-> virtualbox->i_onHostNameResolutionConfigurationChange();292 m->pVirtualBox->i_onHostNameResolutionConfigurationChange(); 294 293 } 295 294 … … 362 361 return true; 363 362 } 364 365 363 366 364 static void dumpHostDnsInformation(const HostDnsInformation& info)
Note:
See TracChangeset
for help on using the changeset viewer.