114
|
1 |
/*
|
|
2 |
* Copyright (c) 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: BS Server - implemenration of CServer2
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <eikenv.h>
|
|
20 |
#include <eikappui.h>
|
|
21 |
#include <apgwgnam.h>
|
|
22 |
#include <e32base.h>
|
|
23 |
|
|
24 |
#include "bsengineglobals.h"
|
|
25 |
#include "bsengine.h"
|
|
26 |
#include "bsserversession.h"
|
|
27 |
#include "bsdebug.h"
|
|
28 |
#include "bsserver.h"
|
|
29 |
|
|
30 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
31 |
|
|
32 |
// -----------------------------------------------------------------------------
|
|
33 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
CBSServer::CBSServer( TInt aPriority ) :
|
|
37 |
CServer2(aPriority)
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
// -----------------------------------------------------------------------------
|
|
42 |
// Symbian 2nd phase constructor can leave.
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
//
|
|
45 |
void CBSServer::ConstructL()
|
|
46 |
{
|
|
47 |
DEBUG(("Start BS Server" ));
|
|
48 |
iEngine = CBSEngine::NewL( );
|
|
49 |
StartL( KBSEngineName );
|
|
50 |
}
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
// Two-phased constructor.
|
|
54 |
// -------------------------------------- ---------------------------------------
|
|
55 |
//
|
|
56 |
CBSServer* CBSServer::NewLC()
|
|
57 |
{
|
|
58 |
CBSServer* self = new( ELeave ) CBSServer( EPriorityNormal );
|
|
59 |
CleanupStack::PushL( self );
|
|
60 |
self->ConstructL( );
|
|
61 |
return self;
|
|
62 |
}
|
|
63 |
|
|
64 |
// -----------------------------------------------------------------------------
|
|
65 |
// Destructor.
|
|
66 |
// -------------------------------------- ---------------------------------------
|
|
67 |
//
|
|
68 |
CBSServer::~CBSServer()
|
|
69 |
{
|
|
70 |
DEBUG(("Destroy BS Server" ));
|
|
71 |
delete iEngine;
|
|
72 |
}
|
|
73 |
|
|
74 |
// -----------------------------------------------------------------------------
|
|
75 |
// Create new session.
|
|
76 |
// -----------------------------------------------------------------------------
|
|
77 |
//
|
|
78 |
CSession2* CBSServer::NewSessionL( const TVersion& aVersion,
|
|
79 |
const RMessage2& /*aMessage*/ ) const
|
|
80 |
{
|
|
81 |
// Check we're the right version
|
|
82 |
if ( !User::QueryVersionSupported( TVersion( KBSEngineMajorVersionNumber,
|
|
83 |
KBSEngineMinorVersionNumber, KBSEngineBuildVersionNumber ), aVersion ) )
|
|
84 |
{
|
|
85 |
User::Leave( KErrNotSupported );
|
|
86 |
}
|
|
87 |
|
|
88 |
return CBSServerSession::NewL( ( CBSServer* ) this );
|
|
89 |
}
|
|
90 |
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
// Increment sessions.
|
|
93 |
// -----------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CBSServer::IncrementSessions()
|
|
96 |
{
|
|
97 |
iSessionCount++;
|
|
98 |
}
|
|
99 |
|
|
100 |
// -----------------------------------------------------------------------------
|
|
101 |
// Decrement sessions.
|
|
102 |
// -----------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
void CBSServer::DecrementSessions()
|
|
105 |
{
|
|
106 |
iSessionCount--;
|
|
107 |
}
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
// RunError is called when RunL leaves.
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
TInt CBSServer::RunError( TInt aError )
|
|
113 |
{
|
|
114 |
DEBUG(("CBSServer::RunError %d", aError ));
|
|
115 |
if ( aError == KErrBadDescriptor )
|
|
116 |
{
|
|
117 |
PanicClient( Message( ), EBSEngineBadDescriptor );
|
|
118 |
}
|
|
119 |
else
|
|
120 |
{
|
|
121 |
Message().Complete( aError );
|
|
122 |
}
|
|
123 |
|
|
124 |
// The leave will result in an early return from CServer::RunL(), skipping
|
|
125 |
// the call to request another message. So do that now in order to keep the
|
|
126 |
// server running.
|
|
127 |
ReStart( );
|
|
128 |
// Handled the error fully
|
|
129 |
return KErrNone;
|
|
130 |
}
|
|
131 |
|
|
132 |
// -----------------------------------------------------------------------------
|
|
133 |
// Panic client.
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
void CBSServer::PanicClient( const RMessage2& aMessage, TBSEnginePanic aPanic )
|
|
137 |
{
|
|
138 |
aMessage.Panic( KBSEngineName, aPanic );
|
|
139 |
}
|
|
140 |
|
|
141 |
// -----------------------------------------------------------------------------
|
|
142 |
// Panic server.
|
|
143 |
// -----------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
void CBSServer::PanicServer( TBSEnginePanic aPanic )
|
|
146 |
{
|
|
147 |
User::Panic( KBSEngineName, aPanic );
|
|
148 |
}
|
|
149 |
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
// Create and start the server.
|
|
152 |
// -----------------------------------------------------------------------------
|
|
153 |
//
|
|
154 |
void CBSServer::ThreadFunctionL()
|
|
155 |
{
|
|
156 |
CBSAppUi* ui = new (ELeave) CBSAppUi;
|
|
157 |
ui->ConstructL( );
|
|
158 |
|
|
159 |
// Construct our server
|
|
160 |
CBSServer* server = CBSServer::NewLC( );
|
|
161 |
|
|
162 |
// set engine to AppUI to get notification about focus changes
|
|
163 |
ui->iEngine = &(server->Engine( ));
|
|
164 |
|
|
165 |
RProcess::Rendezvous( KErrNone );
|
|
166 |
|
|
167 |
// Start handling requests
|
|
168 |
CActiveScheduler::Start( );
|
|
169 |
|
|
170 |
CleanupStack::PopAndDestroy( server );
|
|
171 |
|
|
172 |
ui->PrepareToExit( );
|
|
173 |
|
|
174 |
}
|
|
175 |
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
// Create and start the server.
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
TInt CBSServer::ThreadFunction()
|
|
181 |
{
|
|
182 |
__UHEAP_MARK;
|
|
183 |
|
|
184 |
User::RenameThread( KBSEngineThreadName );
|
|
185 |
|
|
186 |
CBSEikonEnv* env = new CBSEikonEnv;
|
|
187 |
__ASSERT_ALWAYS( env, PanicServer( EBSEngineEIkonEnv ) );
|
|
188 |
|
|
189 |
TRAPD(error, env->ConstructL(););
|
|
190 |
__ASSERT_ALWAYS( !error, PanicServer( EBSEngineEIkonEnv ) );
|
|
191 |
|
|
192 |
TRAPD( err, ThreadFunctionL() );
|
|
193 |
if ( err != KErrNone )
|
|
194 |
{
|
|
195 |
PanicServer( EBSEngineSrvCreateServer );
|
|
196 |
}
|
|
197 |
|
|
198 |
env->DestroyEnvironment( );
|
|
199 |
|
|
200 |
__UHEAP_MARKEND;
|
|
201 |
return KErrNone;
|
|
202 |
}
|
|
203 |
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
// Getter of engine
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
//
|
|
208 |
CBSEngine& CBSServer::Engine()
|
|
209 |
{
|
|
210 |
return *iEngine;
|
|
211 |
}
|
|
212 |
|
|
213 |
// -----------------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
// -----------------------------------------------------------------------------
|
|
216 |
//
|
|
217 |
void CBSServer::CBSEikonEnv::DestroyEnvironment()
|
|
218 |
{
|
|
219 |
CEikonEnv::DestroyEnvironment( );
|
|
220 |
}
|
|
221 |
|
|
222 |
// -----------------------------------------------------------------------------
|
|
223 |
//
|
|
224 |
// -----------------------------------------------------------------------------
|
|
225 |
//
|
|
226 |
void CBSServer::CBSEikonEnv::ConstructL()
|
|
227 |
{
|
|
228 |
CEikonEnv::ConstructL( EFalse );
|
|
229 |
SetAutoForwarding(ETrue);
|
|
230 |
User::SetPriorityControl(EFalse);
|
|
231 |
}
|
|
232 |
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
//
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
CBSServer::CBSAppUi::~CBSAppUi()
|
|
238 |
{
|
|
239 |
}
|
|
240 |
|
|
241 |
// -----------------------------------------------------------------------------
|
|
242 |
//
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
//
|
|
245 |
void CBSServer::CBSAppUi::HandleWsEventL( const TWsEvent& aEvent,
|
|
246 |
CCoeControl* aDestination)
|
|
247 |
{
|
|
248 |
if ( aEvent.Type( ) == EEventFocusGroupChanged
|
|
249 |
|| aEvent.Type( ) == EEventWindowGroupsChanged )
|
|
250 |
{
|
|
251 |
TInt windowsGroupID = iCoeEnv->WsSession().GetFocusWindowGroup( );
|
|
252 |
CApaWindowGroupName* apaWGName = CApaWindowGroupName::NewLC(
|
|
253 |
iCoeEnv->WsSession( ), windowsGroupID );
|
|
254 |
TUid uid = apaWGName->AppUid( );
|
|
255 |
CleanupStack::PopAndDestroy( apaWGName );
|
|
256 |
// if UID is 0, ignore event.
|
|
257 |
// Next event should bring correct information
|
|
258 |
if ( uid.iUid )
|
|
259 |
{
|
|
260 |
iEngine->HandleFocusChangeL( uid );
|
|
261 |
}
|
|
262 |
}
|
|
263 |
CEikAppUi::HandleWsEventL( aEvent, aDestination );
|
|
264 |
}
|
|
265 |
|
|
266 |
// -----------------------------------------------------------------------------
|
|
267 |
//
|
|
268 |
// -----------------------------------------------------------------------------
|
|
269 |
//
|
|
270 |
void CBSServer::CBSAppUi::ConstructL()
|
|
271 |
{
|
|
272 |
CEikAppUi::BaseConstructL( ENoAppResourceFile | ENoScreenFurniture );
|
|
273 |
//get notifications about focus change events
|
|
274 |
iCoeEnv->RootWin().EnableFocusChangeEvents( );
|
|
275 |
//get notifications about windows group change events
|
|
276 |
iCoeEnv->RootWin().EnableGroupChangeEvents( );
|
|
277 |
//disable notifications about layout change
|
|
278 |
iCoeEnv->RootWin().DisableScreenChangeEvents();
|
|
279 |
}
|
|
280 |
|
|
281 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
282 |
|
|
283 |
// -----------------------------------------------------------------------------
|
|
284 |
// E32Main item point.
|
|
285 |
// -----------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
TInt E32Main()
|
|
288 |
{
|
|
289 |
return CBSServer::ThreadFunction( );
|
|
290 |
}
|
|
291 |
|
|
292 |
// End of File
|
|
293 |
|