|
1 /* |
|
2 * Copyright (c) 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: Tacticon server implementation. |
|
15 * Part of : Tacticon Server |
|
16 */ |
|
17 |
|
18 #include <e32debug.h> |
|
19 #include <w32std.h> |
|
20 #include <centralrepository.h> |
|
21 #include <featmgr.h> |
|
22 #include "tacticonserver.h" |
|
23 #include "tacticonsession.h" |
|
24 #include "tacticondefs.h" |
|
25 #include "tacticonshutdown.h" |
|
26 #include "tacticontrace.h" |
|
27 #include "osttracedefinitions.h" |
|
28 #ifdef OST_TRACE_COMPILER_IN_USE |
|
29 #include "tacticonservertraces.h" |
|
30 #endif |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // RunServerL |
|
34 // Initialize and run the server. |
|
35 // -------------------------------------------------------------------------- |
|
36 // |
|
37 static void RunServerL() |
|
38 { |
|
39 TRACE( "Tacticon server RunServer() - Begin" ); |
|
40 User::LeaveIfError( RThread().RenameMe( KTacticonServerName ) ); |
|
41 |
|
42 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
43 CleanupStack::PushL( scheduler ); |
|
44 CActiveScheduler::Install( scheduler ); |
|
45 |
|
46 CTacticonServer* server = CTacticonServer::NewLC(); |
|
47 |
|
48 RProcess::Rendezvous( KErrNone ); |
|
49 |
|
50 CActiveScheduler::Start(); |
|
51 |
|
52 // Cleanup server and scheduler |
|
53 CleanupStack::PopAndDestroy(server); |
|
54 CleanupStack::PopAndDestroy(scheduler); |
|
55 TRACE("Tacticon server RunServer() - End"); |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // E32Main |
|
60 // Server process entry-point. |
|
61 // -------------------------------------------------------------------------- |
|
62 // |
|
63 TInt E32Main() |
|
64 { |
|
65 __UHEAP_MARK; |
|
66 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
67 TInt ret( KErrNoMemory ); |
|
68 if( cleanup ) |
|
69 { |
|
70 TRAP( ret, RunServerL() ); |
|
71 delete cleanup; |
|
72 } |
|
73 __UHEAP_MARKEND; |
|
74 return ret; |
|
75 } |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CTacticonServer::NewL |
|
79 // 2-phased constructor. |
|
80 // -------------------------------------------------------------------------- |
|
81 // |
|
82 CTacticonServer* CTacticonServer::NewLC() |
|
83 { |
|
84 TRACE( "CTacticonServer::NewLC - Begin" ); |
|
85 CTacticonServer* self = new (ELeave) CTacticonServer(); |
|
86 CleanupStack::PushL(self); |
|
87 self->ConstructL(); |
|
88 TRACE("CTacticonServer::NewLC - End"); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CTacticonServer::CTacticonServer() |
|
94 // C++ constructor. |
|
95 // -------------------------------------------------------------------------- |
|
96 // |
|
97 CTacticonServer::CTacticonServer() |
|
98 : CPolicyServer( EPriorityNormal, |
|
99 KTacticonPolicy, |
|
100 ESharableSessions ), |
|
101 iTacticonsEnabled( ETrue ) |
|
102 { |
|
103 } |
|
104 |
|
105 // -------------------------------------------------------------------------- |
|
106 // CTacticonServer::ConstructL |
|
107 // 2nd phase constructor. |
|
108 // -------------------------------------------------------------------------- |
|
109 // |
|
110 void CTacticonServer::ConstructL() |
|
111 { |
|
112 TRACE( "CTacticonServer::ConstructL - Begin" ); |
|
113 StartL( KTacticonServerName); |
|
114 TRACE( "CTacticonServer::ConstructL - Server started" ); |
|
115 iRepository = CRepository::NewL( KCRUidTacticon ); |
|
116 |
|
117 TInt pluginUid(0); |
|
118 User::LeaveIfError( iRepository->Get( KTacticonPlugin, pluginUid ) ); |
|
119 TRACE2( "CTacticonServer::ConstructL - got pluginUid: %d", pluginUid ); |
|
120 |
|
121 TRACE("CTacticonServer::ConstructL - creating player"); |
|
122 // The server is instantiated during boot time. To enable phone to boot up |
|
123 // even if player instatiation fails, trap its possible failure. |
|
124 TRAPD(err, iPlayer = CTacticonPlayer::NewL( TUid::Uid(pluginUid), *iRepository ) ); |
|
125 if ( err ) |
|
126 { |
|
127 TRACE2( "CTacticonServer::ConstructL - Creating Player failed with code %d", err ); |
|
128 iPlayer = NULL; // to ensure that player pointer is not broken |
|
129 } |
|
130 |
|
131 TRACE( "CTacticonServer::ConstructL - Creating shutdown instance" ); |
|
132 iShutdown = CTacticonShutdown::NewL(); |
|
133 TRACE( "CTacticonServer::ConstructL - End" ); |
|
134 } |
|
135 |
|
136 // -------------------------------------------------------------------------- |
|
137 // CTacticonServer::CTacticonServer() |
|
138 // C++ destructor. |
|
139 // -------------------------------------------------------------------------- |
|
140 // |
|
141 CTacticonServer::~CTacticonServer() |
|
142 { |
|
143 delete iPlayer; |
|
144 delete iRepository; |
|
145 delete iShutdown; |
|
146 REComSession::FinalClose(); |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // CTacticonServer::NewSessionL |
|
151 // from CServer2, creates a new session. |
|
152 // -------------------------------------------------------------------------- |
|
153 // |
|
154 CSession2* CTacticonServer::NewSessionL( const TVersion& aVersion, |
|
155 const RMessage2& /*aMessage*/ ) const |
|
156 { |
|
157 TRACE("CTacticonServer::NewSessionL - Begin"); |
|
158 TVersion version( KTacticonServerMajor, |
|
159 KTacticonServerMinor, KTacticonServerBuild ); |
|
160 |
|
161 TBool supported = User::QueryVersionSupported( version, aVersion ); |
|
162 |
|
163 if( !supported ) |
|
164 { |
|
165 TRACE("CTacticonServer::NewSessionL - Version not supported"); |
|
166 User::Leave( KErrNotSupported ); |
|
167 } |
|
168 |
|
169 CTacticonSession* session = new (ELeave) CTacticonSession(); |
|
170 TRACE("CTacticonServer::NewSessionL - End"); |
|
171 return session; |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // CTacticonServer::AddSession |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 void CTacticonServer::AddSession() |
|
179 { |
|
180 TRACE("CTacticonServer::AddSession - Begin"); |
|
181 iSessionCount++; |
|
182 iShutdown->Cancel(); |
|
183 TRACE("CTacticonServer::AddSession - End"); |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CTacticonServer::RemoveSession |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 void CTacticonServer::RemoveSession() |
|
191 { |
|
192 TRACE( "CTacticonServer::RemoveSession - Begin" ); |
|
193 iSessionCount--; |
|
194 |
|
195 // Start the shutdown timer there are no more sessions |
|
196 if ( !iSessionCount && !iShutdown->IsActive() ) |
|
197 { |
|
198 iShutdown->Start(); |
|
199 } |
|
200 TRACE( "CTacticonServer::RemoveSession - End" ); |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CTacticonServer::PlayTacticon |
|
205 // -------------------------------------------------------------------------- |
|
206 // |
|
207 void CTacticonServer::PlayTacticon( TTacticonType aTacticonType ) |
|
208 { |
|
209 if ( iPlayer && iTacticonsEnabled ) |
|
210 { |
|
211 OstTrace0( TACTICON_PERFORMANCE, TACTICON_SERVER_PLAY_TACTICON_1, |
|
212 "e_TACTICON_SERVER_PLAY_TACTICON 1" ); |
|
213 |
|
214 iPlayer->PlayTacticon( aTacticonType ); |
|
215 |
|
216 OstTrace0( TACTICON_PERFORMANCE, TACTICON_SERVER_PLAY_TACTICON_0, |
|
217 "e_TACTICON_SERVER_PLAY_TACTICON 0" ); |
|
218 } |
|
219 else |
|
220 { |
|
221 TRACE("CTacticonServer::PlayTacticon - Player not available"); |
|
222 } |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // CTacticonServer::StopTacticon |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 void CTacticonServer::StopTacticon() |
|
230 { |
|
231 if ( iPlayer ) |
|
232 { |
|
233 OstTrace0( TACTICON_PERFORMANCE, TACTICON_SERVER_STOP_TACTICON_1, |
|
234 "e_TACTICON_SERVER_STOP_TACTICON 1" ); |
|
235 |
|
236 iPlayer->StopTacticon(); |
|
237 |
|
238 OstTrace0( TACTICON_PERFORMANCE, TACTICON_SERVER_STOP_TACTICON_0, |
|
239 "e_TACTICON_SERVER_STOP_TACTICON 0" ); |
|
240 } |
|
241 } |
|
242 |
|
243 // -------------------------------------------------------------------------- |
|
244 // CTacticonServer::EnableTacticons |
|
245 // -------------------------------------------------------------------------- |
|
246 // |
|
247 void CTacticonServer::EnableTacticons( TBool aEnabled ) |
|
248 { |
|
249 iTacticonsEnabled = aEnabled; |
|
250 } |
|
251 |
|
252 // -------------------------------------------------------------------------- |
|
253 // CTacticonServer::EnableTacticons |
|
254 // -------------------------------------------------------------------------- |
|
255 // |
|
256 TBool CTacticonServer::TacticonsEnabled() |
|
257 { |
|
258 return iTacticonsEnabled; |
|
259 } |
|
260 |
|
261 // End of file |