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

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

-neues bootstrap module für dumme periodische broadcasts

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