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

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

-compiler default parameter fix

File size: 6.4 KB
RevLine 
[4733]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"
[4850]42#include "ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.h"
[4879]43#include "ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.h"
[4733]44
45namespace ariba {
46namespace utility {
47
48use_logging_cpp(BootstrapManager);
49
50BootstrapManager::BootstrapManager(){
51}
52
53BootstrapManager::~BootstrapManager(){
54}
55
[7532]56BootstrapManager::RegistrationResult BootstrapManager::registerModule(
57 BootstrapManager::BootstrapType type, string info){
[4733]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){
[4850]70 case BootstrapTypeMulticastDns:
[7532]71 module = new MulticastDns(this, info);
[4850]72 break;
73 case BootstrapTypePeriodicBroadcast:
[7532]74 module = new PeriodicBroadcast(this, info);
[4850]75 break;
[4879]76 case BootstrapTypeBluetoothSdp:
[7532]77 module = new BluetoothSdp(this, info);
[4879]78 break;
[4733]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
[5953]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
[4836]107BootstrapManager::RegistrationResult BootstrapManager::unregisterModule(
108 BootstrapManager::BootstrapType type){
[4733]109
110 boost::mutex::scoped_lock lock( modulesMutex );
111
112 ModuleMap::iterator i = modules.find(type);
[7536]113 if( i == modules.end() ) return RegistrationFailed;
[4733]114
115 BootstrapModule* module = i->second;
116 module->stop();
117 delete module;
118 modules.erase(i);
119
[4758]120 logging_debug("bootstrap module " << module->getName() << " unregistered");
121
[4733]122 return RegistrationSucceeded;
123}
124
[4836]125BootstrapManager::RegistrationResult BootstrapManager::registerAllModules(){
126 RegistrationResult result = RegistrationSucceeded;
[4733]127
[4836]128 { // multicast dns
129 RegistrationResult resone = RegistrationSucceeded;
[7911]130 resone = registerModule(BootstrapTypeMulticastDns, "");
[4850]131
[4836]132 if(resone != RegistrationSucceeded)
133 result = resone;
134 }
135
[4850]136 { // periodic broadcast
137 RegistrationResult resone = RegistrationSucceeded;
[7911]138 resone = registerModule(BootstrapTypePeriodicBroadcast, "");
[4850]139
140 if(resone != RegistrationSucceeded)
141 result = resone;
142 }
143
[4879]144 { // bluetooth sdp
145 RegistrationResult resone = RegistrationSucceeded;
[7911]146 resone = registerModule(BootstrapTypeBluetoothSdp, "");
[4879]147
148 if(resone != RegistrationSucceeded)
149 result = resone;
150 }
151
[4836]152 { // todo
153 /* ... */
154 }
155
156 return result;
157}
158
159BootstrapManager::RegistrationResult BootstrapManager::unregisterAllModules(){
160 unregisterModule(BootstrapTypeMulticastDns);
[4850]161 unregisterModule(BootstrapTypePeriodicBroadcast);
[4879]162 unregisterModule(BootstrapTypeBluetoothSdp);
[4836]163 /* todo ... */
164
165 return RegistrationSucceeded;
166}
167
168void BootstrapManager::onBootstrapServiceFound(string name, string info1, string info2, string info3){
169
[4733]170 BOOST_FOREACH( BootstrapInformationCallback* callback, callbacks ){
[4836]171 callback->onBootstrapServiceFound(name, info1, info2, info3);
[4733]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
[4836]187void BootstrapManager::publish(string name, string info1, string info2, string info3){
[4733]188 boost::mutex::scoped_lock lock( modulesMutex );
189
190 ModuleMap::iterator i = modules.begin();
191 ModuleMap::iterator iend = modules.end();
192
[4758]193 for( ; i != iend; i++ ){
194 logging_info("bootstrap manager publishing service "
195 << name << " on module " << i->second->getName());
[4836]196 i->second->publishService(name, info1, info2, info3);
[4758]197 }
[4733]198}
199
200void BootstrapManager::revoke(string name){
[4836]201 boost::mutex::scoped_lock lock( modulesMutex );
202
[4733]203 ModuleMap::iterator i = modules.begin();
204 ModuleMap::iterator iend = modules.end();
205
[4758]206 for( ; i != iend; i++ ){
207 logging_info("bootstrap manager revoking service "
208 << name << " on module " << i->second->getName());
[4733]209 i->second->revokeService(name);
[4758]210 }
211
[4733]212}
213
214}} //namespace ariba, utility
Note: See TracBrowser for help on using the repository browser.