1 /* |
|
2 * Copyright (c) 2005-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "t_rconnectiondata.h" |
|
21 #include "t_rsocketservdata.h" |
|
22 #include <commdbconnpref.h> |
|
23 |
|
24 /*@{*/ |
|
25 //LIT param read from the ini file |
|
26 _LIT(KSocketServ, "socketserv"); |
|
27 /*@}*/ |
|
28 |
|
29 /*@{*/ |
|
30 //LITs for commands |
|
31 _LIT(KCmdOpen, "Open"); |
|
32 _LIT(KCmdStart, "Start"); |
|
33 _LIT(KCmdClose, "Close"); |
|
34 /*@}*/ |
|
35 |
|
36 |
|
37 /** |
|
38 * Two phase constructor |
|
39 * |
|
40 * @leave system wide error |
|
41 */ |
|
42 CT_RConnectionData* CT_RConnectionData::NewL() |
|
43 { |
|
44 CT_RConnectionData * ret = new (ELeave)CT_RConnectionData(); |
|
45 CleanupStack::PushL(ret); |
|
46 ret->ConstructL(); |
|
47 CleanupStack::Pop(ret); |
|
48 return ret; |
|
49 } |
|
50 |
|
51 /** |
|
52 * Public destructor |
|
53 */ |
|
54 CT_RConnectionData::~CT_RConnectionData() |
|
55 { |
|
56 if (iConnection) |
|
57 { |
|
58 delete iConnection; |
|
59 iConnection = NULL; |
|
60 } |
|
61 } |
|
62 |
|
63 /** |
|
64 * Private constructor. First phase construction |
|
65 */ |
|
66 CT_RConnectionData::CT_RConnectionData() |
|
67 : iConnection(NULL) |
|
68 { |
|
69 } |
|
70 |
|
71 /** |
|
72 * Second phase construction |
|
73 * |
|
74 * @internalComponent |
|
75 * |
|
76 * @return N/A |
|
77 * |
|
78 * @pre None |
|
79 * @post None |
|
80 * |
|
81 * @leave system wide error |
|
82 */ |
|
83 void CT_RConnectionData::ConstructL() |
|
84 { |
|
85 iConnection = new (ELeave)RConnection(); |
|
86 } |
|
87 |
|
88 /** |
|
89 * Return a pointer to the object that the data wraps |
|
90 * |
|
91 * @return pointer to the object that the data wraps |
|
92 */ |
|
93 TAny* CT_RConnectionData::GetObject() |
|
94 { |
|
95 return iConnection; |
|
96 } |
|
97 |
|
98 /** |
|
99 * Process a command read from the Ini file |
|
100 * @param aCommand The command to process |
|
101 * @param aSection The section get from the *.ini file of the project T_Wlan |
|
102 * @param aAsyncErrorIndex Command index dor async calls to returns errors to |
|
103 * @return TBool ETrue if the command is process |
|
104 * @leave system wide error |
|
105 */ |
|
106 TBool CT_RConnectionData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
107 { |
|
108 TBool ret = ETrue; |
|
109 if(aCommand == KCmdOpen) |
|
110 { |
|
111 DoCmdOpen(aSection); |
|
112 } |
|
113 else if(aCommand == KCmdStart) |
|
114 { |
|
115 DoCmdStart(aSection); |
|
116 } |
|
117 else if(aCommand == KCmdClose) |
|
118 { |
|
119 DoCmdClose(); |
|
120 } |
|
121 else |
|
122 { |
|
123 ERR_PRINTF1(_L("Unknown command.")); |
|
124 ret= EFalse; |
|
125 } |
|
126 return ret; |
|
127 } |
|
128 |
|
129 |
|
130 /** |
|
131 * Command to open a connection (RConnection::Open). The errors are management |
|
132 * with SetError() and SetBlockResult(). |
|
133 * @param aSection Section in the ini file for this command |
|
134 * @return |
|
135 */ |
|
136 void CT_RConnectionData::DoCmdOpen(const TTEFSectionName& aSection) |
|
137 { |
|
138 INFO_PRINTF1(_L("*START* CT_RConnectionData::DoCmdOpen")); |
|
139 TBool dataOk = ETrue; |
|
140 |
|
141 // read param from the ini file |
|
142 TPtrC socketServName; |
|
143 if(!GetStringFromConfig(aSection, KSocketServ, socketServName)) |
|
144 { |
|
145 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSocketServ); |
|
146 SetBlockResult(EFail); |
|
147 dataOk = EFalse; |
|
148 } |
|
149 |
|
150 if (dataOk) |
|
151 { |
|
152 RSocketServ* iSocketServ = static_cast<RSocketServ*>(GetDataObjectL(socketServName)); |
|
153 |
|
154 // Open a connection |
|
155 TInt err = iConnection->Open(*iSocketServ); |
|
156 if(err == KErrNone) |
|
157 { |
|
158 INFO_PRINTF1(_L("The connection was opened")); |
|
159 } |
|
160 else |
|
161 { |
|
162 ERR_PRINTF2(_L("iConnection->Open( iSocketServ ) Failed with error %d"), err); |
|
163 SetError(err); |
|
164 } |
|
165 |
|
166 INFO_PRINTF1(_L("*END* CT_RConnectionData::DoCmdOpen")); |
|
167 } |
|
168 } |
|
169 |
|
170 /** |
|
171 * Command to Start a connection with the ID IAP given before in the wrapper CT_RSocketServData. The |
|
172 * errors are management with SetError() and SetBlockResult() |
|
173 * @param aSection Section in the ini file for this command |
|
174 * @return |
|
175 */ |
|
176 void CT_RConnectionData::DoCmdStart(const TTEFSectionName& aSection) |
|
177 { |
|
178 INFO_PRINTF1(_L("*START* CT_RConnectionData::DoCmdStart")); |
|
179 TBool dataOk = ETrue; |
|
180 |
|
181 // read a param from the ini file |
|
182 TPtrC socketServName; |
|
183 if(!GetStringFromConfig(aSection, KSocketServ, socketServName)) |
|
184 { |
|
185 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSocketServ); |
|
186 SetBlockResult(EFail); |
|
187 dataOk = EFalse; |
|
188 } |
|
189 |
|
190 if (dataOk) |
|
191 { |
|
192 TInt err(KErrNone); |
|
193 TUint32 id; |
|
194 |
|
195 // Get complete wrapper |
|
196 CT_RSocketServData* iSocketServ = static_cast<CT_RSocketServData*>(GetDataWrapperL(socketServName)); |
|
197 INFO_PRINTF2(_L("iSocketServ: %S"), &socketServName); |
|
198 |
|
199 if(iSocketServ != NULL) |
|
200 { |
|
201 // Start the connection using the given (WLAN) access point |
|
202 id = iSocketServ->GetIapID(); |
|
203 INFO_PRINTF2(_L("CT_RConnectionData::DoCmdStart: Start RConnection, using IAP [%d]"), id); |
|
204 |
|
205 TCommDbConnPref* connPref = new (ELeave) TCommDbConnPref; |
|
206 connPref->SetIapId(id); |
|
207 connPref->SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
208 connPref->SetDirection( ECommDbConnectionDirectionOutgoing ); |
|
209 connPref->SetBearerSet(KCommDbBearerUnknown); |
|
210 |
|
211 INFO_PRINTF1(_L("CT_RConnectionData: Starting connection")); |
|
212 // Wait before the connection is really made |
|
213 // Wait time is 8 seconds. |
|
214 err = iConnection->Start( *connPref ) ; |
|
215 if(err != KErrNone) |
|
216 { |
|
217 ERR_PRINTF2(_L("iConnection->Start( connPref ) Fail: %d "),err); |
|
218 SetError(err); |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 ERR_PRINTF1(_L("CT_RConnectionData::DoCmdStart: iSocketServ is NULL")); |
|
224 SetBlockResult(EFail); |
|
225 } |
|
226 } |
|
227 |
|
228 INFO_PRINTF1(_L("*END* CT_RConnectionData::DoCmdStart")); |
|
229 } |
|
230 |
|
231 |
|
232 /** |
|
233 * Command to close a connection(RConnection::Close) |
|
234 * @param |
|
235 * @return |
|
236 */ |
|
237 void CT_RConnectionData::DoCmdClose() |
|
238 { |
|
239 INFO_PRINTF1(_L("*START* CT_RConnectionData::DoCmdClose")); |
|
240 Close(); |
|
241 INFO_PRINTF1(_L("*END* CT_RConnectionData::DoCmdClose")); |
|
242 } |
|
243 |
|
244 /** |
|
245 * Helper function for the command DoCmdConnection |
|
246 * @param |
|
247 * @return |
|
248 */ |
|
249 |
|
250 void CT_RConnectionData::Close() |
|
251 { |
|
252 INFO_PRINTF1(_L("Closing connection")); |
|
253 iConnection->Close(); |
|
254 } |
|