34
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: server implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "tsfswserver.h"
|
|
20 |
#include "tsfswsession.h"
|
|
21 |
#include "tsfswappui.h"
|
|
22 |
#include "tsfswengine.h"
|
|
23 |
|
|
24 |
#include <s32mem.h>
|
|
25 |
#include <eikenv.h>
|
|
26 |
#include <apgwgnam.h>
|
|
27 |
|
|
28 |
// --------------------------------------------------------------------------
|
|
29 |
// CTsFswServer::CTsFswServer
|
|
30 |
// --------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
CTsFswServer::CTsFswServer( TInt aPriority, CTsFswAppUi& aAppUi )
|
|
33 |
: CServer2( aPriority ), iAppUi( aAppUi )
|
|
34 |
{
|
|
35 |
}
|
|
36 |
|
|
37 |
// --------------------------------------------------------------------------
|
|
38 |
// CTsFswServer::NewLC
|
|
39 |
// --------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CTsFswServer* CTsFswServer::NewLC( CTsFswAppUi& aAppUi )
|
|
42 |
{
|
|
43 |
CTsFswServer* self = new ( ELeave ) CTsFswServer(
|
|
44 |
EPriorityNormal, aAppUi );
|
|
45 |
CleanupStack::PushL( self );
|
|
46 |
self->ConstructL();
|
|
47 |
return self;
|
|
48 |
}
|
|
49 |
|
|
50 |
// --------------------------------------------------------------------------
|
|
51 |
// CTsFswServer::ConstructL
|
|
52 |
// --------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
void CTsFswServer::ConstructL()
|
|
55 |
{
|
|
56 |
StartL( KTsFswServerName );
|
|
57 |
iEngine = CTsFswEngine::NewL( *this );
|
|
58 |
iAppUi.SetTaskListObserver( *iEngine );
|
|
59 |
iAppUi.SetResourceObserver( *iEngine );
|
|
60 |
}
|
|
61 |
|
|
62 |
// --------------------------------------------------------------------------
|
|
63 |
// CTsFswServer::~CTsFswServer
|
|
64 |
// --------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
CTsFswServer::~CTsFswServer()
|
|
67 |
{
|
|
68 |
delete iBuffer;
|
|
69 |
delete iEngine;
|
|
70 |
}
|
|
71 |
|
|
72 |
// --------------------------------------------------------------------------
|
|
73 |
// CTsFswServer::NewSessionL
|
|
74 |
// --------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
CSession2* CTsFswServer::NewSessionL( const TVersion&,
|
|
77 |
const RMessage2& ) const
|
|
78 |
{
|
|
79 |
return new ( ELeave ) CTsFswSession;
|
|
80 |
}
|
|
81 |
|
|
82 |
// --------------------------------------------------------------------------
|
|
83 |
// CTsFswServer::AddSession
|
|
84 |
// --------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
void CTsFswServer::AddSession()
|
|
87 |
{
|
|
88 |
++iSessionCount;
|
|
89 |
}
|
|
90 |
|
|
91 |
// --------------------------------------------------------------------------
|
|
92 |
// CTsFswServer::DropSession
|
|
93 |
// --------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CTsFswServer::DropSession()
|
|
96 |
{
|
|
97 |
--iSessionCount;
|
|
98 |
}
|
|
99 |
|
|
100 |
// --------------------------------------------------------------------------
|
|
101 |
// CTsFswServer::SerializeAndGetBufferSizeL
|
|
102 |
// --------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
void CTsFswServer::SerializeAndGetBufferSizeL( const RMessage2& aMessage )
|
|
105 |
{
|
|
106 |
const TInt KBufferExpandSize = 128;
|
|
107 |
const RTsFswArray& array( iEngine->FswDataL() );
|
|
108 |
delete iBuffer; iBuffer = NULL;
|
|
109 |
iBuffer = CBufFlat::NewL( KBufferExpandSize );
|
|
110 |
RBufWriteStream ws;
|
|
111 |
CleanupClosePushL( ws );
|
|
112 |
ws.Open( *iBuffer );
|
|
113 |
CTsFswEntry::ExternalizeArrayL( ws, array );
|
|
114 |
CleanupStack::PopAndDestroy( &ws );
|
|
115 |
TPtr8 p( iBuffer->Ptr( 0 ) );
|
|
116 |
TPckg<TInt> size( p.Length() );
|
|
117 |
aMessage.WriteL( 0, size );
|
|
118 |
aMessage.Complete( KErrNone );
|
|
119 |
}
|
|
120 |
|
|
121 |
// --------------------------------------------------------------------------
|
|
122 |
// CTsFswServer::GetBufferL
|
|
123 |
// --------------------------------------------------------------------------
|
|
124 |
//
|
|
125 |
void CTsFswServer::GetBufferL( const RMessage2& aMessage )
|
|
126 |
{
|
|
127 |
if ( !iBuffer )
|
|
128 |
{
|
|
129 |
User::Leave( KErrGeneral );
|
|
130 |
}
|
|
131 |
TPtr8 p( iBuffer->Ptr( 0 ) );
|
|
132 |
// If the size expected by the client does not match indicate it with a leave
|
|
133 |
// so the client can recognize it by checking the return value of SendReceive
|
|
134 |
// and can request the buffer size again.
|
|
135 |
if ( p.Length() != aMessage.Int1() )
|
|
136 |
{
|
|
137 |
User::Leave( KErrArgument );
|
|
138 |
}
|
|
139 |
aMessage.WriteL( 0, p );
|
|
140 |
aMessage.Complete( KErrNone );
|
|
141 |
}
|
|
142 |
|
|
143 |
// --------------------------------------------------------------------------
|
|
144 |
// CTsFswServer::CloseAppL
|
|
145 |
// --------------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
void CTsFswServer::CloseAppL( TInt aWgId )
|
|
148 |
{
|
|
149 |
iEngine->CloseAppL( aWgId );
|
|
150 |
}
|
|
151 |
|
|
152 |
// --------------------------------------------------------------------------
|
|
153 |
// CTsFswServer::SwitchToAppL
|
|
154 |
// --------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CTsFswServer::SwitchToAppL( TInt aWgId )
|
|
157 |
{
|
|
158 |
iEngine->SwitchToAppL( aWgId );
|
|
159 |
}
|
|
160 |
|
|
161 |
// --------------------------------------------------------------------------
|
|
162 |
// CTsFswServer::ForegroundAppUidL
|
|
163 |
// --------------------------------------------------------------------------
|
|
164 |
//
|
|
165 |
void CTsFswServer::ForegroundAppUidL( const RMessage2& aMessage )
|
|
166 |
{
|
|
167 |
TUid uid = iEngine->ForegroundAppUidL( aMessage.Int1() );
|
|
168 |
TPckg<TInt> uidPckg( uid.iUid );
|
|
169 |
aMessage.WriteL( 0, uidPckg );
|
|
170 |
}
|
|
171 |
|
|
172 |
// --------------------------------------------------------------------------
|
|
173 |
// CTsFswServer::FswDataChanged
|
|
174 |
// callback from engine
|
|
175 |
// --------------------------------------------------------------------------
|
|
176 |
//
|
|
177 |
void CTsFswServer::FswDataChanged()
|
|
178 |
{
|
|
179 |
// notify all sessions about the change
|
|
180 |
iSessionIter.SetToFirst();
|
|
181 |
while ( CTsFswSession* session = static_cast<CTsFswSession*>( iSessionIter++ ) )
|
|
182 |
{
|
|
183 |
if ( session->IsListening() )
|
|
184 |
{
|
|
185 |
session->FswDataChanged();
|
|
186 |
}
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
// --------------------------------------------------------------------------
|
|
191 |
// RunServerL
|
|
192 |
// --------------------------------------------------------------------------
|
|
193 |
//
|
|
194 |
static void RunServerL( CTsFswAppUi& aAppUi, CEikonEnv& aEnv )
|
|
195 |
{
|
|
196 |
// change thread name
|
|
197 |
User::LeaveIfError( RThread::RenameMe( KTsFswServerName ) );
|
|
198 |
|
|
199 |
// set app as hidden
|
|
200 |
CApaWindowGroupName* wgName =
|
|
201 |
CApaWindowGroupName::NewL( aEnv.WsSession(),
|
|
202 |
aEnv.RootWin().Identifier() );
|
|
203 |
wgName->SetHidden( ETrue );
|
|
204 |
wgName->SetWindowGroupName( aEnv.RootWin() );
|
|
205 |
delete wgName;
|
|
206 |
|
|
207 |
// start server
|
|
208 |
CTsFswServer* server = CTsFswServer::NewLC( aAppUi );
|
|
209 |
RProcess::Rendezvous( KErrNone );
|
|
210 |
CActiveScheduler::Start();
|
|
211 |
CleanupStack::PopAndDestroy( server );
|
|
212 |
}
|
|
213 |
|
|
214 |
// --------------------------------------------------------------------------
|
|
215 |
// E32Main
|
|
216 |
// --------------------------------------------------------------------------
|
|
217 |
//
|
|
218 |
TInt E32Main()
|
|
219 |
{
|
|
220 |
__UHEAP_MARK;
|
|
221 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
222 |
TInt err = KErrNoMemory;
|
|
223 |
if ( cleanup )
|
|
224 |
{
|
|
225 |
CEikonEnv* env = new CEikonEnv;
|
|
226 |
if ( env )
|
|
227 |
{
|
|
228 |
TRAP( err, env->ConstructL() );
|
|
229 |
if ( err == KErrNone )
|
|
230 |
{
|
|
231 |
env->DisableExitChecks( ETrue );
|
|
232 |
CTsFswAppUi* ui = new CTsFswAppUi;
|
|
233 |
if ( ui )
|
|
234 |
{
|
|
235 |
TRAP( err, ui->ConstructL() );
|
|
236 |
if ( err == KErrNone )
|
|
237 |
{
|
|
238 |
// hide from tasklist and prevent from coming foreground
|
|
239 |
env->RootWin().SetOrdinalPosition( 0,
|
|
240 |
ECoeWinPriorityNeverAtFront );
|
|
241 |
// set as system app so will not be closed when memory is low
|
|
242 |
env->SetSystem( ETrue );
|
|
243 |
|
|
244 |
RFbsSession::Connect();
|
|
245 |
|
|
246 |
TRAP( err, RunServerL( *ui, *env ) );
|
|
247 |
|
|
248 |
RFbsSession::Disconnect();
|
|
249 |
|
|
250 |
ui->PrepareToExit();
|
|
251 |
}
|
|
252 |
}
|
|
253 |
}
|
|
254 |
env->DestroyEnvironment();
|
|
255 |
}
|
|
256 |
delete cleanup;
|
|
257 |
}
|
|
258 |
__UHEAP_MARKEND;
|
|
259 |
return err;
|
|
260 |
}
|
|
261 |
|
|
262 |
|
|
263 |
// end of file
|