Changeset 5316 for source/ariba/utility


Ignore:
Timestamp:
Jul 24, 2009, 8:53:41 PM (15 years ago)
Author:
Christoph Mayer
Message:

merge from bootstrap branch

Location:
source/ariba/utility
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/bootstrap/modules/bluetoothsdp

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • source/ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.cpp

    r4970 r5316  
    4141#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    4242
    43 // Attribute descriptors for SDP
    44 // base was chosen randomly
    45 #define SDP_SPOVNET_BASE                        0x4000
    46 #define SDP_ATTR_SPOVNET_NAME           0x0000 + SDP_SPOVNET_BASE
    47 #define SDP_ATTR_SPOVNET_INFO1          0x0001 + SDP_SPOVNET_BASE
    48 #define SDP_ATTR_SPOVNET_INFO2          0x0002 + SDP_SPOVNET_BASE
    49 #define SDP_ATTR_SPOVNET_INFO3          0x0003 + SDP_SPOVNET_BASE
    50 
    51 // The SpoVNet unique identifier, this should be the same for all SpoVNet implementations
    52 const uint8_t svc_uuid_int[] = {0x59, 0x29, 0x24, 0x34, 0x69, 0x42, 0x11, 0xde, 0x94,
    53         0x3e, 0x00, 0x21, 0x5d, 0xb4, 0xd8, 0x54};
    54 
    55 const char *service_name = "SpoVNet";
    56 const char *svc_dsc = "Spontaneous Virtual Network";
    57 const char *service_prov = "ITM Uni Karlsruhe";
     43        // Attribute descriptors for SDP
     44        // base was chosen randomly
     45        #define SDP_SPOVNET_BASE                        0x4000
     46        #define SDP_ATTR_SPOVNET_NAME           0x0000 + SDP_SPOVNET_BASE
     47        #define SDP_ATTR_SPOVNET_INFO1          0x0001 + SDP_SPOVNET_BASE
     48        #define SDP_ATTR_SPOVNET_INFO2          0x0002 + SDP_SPOVNET_BASE
     49        #define SDP_ATTR_SPOVNET_INFO3          0x0003 + SDP_SPOVNET_BASE
     50
     51        // The SpoVNet unique identifier, this should be the same for all SpoVNet implementations
     52        const uint8_t svc_uuid_int[] = {0x59, 0x29, 0x24, 0x34, 0x69, 0x42, 0x11, 0xde, 0x94,
     53                0x3e, 0x00, 0x21, 0x5d, 0xb4, 0xd8, 0x54};
     54
     55        const char *service_name = "SpoVNet";
     56        const char *svc_dsc = "www.ariba-underlay.org";
     57        const char *service_prov = "ITM Uni Karlsruhe";
    5858
    5959#endif // HAVE_BLUETOOTH_BLUETOOTH_H
     
    6666BluetoothSdp::BluetoothSdp(BootstrapInformationCallback* _callback) :
    6767        BootstrapModule(_callback), scan_timer_(io_service_) {
     68        srand( time(NULL) );
    6869#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    6970
     
    8889bool BluetoothSdp::isFunctional() {
    8990#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    90         return true; // Not tested yet :)
     91        return true;
    9192#else
    9293        return false;
     
    118119        t_.join();
    119120
     121        if(sdp_session_ != NULL)
     122                sdp_close(sdp_session_);
     123
    120124#endif // HAVE_BLUETOOTH_BLUETOOTH_H
    121125}
     
    130134         */
    131135
    132         logging_info("Registering SDP service");
     136        logging_debug("registering SDP service");
    133137
    134138        uint8_t rfcomm_channel = channel_;
     
    142146        sdp_session_ = 0;
    143147
    144         bdaddr_t bdaddr_any = (bdaddr_t) { {0, 0, 0, 0, 0, 0}};
    145         bdaddr_t bdaddr_local = (bdaddr_t) { {0, 0, 0, 0xff, 0xff, 0xff}};
    146 
    147148        // prepare the info attribute buffers
    148149        //string namebuf, info1buf, info2buf, info3buf;
     
    155156
    156157        if((namelen > 256) || (info1len > 256) || (info2len > 256) || (info3len > 256)) {
    157                 logging_error("String Argument too long, max size is 256!");
     158                logging_error("string argument too long, max size is 256!");
    158159                return;
    159160        }
    160 
    161         // we need to save the string len for sdp; do we?
    162         /*
    163         namebuf = (char)namelen;
    164         namebuf.append(name);
    165         info1buf = (char)info1len;
    166         info1buf.append(info1);
    167         info2buf = (char)info2len;
    168         info2buf.append(info2);
    169         info3buf = (char)info3len;
    170         info3buf.append(info3);
    171         */
    172161
    173162        // set the general service ID
     
    222211                        info3.data());
    223212
    224         // connect to the local SDP server, register the service record,
    225         // and disconnect
    226         sdp_session_ = sdp_connect(&bdaddr_any, &bdaddr_local, SDP_RETRY_IF_BUSY);
    227 
    228         if (sdp_session_ == 0) {
    229                 logging_error( "Something is wrong with your SDP server, nothing registered" );
     213        // connect to the local SDP server, register the service record
     214        if( sdp_session_ == NULL ){
     215                sdp_session_ = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
     216        }
     217
     218        if (sdp_session_ == NULL) {
     219                logging_error( "something is wrong with your SDP server, nothing registered" );
    230220        } else {
    231                 sdp_record_register(sdp_session_, &record, 0);
     221                int ret = sdp_record_register(sdp_session_, &record, 0);
     222
     223                if(ret < 0){
     224                        logging_error("failed registering sdp record");
     225                }else{
     226                        logging_debug("sdp record registered using session " << sdp_session_);
     227                }
    232228        }
    233229
     
    247243#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    248244
    249         logging_info("Unregistering SDP service");
     245        logging_debug("unregistering SDP service");
    250246        sdp_close(sdp_session_);
    251247
     
    256252
    257253void BluetoothSdp::bt_scan() {
    258 
    259 
    260254        /*
    261255         * Scans for other bluetooth devices and starts a SDP search on them.
    262          * Repeats 20 seconds after the end of the scan.
    263          */
    264 
    265         logging_info("Scanning for peers");
     256         */
     257
     258        logging_debug("scanning for peers");
    266259
    267260        inquiry_info *ii = NULL;
     
    276269        sock = hci_open_dev(dev_id);
    277270        if (dev_id < 0 || sock < 0) {
    278                 logging_error("opening socket");
    279                 exit(1);
     271                logging_error("opening socket for device " << dev_id << " failed. can not scan for peers");
     272                return;
    280273        }
    281274
     
    287280        num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
    288281        if (num_rsp < 0)
    289                 logging_error("hci_inquiry");
     282                logging_error("hci_inquiry failed with " << num_rsp);
    290283
    291284        for (i = 0; i < num_rsp; i++) {
    292                 /*
    293                  ba2str(&(ii + i)->bdaddr, addr);
    294                  memset(name, 0, sizeof(name));
    295                  if (hci_read_remote_name(sock, &(ii + i)->bdaddr, sizeof(name),
    296                  name, 0) < 0)
    297                  strcpy(name, "[unknown]");
    298                  printf("%s  %s\n", addr, name);
    299                  */
    300285
    301286                address = (ii + i)->bdaddr;
    302 
    303                 logging_info("Found peer " << ba2string(&address) << ", querying SDP.")
     287                logging_debug("found peer " << ba2string(&address) << ", querying SDP.")
    304288
    305289                // TODO: sdp_search can be very slow, fork it!
     
    310294        close(sock);
    311295
    312         logging_info("Next scan in 20 seconds");
    313 
    314         scan_timer_.expires_from_now(boost::posix_time::seconds(20));
     296        int nextscan = (rand() % 40) + 5;
     297        logging_debug("Next sdp scan in " << nextscan << " seconds");
     298
     299        scan_timer_.expires_from_now(boost::posix_time::seconds(nextscan));
    315300        scan_timer_.async_wait(boost::bind(&BluetoothSdp::bt_scan, this));
    316301}
     
    326311        uuid_t svc_uuid;
    327312        sdp_list_t *response_list, *search_list, *attrid_list;
    328         sdp_session_t *session = 0;
     313        sdp_session_t *session = NULL;
    329314        uint32_t range = 0x0000ffff;
    330315        uint8_t port = 0;
    331         bdaddr_t any_addr = (bdaddr_t) { {0, 0, 0, 0, 0, 0}};
    332316
    333317        // prepare the buffers for the attributes
     
    335319
    336320        // connect to the SDP server running on the remote machine
    337         session = sdp_connect(&any_addr, &target, 0);
    338 
    339         if (session == 0) {
    340                 logging_error("Failed to connect to SDP server at " << ba2string(&target) <<".");
     321        logging_debug("querying services from bt device " << ba2string(&target));
     322        session = sdp_connect(BDADDR_ANY, &target, 0);
     323
     324        if (session == NULL) {
     325                logging_error("failed to connect to SDP server at " << ba2string(&target) <<".");
    341326                return;
    342327        }
     
    356341
    357342                // go through each of the service records
    358                 for (; r; r = r->next) {
     343                for ( ; r != NULL; r = r->next) {
    359344                        sdp_record_t *rec = (sdp_record_t*) r->data;
    360345
     
    368353
    369354                                sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_NAME, (char*)&name, 256);
    370                                 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO1, (char*)&name, 256);
    371                                 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO2, (char*)&name, 256);
    372                                 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO3, (char*)&name, 256);
     355                                sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO1, (char*)&info1, 256);
     356                                sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO2, (char*)&info2, 256);
     357                                sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO3, (char*)&info3, 256);
    373358
    374359                                logging_info("Remote peer name is: " << name);
     
    379364                                // Callback
    380365                                callback->onBootstrapServiceFound(name, info1, info2, info3);
    381 
    382366                        }
    383367                        sdp_record_free(rec);
    384368                }
    385         }
     369        } else {
     370                logging_error("sdp_service_search_attr_req failed with timeout");
     371        }
     372
    386373        sdp_list_free(response_list, 0);
    387374        sdp_list_free(search_list, 0);
    388375        sdp_list_free(attrid_list, 0);
    389376        sdp_close(session);
    390 
    391377}
    392378
     
    395381         * Returns a string holding the bt adress in human readable form.
    396382         */
    397         char *str;
     383        char addr[32] = { 0 };
     384        char str[32] = { 0 };
    398385        ba2str(ba, str);
    399386        string result = str;
  • source/ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.h

    r4970 r5316  
    4444#include <iostream>
    4545#include <string>
     46#include <ctime>
    4647#include <boost/bind.hpp>
    4748#include <boost/asio.hpp>
     
    9495        boost::asio::deadline_timer scan_timer_;
    9596        boost::thread t_;
    96 
    9797};
    9898
  • source/ariba/utility/bootstrap/modules/periodicbroadcast

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.cpp

    r4934 r5316  
    6666        : BootstrapModule(_callback),
    6767        server(io_service, &newRemoteServices, &newRemoteServicesMutex) {
    68 
    6968}
    7069
  • source/ariba/utility/configuration/Configuration.cpp

    r3690 r5316  
    5151void Configuration::setConfigFilename(string filename){
    5252        CONFIG_FILE = filename;
    53         instance().reload();
     53        if(haveConfig())
     54                instance().reload();
    5455}
    5556
    5657Configuration::~Configuration(){
    5758        delete config;
     59}
     60
     61bool Configuration::haveConfig(){
     62        std::ifstream in( CONFIG_FILE.c_str() );
     63        if( !in ) return false;
     64
     65        in.close();
     66        return true;
    5867}
    5968
     
    6473
    6574bool Configuration::exists(const string& name){
     75        if(config == NULL) return false;
    6676        return config->keyExists( name );
    6777}
  • source/ariba/utility/configuration/Configuration.h

    r3690 r5316  
    6363        static Configuration& instance();
    6464        static void setConfigFilename(string filename);
     65        static bool haveConfig();
    6566
    6667        /**
  • source/ariba/utility/misc/OvlVis.cpp

    r3690 r5316  
    5050OvlVis::OvlVis() : socket(io_service), socketOpened(false) {
    5151
     52        if( ! Configuration::haveConfig() ) return;
    5253        if( ! Configuration::instance().exists("DEMO_OvlVisIP") )   return;
    5354        if( ! Configuration::instance().exists("DEMO_OvlVisPort") ) return;
  • source/ariba/utility/system/StartupWrapper.cpp

    r5289 r5316  
    9898        {
    9999                log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
    100                 logger->setLevel(log4cxx::Level::getError());
     100                logger->setLevel(log4cxx::Level::getWarn());
    101101        }
    102102
     
    107107        }
    108108        {
    109                 log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseCommunication"));
    110                 logger->setLevel(log4cxx::Level::getError());
     109//              log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseCommunication"));
     110//              logger->setLevel(log4cxx::Level::getError());
    111111        }
    112112
    113113        //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    114         // DON'T SVN COMMIT YOUR CHANTED LOGGING! THE ABOVE CODE MUST REMAIN AS IS!
     114        // DON'T SVN COMMIT YOUR CHANGED LOGGING! THE ABOVE CODE MUST REMAIN AS IS!
    115115        //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    116116}
  • source/ariba/utility/system/SystemQueue.cpp

    r4721 r5316  
    226226                        // call the queue and this will
    227227                        // call the actual event handler
     228                        obj->queueMutex.unlock();
    228229                        obj->onNextQueueItem( ev );
     230                        obj->queueMutex.lock();
    229231
    230232                } // !obj->eventsQueue.empty() )
Note: See TracChangeset for help on using the changeset viewer.