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

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

-von außen konfigurierbare bootstrap module, -periodicbroadcast crash fix

File size: 6.4 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(
57 BootstrapManager::BootstrapType type, string info){
58
59 boost::mutex::scoped_lock lock( modulesMutex );
60
61 ModuleMap::iterator i = modules.find(type);
62 if( i != modules.end() ){
63 logging_error("bootstrap module " << i->second->getName() << " already registered");
64 return RegistrationFailed;
65 }
66
67 BootstrapModule* module = NULL;
68
69 switch(type){
70 case BootstrapTypeMulticastDns:
71 module = new MulticastDns(this, info);
72 break;
73 case BootstrapTypePeriodicBroadcast:
74 module = new PeriodicBroadcast(this, info);
75 break;
76 case BootstrapTypeBluetoothSdp:
77 module = new BluetoothSdp(this, info);
78 break;
79 }
80
81 if( module == NULL){
82 logging_error("bootstrap module for type " << type << " not found");
83 return RegistrationNotSupported;
84 }
85
86 if( !module->isFunctional() ){
87 logging_error("bootstrap module " << module->getName() << " is not functional");
88 delete module;
89 return RegistrationFailed;
90 }
91
92 logging_debug("bootstrap module " << module->getName() << " registered");
93
94 module->start();
95 modules.insert( std::make_pair(type, module) );
96
97 return RegistrationSucceeded;
98}
99
100bool BootstrapManager::isModuleRegistered(BootstrapType type){
101 boost::mutex::scoped_lock lock( modulesMutex );
102
103 ModuleMap::iterator i = modules.find(type);
104 return (i != modules.end());
105}
106
107BootstrapManager::RegistrationResult BootstrapManager::unregisterModule(
108 BootstrapManager::BootstrapType type){
109
110 boost::mutex::scoped_lock lock( modulesMutex );
111
112 ModuleMap::iterator i = modules.find(type);
113 if( i != modules.end() ) return RegistrationFailed;
114
115 BootstrapModule* module = i->second;
116 module->stop();
117 delete module;
118 modules.erase(i);
119
120 logging_debug("bootstrap module " << module->getName() << " unregistered");
121
122 return RegistrationSucceeded;
123}
124
125BootstrapManager::RegistrationResult BootstrapManager::registerAllModules(){
126 RegistrationResult result = RegistrationSucceeded;
127
128 { // multicast dns
129 RegistrationResult resone = RegistrationSucceeded;
130 resone = registerModule(BootstrapTypeMulticastDns);
131
132 if(resone != RegistrationSucceeded)
133 result = resone;
134 }
135
136 { // periodic broadcast
137 RegistrationResult resone = RegistrationSucceeded;
138 resone = registerModule(BootstrapTypePeriodicBroadcast);
139
140 if(resone != RegistrationSucceeded)
141 result = resone;
142 }
143
144 { // bluetooth sdp
145 RegistrationResult resone = RegistrationSucceeded;
146 resone = registerModule(BootstrapTypeBluetoothSdp);
147
148 if(resone != RegistrationSucceeded)
149 result = resone;
150 }
151
152 { // todo
153 /* ... */
154 }
155
156 return result;
157}
158
159BootstrapManager::RegistrationResult BootstrapManager::unregisterAllModules(){
160 unregisterModule(BootstrapTypeMulticastDns);
161 unregisterModule(BootstrapTypePeriodicBroadcast);
162 unregisterModule(BootstrapTypeBluetoothSdp);
163 /* todo ... */
164
165 return RegistrationSucceeded;
166}
167
168void BootstrapManager::onBootstrapServiceFound(string name, string info1, string info2, string info3){
169
170 BOOST_FOREACH( BootstrapInformationCallback* callback, callbacks ){
171 callback->onBootstrapServiceFound(name, info1, info2, info3);
172 }
173}
174
175void BootstrapManager::registerCallback(BootstrapInformationCallback* _callback){
176 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
177 if( i == callbacks.end() )
178 callbacks.push_back(_callback);
179}
180
181void BootstrapManager::unregisterCallback(BootstrapInformationCallback* _callback){
182 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
183 if( i != callbacks.end() )
184 callbacks.erase(i);
185}
186
187void BootstrapManager::publish(string name, string info1, string info2, string info3){
188 boost::mutex::scoped_lock lock( modulesMutex );
189
190 ModuleMap::iterator i = modules.begin();
191 ModuleMap::iterator iend = modules.end();
192
193 for( ; i != iend; i++ ){
194 logging_info("bootstrap manager publishing service "
195 << name << " on module " << i->second->getName());
196 i->second->publishService(name, info1, info2, info3);
197 }
198}
199
200void BootstrapManager::revoke(string name){
201 boost::mutex::scoped_lock lock( modulesMutex );
202
203 ModuleMap::iterator i = modules.begin();
204 ModuleMap::iterator iend = modules.end();
205
206 for( ; i != iend; i++ ){
207 logging_info("bootstrap manager revoking service "
208 << name << " on module " << i->second->getName());
209 i->second->revokeService(name);
210 }
211
212}
213
214}} //namespace ariba, utility
Note: See TracBrowser for help on using the repository browser.