author | wimpie <wimpie> | 2005-01-04 01:42:25 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-04 01:42:25 (UTC) |
commit | 2487b0a05f502e7410715460f390cc80e7e76fd9 (patch) (side-by-side diff) | |
tree | 430dce90a1bdff8eb85cbf1004db094ab6653ab9 /noncore/settings/networksettings2/opietooth2/OTDriverList.cpp | |
parent | e2094d408c9102f8866aafbe725a65f25fdef063 (diff) | |
download | opie-2487b0a05f502e7410715460f390cc80e7e76fd9.zip opie-2487b0a05f502e7410715460f390cc80e7e76fd9.tar.gz opie-2487b0a05f502e7410715460f390cc80e7e76fd9.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTDriverList.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/opietooth2/OTDriverList.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp b/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp new file mode 100644 index 0000000..f703834 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (C) 2003 by Mattia Merzi * + * ottobit@ferrara.linux.it * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include <malloc.h> +#include <bluezlib.h> + +#include <opie2/odebug.h> + +#include <OTDriverList.h> +#include <OTGateway.h> +#include <OTDriver.h> + +using namespace Opietooth2; + +OTDriverList::OTDriverList( OTGateway * _OT ) : QVector<OTDriver>() { + + OT = _OT; + setAutoDelete( true ); +} + +OTDriverList::~OTDriverList() { +} + +void OTDriverList::update() { + + struct hci_dev_list_req *dl; + struct hci_dev_req *dr; + struct hci_dev_info di; + int cur; + + dl = 0; + cur = 0; + do { + cur += 5; + + dl = (struct hci_dev_list_req*) + ::realloc( dl, sizeof( struct hci_dev_list_req ) + + ( cur * sizeof(struct hci_dev_req) ) + ); + + if( dl == 0 ) { + // memory problem + exit(1); + } + + dl->dev_num = cur; + + if( ioctl( OT->getSocket(), HCIGETDEVLIST, (void*)dl) ) { + owarn << "WARNING : cannot read device list. " + << errno + << strerror( errno ) << oendl; + return; + } + + // if num == cur perhaps we did not get all devices yet + } while( dl->dev_num == cur ); + + if( dl->dev_num != count() ) { + // new or missing devices + clear(); + + dr = dl->dev_req; + resize( dl->dev_num ); + + for( cur=0; cur < dl->dev_num; cur ++) { + memset( &di, 0, sizeof( di ) ); + di.dev_id = (dr+cur)->dev_id; + + // get device info + if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) != 0 ) + continue; // uh ? + insert( cur, new OTDriver( OT, &di ) ); + } + + owarn << "Found " << count() << " devices" << oendl; + + ::free( dl ); + } +} |