summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTInquiry.h
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTInquiry.h') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTInquiry.h178
1 files changed, 178 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTInquiry.h b/noncore/settings/networksettings2/opietooth2/OTInquiry.h
new file mode 100644
index 0000000..f7bdeec
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTInquiry.h
@@ -0,0 +1,178 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#ifndef OTINQUIRY_H
13#define OTINQUIRY_H
14
15#include <qstring.h>
16#include <qobject.h>
17
18#include <qguardedptr.h>
19#include <qtimer.h>
20
21#include <OTPeer.h>
22
23// #include <set>
24// #include <deque>
25
26namespace Opietooth2 {
27
28class QSocket;
29class QDateTime;
30
31class OTDriver;
32class OTHCISocket;
33
34/** Scans for nearby bluetooth devices.
35 * This class provides an asynchronous interface to the
36 * inquriy HCI command. To scan for other devices, connect
37 * to the signals neighbourFound() and finished() and call
38 * inquiry(). Inquiry results are signalled as soon as they arrive,
39 * so the information can be displayed before the whole inquiry
40 * process is finished.
41 * Still no connections should be set up before
42 * the finished() signal was sent (hmm, is this always true..?)
43 */
44
45class OTInquiry : public QObject {
46
47 Q_OBJECT
48
49public:
50
51 /** Constructor.
52 @param owner The owning parent object
53 */
54 OTInquiry( OTDriver* Drv );
55
56 /** Destructor. */
57 virtual ~OTInquiry();
58
59 // General/Unlimited Inquiry Access Code
60 static const int GIAC = 0x9E8B33;
61
62 // Limited Dedicated Inquiry Access Code
63 static const int LIAC = 0x9E8B00;
64
65 /** Starts the inquiry.
66 if you start inquiry several times without calling clear(),
67 you will receive each result only once.
68 @param timeout duration of the inquiry in seconds.
69 It will be rounded to the next multiple of 1.28 sec,
70 with a maximum of 61.44 sec.
71 @param lap
72 */
73 bool inquire( double timeout = 8.0,
74 int numResponses = 0,
75 int lap = GIAC);
76
77 void stopInquiring( );
78
79 /** Enters periodic inquiry mode.
80 An inquiry will be started at a random time in the intervall
81 between minduration and maxduration.
82 @param minduration minimum time between two inquiries. Rounded to
83 a multiple of 1.28, (3.84 <= d <= 83884.8)
84 @param maxduration maximum time between two inquiries. Rounded to
85 a multiple of 1.28, (3.84 <= d <= 83884.8)
86 @param timeout duration of the inquiry in seconds.
87 It will be rounded to the next multiple of 1.28 sec,
88 with a maximum of 61.44 sec.
89 @param numResponses Number of responses after which the inquiry
90 will be stopped. 0 means no limit.
91 @param lap
92 */
93 /*
94 void inquirePeriodically( double minduration,
95 double maxduration,
96 double timeout = 8.0,
97 int numResponses = 0,
98 int lap = LIAC
99 );
100*/
101 /** checks if there the inquiry is running currently
102 @return true if there is an inquiry running
103 which was started by this object.
104 @todo possibility to check for "foreign" inquiries. Deal with
105 the fact that we can receive foreign inquiry results.
106 */
107 bool isInquiring();
108
109 /** This function returns true after after an inquiry was
110 started, results were received and the inquiry ended successfully.
111 This can be the case without calling inquiry() at all, because
112 results of inquiries started by other programs are also processed.
113 */
114 bool isFinished();
115
116 /** Resets the list of received results and sets
117 isInquiryComplete() to false.
118 */
119 void reset();
120
121 inline OTDriver * driver() const
122 { return Driver; }
123
124protected:
125
126 /** Called when a new neighbour was found. The default
127 implementation emits the neighbourFound signal.
128 @param bdaddr the address found.
129 */
130 virtual void onPeerFound( OTPeer * Peer, bool );
131
132 enum ErrorCode {
133 InquiryFinishedTimeout = 0x0100
134 };
135
136signals :
137
138 void peerFound( OTPeer *, bool );
139
140 /** Emitted after an inquiry has finished successfully.
141 If the inquiry was canceled, no finished signals is emitted.
142 This signal can be emitted without having called inquiry, since
143 other processes may have started an inquiry.
144 */
145 void finished();
146
147 /** Emitted instead of finished if an error occured after
148 calling inquiry() or periodicInquiryMode()
149 @param code error code.
150 @param message Error message
151 */
152 void error( QString message );
153
154private:
155
156 // std::set<DeviceAddress> addrCache;
157 // double currentTimeout;
158 // QByteArray* buf;
159 // QSocket* hciSocket;
160 QGuardedPtr<OTHCISocket> Socket;
161 OTDriver * Driver;
162
163 //QDateTime *startTime;
164 QTimer *InquiryTimeoutTimer;
165
166 // std::deque<InquiryInfo> infoQueue;
167 bool SuccessfullyStarted;
168 bool SuccessfullyEnded;
169
170private slots:
171
172 void slotInquiryTimeout();
173 void slotHCIEvent(unsigned char eventCode, QByteArray buf);
174
175};
176
177}
178#endif