summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp
authorwimpie <wimpie>2005-01-04 01:42:25 (UTC)
committer wimpie <wimpie>2005-01-04 01:42:25 (UTC)
commit2487b0a05f502e7410715460f390cc80e7e76fd9 (patch) (unidiff)
tree430dce90a1bdff8eb85cbf1004db094ab6653ab9 /noncore/settings/networksettings2/opietooth2/OTDriverList.cpp
parente2094d408c9102f8866aafbe725a65f25fdef063 (diff)
downloadopie-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.cpp86
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 @@
1/***************************************************************************
2 * Copyright (C) 2003 by Mattia Merzi *
3 * ottobit@ferrara.linux.it *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10
11#include <malloc.h>
12#include <bluezlib.h>
13
14#include <opie2/odebug.h>
15
16#include <OTDriverList.h>
17#include <OTGateway.h>
18#include <OTDriver.h>
19
20using namespace Opietooth2;
21
22OTDriverList::OTDriverList( OTGateway * _OT ) : QVector<OTDriver>() {
23
24 OT = _OT;
25 setAutoDelete( true );
26}
27
28OTDriverList::~OTDriverList() {
29}
30
31void OTDriverList::update() {
32
33 struct hci_dev_list_req *dl;
34 struct hci_dev_req *dr;
35 struct hci_dev_info di;
36 int cur;
37
38 dl = 0;
39 cur = 0;
40 do {
41 cur += 5;
42
43 dl = (struct hci_dev_list_req*)
44 ::realloc( dl, sizeof( struct hci_dev_list_req ) +
45 ( cur * sizeof(struct hci_dev_req) )
46 );
47
48 if( dl == 0 ) {
49 // memory problem
50 exit(1);
51 }
52
53 dl->dev_num = cur;
54
55 if( ioctl( OT->getSocket(), HCIGETDEVLIST, (void*)dl) ) {
56 owarn << "WARNING : cannot read device list. "
57 << errno
58 << strerror( errno ) << oendl;
59 return;
60 }
61
62 // if num == cur perhaps we did not get all devices yet
63 } while( dl->dev_num == cur );
64
65 if( dl->dev_num != count() ) {
66 // new or missing devices
67 clear();
68
69 dr = dl->dev_req;
70 resize( dl->dev_num );
71
72 for( cur=0; cur < dl->dev_num; cur ++) {
73 memset( &di, 0, sizeof( di ) );
74 di.dev_id = (dr+cur)->dev_id;
75
76 // get device info
77 if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) != 0 )
78 continue; // uh ?
79 insert( cur, new OTDriver( OT, &di ) );
80 }
81
82 owarn << "Found " << count() << " devices" << oendl;
83
84 ::free( dl );
85 }
86}