source: source/ariba/utility/bootstrap/BootstrapManager.cpp@ 6796

Last change on this file since 6796 was 5953, checked in by Christoph Mayer, 15 years ago

more agressive sdp scan, sdp off when in spovnet, sdp on and agressive when not

File size: 6.3 KB
Line 
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
45namespace ariba {
46namespace utility {
47
48use_logging_cpp(BootstrapManager);
49
50BootstrapManager::BootstrapManager(){
51}
52
53BootstrapManager::~BootstrapManager(){
54}
55
56BootstrapManager::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
99bool BootstrapManager::isModuleRegistered(BootstrapType type){
100 boost::mutex::scoped_lock lock( modulesMutex );
101
102 ModuleMap::iterator i = modules.find(type);
103 return (i != modules.end());
104}
105
106BootstrapManager::RegistrationResult BootstrapManager::unregisterModule(
107 BootstrapManager::BootstrapType type){
108
109 boost::mutex::scoped_lock lock( modulesMutex );
110
111 ModuleMap::iterator i = modules.find(type);
112 if( i != modules.end() ) return RegistrationFailed;
113
114 BootstrapModule* module = i->second;
115 module->stop();
116 delete module;
117 modules.erase(i);
118
119 logging_debug("bootstrap module " << module->getName() << " unregistered");
120
121 return RegistrationSucceeded;
122}
123
124BootstrapManager::RegistrationResult BootstrapManager::registerAllModules(){
125 RegistrationResult result = RegistrationSucceeded;
126
127 { // multicast dns
128 RegistrationResult resone = RegistrationSucceeded;
129 resone = registerModule(BootstrapTypeMulticastDns);
130
131 if(resone != RegistrationSucceeded)
132 result = resone;
133 }
134
135 { // periodic broadcast
136 RegistrationResult resone = RegistrationSucceeded;
137 resone = registerModule(BootstrapTypePeriodicBroadcast);
138
139 if(resone != RegistrationSucceeded)
140 result = resone;
141 }
142
143 { // bluetooth sdp
144 RegistrationResult resone = RegistrationSucceeded;
145 resone = registerModule(BootstrapTypeBluetoothSdp);
146
147 if(resone != RegistrationSucceeded)
148 result = resone;
149 }
150
151 { // todo
152 /* ... */
153 }
154
155 return result;
156}
157
158BootstrapManager::RegistrationResult BootstrapManager::unregisterAllModules(){
159 unregisterModule(BootstrapTypeMulticastDns);
160 unregisterModule(BootstrapTypePeriodicBroadcast);
161 unregisterModule(BootstrapTypeBluetoothSdp);
162 /* todo ... */
163
164 return RegistrationSucceeded;
165}
166
167void BootstrapManager::onBootstrapServiceFound(string name, string info1, string info2, string info3){
168
169 BOOST_FOREACH( BootstrapInformationCallback* callback, callbacks ){
170 callback->onBootstrapServiceFound(name, info1, info2, info3);
171 }
172}
173
174void BootstrapManager::registerCallback(BootstrapInformationCallback* _callback){
175 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
176 if( i == callbacks.end() )
177 callbacks.push_back(_callback);
178}
179
180void BootstrapManager::unregisterCallback(BootstrapInformationCallback* _callback){
181 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
182 if( i != callbacks.end() )
183 callbacks.erase(i);
184}
185
186void BootstrapManager::publish(string name, string info1, string info2, string info3){
187 boost::mutex::scoped_lock lock( modulesMutex );
188
189 ModuleMap::iterator i = modules.begin();
190 ModuleMap::iterator iend = modules.end();
191
192 for( ; i != iend; i++ ){
193 logging_info("bootstrap manager publishing service "
194 << name << " on module " << i->second->getName());
195 i->second->publishService(name, info1, info2, info3);
196 }
197}
198
199void BootstrapManager::revoke(string name){
200 boost::mutex::scoped_lock lock( modulesMutex );
201
202 ModuleMap::iterator i = modules.begin();
203 ModuleMap::iterator iend = modules.end();
204
205 for( ; i != iend; i++ ){
206 logging_info("bootstrap manager revoking service "
207 << name << " on module " << i->second->getName());
208 i->second->revokeService(name);
209 }
210
211}
212
213}} //namespace ariba, utility
Note: See TracBrowser for help on using the repository browser.