Changeset 50263 in vbox for trunk/src/VBox/Main/src-server/darwin
- Timestamp:
- Jan 28, 2014 7:29:52 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 91891
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp
r50213 r50263 32 32 33 33 34 35 SCDynamicStoreRef g_store; 36 CFRunLoopSourceRef g_DnsWatcher; 37 CFRunLoopRef g_RunLoopRef; 38 RTTHREAD g_DnsMonitoringThread; 39 RTSEMEVENT g_DnsInitEvent; 34 struct HostDnsServiceDarwin::Data 35 { 36 SCDynamicStoreRef m_store; 37 CFRunLoopSourceRef m_DnsWatcher; 38 CFRunLoopRef m_RunLoopRef; 39 CFRunLoopSourceRef m_Stopper; 40 bool m_fStop; 41 RTSEMEVENT m_evtStop; 42 static void performShutdownCallback(void *); 43 }; 44 40 45 41 46 static const CFStringRef kStateNetworkGlobalDNSKey = CFSTR("State:/Network/Global/DNS"); 42 47 43 static int hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser) 44 { 45 NOREF(ThreadSelf); 46 NOREF(pvUser); 47 g_RunLoopRef = CFRunLoopGetCurrent(); 48 AssertReturn(g_RunLoopRef, VERR_INTERNAL_ERROR); 49 50 CFRetain(g_RunLoopRef); 48 49 HostDnsServiceDarwin::HostDnsServiceDarwin():HostDnsMonitor(true),m(NULL) 50 { 51 m = new HostDnsServiceDarwin::Data(); 52 } 53 54 55 HostDnsServiceDarwin::~HostDnsServiceDarwin() 56 { 57 if (!m) 58 return; 59 60 monitorThreadShutdown(); 61 62 CFRelease(m->m_RunLoopRef); 63 64 CFRelease(m->m_DnsWatcher); 65 66 CFRelease(m->m_store); 67 68 RTSemEventDestroy(m->m_evtStop); 69 70 delete m; 71 m = NULL; 72 } 73 74 75 void HostDnsServiceDarwin::hostDnsServiceStoreCallback(void *, void *, void *info) 76 { 77 HostDnsServiceDarwin *pThis = (HostDnsServiceDarwin *)info; 78 79 ALock l(pThis); 80 pThis->updateInfo(); 81 pThis->notifyAll(); 82 } 83 84 85 HRESULT HostDnsServiceDarwin::init() 86 { 87 SCDynamicStoreContext ctx; 88 RT_ZERO(ctx); 89 90 ctx.info = this; 91 92 m->m_store = SCDynamicStoreCreate(NULL, CFSTR("org.virtualbox.VBoxSVC"), 93 (SCDynamicStoreCallBack)HostDnsServiceDarwin::hostDnsServiceStoreCallback, 94 &ctx); 95 AssertReturn(m->m_store, E_FAIL); 96 97 m->m_DnsWatcher = SCDynamicStoreCreateRunLoopSource(NULL, m->m_store, 0); 98 if (!m->m_DnsWatcher) 99 return E_OUTOFMEMORY; 100 101 int rc = RTSemEventCreate(&m->m_evtStop); 102 AssertRCReturn(rc, E_FAIL); 103 104 CFRunLoopSourceContext sctx; 105 RT_ZERO(sctx); 106 sctx.perform = HostDnsServiceDarwin::Data::performShutdownCallback; 107 m->m_Stopper = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &sctx); 108 AssertReturn(m->m_Stopper, E_FAIL); 109 110 HRESULT hrc = HostDnsMonitor::init(); 111 AssertComRCReturn(hrc, hrc); 112 113 return updateInfo(); 114 } 115 116 117 void HostDnsServiceDarwin::monitorThreadShutdown() 118 { 119 ALock l(this); 120 if (!m->m_fStop) 121 { 122 CFRunLoopSourceSignal(m->m_Stopper); 123 CFRunLoopWakeUp(m->m_RunLoopRef); 124 125 RTSemEventWait(m->m_evtStop, RT_INDEFINITE_WAIT); 126 } 127 } 128 129 130 int HostDnsServiceDarwin::monitorWorker() 131 { 132 m->m_RunLoopRef = CFRunLoopGetCurrent(); 133 AssertReturn(m->m_RunLoopRef, VERR_INTERNAL_ERROR); 134 135 CFRetain(m->m_RunLoopRef); 51 136 52 137 CFArrayRef watchingArrayRef = CFArrayCreate(NULL, … … 55 140 if (!watchingArrayRef) 56 141 { 57 CFRelease( g_DnsWatcher);142 CFRelease(m->m_DnsWatcher); 58 143 return E_OUTOFMEMORY; 59 144 } 60 145 61 if(SCDynamicStoreSetNotificationKeys( g_store, watchingArrayRef, NULL))62 CFRunLoopAddSource(CFRunLoopGetCurrent(), g_DnsWatcher, kCFRunLoopCommonModes);146 if(SCDynamicStoreSetNotificationKeys(m->m_store, watchingArrayRef, NULL)) 147 CFRunLoopAddSource(CFRunLoopGetCurrent(), m->m_DnsWatcher, kCFRunLoopCommonModes); 63 148 64 149 CFRelease(watchingArrayRef); 65 150 66 RTSemEventSignal(g_DnsInitEvent); 67 68 CFRunLoopRun(); 69 70 CFRelease(g_RunLoopRef); 151 monitorThreadInitializationDone(); 152 153 while (!m->m_fStop) 154 { 155 CFRunLoopRun(); 156 } 157 158 CFRelease(m->m_RunLoopRef); 159 160 /* We're notifying stopper thread. */ 161 RTSemEventSignal(m->m_evtStop); 71 162 72 163 return VINF_SUCCESS; … … 74 165 75 166 76 HostDnsServiceDarwin::HostDnsServiceDarwin(){}77 78 79 HostDnsServiceDarwin::~HostDnsServiceDarwin()80 {81 if (g_RunLoopRef)82 CFRunLoopStop(g_RunLoopRef);83 84 CFRelease(g_DnsWatcher);85 86 CFRelease(g_store);87 }88 89 90 void HostDnsServiceDarwin::hostDnsServiceStoreCallback(void *arg0, void *arg1, void *info)91 {92 HostDnsServiceDarwin *pThis = (HostDnsServiceDarwin *)info;93 94 NOREF(arg0); /* SCDynamicStore */95 NOREF(arg1); /* CFArrayRef */96 97 ALock l(pThis);98 pThis->updateInfo();99 pThis->notifyAll();100 }101 102 103 HRESULT HostDnsServiceDarwin::init()104 {105 SCDynamicStoreContext ctx;106 RT_ZERO(ctx);107 108 ctx.info = this;109 110 g_store = SCDynamicStoreCreate(NULL, CFSTR("org.virtualbox.VBoxSVC"),111 (SCDynamicStoreCallBack)HostDnsServiceDarwin::hostDnsServiceStoreCallback,112 &ctx);113 AssertReturn(g_store, E_FAIL);114 115 g_DnsWatcher = SCDynamicStoreCreateRunLoopSource(NULL, g_store, 0);116 if (!g_DnsWatcher)117 return E_OUTOFMEMORY;118 119 HRESULT hrc = HostDnsMonitor::init();120 AssertComRCReturn(hrc, hrc);121 122 int rc = RTSemEventCreate(&g_DnsInitEvent);123 AssertRCReturn(rc, E_FAIL);124 125 rc = RTThreadCreate(&g_DnsMonitoringThread, hostMonitoringRoutine,126 this, 128 * _1K, RTTHREADTYPE_IO, 0, "dns-monitor");127 AssertRCReturn(rc, E_FAIL);128 129 RTSemEventWait(g_DnsInitEvent, RT_INDEFINITE_WAIT);130 return updateInfo();131 }132 133 134 167 HRESULT HostDnsServiceDarwin::updateInfo() 135 168 { 136 CFPropertyListRef propertyRef = SCDynamicStoreCopyValue( g_store,169 CFPropertyListRef propertyRef = SCDynamicStoreCopyValue(m->m_store, 137 170 kStateNetworkGlobalDNSKey); 138 171 /** … … 216 249 return S_OK; 217 250 } 251 252 void HostDnsServiceDarwin::Data::performShutdownCallback(void *info) 253 { 254 HostDnsServiceDarwin::Data *pThis = static_cast<HostDnsServiceDarwin::Data *>(info); 255 pThis->m_fStop = true; 256 }
Note:
See TracChangeset
for help on using the changeset viewer.