|
1 /* |
|
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Name : CBtClient.h |
|
16 * Part of : ex_btsocket |
|
17 * Created : 17/11/2004 by Shane Kearns |
|
18 * Client "smart connector" class |
|
19 * Version : |
|
20 * |
|
21 * |
|
22 */ |
|
23 |
|
24 |
|
25 |
|
26 #ifndef CBTCLIENT_H |
|
27 #define CBTCLIENT_H |
|
28 |
|
29 #include <e32std.h> |
|
30 #include <bt_sock.h> |
|
31 #include <btsdp.h> |
|
32 #include "exbtutil.h" |
|
33 #include "mconnectionobserver.h" |
|
34 |
|
35 /** |
|
36 A helper class for parsing the protocol descriptor list SDP attribute, |
|
37 in order to retrieve the protocol and port required for connecting |
|
38 */ |
|
39 class TBtClientSdpProtocolListParser : public MSdpAttributeValueVisitor |
|
40 { |
|
41 public: |
|
42 TBtClientSdpProtocolListParser(); |
|
43 private: |
|
44 //virtual functions from MSdpAttributeValueVisitor |
|
45 virtual void VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType); |
|
46 virtual void StartListL(CSdpAttrValueList &aList); |
|
47 virtual void EndListL(); |
|
48 |
|
49 public: |
|
50 //data members |
|
51 TUint iPort; |
|
52 TUUID iProtocol; |
|
53 enum |
|
54 { |
|
55 EFoundPort = 0x1, |
|
56 EFoundProtocol = 0x2, |
|
57 }; |
|
58 TUint iFoundFlags; |
|
59 }; |
|
60 |
|
61 /** |
|
62 This class implements a simple bluetooth application client. |
|
63 Its responsibility is to make outgoing bluetooth connections. |
|
64 Most of the complexity in this class deals with using the SDP agent API to |
|
65 retrieve connection parameters from the remote device. |
|
66 */ |
|
67 class CBtClient : public CActive, MSdpAgentNotifier |
|
68 { |
|
69 public: |
|
70 IMPORT_C static CBtClient* NewL(const TUUID& aServiceUUID, RSocketServ& aSocketServer, MConnectionObserver& aOwner, TBTServiceSecurity* aSecurityRequirements = NULL); |
|
71 IMPORT_C ~CBtClient(); |
|
72 |
|
73 IMPORT_C void ConnectToRemoteDeviceL(MBluetoothSocketNotifier& aSocketOwner); |
|
74 IMPORT_C void ConnectToRemoteDeviceL(TBTDevAddr& aAddr, MBluetoothSocketNotifier& aSocketOwner); |
|
75 private: |
|
76 void ConstructL(TBTServiceSecurity* aSecurityRequirements); |
|
77 CBtClient(const TUUID& aServiceUUID, RSocketServ& aSocketServer, MConnectionObserver& aOwner); |
|
78 |
|
79 void ConnectFailed(TInt aError); |
|
80 void NewConnection(); |
|
81 void AttemptConnection(TUUID aProtocol, TUint16 aPort); |
|
82 |
|
83 void CallOut(TInt aErr); |
|
84 //virtual functions from CActive |
|
85 virtual void RunL(); |
|
86 virtual void DoCancel(); |
|
87 |
|
88 //Virtual functions from MSdpAgentNotifier |
|
89 virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount); |
|
90 virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue); |
|
91 virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError); |
|
92 |
|
93 //Data members |
|
94 /** A socket created in order to make a connection */ |
|
95 CBluetoothSocket *iConnectionSocket; |
|
96 /** Handle to the socket server*/ |
|
97 RSocketServ& iSocketServer; |
|
98 /** SDP UUID of the service to find */ |
|
99 TUUID iServiceUUID; |
|
100 /** SDP agent for performing service search */ |
|
101 CSdpAgent *iSdpAgent; |
|
102 /** 48 bit Bluetooth address of the device selected to connect to */ |
|
103 TBTDevAddr iConnectingToDevice; |
|
104 /** Security requirements specified by the application */ |
|
105 TBTServiceSecurity iSecurityRequirements; |
|
106 /** Handle to an application object - callbacks are sent here */ |
|
107 MConnectionObserver& iOwner; |
|
108 /** Helper class for parsing SDP results */ |
|
109 TBtClientSdpProtocolListParser iParser; |
|
110 /** Handle to an application object - the socket is created with this as owner*/ |
|
111 MBluetoothSocketNotifier* iSocketOwner; //not owned |
|
112 /** Buffer for formatting a socket address*/ |
|
113 TL2CAPSockAddr iAddrL2CAP; |
|
114 /** Buffer for formatting a socket address*/ |
|
115 TRfcommSockAddr iAddrRFCOMM; |
|
116 }; |
|
117 |
|
118 #endif //CBTCLIENT_H |