|
1 // Copyright (c) 2005-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 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 #include <bt_sock.h> |
|
21 #include "BTGPSPairingHandler.h" |
|
22 #include "BTGPSConnectManagerExt.h" |
|
23 #include "BTGPSDeviceManager.h" |
|
24 #include "BTGPSHandlerFactory.h" |
|
25 #include "BTGPSLogging.h" |
|
26 #include "btgpssimstubs.h" |
|
27 |
|
28 // EXTERNAL DATA STRUCTURES |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // MACROS |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 |
|
38 // MODULE DATA STRUCTURES |
|
39 |
|
40 // LOCAL FUNCTION PROTOTYPES |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 |
|
44 // ============================= LOCAL FUNCTIONS =============================== |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CBTGPSPairingHandler::NewL |
|
51 // ----------------------------------------------------------------------------- |
|
52 CBTGPSPairingHandler* CBTGPSPairingHandler::NewL( |
|
53 MBTGPSConnectManagerExt& aManagerExt) |
|
54 { |
|
55 CBTGPSPairingHandler* self = new (ELeave) CBTGPSPairingHandler( |
|
56 aManagerExt); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CBTGPSPairingHandler::~CBTGPSPairingHandler |
|
65 // ----------------------------------------------------------------------------- |
|
66 CBTGPSPairingHandler::~CBTGPSPairingHandler() |
|
67 { |
|
68 Cancel(); |
|
69 } |
|
70 |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CBTGPSPairingHandler::ConstructL |
|
74 // ----------------------------------------------------------------------------- |
|
75 void CBTGPSPairingHandler::ConstructL() |
|
76 { |
|
77 TRACESTRING("CBTGPSPairingHandler::ConstructL start...") |
|
78 |
|
79 TSockAddr sockAddr; |
|
80 TUint protocol = KRFCOMM; |
|
81 sockAddr.SetFamily(KBTAddrFamily); |
|
82 |
|
83 //Get socket address |
|
84 TBTSockAddr& sockAddrBt = TBTSockAddr::Cast(sockAddr); |
|
85 sockAddrBt.SetBTAddr(iManagerExt.DeviceManager().BtDevice().BDAddr()); |
|
86 sockAddrBt.SetPort(iManagerExt.DeviceManager().Port()); |
|
87 //Set authentication |
|
88 TBTServiceSecurity security; |
|
89 security.SetAuthentication(ETrue); |
|
90 sockAddrBt.SetSecurity(security); |
|
91 |
|
92 //Get pointer to socket server and socket |
|
93 iManagerExt.GetSocket(iSocketServ, iSocket); |
|
94 |
|
95 //Connect to socket server |
|
96 if(iSocketServ->Handle()==0) |
|
97 { |
|
98 User::LeaveIfError(iSocketServ->Connect()); |
|
99 } |
|
100 |
|
101 #ifdef LBS_BTGPSPSY_SIM |
|
102 GetSimSockAddr(sockAddr, protocol); |
|
103 #endif |
|
104 |
|
105 iSocket->Close(); |
|
106 User::LeaveIfError(iSocket->Open(*iSocketServ, |
|
107 sockAddr.Family(),KSockStream,protocol)); |
|
108 |
|
109 iSocket->Connect( |
|
110 sockAddr, |
|
111 iStatus); |
|
112 |
|
113 SetActive(); |
|
114 |
|
115 TRACESTRING("CBTGPSPairingHandler::ConstructL end") |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CBTGPSPairingHandler::CBTGPSPairingHandler |
|
120 // C++ default constructor can NOT contain any code, that |
|
121 // might leave. |
|
122 // ----------------------------------------------------------------------------- |
|
123 CBTGPSPairingHandler::CBTGPSPairingHandler( |
|
124 MBTGPSConnectManagerExt& aManagerExt) |
|
125 : CActive(CActive::EPriorityStandard), |
|
126 iManagerExt(aManagerExt) |
|
127 { |
|
128 CActiveScheduler::Add(this); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CBTGPSPairingHandler::RunL |
|
133 // ----------------------------------------------------------------------------- |
|
134 void CBTGPSPairingHandler::RunL() |
|
135 { |
|
136 TRACESTRING2("CBTGPSPairingHandler::RunL start...", iStatus.Int()); |
|
137 if(iStatus.Int()==KErrNone) |
|
138 { |
|
139 iManagerExt.DeviceManager().SetPaired(ETrue); |
|
140 } |
|
141 iManagerExt.HandlerComplete(EPairingHandler, iStatus.Int()); |
|
142 TRACESTRING("CBTGPSPairingHandler::RunL end") |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CBTGPSPairingHandler::DoCancel |
|
147 // ----------------------------------------------------------------------------- |
|
148 void CBTGPSPairingHandler::DoCancel() |
|
149 { |
|
150 if(iSocket!=NULL) |
|
151 { |
|
152 iSocket->CancelConnect(); |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 // End of File |
|
158 |
|
159 |
|
160 |