BluetoothAnnounce.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Baylor University
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #include <config.h>
00018 
00019 #ifdef OASYS_BLUETOOTH_ENABLED
00020 
00021 #include <oasys/util/OptParser.h>
00022 #include <oasys/bluez/Bluetooth.h>
00023 #include "contacts/ContactManager.h"
00024 #include "bundling/BundleDaemon.h"
00025 #include "conv_layers/BluetoothConvergenceLayer.h"
00026 
00027 #include "BluetoothAnnounce.h"
00028 
00029 namespace dtn {
00030 
00031 BluetoothAnnounce::BluetoothAnnounce()
00032     : sdp_reg_(BundleDaemon::instance()->local_eid().c_str())
00033 {
00034     oasys::Bluetooth::hci_get_bdaddr(&cl_addr_);
00035 }
00036 
00037 bool
00038 BluetoothAnnounce::configure(const std::string& name, ConvergenceLayer* cl,
00039                              int argc, const char* argv[])
00040 {
00041     cl_ = cl;
00042     name_ = name;
00043     type_.assign(cl->name());
00044 
00045     oasys::OptParser p;
00046     p.addopt(new oasys::BdAddrOpt("cl_addr",&cl_addr_));
00047     bool setinterval = false;
00048     p.addopt(new oasys::UIntOpt("interval",&interval_,"","",&setinterval));
00049     cl_channel_ = BluetoothConvergenceLayer::BTCL_DEFAULT_CHANNEL;
00050     //p.addopt(new oasys::UInt8Opt("cl_channel",&cl_channel_));
00051     const char* invalid;
00052     if (! p.parse(argc, argv, &invalid))
00053     {
00054         log_err("bad parameter %s",invalid);
00055         return false;
00056     }
00057 
00058     if (! setinterval)
00059     {
00060         log_err("required parameter missing: interval");
00061         return false;
00062     }
00063     else
00064     {
00065         // convert to milliseconds
00066         interval_ *= 1000;
00067     }
00068 
00069     local_.assign(bd2str(cl_addr_));
00070     return true;
00071 }
00072 
00073 size_t
00074 BluetoothAnnounce::format_advertisement(u_char*,size_t)
00075 {
00076     return 0;
00077 }
00078 
00079 void
00080 BluetoothAnnounce::handle_neighbor_discovered(const std::string& nexthop,
00081                                               const EndpointID& remote_eid)
00082 {
00083     (void)remote_eid;
00084     (void)nexthop;
00085     bdaddr_t remote_addr;
00086     oasys::Bluetooth::strtoba(nexthop.c_str(),&remote_addr);
00087 
00088     ASSERT(type() == "bt");
00089 
00090     ContactManager* cm = BundleDaemon::instance()->contactmgr();
00091     Link* link = cm->find_link_to(cl_, "", remote_eid);
00092     if (link != NULL)
00093         return; // log something? send up signal regardless?
00094 
00095     BluetoothConvergenceLayer* btcl = 
00096         dynamic_cast<BluetoothConvergenceLayer*>(cl_);
00097 
00098     BluetoothConvergenceLayer::BluetoothLinkParams* params =
00099         dynamic_cast<BluetoothConvergenceLayer::BluetoothLinkParams*>
00100             (btcl->new_link_params());
00101 
00102     bacpy(&params->remote_addr_,&remote_addr);
00103 
00104     CLConnection* conn = btcl->new_connection(params);
00105     conn->start();
00106 }
00107 
00108 } // dtn
00109 
00110 #endif // OASYS_BLUETOOTH_ENABLED

Generated on Sat Sep 8 08:36:15 2007 for DTN Reference Implementation by  doxygen 1.5.3