|
1 /* |
|
2 * Component Name: Headset Simulator |
|
3 * Author: Comarch S.A. |
|
4 * Version: 1.0 |
|
5 * Copyright (c) 2010 Comarch S.A. |
|
6 * |
|
7 * This Software is submitted by Comarch S.A. to Symbian Foundation Limited on |
|
8 * the basis of the Member Contribution Agreement entered between Comarch S.A. |
|
9 * and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be |
|
10 * used only in accordance with the terms and conditions of the Agreement. |
|
11 * Any other usage, duplication or redistribution of this Software is not |
|
12 * allowed without written permission of Comarch S.A. |
|
13 * |
|
14 */ |
|
15 |
|
16 #include "hsrcbttools.h" |
|
17 #include "debug.h" |
|
18 |
|
19 CHsRCDeviceDiscoverer* CHsRCDeviceDiscoverer::NewL( |
|
20 MHsRCDeviceDiscovererObserver* aDeviceObserver, RSocketServ& aSServ ) |
|
21 { |
|
22 CHsRCDeviceDiscoverer *self = CHsRCDeviceDiscoverer::NewLC( |
|
23 aDeviceObserver, aSServ ); |
|
24 CleanupStack::Pop( self ); |
|
25 return self; |
|
26 } |
|
27 |
|
28 CHsRCDeviceDiscoverer* CHsRCDeviceDiscoverer::NewLC( |
|
29 MHsRCDeviceDiscovererObserver* aDeviceObserver, RSocketServ& aSServ ) |
|
30 { |
|
31 CHsRCDeviceDiscoverer *self = new ( ELeave ) CHsRCDeviceDiscoverer( |
|
32 aDeviceObserver, aSServ ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CHsRCDeviceDiscoverer::~CHsRCDeviceDiscoverer() |
|
39 { |
|
40 TRACE_FUNC_ENTRY |
|
41 Cancel(); |
|
42 iHRes.Close(); |
|
43 TRACE_FUNC_EXIT |
|
44 } |
|
45 |
|
46 void CHsRCDeviceDiscoverer::DeviceSearchL() |
|
47 { |
|
48 TRACE_FUNC_ENTRY |
|
49 |
|
50 Cancel(); |
|
51 ConnectHostResolverL(); |
|
52 iSearching = ETrue; |
|
53 iHRes.GetByAddress( iSockAddr, iEntry, iStatus ); |
|
54 SetActive(); |
|
55 |
|
56 TRACE_FUNC_EXIT |
|
57 } |
|
58 |
|
59 TBTDevAddr CHsRCDeviceDiscoverer::GetBTDevAddress() |
|
60 { |
|
61 return iDevAddr; |
|
62 } |
|
63 |
|
64 CHsRCDeviceDiscoverer::CHsRCDeviceDiscoverer( |
|
65 MHsRCDeviceDiscovererObserver* aDeviceObserver, RSocketServ& aSServ ) : |
|
66 CActive( EPriorityNormal ), iSServ( aSServ ), iDeviceObserver( |
|
67 aDeviceObserver ) |
|
68 { |
|
69 CActiveScheduler::Add( this ); |
|
70 } |
|
71 |
|
72 void CHsRCDeviceDiscoverer::ConstructL() |
|
73 { |
|
74 } |
|
75 |
|
76 void CHsRCDeviceDiscoverer::ConnectHostResolverL() |
|
77 { |
|
78 |
|
79 TRACE_FUNC_ENTRY |
|
80 TProtocolDesc protDesc; |
|
81 _LIT(KHsProtocolName,"BTLinkManager"); |
|
82 TProtocolName protName( KHsProtocolName ); |
|
83 |
|
84 User::LeaveIfError( iSServ.FindProtocol( protName, protDesc ) ); |
|
85 User::LeaveIfError( iHRes.Open( iSServ, protDesc.iAddrFamily, |
|
86 protDesc.iProtocol ) ); |
|
87 iSockAddr.SetIAC( KGIAC ); |
|
88 iSockAddr.SetAction( KHostResInquiry | KHostResName ); |
|
89 |
|
90 TRACE_FUNC_EXIT |
|
91 |
|
92 } |
|
93 |
|
94 void CHsRCDeviceDiscoverer::RunL() |
|
95 { |
|
96 TRACE_FUNC_ENTRY |
|
97 TRACE_ERROR((_L("iStatus value = %d"), iStatus.Int())) |
|
98 |
|
99 if ( iStatus.Int() == KErrNone ) |
|
100 { |
|
101 |
|
102 //dev found |
|
103 TInquirySockAddr& sockAddr = TInquirySockAddr::Cast( iEntry().iAddr ); |
|
104 |
|
105 TBuf <KDevAddrLength> devAddrBuf; |
|
106 TBuf <KMaxBluetoothNameLen> devNameBuf; |
|
107 |
|
108 sockAddr.BTAddr().GetReadable( devAddrBuf ); |
|
109 devNameBuf.Copy( iEntry().iName ); |
|
110 |
|
111 TBuf8 <KDevAddrLength> addrBuf8; |
|
112 TBuf8 <KMaxBluetoothNameLen> nameBuf8; |
|
113 |
|
114 addrBuf8.Copy( devAddrBuf ); |
|
115 nameBuf8.Copy( devNameBuf ); |
|
116 |
|
117 if ( iDeviceObserver ) |
|
118 { |
|
119 iDeviceObserver->HandleDeviceFindSuccessL( addrBuf8, nameBuf8, |
|
120 sockAddr.MajorServiceClass(), |
|
121 sockAddr.MajorClassOfDevice(), |
|
122 sockAddr.MinorClassOfDevice() ); |
|
123 } |
|
124 |
|
125 // Get next device |
|
126 iHRes.Next( iEntry, iStatus ); |
|
127 SetActive(); |
|
128 } |
|
129 else |
|
130 { |
|
131 //Inquiry finished or error |
|
132 Cancel(); |
|
133 iHRes.Close(); |
|
134 iSearching = EFalse; |
|
135 |
|
136 if ( iDeviceObserver ) |
|
137 { |
|
138 iDeviceObserver->HandleDeviceFindFailed( iStatus.Int() ); |
|
139 } |
|
140 } |
|
141 TRACE_FUNC_EXIT |
|
142 |
|
143 } |
|
144 |
|
145 void CHsRCDeviceDiscoverer::DoCancel() |
|
146 { |
|
147 TRACE_FUNC_ENTRY |
|
148 |
|
149 if ( iSearching ) |
|
150 { |
|
151 iHRes.Cancel(); |
|
152 iHRes.Close(); |
|
153 } |
|
154 |
|
155 TRACE_FUNC_EXIT |
|
156 |
|
157 } |