|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // BT socket active object helpers |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef BTSOCKETHELPERS_H |
|
19 #define BTSOCKETHELPERS_H |
|
20 |
|
21 |
|
22 #include <bluetooth/btbaseband.h> |
|
23 |
|
24 //============================================================================= |
|
25 //Active Objects |
|
26 // |
|
27 |
|
28 |
|
29 |
|
30 //CBluetoothSocket Active Objects... |
|
31 NONSHARABLE_CLASS(CBTConnecter) : public CActive |
|
32 { |
|
33 public: |
|
34 static CBTConnecter* NewL(CBluetoothSocket& aParent); |
|
35 void Connect(TBTSockAddr& aSockAddr); |
|
36 void Connect(TBTSockAddr& aSockAddr, const TDesC8& aConnectDataOut, TDes8& aConnectDataIn); |
|
37 |
|
38 ~CBTConnecter(); |
|
39 |
|
40 |
|
41 private: |
|
42 CBTConnecter(CBluetoothSocket& aParent); |
|
43 void ConstructL(); |
|
44 void DoCancel(); |
|
45 void RunL(); |
|
46 TInt RunError(TInt aError); |
|
47 TInt BasebandAccessor(); |
|
48 |
|
49 CBluetoothSocket& iParent; |
|
50 RBTBaseband iActiveModeRequester; |
|
51 }; |
|
52 |
|
53 |
|
54 NONSHARABLE_CLASS(CBTAccepter) : public CActive |
|
55 { |
|
56 public: |
|
57 static CBTAccepter* NewL(CBluetoothSocket& aParent, CBluetoothSocket& aBlankSocket); |
|
58 |
|
59 void Accept(); |
|
60 void Accept(TDes8& aConnectData); |
|
61 ~CBTAccepter(); |
|
62 void SetActive(){CActive::SetActive();}; |
|
63 |
|
64 private: |
|
65 CBTAccepter(CBluetoothSocket& aParent, CBluetoothSocket& aBlankSocket); |
|
66 void ConstructL(); |
|
67 void DoCancel(); |
|
68 void RunL(); |
|
69 TInt RunError(TInt aError); |
|
70 void BasebandAccessor(); |
|
71 |
|
72 CBluetoothSocket& iParent; |
|
73 CBluetoothSocket& iBlankSocket; |
|
74 }; |
|
75 |
|
76 |
|
77 |
|
78 NONSHARABLE_CLASS(CBTShutdowner) : public CActive |
|
79 { |
|
80 public: |
|
81 static CBTShutdowner* NewL(CBluetoothSocket& aParent); |
|
82 void Shutdown(RSocket::TShutdown aHow,const TDesC8& aDisconnectDataOut,TDes8& aDisconnectDataIn); |
|
83 void Shutdown(RSocket::TShutdown aHow); |
|
84 void BasebandShutdown(/*TBTDevAddr aAddr*/); |
|
85 ~CBTShutdowner(); |
|
86 |
|
87 |
|
88 private: |
|
89 CBTShutdowner(CBluetoothSocket& aParent); |
|
90 void ConstructL(); |
|
91 void DoCancel(); |
|
92 void RunL(); |
|
93 TInt RunError(TInt aError); |
|
94 |
|
95 CBluetoothSocket& iParent; |
|
96 }; |
|
97 |
|
98 |
|
99 NONSHARABLE_CLASS(CBTSender) : public CActive |
|
100 { |
|
101 public: |
|
102 static CBTSender* NewL(CBluetoothSocket& aParent); |
|
103 ~CBTSender(); |
|
104 |
|
105 void Write(const TDesC8& aDesc); |
|
106 void Send(const TDesC8& aDesc,TUint someFlags); |
|
107 void Send(const TDesC8& aDesc,TUint someFlags,TSockXfrLength& aLen); |
|
108 void SendTo(const TDesC8& aDesc,TSockAddr& aAddr,TUint flags); |
|
109 void SendTo(const TDesC8& aDesc,TSockAddr& aAddr,TUint flags,TSockXfrLength& aLen); |
|
110 |
|
111 |
|
112 private: |
|
113 enum TCurrentRequest |
|
114 { |
|
115 ENone, |
|
116 EWrite, |
|
117 ESend, |
|
118 }; |
|
119 CBTSender(CBluetoothSocket& aParent); |
|
120 void ConstructL(); |
|
121 void DoCancel(); |
|
122 void RunL(); |
|
123 TInt RunError(TInt aError); |
|
124 |
|
125 CBluetoothSocket& iParent; |
|
126 TCurrentRequest iCurrentRequest; |
|
127 }; |
|
128 |
|
129 |
|
130 NONSHARABLE_CLASS(CBTReceiver) : public CActive |
|
131 { |
|
132 public: |
|
133 static CBTReceiver* NewL(CBluetoothSocket& aParent); |
|
134 ~CBTReceiver(); |
|
135 |
|
136 void Read(TDes8& aDesc); |
|
137 void ReadSCOData(const TDesC8& aSCOData, TUint32 aPreferredPacket); |
|
138 void Recv(TDes8& aDesc,TUint flags); |
|
139 void Recv(TDes8& aDesc,TUint flags,TSockXfrLength& aLen); |
|
140 void RecvOneOrMore(TDes8& aDesc,TUint flags,TSockXfrLength& aLen); |
|
141 void RecvFrom(TDes8& aDesc,TSockAddr& aAddr,TUint flags); |
|
142 void RecvFrom(TDes8& aDesc,TSockAddr& aAddr,TUint flags,TSockXfrLength& aLen); |
|
143 |
|
144 |
|
145 private: |
|
146 enum TCurrentRequest |
|
147 { |
|
148 ENone, |
|
149 ERead, |
|
150 ERecv, |
|
151 }; |
|
152 CBTReceiver(CBluetoothSocket& aParent); |
|
153 void ConstructL(); |
|
154 void DoCancel(); |
|
155 void RunL(); |
|
156 TInt RunError(TInt aError); |
|
157 |
|
158 CBluetoothSocket& iParent; |
|
159 TCurrentRequest iCurrentRequest; |
|
160 }; |
|
161 |
|
162 |
|
163 NONSHARABLE_CLASS(CBTIoctler) : public CActive |
|
164 { |
|
165 public: |
|
166 static CBTIoctler* NewL(CBluetoothSocket& aParent); |
|
167 ~CBTIoctler(); |
|
168 |
|
169 void Ioctl(TUint aCommand, TDes8* aDesc=NULL, TUint aLevel=KLevelUnspecified); |
|
170 |
|
171 private: |
|
172 CBTIoctler(CBluetoothSocket& aParent); |
|
173 void ConstructL(); |
|
174 void DoCancel(); |
|
175 void RunL(); |
|
176 TInt RunError(TInt aError); |
|
177 |
|
178 CBluetoothSocket& iParent; |
|
179 }; |
|
180 |
|
181 |
|
182 NONSHARABLE_CLASS(MBTBasebandHandler) |
|
183 { |
|
184 public: |
|
185 virtual RBTBaseband& MbbhBTBaseband() = 0; |
|
186 virtual void MbbhHandleActivateBasebandEventNotifierCompleteL(TInt aErr, TBTBasebandEventNotification& aEventNotification) = 0; |
|
187 virtual TInt MbbhOpen(RSocketServ& aSocketServ, RSocket& aSocket) = 0; |
|
188 virtual void MbbhClose() = 0; |
|
189 }; |
|
190 |
|
191 NONSHARABLE_CLASS(CBTBasebandChangeEventNotifier) : public CActive |
|
192 { |
|
193 public: |
|
194 static CBTBasebandChangeEventNotifier* NewL(MBTBasebandHandler& aUser); |
|
195 ~CBTBasebandChangeEventNotifier(); |
|
196 |
|
197 void SetNotifyNextModeChange(); |
|
198 void SetNotify(TUint32 aNotifications); |
|
199 |
|
200 |
|
201 private: |
|
202 CBTBasebandChangeEventNotifier(MBTBasebandHandler& aUser); |
|
203 void ConstructL(); |
|
204 //void SetNotify(TUint32 aNotifications); |
|
205 void RunL(); |
|
206 TInt RunError(TInt aError); |
|
207 void DoCancel(); |
|
208 |
|
209 private: |
|
210 MBTBasebandHandler& iUser; |
|
211 TUint iCurrentRequest; |
|
212 TBTBasebandEvent iEvent; |
|
213 }; |
|
214 |
|
215 |
|
216 NONSHARABLE_CLASS(CAutoSniffDelayTimer) : public CTimer, |
|
217 public MBTBasebandHandler |
|
218 /** |
|
219 This class provides a timer which when it expires requests Sniff Mode. |
|
220 **/ |
|
221 { |
|
222 public: |
|
223 static CAutoSniffDelayTimer* NewL(CBluetoothSocket& aParent, TInt aIdleSecondsBeforeSniffRequest); |
|
224 ~CAutoSniffDelayTimer(); |
|
225 |
|
226 void Start(); |
|
227 void StartActive(); |
|
228 |
|
229 virtual RBTBaseband& MbbhBTBaseband(); |
|
230 virtual void MbbhHandleActivateBasebandEventNotifierCompleteL(TInt aErr, TBTBasebandEventNotification& aEventNotification); |
|
231 virtual TInt MbbhOpen(RSocketServ& aSocketServ, RSocket& aSocket); |
|
232 virtual void MbbhClose(); |
|
233 |
|
234 |
|
235 private: |
|
236 CAutoSniffDelayTimer(CBluetoothSocket& aParent, TInt aIdleSecondsBeforeSniffRequest); |
|
237 void ConstructL(); |
|
238 void RunL(); |
|
239 TInt MakeSniffRequest(); |
|
240 |
|
241 private: |
|
242 CBluetoothSocket& iParent; |
|
243 RBTBaseband iBTAutoSniffBaseband; |
|
244 CBTBasebandChangeEventNotifier* iBTAutoSniffBasebandChangeEventNotifier; |
|
245 TTimeIntervalMicroSeconds32 iAutoSniffDelay; |
|
246 TBool iSniffModeRequested; |
|
247 }; |
|
248 |
|
249 |
|
250 NONSHARABLE_CLASS(CBTBasebandManager) : public CBase |
|
251 /** |
|
252 This class manages all basebands in order to keep them in step. |
|
253 **/ |
|
254 { |
|
255 public: |
|
256 static CBTBasebandManager* NewL(); |
|
257 ~CBTBasebandManager(); |
|
258 |
|
259 TInt RegisterBTBaseband(MBTBasebandHandler& aBasebandHandler); |
|
260 TInt UnRegisterBTBaseband(MBTBasebandHandler& aBasebandHandler); |
|
261 TInt HandleConnectionUp(RSocketServ& aSocketServ, RSocket& aSocket); |
|
262 void HandleConnectionDown(); |
|
263 TBool Connected() const; |
|
264 |
|
265 private: |
|
266 void ConstructL(); |
|
267 CBTBasebandManager(); |
|
268 void CloseAllBasebands(); |
|
269 |
|
270 private: |
|
271 TBool iConnected; |
|
272 RSocketServ* iSocketServ; |
|
273 RSocket* iSocket; |
|
274 |
|
275 // unowned |
|
276 RPointerArray<MBTBasebandHandler> iBasebandHandlers; |
|
277 }; |
|
278 |
|
279 NONSHARABLE_CLASS(CBTBasebandChangeEventDelegate) : public CBase, |
|
280 public MBTBasebandHandler |
|
281 /** |
|
282 This class provides CBluetoothSocket a proxy to access virtual functions in MBTBasebandHandler |
|
283 **/ |
|
284 { |
|
285 public: |
|
286 static CBTBasebandChangeEventDelegate* NewL(CBluetoothSocket& Parent); |
|
287 |
|
288 virtual RBTBaseband& MbbhBTBaseband(); |
|
289 virtual void MbbhHandleActivateBasebandEventNotifierCompleteL(TInt aErr, TBTBasebandEventNotification& aEventNotification); |
|
290 virtual TInt MbbhOpen(RSocketServ& aSocketServ, RSocket& aSocket); |
|
291 virtual void MbbhClose(); |
|
292 |
|
293 private: |
|
294 CBTBasebandChangeEventDelegate(CBluetoothSocket& Parent); |
|
295 void ConstructL(); |
|
296 |
|
297 private: |
|
298 CBluetoothSocket& iParent; |
|
299 }; |
|
300 |
|
301 #endif |
|
302 |