BluetoothInquiry.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 #ifdef OASYS_BLUETOOTH_ENABLED
00019 
00020 #include <stdlib.h>
00021 #include <sys/types.h>
00022 #include <sys/fcntl.h>
00023 #include <sys/socket.h>
00024 
00025 #include "Bluetooth.h"
00026 #include "BluetoothInquiry.h"
00027 
00028 namespace oasys {
00029 
00030 BluetoothInquiry::BluetoothInquiry(const char * logbase)
00031     : Logger("BluetoothInquiry", logbase),
00032       num_responses_i_(-1),
00033       pos_(0),
00034       flags_(0L)
00035 {
00036     memset(&info_[0],0,sizeof(inquiry_info)*BT_INQ_NUM_RESP);
00037 }
00038 
00039 BluetoothInquiry::~BluetoothInquiry()
00040 {
00041 }
00042 
00043 int
00044 BluetoothInquiry::inquire()
00045 {
00046     // set dev_id to -1 to have BlueZ autodetermine which device
00047     // set len = 8 for default 10.24s duration
00048     // set nrsp = BT_INQ_NUM_RESP to match sizeof(info_)
00049     // Lower Address Part (lap) is ignored (0)
00050     // info_ is return array of inquiry data
00051     // flags_ changes the default inquiry behavior
00052     inquiry_info *ii = &info_[0];
00053     num_responses_i_ = Bluetooth::hci_inquiry(-1,BT_INQ_LENGTH,BT_INQ_NUM_RESP,
00054                                               0,&ii,flags_);
00055     return num_responses_i_;
00056 }
00057 
00058 void
00059 BluetoothInquiry::reset()
00060 {
00061     pos_ = 0;
00062     num_responses_i_ = -1;
00063     memset(&info_[0],0,sizeof(inquiry_info)*BT_INQ_NUM_RESP);
00064     flags_ |= IREQ_CACHE_FLUSH;
00065 }
00066 
00067 int
00068 BluetoothInquiry::first(bdaddr_t& addr)
00069 {
00070     reset();
00071     return next(addr);
00072 }
00073 
00074 int
00075 BluetoothInquiry::next(bdaddr_t& addr)
00076 {
00077     if((pos_ >= num_responses_i_) || 
00078        (bacmp(&(info_[pos_].bdaddr),BDADDR_ANY) == 0))
00079     {
00080         reset();
00081         return -1;
00082     }
00083     log_debug("BluetoothInquiry::next(%d)",pos_);
00084     bacpy(&addr,&(info_[pos_].bdaddr));
00085     pos_++;
00086     return 0;
00087 }
00088 
00089 } // namespace oasys
00090 #endif /* OASYS_BLUETOOTH_ENABLED */

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