|
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 "debug.h" |
|
17 #include "hstools.h" |
|
18 |
|
19 CHsDeviceDiscoverer* CHsDeviceDiscoverer::NewL( |
|
20 MHsDeviceDiscovererObserver* aDeviceObserver, RSocketServ& aSocketServ ) |
|
21 { |
|
22 CHsDeviceDiscoverer *self = CHsDeviceDiscoverer::NewLC( aDeviceObserver, |
|
23 aSocketServ ); |
|
24 CleanupStack::Pop( self ); |
|
25 return self; |
|
26 } |
|
27 |
|
28 CHsDeviceDiscoverer* CHsDeviceDiscoverer::NewLC( |
|
29 MHsDeviceDiscovererObserver* aDeviceObserver, RSocketServ& aSocketServ ) |
|
30 { |
|
31 CHsDeviceDiscoverer *self = new ( ELeave ) CHsDeviceDiscoverer( |
|
32 aDeviceObserver, aSocketServ ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CHsDeviceDiscoverer::CHsDeviceDiscoverer( |
|
39 MHsDeviceDiscovererObserver* aDeviceObserver, |
|
40 RSocketServ& aSocketServ ) : CActive( EPriorityNormal ), |
|
41 iSocketServ( aSocketServ ), iDeviceObserver( |
|
42 aDeviceObserver ) |
|
43 { |
|
44 CActiveScheduler::Add( this ); |
|
45 iSearching = EFalse; |
|
46 } |
|
47 |
|
48 CHsDeviceDiscoverer::~CHsDeviceDiscoverer() |
|
49 { |
|
50 TRACE_FUNC_ENTRY |
|
51 Cancel(); |
|
52 iHostResolver.Close(); |
|
53 TRACE_FUNC_EXIT |
|
54 } |
|
55 |
|
56 void CHsDeviceDiscoverer::ConstructL() |
|
57 { |
|
58 } |
|
59 |
|
60 void CHsDeviceDiscoverer::DeviceSearchL() |
|
61 { |
|
62 TRACE_FUNC_ENTRY |
|
63 Cancel(); |
|
64 |
|
65 ConnectHostResolverL(); |
|
66 iSearching = ETrue; |
|
67 iHostResolver.GetByAddress( iSockAddr, iEntry, iStatus ); |
|
68 SetActive(); |
|
69 |
|
70 TRACE_FUNC_EXIT |
|
71 } |
|
72 |
|
73 void CHsDeviceDiscoverer::ConnectHostResolverL() |
|
74 { |
|
75 TRACE_FUNC_ENTRY |
|
76 TProtocolDesc protDesc; |
|
77 TProtocolName protName( KHsProtocolName ); |
|
78 |
|
79 User::LeaveIfError( iSocketServ.FindProtocol( protName, protDesc ) ); |
|
80 User::LeaveIfError( iHostResolver.Open( iSocketServ, protDesc.iAddrFamily, |
|
81 protDesc.iProtocol ) ); |
|
82 iSockAddr.SetIAC( KGIAC ); |
|
83 iSockAddr.SetAction( KHostResInquiry | KHostResName ); |
|
84 |
|
85 TRACE_FUNC_EXIT |
|
86 } |
|
87 |
|
88 void CHsDeviceDiscoverer::RunL() |
|
89 { |
|
90 TRACE_FUNC_ENTRY |
|
91 |
|
92 TRACE_INFO( (_L("Status value = %d"), iStatus.Int() ) ) |
|
93 if ( iStatus.Int() == KErrNone ) |
|
94 { |
|
95 |
|
96 TInquirySockAddr& sa = TInquirySockAddr::Cast( iEntry().iAddr ); |
|
97 TBuf <KDevAddrLength> devAddrBuf; |
|
98 sa.BTAddr().GetReadable( devAddrBuf ); |
|
99 TBuf8 <KDevAddrLength> devAddrBuf8; |
|
100 devAddrBuf8.Copy( devAddrBuf ); |
|
101 |
|
102 TBuf8 <KMaxBluetoothNameLen> devNameBuf; |
|
103 devNameBuf.Copy( iEntry().iName ); |
|
104 iDeviceObserver->HandleDeviceFindSuccessL( devAddrBuf8, devNameBuf, |
|
105 sa.MajorServiceClass(), sa.MajorClassOfDevice(), |
|
106 sa.MinorClassOfDevice() ); |
|
107 // Get next device if no previous errors |
|
108 iHostResolver.Next( iEntry, iStatus ); |
|
109 SetActive(); |
|
110 } |
|
111 else |
|
112 { |
|
113 Cancel(); |
|
114 iHostResolver.Close(); |
|
115 iSearching = EFalse; |
|
116 if ( iDeviceObserver ) |
|
117 { |
|
118 iDeviceObserver->HandleDeviceFindFailed( iStatus.Int() ); |
|
119 } |
|
120 } |
|
121 TRACE_FUNC_EXIT |
|
122 } |
|
123 |
|
124 void CHsDeviceDiscoverer::DoCancel() |
|
125 { |
|
126 TRACE_FUNC_ENTRY |
|
127 if ( iSearching ) |
|
128 { |
|
129 iHostResolver.Cancel(); |
|
130 iHostResolver.Close(); |
|
131 } |
|
132 TRACE_FUNC_EXIT |
|
133 |
|
134 } |