author | mickeyl <mickeyl> | 2005-07-14 10:34:55 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-07-14 10:34:55 (UTC) |
commit | 237cf3ec5134e299a9da0ce7deb533383f3d11f0 (patch) (side-by-side diff) | |
tree | 299215ea1616d3625b7294744ecfebbb2b0b1d7e /libopie2/opiebluez/obluetooth.cpp | |
parent | 27646acf1280d2644b740d0fea03723030aa19cf (diff) | |
download | opie-237cf3ec5134e299a9da0ce7deb533383f3d11f0.zip opie-237cf3ec5134e299a9da0ce7deb533383f3d11f0.tar.gz opie-237cf3ec5134e299a9da0ce7deb533383f3d11f0.tar.bz2 |
- add bool OBluetoothInterface::setUp( bool )
- add void OBluetoothInterface::isUp() const
Diffstat (limited to 'libopie2/opiebluez/obluetooth.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiebluez/obluetooth.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/libopie2/opiebluez/obluetooth.cpp b/libopie2/opiebluez/obluetooth.cpp index b5df96e..c99a822 100644 --- a/libopie2/opiebluez/obluetooth.cpp +++ b/libopie2/opiebluez/obluetooth.cpp @@ -101,49 +101,59 @@ void OBluetooth::synchronize() return; } dl->dev_num = HCI_MAX_DEV; dr = dl->dev_req; - if (ioctl( _fd, HCIGETDEVLIST, (void *) dl) == -1) + if (::ioctl( _fd, HCIGETDEVLIST, (void *) dl) == -1) { owarn << "OBluetooth::synchronize() - can't complete HCIGETDEVLIST (" << strerror( errno ) << ")" << oendl; return; } for ( int i = 0; i < dl->dev_num; ++i ) { di.dev_id = ( dr + i )->dev_id; - if ( ioctl( _fd, HCIGETDEVINFO, (void *) &di) == -1 ) + if ( ::ioctl( _fd, HCIGETDEVINFO, (void *) &di ) == -1 ) { owarn << "OBluetooth::synchronize() - can't issue HCIGETDEVINFO on device " << i << " (" << strerror( errno ) << ") - skipping that device. " << oendl; continue; } odebug << "OBluetooth::synchronize() - found device #" << di.dev_id << oendl; - _interfaces.insert( di.name, new OBluetoothInterface( this, di.name, (void*) &di ) ); + _interfaces.insert( di.name, new OBluetoothInterface( this, di.name, (void*) &di, _fd ) ); } } /*====================================================================================== * OBluetoothInterface *======================================================================================*/ class OBluetoothInterface::Private { public: - Private( struct hci_dev_info* di ) + Private( struct hci_dev_info* di, int fd ) { ::memcpy( &devinfo, di, sizeof(struct hci_dev_info) ); + ctlfd = fd; + } + void reloadInfo() + { + int result = ::ioctl( ctlfd, HCIGETDEVINFO, (void *) &devinfo ); + if ( result == -1 ) + { + owarn << "OBluetoothInterface::Private - can't reload device info (" << strerror( errno ) << ")" << oendl; + } } struct hci_dev_info devinfo; + int ctlfd; }; -OBluetoothInterface::OBluetoothInterface( QObject* parent, const char* name, void* devinfo ) +OBluetoothInterface::OBluetoothInterface( QObject* parent, const char* name, void* devinfo, int ctlfd ) :QObject( parent, name ) { - d = new OBluetoothInterface::Private( (struct hci_dev_info*) devinfo ); + d = new OBluetoothInterface::Private( (struct hci_dev_info*) devinfo, ctlfd ); } OBluetoothInterface::~OBluetoothInterface() { } @@ -155,9 +165,30 @@ QString OBluetoothInterface::macAddress() const d->devinfo.bdaddr.b[3], d->devinfo.bdaddr.b[2], d->devinfo.bdaddr.b[1], d->devinfo.bdaddr.b[0] ); } +bool OBluetoothInterface::setUp( bool b ) +{ + int cmd = b ? HCIDEVUP : HCIDEVDOWN; + int result = ::ioctl( d->ctlfd, cmd, d->devinfo.dev_id ); + if ( result == -1 && errno != EALREADY ) + { + owarn << "OBluetoothInterface::setUp( " << b << " ) - couldn't change interface state (" << strerror( errno ) << ")" << oendl; + return false; + } + else + { + d->reloadInfo(); + return true; + } +} + +bool OBluetoothInterface::isUp() const +{ + return hci_test_bit( HCI_UP, &d->devinfo.flags ); +} + } } |