Changeset 4758 for source/ariba/utility


Ignore:
Timestamp:
Jul 6, 2009, 11:43:01 AM (15 years ago)
Author:
Christoph Mayer
Message:

avahi paar sachen gefixt, initiale tests mit poolrechnern klappen

Location:
source/ariba/utility/bootstrap
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/bootstrap/BootstrapManager.cpp

    r4733 r4758  
    5050
    5151BootstrapManager::~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        }
    5259}
    5360
     
    6370
    6471        BootstrapModule* module = NULL;
    65         string servicetype = "_spovnet._tcp";
    6672
    6773        switch(type){
    6874                case BootstrapTypeMulticastDns:
    69                         module = new MulticastDns(servicetype, this);
     75                        module = new MulticastDns(this);
    7076                        break;
    7177        }
     
    102108        modules.erase(i);
    103109
     110        logging_debug("bootstrap module " << module->getName() << " unregistered");
     111
    104112        return RegistrationSucceeded;
    105113}
     
    130138        ModuleMap::iterator iend = modules.end();
    131139
    132         for( ; i != iend; i++ )
     140        for( ; i != iend; i++ ){
     141                logging_info("bootstrap manager publishing service "
     142                                << name << " on module " << i->second->getName());
    133143                i->second->publishService(name, info);
     144        }
    134145}
    135146
     
    138149        ModuleMap::iterator iend = modules.end();
    139150
    140         for( ; i != iend; i++ )
     151        for( ; i != iend; i++ ){
     152                logging_info("bootstrap manager revoking service "
     153                                << name << " on module " << i->second->getName());
    141154                i->second->revokeService(name);
     155        }
     156
    142157}
    143158
  • source/ariba/utility/bootstrap/modules/BootstrapModule.cpp

    r4733 r4758  
    4242namespace utility {
    4343
    44 BootstrapModule::BootstrapModule(string type, BootstrapInformationCallback* _callback)
     44BootstrapModule::BootstrapModule(BootstrapInformationCallback* _callback)
    4545        : callback(_callback){
    4646}
  • source/ariba/utility/bootstrap/modules/BootstrapModule.h

    r4733 r4758  
    5050class BootstrapModule {
    5151public:
    52         BootstrapModule(string type, BootstrapInformationCallback* _callback);
     52        BootstrapModule(BootstrapInformationCallback* _callback);
    5353        virtual ~BootstrapModule();
    5454
  • source/ariba/utility/bootstrap/modules/multicastdns/MulticastDns.cpp

    r4733 r4758  
    4242namespace utility {
    4343
     44const string MulticastDns::serviceType = "_spovnet._tcp";
    4445use_logging_cpp(MulticastDns);
    4546
    46 MulticastDns::MulticastDns(string type, BootstrapInformationCallback* _callback)
    47         : BootstrapModule(type, _callback), serviceType(type){
     47MulticastDns::MulticastDns(BootstrapInformationCallback* _callback) : BootstrapModule(_callback) {
    4848  #ifdef HAVE_LIBAVAHI_CLIENT
    4949        avahiclient = NULL;
    50         avahigroup = NULL;
    5150        avahipoll = NULL;
    5251        avahibrowser = NULL;
     
    8079        // create a new avahi polling thread
    8180        avahipoll = avahi_threaded_poll_new();
    82         assert( avahipoll != NULL );
     81        if( avahipoll == NULL){
     82                logging_error("creating avahi poll failed");
     83                return;
     84        }
    8385
    8486        // create a new avahi client
    8587        avahiclient = avahi_client_new( avahi_threaded_poll_get(avahipoll),
    8688                        (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        }
    8893
    8994        // block the event loop
    9095        avahi_threaded_poll_lock( avahipoll );
    9196
    92         // create the service browser
     97        // create the service browser for the specified type
    9398        avahibrowser = avahi_service_browser_new(
    9499                        avahiclient, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
     
    96101                        (AvahiLookupFlags)0, MulticastDns::browse_callback, this);
    97102
     103        if( avahibrowser == NULL){
     104                logging_error("creating avahi browser failed");
     105                return;
     106        }
     107
    98108        //unblock the event loop and let it run
    99109        avahi_threaded_poll_unlock( avahipoll );
     
    106116  #ifdef HAVE_LIBAVAHI_CLIENT
    107117
     118        //
     119        // stop poll and free browser
     120        //
     121
    108122        avahi_threaded_poll_stop( avahipoll );
    109123        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
    111140        avahi_client_free( avahiclient );
     141        avahiclient = NULL;
     142
    112143        avahi_threaded_poll_free( avahipoll );
     144        avahipoll = NULL;
    113145
    114146  #endif // HAVE_LIBAVAHI_CLIENT
     
    117149void MulticastDns::publishService(string name, string info){
    118150  #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
    119158
    120159        avahi_threaded_poll_lock(avahipoll);
    121160        assert( avahiclient != NULL );
    122161
    123         char* n = NULL;
    124162        int ret = 0;
    125163
    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);
    132180                        return;
    133181                }
    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");
    137189
    138190        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
    141202
    142203        if( ret < 0 ){
    143 
    144204                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;
    148208        }
    149209
    150210        // tell the server to register the service
    151         ret = avahi_entry_group_commit(avahigroup);
     211        ret = avahi_entry_group_commit( currentgroup );
    152212        if(ret < 0) {
    153213                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;
    155217        }
    156218
     
    163225  #ifdef HAVE_LIBAVAHI_CLIENT
    164226
    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);
    167240
    168241  #endif // HAVE_LIBAVAHI_CLIENT
     
    187260        case AVAHI_CLIENT_FAILURE:
    188261
    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" );
    190264            avahi_threaded_poll_quit(obj->avahipoll);
    191265
     
    199273        case AVAHI_CLIENT_S_REGISTERING:
    200274
    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");
    211276            break;
    212277
    213278        case AVAHI_CLIENT_CONNECTING:
     279
     280                logging_debug("avahi client conencting");
    214281            break;
    215282    }
     
    223290        MulticastDns* obj = (MulticastDns*)userdata;
    224291        assert(obj != NULL);
    225         obj->avahigroup = group;
    226292
    227293        //
     
    232298                case AVAHI_ENTRY_GROUP_ESTABLISHED:
    233299
    234                         // entry group has been established successfully
    235300                        logging_debug( "service entry group successfully established" );
    236301                        break;
     
    238303                case AVAHI_ENTRY_GROUP_COLLISION:
    239304
    240                         // service name collision
    241305                        logging_warn("service name collision for name");
    242306                        break;
     
    250314
    251315                case AVAHI_ENTRY_GROUP_UNCOMMITED:
     316
     317                        logging_debug("avahi entry group uncommited");
    252318                        break;
    253319
    254320                case AVAHI_ENTRY_GROUP_REGISTERING:
    255                         break;
     321
     322                        logging_debug("avahi entry group registering");
     323                        break;
     324
    256325        } //switch(state)
    257326}
     
    281350                                        AVAHI_PROTO_UNSPEC, (AvahiLookupFlags)0,
    282351                                        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)));
    284354                        }
    285355
     
    287357
    288358                case AVAHI_BROWSER_REMOVE:
     359
     360                        logging_debug("avahi browser remove");
    289361                        break;
    290362
    291363                case AVAHI_BROWSER_ALL_FOR_NOW:
     364
     365                        logging_debug("avahi all for now");
    292366                        break;
    293367
    294368                case AVAHI_BROWSER_CACHE_EXHAUSTED:
     369
     370                        logging_debug("avahi browser cache exhausted");
    295371                        break;
    296372        }
     
    312388                case AVAHI_RESOLVER_FAILURE:
    313389
    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;
    333407        }
    334408
  • source/ariba/utility/bootstrap/modules/multicastdns/MulticastDns.h

    r4733 r4758  
    5353#endif
    5454
     55#include <iostream>
     56#include <string>
     57#include <map>
    5558#include <boost/thread/mutex.hpp>
    5659#include <boost/thread/thread.hpp>
    57 #include <iostream>
    58 #include <string>
    5960#include "ariba/utility/bootstrap/modules/BootstrapModule.h"
    6061#include "ariba/utility/logging/Logging.h"
     62
     63using std::string;
     64using std::map;
     65using std::make_pair;
    6166
    6267namespace ariba {
     
    6671        use_logging_h(MulticastDns);
    6772public:
    68         MulticastDns(string type, BootstrapInformationCallback* _callback);
     73        MulticastDns(BootstrapInformationCallback* _callback);
    6974        virtual ~MulticastDns();
    7075
     
    7984
    8085private:
    81         string serviceType;
     86        static const string serviceType;
    8287
    8388#ifdef HAVE_LIBAVAHI_CLIENT
    8489
    8590        AvahiClient*         avahiclient;
    86         AvahiEntryGroup*     avahigroup;
    8791        AvahiThreadedPoll*   avahipoll;
    8892        AvahiServiceBrowser* avahibrowser;
     93
     94        typedef map<string, AvahiEntryGroup*> AvahiGroupMap;
     95        AvahiGroupMap avahigroups;
    8996
    9097        static void client_callback(
Note: See TracChangeset for help on using the changeset viewer.