|
1 // Copyright (c) 2004-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 #include "CNetConDlgProcessor.h" |
|
17 #include <comms-infras/dialogprocessor.h> |
|
18 #include "CNetworkController.h" |
|
19 #include "MNetConDialogProcAccess.h" |
|
20 #include "NetConPanic.h" |
|
21 |
|
22 |
|
23 /* |
|
24 Template adapter class: |
|
25 Implement MNetConDialogProcAccess by forwarding all calls to 'Implementor' class |
|
26 Also can optionally 'own' the instance of the implementor (i.e. deletes it on destruction) |
|
27 */ |
|
28 template<typename Implementor> |
|
29 class CMDialogProcessorImpl : public CBase, public MNetConDialogProcAccess |
|
30 { |
|
31 protected: |
|
32 typedef Implementor TImplementation; //< Type of the implementor |
|
33 |
|
34 public: |
|
35 /** |
|
36 Construct an MDialogProcessorImpl object. |
|
37 |
|
38 @param aPimpl Points to implementation object |
|
39 @param aOwnImpl If ETrue, then the aPimpl will be destroyed when *this is destroyed. |
|
40 @return Instance of CMDialogProcessorImpl |
|
41 */ |
|
42 static CMDialogProcessorImpl* NewL( TImplementation* aPimpl, TBool aOwnImpl ) |
|
43 { |
|
44 CMDialogProcessorImpl* self = new (ELeave) CMDialogProcessorImpl( aPimpl, aOwnImpl ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 /** |
|
49 Forward the CancelEverything request to the implementation |
|
50 */ |
|
51 virtual void CancelEverything() |
|
52 { |
|
53 GetImpl()->CancelEverything(); |
|
54 } |
|
55 /** |
|
56 Forward the SelectConnection request to the implementation |
|
57 */ |
|
58 virtual void SelectConnection(MDialogProcessorObserver& aObserver, const TConnectionPrefs& aPrefs) |
|
59 { |
|
60 GetImpl()->SelectConnection( aObserver, aPrefs ); |
|
61 } |
|
62 /** |
|
63 Forward the SelectConnection request to the implementation |
|
64 */ |
|
65 virtual void SelectConnection(MDialogProcessorObserver& aObserver, const TConnectionPrefs& aPrefs, TInt aLastError ) |
|
66 { |
|
67 GetImpl()->SelectConnection( aObserver, aPrefs, aLastError ); |
|
68 } |
|
69 /** |
|
70 Forward the SelectModemAndLocation request to the implementation |
|
71 */ |
|
72 virtual void SelectModemAndLocation(MDialogProcessorObserver& aObserver) |
|
73 { |
|
74 GetImpl()->SelectModemAndLocation( aObserver ); |
|
75 } |
|
76 /** |
|
77 Forward the WarnNewConnection request to the implementation |
|
78 */ |
|
79 virtual void WarnNewConnection(MDialogProcessorObserver& aObserver, const TConnectionPrefs& aPrefs, const TDesC* aNewIapName, const TIspConnectionNames* aNewConnectionNames, TInt aLastError ) |
|
80 { |
|
81 GetImpl()->WarnNewConnection( aObserver, aPrefs, aNewIapName, aNewConnectionNames, aLastError ); |
|
82 } |
|
83 /** |
|
84 Forward the Reconnect request to the implementation |
|
85 */ |
|
86 virtual void Reconnect(MDialogProcessorObserver& aObserver ) |
|
87 { |
|
88 GetImpl()->Reconnect( aObserver ); |
|
89 } |
|
90 |
|
91 /** |
|
92 Destroy this object. |
|
93 */ |
|
94 virtual ~CMDialogProcessorImpl() |
|
95 { |
|
96 if( iOwnImpl ) |
|
97 { |
|
98 delete iPimpl; // We own it, so get rid of it |
|
99 } |
|
100 iPimpl = 0; |
|
101 } |
|
102 protected: |
|
103 /** |
|
104 Constructor. Unexciting in the extreme. |
|
105 @param aPimpl pointer to implementation |
|
106 @param aOwnImpl If ETrue, transfers ownership of the implementation to this wrapper |
|
107 */ |
|
108 CMDialogProcessorImpl( TImplementation *aPimpl, TBool aOwnImpl ) |
|
109 :iPimpl(aPimpl), iOwnImpl(aOwnImpl) |
|
110 { |
|
111 __ASSERT_DEBUG( iPimpl, NetConPanic(NetworkController::ETelBearerBadState)); |
|
112 } |
|
113 |
|
114 private: |
|
115 /** |
|
116 Return the implementation pointer |
|
117 */ |
|
118 inline TImplementation* GetImpl() const |
|
119 { |
|
120 __ASSERT_DEBUG( iPimpl, NetConPanic(NetworkController::ETelBearerBadState)); |
|
121 return iPimpl; |
|
122 } |
|
123 private: |
|
124 TImplementation* iPimpl; //< Pointer to class that implements the interface in a non-virtual fashion |
|
125 TBool iOwnImpl; //< ETrue if the destructor should delete iPimpl |
|
126 }; |
|
127 |
|
128 |
|
129 |
|
130 /** |
|
131 Implement MNetConDialogProcAccess destructor |
|
132 */ |
|
133 MNetConDialogProcAccess::~MNetConDialogProcAccess() |
|
134 { |
|
135 } |
|
136 |
|
137 /** |
|
138 Construct a CNetConDlgProcessor using the default CDialogProcessor implementation |
|
139 |
|
140 @return a pointer to the newly created CNetConDlgProcessor |
|
141 */ |
|
142 CNetConDlgProcessor* CNetConDlgProcessor::NewL() |
|
143 { |
|
144 // To do this, we have to wrap a CDialogProcessor up so it looks like a MNetConDialogProcAccess. |
|
145 // so use the CMDialogProcessorImpl wrapper class |
|
146 |
|
147 // First, construct the CDialogProcessor itself... |
|
148 CDialogProcessor* processor = CDialogProcessor::NewL(); |
|
149 CleanupStack::PushL( processor ); |
|
150 |
|
151 // Now costruct the MNetConDialogProcAccess wrapper for it |
|
152 CMDialogProcessorImpl<CDialogProcessor>* impl = CMDialogProcessorImpl<CDialogProcessor>::NewL( processor, ETrue ); |
|
153 |
|
154 // impl now owns aProcess, so get it back from the cleanup stack |
|
155 CleanupStack::Pop( processor ); |
|
156 |
|
157 // and save impl... |
|
158 CleanupStack::PushL( impl ); |
|
159 |
|
160 // Construct the CNetConDlgProcessor itself |
|
161 CNetConDlgProcessor* self = new (ELeave) CNetConDlgProcessor( impl ); |
|
162 |
|
163 // and cleanup the cleanup |
|
164 CleanupStack::Pop( impl ); |
|
165 return self; |
|
166 } |
|
167 |
|
168 /** |
|
169 Construct a CNetConDlgProcessor using a supplied MNetConDialogProcAccess implementation |
|
170 |
|
171 @param aImpl The supplied implementation |
|
172 @param aOwnImpl True if the CNetConDlgProcessor takes ownership of aImpl |
|
173 |
|
174 @return a pointer to the newly created CNetConDlgProcessor |
|
175 */ |
|
176 CNetConDlgProcessor* CNetConDlgProcessor::NewL( MNetConDialogProcAccess* aImpl, TBool aOwnImpl ) |
|
177 { |
|
178 // Note: We can probably get away without the CMDialogProcessorImpl wrapper in the case where aOwnImpl is true |
|
179 // Construct a wrapper for the implementation |
|
180 CMDialogProcessorImpl<MNetConDialogProcAccess>* impl = CMDialogProcessorImpl<MNetConDialogProcAccess>::NewL( aImpl, aOwnImpl ); |
|
181 CleanupStack::PushL( impl ); |
|
182 // Transfer ownership of the wrapper to the dialog processor itself |
|
183 CNetConDlgProcessor* self = new (ELeave) CNetConDlgProcessor( impl ); |
|
184 CleanupStack::Pop( impl ); |
|
185 return self; |
|
186 } |
|
187 |
|
188 CNetConDlgProcessor::~CNetConDlgProcessor() |
|
189 { |
|
190 delete iDialogProc; |
|
191 } |
|
192 |
|
193 /** |
|
194 Constructor |
|
195 |
|
196 @param aImpl Pointer to dialog processor implementation |
|
197 */ |
|
198 CNetConDlgProcessor::CNetConDlgProcessor( MNetConDialogProcAccess* aImpl ) |
|
199 :iDialogProc( aImpl ) |
|
200 { |
|
201 ASSERT( aImpl ); |
|
202 } |
|
203 |
|
204 /** |
|
205 Retrieve the implementation pointer |
|
206 */ |
|
207 MNetConDialogProcAccess* CNetConDlgProcessor::GetImpl() const |
|
208 { |
|
209 __ASSERT_DEBUG( iDialogProc, NetConPanic(NetworkController::ETelBearerBadState)); |
|
210 return iDialogProc; |
|
211 } |
|
212 |
|
213 |
|
214 /** |
|
215 Cancel all outstanding dialog processor requests |
|
216 */ |
|
217 void CNetConDlgProcessor::CancelEverything() |
|
218 { |
|
219 GetImpl()->CancelEverything(); |
|
220 } |
|
221 |
|
222 /** |
|
223 Display a dialog to the user asking them to select an IAP to connect to |
|
224 |
|
225 @param aObserver the object to receive notification when the dialog box completes |
|
226 @param aPrefs the connection preferences used to select this IAP |
|
227 */ |
|
228 void CNetConDlgProcessor::SelectConnection(MDialogProcessorObserver& aObserver, const TConnectionPrefs& aPrefs) |
|
229 { |
|
230 GetImpl()->SelectConnection( aObserver, aPrefs ); |
|
231 } |
|
232 |
|
233 /** |
|
234 Display a dialog to the user asking them to select an IAP to connect to |
|
235 |
|
236 @param aObserver the object to receive notification when the dialog box completes |
|
237 @param aPrefs the connection preferences used to select this IAP |
|
238 @param aLastError if this is not the 1st connection attempt this is the error of the last attempt |
|
239 */ |
|
240 void CNetConDlgProcessor::SelectConnection(MDialogProcessorObserver& aObserver, const TConnectionPrefs& aPrefs, TInt aLastError ) |
|
241 { |
|
242 GetImpl()->SelectConnection( aObserver, aPrefs, aLastError ); |
|
243 } |
|
244 |
|
245 /** |
|
246 Display a dialog to the user asking the user to select a modem and location entry from CommDb |
|
247 |
|
248 @param aObserver the object to receive notification when the dialog box completes |
|
249 */ |
|
250 void CNetConDlgProcessor::SelectModemAndLocation(MDialogProcessorObserver& aObserver) |
|
251 { |
|
252 GetImpl()->SelectModemAndLocation( aObserver ); |
|
253 } |
|
254 |
|
255 /** |
|
256 Display a dialog to the user warning that a new connection is about to be attempted to the specified IAP |
|
257 |
|
258 @param aObserver the object to receive notification when the dialog box completes |
|
259 @param aPrefs the connection preferences used to select this IAP |
|
260 @param aNewIapName the name of the IAP used for the connection. |
|
261 @param aNewConnectionNames this parameter is no-longer used. |
|
262 @param aLastError if this is not the 1st connection attempt this is the error of the last attempt |
|
263 */ |
|
264 void CNetConDlgProcessor::WarnNewConnection(MDialogProcessorObserver& aObserver, const TConnectionPrefs& aPrefs, const TDesC* aNewIapName, const TIspConnectionNames* aNewConnectionNames, TInt aLastError ) |
|
265 { |
|
266 GetImpl()->WarnNewConnection( aObserver, aPrefs, aNewIapName, aNewConnectionNames, aLastError ); |
|
267 } |
|
268 |
|
269 /** |
|
270 Display a dialog to the user asking whether to reconnect a failed connection |
|
271 |
|
272 @param aObserver the object to receive notification when the dialog box completes |
|
273 */ |
|
274 void CNetConDlgProcessor::Reconnect(MDialogProcessorObserver& aObserver ) |
|
275 { |
|
276 GetImpl()->Reconnect( aObserver ); |
|
277 } |
|
278 |