00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "BootstrapManager.h"
00041 #include "ariba/utility/bootstrap/modules/multicastdns/MulticastDns.h"
00042 #include "ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.h"
00043 #include "ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.h"
00044
00045 namespace ariba {
00046 namespace utility {
00047
00048 use_logging_cpp(BootstrapManager);
00049
00050 BootstrapManager::BootstrapManager(){
00051 }
00052
00053 BootstrapManager::~BootstrapManager(){
00054 }
00055
00056 BootstrapManager::RegistrationResult BootstrapManager::registerModule(
00057 BootstrapManager::BootstrapType type, string info){
00058
00059 boost::mutex::scoped_lock lock( modulesMutex );
00060
00061 ModuleMap::iterator i = modules.find(type);
00062 if( i != modules.end() ){
00063 logging_error("bootstrap module " << i->second->getName() << " already registered");
00064 return RegistrationFailed;
00065 }
00066
00067 BootstrapModule* module = NULL;
00068
00069 switch(type){
00070 case BootstrapTypeMulticastDns:
00071 module = new MulticastDns(this, info);
00072 break;
00073 case BootstrapTypePeriodicBroadcast:
00074 module = new PeriodicBroadcast(this, info);
00075 break;
00076 case BootstrapTypeBluetoothSdp:
00077 module = new BluetoothSdp(this, info);
00078 break;
00079 }
00080
00081 if( module == NULL){
00082 logging_error("bootstrap module for type " << type << " not found");
00083 return RegistrationNotSupported;
00084 }
00085
00086 if( !module->isFunctional() ){
00087 logging_error("bootstrap module " << module->getName() << " is not functional");
00088 delete module;
00089 return RegistrationFailed;
00090 }
00091
00092 logging_debug("bootstrap module " << module->getName() << " registered");
00093
00094 module->start();
00095 modules.insert( std::make_pair(type, module) );
00096
00097 return RegistrationSucceeded;
00098 }
00099
00100 bool BootstrapManager::isModuleRegistered(BootstrapType type){
00101 boost::mutex::scoped_lock lock( modulesMutex );
00102
00103 ModuleMap::iterator i = modules.find(type);
00104 return (i != modules.end());
00105 }
00106
00107 BootstrapManager::RegistrationResult BootstrapManager::unregisterModule(
00108 BootstrapManager::BootstrapType type){
00109
00110 boost::mutex::scoped_lock lock( modulesMutex );
00111
00112 ModuleMap::iterator i = modules.find(type);
00113 if( i == modules.end() ) return RegistrationFailed;
00114
00115 BootstrapModule* module = i->second;
00116 module->stop();
00117 delete module;
00118 modules.erase(i);
00119
00120 logging_debug("bootstrap module " << module->getName() << " unregistered");
00121
00122 return RegistrationSucceeded;
00123 }
00124
00125 BootstrapManager::RegistrationResult BootstrapManager::registerAllModules(){
00126 RegistrationResult result = RegistrationSucceeded;
00127
00128 {
00129 RegistrationResult resone = RegistrationSucceeded;
00130 resone = registerModule(BootstrapTypeMulticastDns, "");
00131
00132 if(resone != RegistrationSucceeded)
00133 result = resone;
00134 }
00135
00136 {
00137 RegistrationResult resone = RegistrationSucceeded;
00138 resone = registerModule(BootstrapTypePeriodicBroadcast, "");
00139
00140 if(resone != RegistrationSucceeded)
00141 result = resone;
00142 }
00143
00144 {
00145 RegistrationResult resone = RegistrationSucceeded;
00146 resone = registerModule(BootstrapTypeBluetoothSdp, "");
00147
00148 if(resone != RegistrationSucceeded)
00149 result = resone;
00150 }
00151
00152 {
00153
00154 }
00155
00156 return result;
00157 }
00158
00159 BootstrapManager::RegistrationResult BootstrapManager::unregisterAllModules(){
00160 unregisterModule(BootstrapTypeMulticastDns);
00161 unregisterModule(BootstrapTypePeriodicBroadcast);
00162 unregisterModule(BootstrapTypeBluetoothSdp);
00163
00164
00165 return RegistrationSucceeded;
00166 }
00167
00168 void BootstrapManager::onBootstrapServiceFound(string name, string info1, string info2, string info3){
00169
00170 BOOST_FOREACH( BootstrapInformationCallback* callback, callbacks ){
00171 callback->onBootstrapServiceFound(name, info1, info2, info3);
00172 }
00173 }
00174
00175 void BootstrapManager::registerCallback(BootstrapInformationCallback* _callback){
00176 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
00177 if( i == callbacks.end() )
00178 callbacks.push_back(_callback);
00179 }
00180
00181 void BootstrapManager::unregisterCallback(BootstrapInformationCallback* _callback){
00182 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
00183 if( i != callbacks.end() )
00184 callbacks.erase(i);
00185 }
00186
00187 void BootstrapManager::publish(string name, string info1, string info2, string info3){
00188 boost::mutex::scoped_lock lock( modulesMutex );
00189
00190 ModuleMap::iterator i = modules.begin();
00191 ModuleMap::iterator iend = modules.end();
00192
00193 for( ; i != iend; i++ ){
00194 logging_info("bootstrap manager publishing service "
00195 << name << " on module " << i->second->getName());
00196 i->second->publishService(name, info1, info2, info3);
00197 }
00198 }
00199
00200 void BootstrapManager::revoke(string name){
00201 boost::mutex::scoped_lock lock( modulesMutex );
00202
00203 ModuleMap::iterator i = modules.begin();
00204 ModuleMap::iterator iend = modules.end();
00205
00206 for( ; i != iend; i++ ){
00207 logging_info("bootstrap manager revoking service "
00208 << name << " on module " << i->second->getName());
00209 i->second->revokeService(name);
00210 }
00211
00212 }
00213
00214 }}