Changeset 4758 for source/ariba/utility/bootstrap
- Timestamp:
- Jul 6, 2009, 11:43:01 AM (15 years ago)
- Location:
- source/ariba/utility/bootstrap
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/bootstrap/BootstrapManager.cpp
r4733 r4758 50 50 51 51 BootstrapManager::~BootstrapManager(){ 52 53 boost::mutex::scoped_lock lock( modulesMutex ); 54 55 while( modules.size() > 0 ){ 56 ModuleMap::iterator i = modules.begin(); 57 unregisterModule( i->first ); 58 } 52 59 } 53 60 … … 63 70 64 71 BootstrapModule* module = NULL; 65 string servicetype = "_spovnet._tcp";66 72 67 73 switch(type){ 68 74 case BootstrapTypeMulticastDns: 69 module = new MulticastDns( servicetype,this);75 module = new MulticastDns(this); 70 76 break; 71 77 } … … 102 108 modules.erase(i); 103 109 110 logging_debug("bootstrap module " << module->getName() << " unregistered"); 111 104 112 return RegistrationSucceeded; 105 113 } … … 130 138 ModuleMap::iterator iend = modules.end(); 131 139 132 for( ; i != iend; i++ ) 140 for( ; i != iend; i++ ){ 141 logging_info("bootstrap manager publishing service " 142 << name << " on module " << i->second->getName()); 133 143 i->second->publishService(name, info); 144 } 134 145 } 135 146 … … 138 149 ModuleMap::iterator iend = modules.end(); 139 150 140 for( ; i != iend; i++ ) 151 for( ; i != iend; i++ ){ 152 logging_info("bootstrap manager revoking service " 153 << name << " on module " << i->second->getName()); 141 154 i->second->revokeService(name); 155 } 156 142 157 } 143 158 -
source/ariba/utility/bootstrap/modules/BootstrapModule.cpp
r4733 r4758 42 42 namespace utility { 43 43 44 BootstrapModule::BootstrapModule( string type,BootstrapInformationCallback* _callback)44 BootstrapModule::BootstrapModule(BootstrapInformationCallback* _callback) 45 45 : callback(_callback){ 46 46 } -
source/ariba/utility/bootstrap/modules/BootstrapModule.h
r4733 r4758 50 50 class BootstrapModule { 51 51 public: 52 BootstrapModule( string type,BootstrapInformationCallback* _callback);52 BootstrapModule(BootstrapInformationCallback* _callback); 53 53 virtual ~BootstrapModule(); 54 54 -
source/ariba/utility/bootstrap/modules/multicastdns/MulticastDns.cpp
r4733 r4758 42 42 namespace utility { 43 43 44 const string MulticastDns::serviceType = "_spovnet._tcp"; 44 45 use_logging_cpp(MulticastDns); 45 46 46 MulticastDns::MulticastDns(string type, BootstrapInformationCallback* _callback) 47 : BootstrapModule(type, _callback), serviceType(type){ 47 MulticastDns::MulticastDns(BootstrapInformationCallback* _callback) : BootstrapModule(_callback) { 48 48 #ifdef HAVE_LIBAVAHI_CLIENT 49 49 avahiclient = NULL; 50 avahigroup = NULL;51 50 avahipoll = NULL; 52 51 avahibrowser = NULL; … … 80 79 // create a new avahi polling thread 81 80 avahipoll = avahi_threaded_poll_new(); 82 assert( avahipoll != NULL ); 81 if( avahipoll == NULL){ 82 logging_error("creating avahi poll failed"); 83 return; 84 } 83 85 84 86 // create a new avahi client 85 87 avahiclient = avahi_client_new( avahi_threaded_poll_get(avahipoll), 86 88 (AvahiClientFlags)0, MulticastDns::client_callback, this, &error ); 87 assert( avahiclient != NULL ); 89 if( avahiclient == NULL){ 90 logging_error("creating avahi client failed"); 91 return; 92 } 88 93 89 94 // block the event loop 90 95 avahi_threaded_poll_lock( avahipoll ); 91 96 92 // create the service browser 97 // create the service browser for the specified type 93 98 avahibrowser = avahi_service_browser_new( 94 99 avahiclient, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, … … 96 101 (AvahiLookupFlags)0, MulticastDns::browse_callback, this); 97 102 103 if( avahibrowser == NULL){ 104 logging_error("creating avahi browser failed"); 105 return; 106 } 107 98 108 //unblock the event loop and let it run 99 109 avahi_threaded_poll_unlock( avahipoll ); … … 106 116 #ifdef HAVE_LIBAVAHI_CLIENT 107 117 118 // 119 // stop poll and free browser 120 // 121 108 122 avahi_threaded_poll_stop( avahipoll ); 109 123 avahi_service_browser_free( avahibrowser ); 110 if( avahigroup != NULL ) avahi_entry_group_free( avahigroup ); 124 avahibrowser = NULL; 125 126 // 127 // free all registered groups 128 // 129 130 AvahiGroupMap::iterator i = avahigroups.begin(); 131 AvahiGroupMap::iterator iend = avahigroups.end(); 132 133 for( ; i != iend; i++) 134 avahi_entry_group_free( i->second ); 135 136 // 137 // free client and poll 138 // 139 111 140 avahi_client_free( avahiclient ); 141 avahiclient = NULL; 142 112 143 avahi_threaded_poll_free( avahipoll ); 144 avahipoll = NULL; 113 145 114 146 #endif // HAVE_LIBAVAHI_CLIENT … … 117 149 void MulticastDns::publishService(string name, string info){ 118 150 #ifdef HAVE_LIBAVAHI_CLIENT 151 152 if(name.length() > 63){ 153 logging_error("service name length must not exceed 63 characters. " 154 << name << " is " << name.length() << " characters"); 155 return; 156 } 157 119 158 120 159 avahi_threaded_poll_lock(avahipoll); 121 160 assert( avahiclient != NULL ); 122 161 123 char* n = NULL;124 162 int ret = 0; 125 163 126 if( avahigroup == NULL){ 127 avahigroup = avahi_entry_group_new(avahiclient, MulticastDns::entry_group_callback, this); 128 129 if(avahigroup == NULL) { 130 logging_warn("avahi_entry_group_new failed " << avahi_strerror(avahi_client_errno(avahiclient))); 131 avahi_threaded_poll_quit(avahipoll); 164 // 165 // if we have no group for this service, create one 166 // 167 168 AvahiGroupMap::iterator igroup = avahigroups.find(name); 169 AvahiEntryGroup* currentgroup = (igroup != avahigroups.end() ? igroup->second : NULL); 170 171 if( currentgroup == NULL ){ 172 173 logging_debug("creating group for service " << name); 174 currentgroup = avahi_entry_group_new(avahiclient, MulticastDns::entry_group_callback, this); 175 176 if(currentgroup == NULL){ 177 logging_error("failed creating avahi group for service " 178 << name << ": " << avahi_strerror(avahi_client_errno(avahiclient))); 179 avahi_threaded_poll_unlock(avahipoll); 132 180 return; 133 181 } 134 } 135 136 logging_debug("avahi adding service " << name); 182 183 avahigroups.insert( make_pair(name, currentgroup) ); 184 } 185 186 assert( currentgroup != NULL ); 187 188 logging_debug("avahi adding service " << name << " to new group"); 137 189 138 190 ret = avahi_entry_group_add_service( 139 avahigroup, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, 140 name.c_str(), serviceType.c_str(), NULL, NULL, 0, info.c_str(), NULL); 191 currentgroup, // group to add service to 192 AVAHI_IF_UNSPEC, // interface to announce, we use all interfaces 193 AVAHI_PROTO_UNSPEC, // protocol to announce, we use all protocols 194 (AvahiPublishFlags)0, // no special flags 195 name.c_str(), // name of the service, no more than 63 characters 196 serviceType.c_str(), // type of the service: _spovnet._tcp (tcp does not mean anything here, just have to stick with this structure 197 NULL, // publish in all domains 198 NULL, // host name of our machine, let avahi find out 199 3333, // port number the service is on, just dummy, everything is encoded in TXT 200 info.c_str(), // arbitrary info 201 NULL); // make that this is the last info field 141 202 142 203 if( ret < 0 ){ 143 144 204 logging_warn("failed to add service " << name << ": " << avahi_strerror(ret)); 145 avahi _threaded_poll_quit(avahipoll);146 return;147 205 avahigroups.erase(name); 206 avahi_threaded_poll_unlock(avahipoll); 207 return; 148 208 } 149 209 150 210 // tell the server to register the service 151 ret = avahi_entry_group_commit( avahigroup);211 ret = avahi_entry_group_commit( currentgroup ); 152 212 if(ret < 0) { 153 213 logging_warn("failed to commit entry group: " << avahi_strerror(ret)); 154 avahi_threaded_poll_quit(avahipoll); 214 avahigroups.erase(name); 215 avahi_threaded_poll_unlock(avahipoll); 216 return; 155 217 } 156 218 … … 163 225 #ifdef HAVE_LIBAVAHI_CLIENT 164 226 165 if (avahigroup) 166 avahi_entry_group_reset(avahigroup); 227 avahi_threaded_poll_lock(avahipoll); 228 229 AvahiGroupMap::iterator i = avahigroups.find(name); 230 if( i != avahigroups.end() ){ 231 232 logging_debug("revoking service " << name); 233 avahi_entry_group_reset( i->second ); 234 235 } else { 236 logging_warn("service " << name << " is not registered, cannot revoke"); 237 } 238 239 avahi_threaded_poll_unlock(avahipoll); 167 240 168 241 #endif // HAVE_LIBAVAHI_CLIENT … … 187 260 case AVAHI_CLIENT_FAILURE: 188 261 189 logging_warn( "avahi client failure " << avahi_strerror(avahi_client_errno(client)) ); 262 logging_warn( "avahi client failure " 263 << avahi_strerror(avahi_client_errno(client)) << ". quitting" ); 190 264 avahi_threaded_poll_quit(obj->avahipoll); 191 265 … … 199 273 case AVAHI_CLIENT_S_REGISTERING: 200 274 201 // 202 // the server records are now being established. This 203 // might be caused by a host name change. We need to wait 204 // for our own records to register until the host name is 205 // properly esatblished 206 // 207 208 if( obj->avahigroup != NULL ) 209 avahi_entry_group_reset(obj->avahigroup); 210 275 logging_debug("avahi client registering"); 211 276 break; 212 277 213 278 case AVAHI_CLIENT_CONNECTING: 279 280 logging_debug("avahi client conencting"); 214 281 break; 215 282 } … … 223 290 MulticastDns* obj = (MulticastDns*)userdata; 224 291 assert(obj != NULL); 225 obj->avahigroup = group;226 292 227 293 // … … 232 298 case AVAHI_ENTRY_GROUP_ESTABLISHED: 233 299 234 // entry group has been established successfully235 300 logging_debug( "service entry group successfully established" ); 236 301 break; … … 238 303 case AVAHI_ENTRY_GROUP_COLLISION: 239 304 240 // service name collision241 305 logging_warn("service name collision for name"); 242 306 break; … … 250 314 251 315 case AVAHI_ENTRY_GROUP_UNCOMMITED: 316 317 logging_debug("avahi entry group uncommited"); 252 318 break; 253 319 254 320 case AVAHI_ENTRY_GROUP_REGISTERING: 255 break; 321 322 logging_debug("avahi entry group registering"); 323 break; 324 256 325 } //switch(state) 257 326 } … … 281 350 AVAHI_PROTO_UNSPEC, (AvahiLookupFlags)0, 282 351 MulticastDns::resolve_callback, obj))){ 283 logging_warn( "failed to resolve service " << name << ", error " << avahi_strerror(avahi_client_errno(client))); 352 logging_warn( "failed to resolve service " << name 353 << ", error " << avahi_strerror(avahi_client_errno(client))); 284 354 } 285 355 … … 287 357 288 358 case AVAHI_BROWSER_REMOVE: 359 360 logging_debug("avahi browser remove"); 289 361 break; 290 362 291 363 case AVAHI_BROWSER_ALL_FOR_NOW: 364 365 logging_debug("avahi all for now"); 292 366 break; 293 367 294 368 case AVAHI_BROWSER_CACHE_EXHAUSTED: 369 370 logging_debug("avahi browser cache exhausted"); 295 371 break; 296 372 } … … 312 388 case AVAHI_RESOLVER_FAILURE: 313 389 314 logging_warn("resolver failed to resolve service " << name << ", error " << avahi_strerror(avahi_client_errno(client))); 315 break; 316 317 case AVAHI_RESOLVER_FOUND: { 318 319 char a[AVAHI_ADDRESS_STR_MAX]; 320 char* t = NULL; 321 322 avahi_address_snprint(a, sizeof(a), address); 323 t = avahi_string_list_to_string(txt); 324 325 if(obj != NULL && obj->callback != NULL){ 326 obj->callback->onBootstrapServiceFound(name, t); 327 //foundNewService(name, type, domain, host_name, (int)port, a, t); 328 } 329 330 avahi_free( resolver ); 331 break; 332 } 390 logging_warn("resolver failed to resolve service " << name 391 << ", error " << avahi_strerror(avahi_client_errno(client))); 392 break; 393 394 case AVAHI_RESOLVER_FOUND: 395 396 char addr[AVAHI_ADDRESS_STR_MAX]; 397 char* text = NULL; 398 399 avahi_address_snprint(addr, sizeof(addr), address); 400 text = avahi_string_list_to_string(txt); 401 402 if(obj != NULL && obj->callback != NULL) 403 obj->callback->onBootstrapServiceFound(name, text); 404 405 avahi_free( text ); 406 break; 333 407 } 334 408 -
source/ariba/utility/bootstrap/modules/multicastdns/MulticastDns.h
r4733 r4758 53 53 #endif 54 54 55 #include <iostream> 56 #include <string> 57 #include <map> 55 58 #include <boost/thread/mutex.hpp> 56 59 #include <boost/thread/thread.hpp> 57 #include <iostream>58 #include <string>59 60 #include "ariba/utility/bootstrap/modules/BootstrapModule.h" 60 61 #include "ariba/utility/logging/Logging.h" 62 63 using std::string; 64 using std::map; 65 using std::make_pair; 61 66 62 67 namespace ariba { … … 66 71 use_logging_h(MulticastDns); 67 72 public: 68 MulticastDns( string type,BootstrapInformationCallback* _callback);73 MulticastDns(BootstrapInformationCallback* _callback); 69 74 virtual ~MulticastDns(); 70 75 … … 79 84 80 85 private: 81 st ring serviceType;86 static const string serviceType; 82 87 83 88 #ifdef HAVE_LIBAVAHI_CLIENT 84 89 85 90 AvahiClient* avahiclient; 86 AvahiEntryGroup* avahigroup;87 91 AvahiThreadedPoll* avahipoll; 88 92 AvahiServiceBrowser* avahibrowser; 93 94 typedef map<string, AvahiEntryGroup*> AvahiGroupMap; 95 AvahiGroupMap avahigroups; 89 96 90 97 static void client_callback(
Note:
See TracChangeset
for help on using the changeset viewer.