1 | /* $Id: HostDnsService.cpp 49228 2013-10-22 12:24:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Base class fo Host DNS & Co services.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <VBox/com/array.h>
|
---|
19 | #include <VBox/com/ptr.h>
|
---|
20 | #include <VBox/com/string.h>
|
---|
21 |
|
---|
22 | #include <iprt/cpp/utils.h>
|
---|
23 |
|
---|
24 | #include "VirtualBoxImpl.h"
|
---|
25 | #include <iprt/thread.h>
|
---|
26 | #include <iprt/semaphore.h>
|
---|
27 | #include <iprt/critsect.h>
|
---|
28 | #include "HostDnsService.h"
|
---|
29 |
|
---|
30 | /* Lockee */
|
---|
31 | Lockee::Lockee(){ RTCritSectInit(&mLock);}
|
---|
32 |
|
---|
33 |
|
---|
34 | Lockee::~Lockee(){RTCritSectDelete(&mLock);}
|
---|
35 |
|
---|
36 |
|
---|
37 | const RTCRITSECT* Lockee::lock() const {return &mLock;}
|
---|
38 |
|
---|
39 | /* ALock */
|
---|
40 | ALock::ALock(const Lockee *l):lck(l)
|
---|
41 | {
|
---|
42 | RTCritSectEnter(const_cast<PRTCRITSECT>(lck->lock()));
|
---|
43 | }
|
---|
44 |
|
---|
45 | ALock::~ALock()
|
---|
46 | {
|
---|
47 | RTCritSectLeave(const_cast<PRTCRITSECT>(lck->lock()));
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | HostDnsService::HostDnsService(){}
|
---|
52 |
|
---|
53 | HostDnsService::~HostDnsService ()
|
---|
54 | {
|
---|
55 | int rc = RTCritSectDelete(&m_hCritSect);
|
---|
56 | AssertRC(rc);
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | HRESULT HostDnsService::init(const VirtualBox *aParent)
|
---|
61 | {
|
---|
62 | mParent = aParent;
|
---|
63 |
|
---|
64 | int rc = RTCritSectInit(&m_hCritSect);
|
---|
65 | AssertRCReturn(rc, E_FAIL);
|
---|
66 | return S_OK;
|
---|
67 | }
|
---|
68 |
|
---|
69 | HRESULT HostDnsService::start()
|
---|
70 | {
|
---|
71 | return S_OK;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void HostDnsService::stop()
|
---|
75 | {
|
---|
76 | }
|
---|
77 |
|
---|
78 | HRESULT HostDnsService::update()
|
---|
79 | {
|
---|
80 | unconst(mParent)->onHostNameResolutionConfigurationChange();
|
---|
81 | return S_OK;
|
---|
82 | }
|
---|
83 |
|
---|
84 | STDMETHODIMP HostDnsService::COMGETTER(NameServers)(ComSafeArrayOut(BSTR, aNameServers))
|
---|
85 | {
|
---|
86 | RTCritSectEnter(&m_hCritSect);
|
---|
87 | com::SafeArray<BSTR> nameServers(m_llNameServers.size());
|
---|
88 |
|
---|
89 | Utf8StrListIterator it;
|
---|
90 | int i = 0;
|
---|
91 | for (it = m_llNameServers.begin(); it != m_llNameServers.end(); ++it, ++i)
|
---|
92 | (*it).cloneTo(&nameServers[i]);
|
---|
93 |
|
---|
94 | nameServers.detachTo(ComSafeArrayOutArg(aNameServers));
|
---|
95 |
|
---|
96 | RTCritSectLeave(&m_hCritSect);
|
---|
97 |
|
---|
98 | return S_OK;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | STDMETHODIMP HostDnsService::COMGETTER(DomainName)(BSTR *aDomainName)
|
---|
103 | {
|
---|
104 | RTCritSectEnter(&m_hCritSect);
|
---|
105 |
|
---|
106 | m_DomainName.cloneTo(aDomainName);
|
---|
107 |
|
---|
108 | RTCritSectLeave(&m_hCritSect);
|
---|
109 |
|
---|
110 | return S_OK;
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | STDMETHODIMP HostDnsService::COMGETTER(SearchStrings)(ComSafeArrayOut(BSTR, aSearchStrings))
|
---|
115 | {
|
---|
116 | RTCritSectEnter(&m_hCritSect);
|
---|
117 |
|
---|
118 | com::SafeArray<BSTR> searchString(m_llSearchStrings.size());
|
---|
119 |
|
---|
120 | Utf8StrListIterator it;
|
---|
121 | int i = 0;
|
---|
122 | for (it = m_llSearchStrings.begin(); it != m_llSearchStrings.end(); ++it, ++i)
|
---|
123 | (*it).cloneTo(&searchString[i]);
|
---|
124 |
|
---|
125 |
|
---|
126 | searchString.detachTo(ComSafeArrayOutArg(aSearchStrings));
|
---|
127 |
|
---|
128 | RTCritSectLeave(&m_hCritSect);
|
---|
129 |
|
---|
130 | return S_OK;
|
---|
131 | }
|
---|
132 |
|
---|