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(BootstrapManager::BootstrapType type){
00057
00058 boost::mutex::scoped_lock lock( modulesMutex );
00059
00060 ModuleMap::iterator i = modules.find(type);
00061 if( i != modules.end() ){
00062 logging_error("bootstrap module " << i->second->getName() << " already registered");
00063 return RegistrationFailed;
00064 }
00065
00066 BootstrapModule* module = NULL;
00067
00068 switch(type){
00069 case BootstrapTypeMulticastDns:
00070 module = new MulticastDns(this);
00071 break;
00072 case BootstrapTypePeriodicBroadcast:
00073 module = new PeriodicBroadcast(this);
00074 break;
00075 case BootstrapTypeBluetoothSdp:
00076 module = new BluetoothSdp(this);
00077 break;
00078 }
00079
00080 if( module == NULL){
00081 logging_error("bootstrap module for type " << type << " not found");
00082 return RegistrationNotSupported;
00083 }
00084
00085 if( !module->isFunctional() ){
00086 logging_error("bootstrap module " << module->getName() << " is not functional");
00087 delete module;
00088 return RegistrationFailed;
00089 }
00090
00091 logging_debug("bootstrap module " << module->getName() << " registered");
00092
00093 module->start();
00094 modules.insert( std::make_pair(type, module) );
00095
00096 return RegistrationSucceeded;
00097 }
00098
00099 bool BootstrapManager::isModuleRegistered(BootstrapType type){
00100 boost::mutex::scoped_lock lock( modulesMutex );
00101
00102 ModuleMap::iterator i = modules.find(type);
00103 return (i != modules.end());
00104 }
00105
00106 BootstrapManager::RegistrationResult BootstrapManager::unregisterModule(
00107 BootstrapManager::BootstrapType type){
00108
00109 boost::mutex::scoped_lock lock( modulesMutex );
00110
00111 ModuleMap::iterator i = modules.find(type);
00112 if( i != modules.end() ) return RegistrationFailed;
00113
00114 BootstrapModule* module = i->second;
00115 module->stop();
00116 delete module;
00117 modules.erase(i);
00118
00119 logging_debug("bootstrap module " << module->getName() << " unregistered");
00120
00121 return RegistrationSucceeded;
00122 }
00123
00124 BootstrapManager::RegistrationResult BootstrapManager::registerAllModules(){
00125 RegistrationResult result = RegistrationSucceeded;
00126
00127 {
00128 RegistrationResult resone = RegistrationSucceeded;
00129 resone = registerModule(BootstrapTypeMulticastDns);
00130
00131 if(resone != RegistrationSucceeded)
00132 result = resone;
00133 }
00134
00135 {
00136 RegistrationResult resone = RegistrationSucceeded;
00137 resone = registerModule(BootstrapTypePeriodicBroadcast);
00138
00139 if(resone != RegistrationSucceeded)
00140 result = resone;
00141 }
00142
00143 {
00144 RegistrationResult resone = RegistrationSucceeded;
00145 resone = registerModule(BootstrapTypeBluetoothSdp);
00146
00147 if(resone != RegistrationSucceeded)
00148 result = resone;
00149 }
00150
00151 {
00152
00153 }
00154
00155 return result;
00156 }
00157
00158 BootstrapManager::RegistrationResult BootstrapManager::unregisterAllModules(){
00159 unregisterModule(BootstrapTypeMulticastDns);
00160 unregisterModule(BootstrapTypePeriodicBroadcast);
00161 unregisterModule(BootstrapTypeBluetoothSdp);
00162
00163
00164 return RegistrationSucceeded;
00165 }
00166
00167 void BootstrapManager::onBootstrapServiceFound(string name, string info1, string info2, string info3){
00168
00169 BOOST_FOREACH( BootstrapInformationCallback* callback, callbacks ){
00170 callback->onBootstrapServiceFound(name, info1, info2, info3);
00171 }
00172 }
00173
00174 void BootstrapManager::registerCallback(BootstrapInformationCallback* _callback){
00175 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
00176 if( i == callbacks.end() )
00177 callbacks.push_back(_callback);
00178 }
00179
00180 void BootstrapManager::unregisterCallback(BootstrapInformationCallback* _callback){
00181 Callbacks::iterator i = find( callbacks.begin(), callbacks.end(), _callback );
00182 if( i != callbacks.end() )
00183 callbacks.erase(i);
00184 }
00185
00186 void BootstrapManager::publish(string name, string info1, string info2, string info3){
00187 boost::mutex::scoped_lock lock( modulesMutex );
00188
00189 ModuleMap::iterator i = modules.begin();
00190 ModuleMap::iterator iend = modules.end();
00191
00192 for( ; i != iend; i++ ){
00193 logging_info("bootstrap manager publishing service "
00194 << name << " on module " << i->second->getName());
00195 i->second->publishService(name, info1, info2, info3);
00196 }
00197 }
00198
00199 void BootstrapManager::revoke(string name){
00200 boost::mutex::scoped_lock lock( modulesMutex );
00201
00202 ModuleMap::iterator i = modules.begin();
00203 ModuleMap::iterator iend = modules.end();
00204
00205 for( ; i != iend; i++ ){
00206 logging_info("bootstrap manager revoking service "
00207 << name << " on module " << i->second->getName());
00208 i->second->revokeService(name);
00209 }
00210
00211 }
00212
00213 }}