|
1 // Copyright (c) 2000-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 // Implementation of the dummy version of class CNifAgentRef |
|
15 // for testing purposes |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32uid.h> |
|
20 #include <e32base.h> |
|
21 #include <comms-infras/nifagt.h> |
|
22 #include "TNifAgentRef.h" |
|
23 |
|
24 const TUid KUidAGT = { 0x10003d39 }; |
|
25 |
|
26 // Function pointer used to access DLL through first ordinal function |
|
27 typedef CNifAgentFactory* (*CreateNifAgentFactoryFunctionL)(); |
|
28 |
|
29 CNifAgentRef::CNifAgentRef(MDummyNifToAgtHarnessNotify* aNotify) |
|
30 : iNotify(aNotify), iDisconnectRequired(EFalse) |
|
31 { } |
|
32 |
|
33 |
|
34 EXPORT_C CNifAgentRef::~CNifAgentRef() |
|
35 // |
|
36 // Free resources allocated during the test if it is |
|
37 // interrupted before completion |
|
38 // |
|
39 { |
|
40 |
|
41 if(iDisconnectRequired) |
|
42 Disconnect(); |
|
43 |
|
44 if(iAgent) |
|
45 delete iAgent; |
|
46 |
|
47 iLibrary.Close(); |
|
48 } |
|
49 |
|
50 |
|
51 EXPORT_C CNifAgentRef* CNifAgentRef::NewL(MDummyNifToAgtHarnessNotify* aNotify, const TBool aCSDAgent) |
|
52 // |
|
53 // When constructing a new CNifAgentRef, the client test object is passed |
|
54 // as a MNifManTestNotify, allowing notifications to be passed up. |
|
55 // |
|
56 { |
|
57 |
|
58 CNifAgentRef* ref = new (ELeave) CNifAgentRef(aNotify); |
|
59 CleanupStack::PushL(ref); |
|
60 ref->ConstructL(aCSDAgent); |
|
61 CleanupStack::Pop(); |
|
62 return ref; |
|
63 } |
|
64 |
|
65 void CNifAgentRef::ConstructL(const TBool aCSDAgent) |
|
66 { |
|
67 |
|
68 // Factory to create the CSD/PSD Agents |
|
69 CNifAgentFactory *factory; |
|
70 |
|
71 // Load the DUMMYCSD.AGT or DUMMYPSD.AGT library |
|
72 if (aCSDAgent == TRUE) |
|
73 { |
|
74 _LIT(KAGTLibraryName, "DUMMYCSD.AGT"); |
|
75 TUidType uidType(KDynamicLibraryUid,KUidAGT); |
|
76 User::LeaveIfError(iLibrary.Load(KAGTLibraryName, uidType)); |
|
77 } |
|
78 else |
|
79 { |
|
80 _LIT(KAGTLibraryName, "DUMMYPSD.AGT"); |
|
81 TUidType uidType(KDynamicLibraryUid,KUidAGT); |
|
82 User::LeaveIfError(iLibrary.Load(KAGTLibraryName, uidType)); |
|
83 } |
|
84 |
|
85 // Obtain a pointer to the |
|
86 // extern "C" EXPORT_C CNifAgentFactory* NewAgentFactoryL() |
|
87 // function in the CSD/PSD Agent |
|
88 CreateNifAgentFactoryFunctionL funcL = |
|
89 (CreateNifAgentFactoryFunctionL)iLibrary.Lookup(1); |
|
90 |
|
91 if (!funcL) |
|
92 User::Leave(KErrNotSupported); |
|
93 |
|
94 // Create a new agent factory |
|
95 factory = (*funcL)(); |
|
96 CleanupStack::PushL(TCleanupItem(CNifAgentFactory::Cleanup, factory)); |
|
97 |
|
98 // Use the factory to create a new instance of the CSD or PSD Agent |
|
99 if (aCSDAgent == TRUE) |
|
100 { |
|
101 TNifAgentInfo info; |
|
102 TInt index=0; |
|
103 _LIT(KCSDAgentName, "CSD"); |
|
104 iAgent = factory->NewAgentL(KCSDAgentName); |
|
105 factory->InstallL(); |
|
106 factory->Info(info,index); |
|
107 } |
|
108 else |
|
109 { |
|
110 TNifAgentInfo info; |
|
111 TInt index=0; |
|
112 _LIT(KPSDAgentName, "PSD"); |
|
113 iAgent = factory->NewAgentL(KPSDAgentName); |
|
114 factory->InstallL(); |
|
115 factory->Info(info,index); |
|
116 } |
|
117 |
|
118 iAgent->iNotify = this; |
|
119 |
|
120 |
|
121 // Cleanup the agent factory |
|
122 CleanupStack::PopAndDestroy(); |
|
123 |
|
124 } |
|
125 |
|
126 EXPORT_C void CNifAgentRef::Connect() |
|
127 // |
|
128 // Starts the agent connection attempt |
|
129 // |
|
130 { |
|
131 |
|
132 iCompletionCode = 0x7FFFFFFF; |
|
133 if(iAgent) |
|
134 { |
|
135 |
|
136 // Connection Settings |
|
137 TConnectionSettings settings; |
|
138 TRAPD(ret,settings = iAgent->ConnectionSettingsL()); |
|
139 if(ret!=KErrNone) |
|
140 { |
|
141 ConnectComplete(ret); |
|
142 return; |
|
143 } |
|
144 settings.iDirection = ECommDbConnectionDirectionOutgoing; |
|
145 settings.iDialogPref = ECommDbDialogPrefDoNotPrompt; |
|
146 settings.iRank = 1; |
|
147 TRAP(ret,iAgent->SetConnectionSettingsL(settings)); |
|
148 if(ret!=KErrNone) |
|
149 { |
|
150 // Cannot stop CActiveScheduler object before it's started |
|
151 /* |
|
152 ConnectComplete(ret); |
|
153 return; |
|
154 */ |
|
155 iCompletionCode = ret; |
|
156 iDisconnectRequired = EFalse; |
|
157 return; |
|
158 } |
|
159 |
|
160 // Connection |
|
161 iDisconnectRequired=ETrue; |
|
162 iAgent->Connect(EAgentStartDialOut); |
|
163 |
|
164 // Block execution until connect complete is called |
|
165 CActiveScheduler::Start(); |
|
166 } |
|
167 } |
|
168 |
|
169 void CNifAgentRef::ConnectComplete(TInt aStatus) |
|
170 { |
|
171 iCompletionCode = aStatus; |
|
172 iDisconnectRequired=EFalse; |
|
173 |
|
174 // Unblock execution |
|
175 CActiveScheduler::Stop(); |
|
176 } |
|
177 |
|
178 |
|
179 EXPORT_C void CNifAgentRef::ReConnect() |
|
180 // |
|
181 // Reconnect must be called after calling connect and before calling Disconnect |
|
182 // |
|
183 { |
|
184 iCompletionCode = 0x7FFFFFFF; |
|
185 if(iAgent) |
|
186 { |
|
187 iDisconnectRequired=ETrue; |
|
188 |
|
189 // Call the agent's Reconnect function |
|
190 iAgent->Connect(EAgentReconnect); |
|
191 |
|
192 // Block execution until ReconnectComplete is called |
|
193 CActiveScheduler::Start(); |
|
194 } |
|
195 } |
|
196 |
|
197 |
|
198 void CNifAgentRef::ReconnectComplete(TInt aStatus) |
|
199 { |
|
200 |
|
201 // When the Agent calls back this function then call |
|
202 // the Connect function to perform the reconnection |
|
203 iCompletionCode = aStatus; |
|
204 iDisconnectRequired=EFalse; |
|
205 |
|
206 // Unblock execution |
|
207 CActiveScheduler::Stop(); |
|
208 } |
|
209 |
|
210 |
|
211 EXPORT_C void CNifAgentRef::Disconnect() |
|
212 // |
|
213 // Stops the agent |
|
214 // |
|
215 { |
|
216 |
|
217 iCompletionCode = 0x7FFFFFFF; |
|
218 if(iAgent) |
|
219 { |
|
220 iAgent->Disconnect(0); |
|
221 |
|
222 // Block execution until DisconnectComplete is called |
|
223 CActiveScheduler::Start(); |
|
224 } |
|
225 } |
|
226 |
|
227 void CNifAgentRef::DisconnectComplete() |
|
228 { |
|
229 |
|
230 iCompletionCode=0; |
|
231 |
|
232 // Unblock execution |
|
233 CActiveScheduler::Stop(); |
|
234 } |
|
235 |
|
236 void CNifAgentRef::AgentProgress(TInt aStage, TInt aError) |
|
237 { |
|
238 |
|
239 if(iCompletionCode == 0x7FFFFFFF) |
|
240 iProgressStage=aStage; |
|
241 |
|
242 // Let the test harness know, just in case it's interested |
|
243 iNotify->AgentProgress(aStage, aError); |
|
244 } |
|
245 |
|
246 void CNifAgentRef::AgentProgress(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TInt /*aStage*/, TInt /*aError*/) |
|
247 { |
|
248 // @todo add some implementation here if necessary for the testing... |
|
249 } |
|
250 |
|
251 TInt CNifAgentRef::Notification(TAgentToNifEventType aEvent, TAny* aInfo) |
|
252 { |
|
253 |
|
254 // Let the Agt test module decide what to do with the notification |
|
255 return iNotify->Notification(aEvent, aInfo); |
|
256 } |
|
257 |
|
258 |
|
259 EXPORT_C void CNifAgentRef::GetCompletionCode(TInt& aCompletionCode) |
|
260 // |
|
261 // Retrieves the last error returned by the CSD agent |
|
262 // |
|
263 { |
|
264 aCompletionCode = iCompletionCode; |
|
265 } |
|
266 |
|
267 EXPORT_C void CNifAgentRef::GetProgressStage(TInt& aProgressStage) |
|
268 // |
|
269 // Retrieves the last progress stage before a call to one of the |
|
270 // asyncronous completion functions |
|
271 // |
|
272 { |
|
273 aProgressStage = iProgressStage; |
|
274 } |
|
275 |
|
276 |
|
277 void CNifAgentRef::AuthenticateComplete(TInt aStatus) |
|
278 { |
|
279 iCompletionCode = aStatus; |
|
280 CActiveScheduler::Stop(); |
|
281 } |
|
282 |
|
283 void CNifAgentRef::ServiceStarted() |
|
284 { |
|
285 } |
|
286 |
|
287 void CNifAgentRef::ServiceClosed() |
|
288 { |
|
289 } |
|
290 |
|
291 TInt CNifAgentRef::IncomingConnectionReceived() |
|
292 { |
|
293 return 0; |
|
294 } |
|
295 |
|
296 void CNifAgentRef::AgentEvent(TNetworkAdaptorEventType /*aEventType*/, TUint /*aEvent*/, const TDesC8& /*aEventData*/, TAny* /*aSource*/) |
|
297 { |
|
298 } |
|
299 |
|
300 TName CNifAgentRef::Name() const |
|
301 { |
|
302 return iName; |
|
303 } |
|
304 |
|
305 void CNifAgentRef::Close() |
|
306 { |
|
307 } |
|
308 |
|
309 EXPORT_C void CNifAgentRef::WaitForIncoming() |
|
310 { |
|
311 iCompletionCode = 0x7FFFFFFF; |
|
312 if(iAgent) |
|
313 { |
|
314 iAgent->Connect(EAgentStartDialIn); |
|
315 } |
|
316 } |