|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Implementation of the UpnpAiwEnableExternalService |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AiwMenu.h> |
|
20 #include <AiwCommon.hrh> |
|
21 #include <aknnotewrappers.h> |
|
22 #include <upnpaiwmenuresources.rsg> |
|
23 #include "upnpaiwengine.h" |
|
24 #include "upnpaiwenableexternalservice.h" |
|
25 |
|
26 _LIT( KComponentLogfile, "upnpaiwprovider.log" ); |
|
27 #include "upnplog.h" |
|
28 |
|
29 // CONSTANTS |
|
30 _LIT( KResFileName, "\\resource\\upnpaiwmenuresources.rsc" ); |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // CUPnPAiwEnableExternalService::NewL |
|
34 // NewL. |
|
35 // -------------------------------------------------------------------------- |
|
36 CUPnPAiwEnableExternalService* CUPnPAiwEnableExternalService::NewL() |
|
37 { |
|
38 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService::NewL" ); |
|
39 |
|
40 CUPnPAiwEnableExternalService* self = |
|
41 new (ELeave) CUPnPAiwEnableExternalService; |
|
42 CleanupStack::PushL( self ); |
|
43 |
|
44 self->ConstructL(); |
|
45 |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // -------------------------------------------------------------------------- |
|
51 // CUPnPAiwEnableExternalService::CUPnPAiwEnableExternalService |
|
52 // Constructor. |
|
53 // -------------------------------------------------------------------------- |
|
54 CUPnPAiwEnableExternalService::CUPnPAiwEnableExternalService() |
|
55 { |
|
56 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService::\ |
|
57 CUPnPAiwEnableExternalService" ); |
|
58 } |
|
59 |
|
60 // -------------------------------------------------------------------------- |
|
61 // CUPnPAiwEnableExternalService::~CUPnPAiwEnableExternalService |
|
62 // Destructor. |
|
63 // -------------------------------------------------------------------------- |
|
64 CUPnPAiwEnableExternalService::~CUPnPAiwEnableExternalService() |
|
65 { |
|
66 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService::\ |
|
67 ~CUPnPAiwEnableExternalService" ); |
|
68 |
|
69 // Release the engine instance |
|
70 if( iEngine ) |
|
71 { |
|
72 |
|
73 // If the UPnP is enabled, disable it |
|
74 TInt engineState = KErrGeneral; |
|
75 engineState = iEngine->EngineState(); |
|
76 |
|
77 if( engineState != EUPnPEngineNotConnected ) |
|
78 { |
|
79 iEngine->DisableExternal(); |
|
80 } |
|
81 |
|
82 CUPnPAiwEngine::ReleaseInstance(); |
|
83 iEngine = NULL; |
|
84 } |
|
85 |
|
86 // Set the client call back reference to NULL |
|
87 iClient = NULL; |
|
88 } |
|
89 |
|
90 // -------------------------------------------------------------------------- |
|
91 // CUPnPAiwEnableExternalService::ConstructL |
|
92 // Second phase constructor. |
|
93 // -------------------------------------------------------------------------- |
|
94 void CUPnPAiwEnableExternalService::ConstructL() |
|
95 { |
|
96 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService::ConstructL" ); |
|
97 |
|
98 // Create the engine and register as an observer for call backs |
|
99 iEngine = CUPnPAiwEngine::NewL(); |
|
100 } |
|
101 |
|
102 // -------------------------------------------------------------------------- |
|
103 // CUPnPAiwEnableExternalService::HandleServiceCmdL |
|
104 // AIW Framework's method for handling service commands |
|
105 // -------------------------------------------------------------------------- |
|
106 void CUPnPAiwEnableExternalService::HandleServiceCmdL( |
|
107 const TInt& aCmdId, |
|
108 const CAiwGenericParamList& /*aInParamList*/, |
|
109 CAiwGenericParamList& aOutParamList, |
|
110 TUint /*aCmdOptions*/, |
|
111 const MAiwNotifyCallback* aCallback ) |
|
112 { |
|
113 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService::\ |
|
114 HandleServiceCmdL" ); |
|
115 |
|
116 // Cast the aCallback reference to non-const and store the reference |
|
117 iClient = const_cast<MAiwNotifyCallback*>( aCallback ); |
|
118 |
|
119 if( aCmdId == KAiwCmdUPnPEnableExternal ) |
|
120 { |
|
121 |
|
122 TInt status = KErrNone; |
|
123 |
|
124 if( iEngine ) |
|
125 { |
|
126 TInt engineState = KErrGeneral; |
|
127 engineState = iEngine->EngineState(); |
|
128 |
|
129 if( engineState == EUPnPEngineNotConnected ) |
|
130 { |
|
131 TRAP( status, iEngine->EnableExternalL() ); |
|
132 } |
|
133 else |
|
134 { |
|
135 iEngine->DisableExternal(); |
|
136 |
|
137 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService, \ |
|
138 send stopped event." ); |
|
139 |
|
140 // send STOPPED event |
|
141 CAiwGenericParamList* emptyParamlist = |
|
142 CAiwGenericParamList::NewLC(); |
|
143 if( iClient ) |
|
144 { |
|
145 iClient->HandleNotifyL( KAiwCmdUPnPPlay, |
|
146 KAiwEventStopped, |
|
147 *emptyParamlist, |
|
148 *emptyParamlist ); |
|
149 } |
|
150 CleanupStack::PopAndDestroy( emptyParamlist ); |
|
151 emptyParamlist = NULL; |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 status = KErrDied; |
|
157 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService, \ |
|
158 engine is dead!" ); |
|
159 } |
|
160 |
|
161 // Add the return value on the out param list |
|
162 TAiwGenericParam statusParameter( EGenericParamError, status ); |
|
163 aOutParamList.AppendL( statusParameter ); |
|
164 |
|
165 } |
|
166 } |
|
167 |
|
168 // -------------------------------------------------------------------------- |
|
169 // CUPnPAiwEnableExternalService::InitializeMenuPaneL |
|
170 // AIW Framework's method for initialising the menu |
|
171 // -------------------------------------------------------------------------- |
|
172 void CUPnPAiwEnableExternalService::InitializeMenuPaneL( |
|
173 CAiwMenuPane& aMenuPane, |
|
174 TInt aIndex, |
|
175 TInt /*aCascadeId*/, |
|
176 const CAiwGenericParamList& /*aInParamList*/ ) |
|
177 { |
|
178 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService::\ |
|
179 InitializeMenuPaneL" ); |
|
180 |
|
181 // Update the drive letter to the path of the resource file name |
|
182 TFileName resFile( KResFileName ); |
|
183 TFileName dllName; |
|
184 Dll::FileName( dllName ); |
|
185 TBuf<2> drive = dllName.Left(2); // Drive letter followed by ':' |
|
186 resFile.Insert( 0, drive ); |
|
187 |
|
188 // Select the correct menu resource, depending on the state of Provider |
|
189 if( iEngine ) |
|
190 { |
|
191 TUPnPEngineState engineState = iEngine->EngineState(); |
|
192 if( engineState == EUPnPEngineNotConnected || |
|
193 engineState == EUPnPEngineConnectionLost ) |
|
194 { |
|
195 aMenuPane.AddMenuItemsL( resFile, |
|
196 R_AIW_ENABLE_EXTERNAL_MENU, |
|
197 KAiwCmdUPnPEnableExternal, |
|
198 aIndex ); |
|
199 } |
|
200 else |
|
201 { |
|
202 aMenuPane.AddMenuItemsL( resFile, |
|
203 R_AIW_DISABLE_EXTERNAL_MENU, |
|
204 KAiwCmdUPnPEnableExternal, |
|
205 aIndex ); |
|
206 } |
|
207 } |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // CUPnPAiwEnableExternalService::HandleMenuCmdL |
|
212 // AIW Framework's method for handling menu commands |
|
213 // -------------------------------------------------------------------------- |
|
214 void CUPnPAiwEnableExternalService::HandleMenuCmdL( |
|
215 TInt aMenuCmdId, |
|
216 const CAiwGenericParamList& /*aInParamList*/, |
|
217 CAiwGenericParamList& aOutParamList, |
|
218 TUint /*aCmdOptions*/, |
|
219 const MAiwNotifyCallback* aCallback ) |
|
220 { |
|
221 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService::\ |
|
222 HandleMenuCmdL" ); |
|
223 |
|
224 // Cast the aCallback reference to non-const and store the reference |
|
225 iClient = const_cast<MAiwNotifyCallback*>( aCallback ); |
|
226 |
|
227 TInt status = KErrNone; |
|
228 |
|
229 if( iEngine ) |
|
230 { |
|
231 TInt engineState = iEngine->EngineState(); |
|
232 |
|
233 if( aMenuCmdId == KAiwCmdUPnPEnableExternal ) |
|
234 { |
|
235 if( engineState == EUPnPEngineNotConnected ) |
|
236 { |
|
237 TRAP( status, iEngine->EnableExternalL() ); |
|
238 } |
|
239 else |
|
240 { |
|
241 iEngine->DisableExternal(); |
|
242 |
|
243 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService, \ |
|
244 send stopped event." ); |
|
245 |
|
246 // send STOPPED event |
|
247 CAiwGenericParamList* emptyParamlist = |
|
248 CAiwGenericParamList::NewLC(); |
|
249 if( iClient ) |
|
250 { |
|
251 iClient->HandleNotifyL( KAiwCmdUPnPPlay, |
|
252 KAiwEventStopped, |
|
253 *emptyParamlist, |
|
254 *emptyParamlist ); |
|
255 } |
|
256 CleanupStack::PopAndDestroy( emptyParamlist ); |
|
257 emptyParamlist = NULL; |
|
258 } |
|
259 } |
|
260 } |
|
261 else |
|
262 { |
|
263 status = KErrDied; |
|
264 __LOG( "[UpnpAiwProvider]\t CUPnPAiwEnableExternalService, \ |
|
265 engine is dead!" ); |
|
266 } |
|
267 |
|
268 // Add the return value on the out param list |
|
269 TAiwGenericParam statusParameter( EGenericParamError, status ); |
|
270 aOutParamList.AppendL( statusParameter ); |
|
271 } |
|
272 |
|
273 // End of file |