1 | // [License]
|
---|
2 | // The Ariba-Underlay Copyright
|
---|
3 | //
|
---|
4 | // Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
|
---|
5 | //
|
---|
6 | // Institute of Telematics
|
---|
7 | // UniversitÀt Karlsruhe (TH)
|
---|
8 | // Zirkel 2, 76128 Karlsruhe
|
---|
9 | // Germany
|
---|
10 | //
|
---|
11 | // Redistribution and use in source and binary forms, with or without
|
---|
12 | // modification, are permitted provided that the following conditions are
|
---|
13 | // met:
|
---|
14 | //
|
---|
15 | // 1. Redistributions of source code must retain the above copyright
|
---|
16 | // notice, this list of conditions and the following disclaimer.
|
---|
17 | // 2. Redistributions in binary form must reproduce the above copyright
|
---|
18 | // notice, this list of conditions and the following disclaimer in the
|
---|
19 | // documentation and/or other materials provided with the distribution.
|
---|
20 | //
|
---|
21 | // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
|
---|
22 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
23 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
|
---|
25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
32 | //
|
---|
33 | // The views and conclusions contained in the software and documentation
|
---|
34 | // are those of the authors and should not be interpreted as representing
|
---|
35 | // official policies, either expressed or implied, of the Institute of
|
---|
36 | // Telematics.
|
---|
37 | // [License]
|
---|
38 |
|
---|
39 |
|
---|
40 | #include "BootstrapManager.h"
|
---|
41 | #include "ariba/utility/bootstrap/modules/multicastdns/MulticastDns.h"
|
---|
42 | #include "ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.h"
|
---|
43 | #include "ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.h"
|
---|
44 |
|
---|
45 | namespace ariba {
|
---|
46 | namespace utility {
|
---|
47 |
|
---|
48 | use_logging_cpp(BootstrapManager);
|
---|
49 |
|
---|
50 | BootstrapManager::BootstrapManager(){
|
---|
51 | }
|
---|
52 |
|
---|
53 | BootstrapManager::~BootstrapManager(){
|
---|
54 | }
|
---|
55 |
|
---|
56 | BootstrapManager::RegistrationResult BootstrapManager::registerModule(BootstrapManager::BootstrapType type){
|
---|
57 |
|
---|
58 | boost::mutex::scoped_lock lock( modulesMutex );
|
---|
59 |
|
---|
60 | ModuleMap::iterator i = modules.find(type);
|
---|
61 | if( i != modules.end() ){
|
---|
62 | logging_error("bootstrap module " << i->second->getName() << " already registered");
|
---|
63 | return RegistrationFailed;
|
---|
64 | }
|
---|
65 |
|
---|
66 | BootstrapModule* module = NULL;
|
---|
67 |
|
---|
68 | switch(type){
|
---|
69 | case BootstrapTypeMulticastDns:
|
---|
70 | module = new MulticastDns(this);
|
---|
71 | break;
|
---|
72 | case BootstrapTypePeriodicBroadcast:
|
---|
73 | module = new PeriodicBroadcast(this);
|
---|
74 | break;
|
---|
75 | case BootstrapTypeBluetoothSdp:
|
---|
76 | module = new BluetoothSdp(this);
|
---|
77 | break;
|
---|
78 | }
|
---|
79 |
|
---|
80 | if( module == NULL){
|
---|
81 | logging_error("bootstrap module for type " << type << " not found");
|
---|
82 | return RegistrationNotSupported;
|
---|
83 | }
|
---|
84 |
|
---|
85 | if( !module->isFunctional() ){
|
---|
86 | logging_error("bootstrap module " << module->getName() << " is not functional");
|
---|
87 | delete module;
|
---|
88 | return RegistrationFailed;
|
---|
89 | }
|
---|
90 |
|
---|
91 | logging_debug("bootstrap module " << module->getName() << " registered");
|
---|
92 |
|
---|
93 | module->start();
|
---|
94 | modules.insert( std::make_pair(type, module) );
|
---|
95 |
|
---|
96 | return RegistrationSucceeded;
|
---|
97 | }
|
---|
98 |
|
---|
99 | BootstrapManager::RegistrationResult BootstrapManager::unregisterModule(
|
---|
100 | BootstrapManager::BootstrapType type){
|
---|
101 |
|
---|
102 | boost::mutex::scoped_lock lock( modulesMutex );
|
---|
103 |
|
---|
104 | ModuleMap::iterator i = modules.find(type);
|
---|
105 | if( i != modules.end() ) return RegistrationFailed;
|
---|
106 |
|
---|
107 | BootstrapModule* module = i->second;
|
---|
108 | module->stop();
|
---|
109 | delete module;
|
---|
110 | modules.erase(i);
|
---|
111 |
|
---|
112 | logging_debug("bootstrap module " << module->getName() << " unregistered");
|
---|
113 |
|
---|
114 | return RegistrationSucceeded;
|
---|
115 | }
|
---|
116 |
|
---|
117 | BootstrapManager::RegistrationResult BootstrapManager::registerAllModules(){
|
---|
118 | RegistrationResult result = RegistrationSucceeded;
|
---|
119 |
|
---|
120 | { // multicast dns
|
---|
121 | RegistrationResult resone = RegistrationSucceeded;
|
---|
122 | resone = registerModule(BootstrapTypeMulticastDns);
|
---|
123 |
|
---|
124 | if(resone != RegistrationSucceeded)
|
---|
125 | result = resone;
|
---|
126 | }
|
---|
127 |
|
---|
128 | { // periodic broadcast
|
---|
129 | RegistrationResult resone = RegistrationSucceeded;
|
---|
130 | resone = registerModule(BootstrapTypePeriodicBroadcast);
|
---|
131 |
|
---|
132 | if(resone != RegistrationSucceeded)
|
---|
133 | result = resone;
|
---|
134 | }
|
---|
135 |
|
---|
136 | { // bluetooth sdp
|
---|
137 | RegistrationResult resone = RegistrationSucceeded;
|
---|
138 | resone = registerModule(BootstrapTypeBluetoothSdp);
|
---|
139 |
|
---|
140 | if(resone != RegistrationSucceeded)
|
---|
141 | result = resone;
|
---|
142 | }
|
---|
143 |
|
---|
144 | { // todo
|
---|
145 | /* ... */
|
---|
146 | }
|
---|
147 |
|
---|
148 | return result;
|
---|
149 | }
|
---|
150 |
|
---|
151 | BootstrapManager::RegistrationResult BootstrapManager::unregisterAllModules(){
|
---|
152 | unregisterModule(BootstrapTypeMulticastDns);
|
---|
153 | unregisterModule(BootstrapTypePeriodicBroadcast);
|
---|
154 | unregisterModule(BootstrapTypeBluetoothSdp);
|
---|
155 | /* todo ... */
|
---|
156 |
|
---|
157 | return RegistrationSucceeded;
|
---|
158 | }
|
---|
159 |
|
---|
160 | void BootstrapManager::onBootstrapServiceFound(string name, string info1, string info2, string info3){
|
---|
161 |
|
---|
162 | BOOST_FOREACH( BootstrapInformationCallback* callback, callbacks ){
|
---|
163 | callback->onBootstrapServiceFound(name, info1, info2, info3);
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | void BootstrapManager::registerCallback(BootstrapInformationCallback* _callback){
|
---|
168 | Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
|
---|
169 | if( i == callbacks.end() )
|
---|
170 | callbacks.push_back(_callback);
|
---|
171 | }
|
---|
172 |
|
---|
173 | void BootstrapManager::unregisterCallback(BootstrapInformationCallback* _callback){
|
---|
174 | Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
|
---|
175 | if( i != callbacks.end() )
|
---|
176 | callbacks.erase(i);
|
---|
177 | }
|
---|
178 |
|
---|
179 | void BootstrapManager::publish(string name, string info1, string info2, string info3){
|
---|
180 | boost::mutex::scoped_lock lock( modulesMutex );
|
---|
181 |
|
---|
182 | ModuleMap::iterator i = modules.begin();
|
---|
183 | ModuleMap::iterator iend = modules.end();
|
---|
184 |
|
---|
185 | for( ; i != iend; i++ ){
|
---|
186 | logging_info("bootstrap manager publishing service "
|
---|
187 | << name << " on module " << i->second->getName());
|
---|
188 | i->second->publishService(name, info1, info2, info3);
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | void BootstrapManager::revoke(string name){
|
---|
193 | boost::mutex::scoped_lock lock( modulesMutex );
|
---|
194 |
|
---|
195 | ModuleMap::iterator i = modules.begin();
|
---|
196 | ModuleMap::iterator iend = modules.end();
|
---|
197 |
|
---|
198 | for( ; i != iend; i++ ){
|
---|
199 | logging_info("bootstrap manager revoking service "
|
---|
200 | << name << " on module " << i->second->getName());
|
---|
201 | i->second->revokeService(name);
|
---|
202 | }
|
---|
203 |
|
---|
204 | }
|
---|
205 |
|
---|
206 | }} //namespace ariba, utility
|
---|