114
|
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: Content publisher Server
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <mw/MemoryManager.h>
|
|
19 |
#include <liwcommon.h>
|
|
20 |
#include <ecom/ecom.h>
|
|
21 |
#include <fbs.h>
|
|
22 |
|
|
23 |
#include "cpublisherregistrymap.h"
|
|
24 |
#include "cpserver.h"
|
|
25 |
#include "cpglobals.h"
|
|
26 |
#include "cpdebug.h"
|
|
27 |
#include "cpserversession.h"
|
|
28 |
#include "cpserverdatamanager.h"
|
|
29 |
#include "cpactionhandlerthread.h"
|
|
30 |
|
|
31 |
|
|
32 |
// Policy Server
|
|
33 |
// ============================================================================
|
|
34 |
const TUint KServerPolicyRangeCount = 3;
|
|
35 |
const TInt KServerPolicyRanges[KServerPolicyRangeCount] =
|
|
36 |
{
|
|
37 |
0, // range 0 -- ECpServerExecuteAction - 1
|
|
38 |
ECpServerGetListSize, // range ECpServerGetListSize -- ECpServerExecuteAction - 1
|
|
39 |
ECpServerExecuteAction
|
|
40 |
// range ECpServerExecuteAction -- inf
|
|
41 |
};
|
|
42 |
|
|
43 |
const TUint8 KServerPolicyElementsIndex[KServerPolicyRangeCount] =
|
|
44 |
{
|
|
45 |
0, // applies to 0th range
|
|
46 |
1, // applies to 1st range
|
|
47 |
CPolicyServer::EAlwaysPass
|
|
48 |
};
|
|
49 |
|
|
50 |
const CPolicyServer::TPolicyElement KServerPolicyElements[] =
|
|
51 |
{
|
|
52 |
{
|
|
53 |
_INIT_SECURITY_POLICY_C1(ECapability_None), CPolicyServer::EFailClient
|
|
54 |
},
|
|
55 |
{
|
|
56 |
_INIT_SECURITY_POLICY_C1(ECapability_None), CPolicyServer::EFailClient
|
|
57 |
}
|
|
58 |
};
|
|
59 |
|
|
60 |
const CPolicyServer::TPolicy KServerPolicy =
|
|
61 |
{
|
|
62 |
CPolicyServer::EAlwaysPass, // specifies all connect attempts should pass
|
|
63 |
KServerPolicyRangeCount,
|
|
64 |
KServerPolicyRanges,
|
|
65 |
KServerPolicyElementsIndex,
|
|
66 |
KServerPolicyElements
|
|
67 |
};
|
|
68 |
// ============================================================================
|
|
69 |
|
|
70 |
|
|
71 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
72 |
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
// CCPServer::CCPServer
|
|
75 |
// C++ default constructor can NOT contain any code, that
|
|
76 |
// might leave.
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
//
|
|
79 |
CCPServer::CCPServer( TInt aPriority ) :
|
|
80 |
CPolicyServer( aPriority, KServerPolicy, EUnsharableSessions)
|
|
81 |
{
|
|
82 |
}
|
|
83 |
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
// CCPServer::ConstructL
|
|
86 |
// Symbian 2nd phase constructor can leave.
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
//
|
|
89 |
void CCPServer::ConstructL()
|
|
90 |
{
|
|
91 |
CP_DEBUG( _L8("CCPServer::ConstructL()" ) );
|
|
92 |
StartL(KCPServerName);
|
|
93 |
iBURListener = CCPServerBURListener::NewL(this);
|
|
94 |
iCountSession = 0;
|
|
95 |
iBURLock = iBURListener->CheckBUR();
|
|
96 |
iDataManager = CCPDataManager::NewL(iDataMapCache, iBURLock);
|
|
97 |
iActionHandlerThread = CCPActionHandlerThread::NewL();
|
|
98 |
if (!iBURLock)
|
|
99 |
{
|
|
100 |
TRAP_IGNORE( DeactivatePublishersL() );
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
// -----------------------------------------------------------------------------
|
|
105 |
// CCPServer::NewL
|
|
106 |
// Two-phased constructor.
|
|
107 |
// -------------------------------------- ---------------------------------------
|
|
108 |
//
|
|
109 |
CCPServer* CCPServer::NewLC()
|
|
110 |
{
|
|
111 |
CP_DEBUG( _L8("CCPServer::NewLC()" ) );
|
|
112 |
CCPServer* self = new( ELeave ) CCPServer( EPriorityNormal );
|
|
113 |
CleanupStack::PushL( self );
|
|
114 |
self->ConstructL( );
|
|
115 |
return self;
|
|
116 |
}
|
|
117 |
|
|
118 |
// -----------------------------------------------------------------------------
|
|
119 |
// CCPServer::~CCPServer()
|
|
120 |
// Destructor.
|
|
121 |
// -------------------------------------- ---------------------------------------
|
|
122 |
//
|
|
123 |
CCPServer::~CCPServer()
|
|
124 |
{
|
|
125 |
CP_DEBUG( _L8("CCPServer::~CCPServer()" ) );
|
|
126 |
iDataMapCache.Reset();
|
|
127 |
for ( TInt i(0); i< iNotifications.Count( ); i++ )
|
|
128 |
{
|
|
129 |
iNotifications[i]->Close( );
|
|
130 |
}
|
|
131 |
iNotifications.Close( );
|
|
132 |
delete iDataManager;
|
|
133 |
delete iActionHandlerThread;
|
|
134 |
delete iBURListener;
|
|
135 |
}
|
|
136 |
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
// ---------------------------------------------------------------------------
|
|
140 |
//
|
|
141 |
void CCPServer::RemoveSession()
|
|
142 |
{
|
|
143 |
CP_DEBUG( _L8("CCPServer::RemoveSession()" ) );
|
|
144 |
iCountSession--;
|
|
145 |
if ( !iCountSession )
|
|
146 |
{
|
|
147 |
Stop( );
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
// ---------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
void CCPServer::AddSession()
|
|
156 |
{
|
|
157 |
CP_DEBUG( _L8("CCPServer::AddSession()" ) );
|
|
158 |
iCountSession++;
|
|
159 |
}
|
|
160 |
|
|
161 |
// ---------------------------------------------------------------------------
|
|
162 |
// CCPServer::HandleBUREventL
|
|
163 |
// ---------------------------------------------------------------------------
|
|
164 |
//
|
|
165 |
void CCPServer::HandleBUREventL( TBURStatus aStatus )
|
|
166 |
{
|
|
167 |
CP_DEBUG( _L8("CCPServer::HandleBUREventL()" ) );
|
|
168 |
if ( (aStatus == EBURStatusBackup ) || (aStatus == EBURStatusRestore ) )
|
|
169 |
{
|
|
170 |
iBURLock = ETrue;
|
|
171 |
iDataManager->CloseDatabase( );
|
|
172 |
}
|
|
173 |
else
|
|
174 |
{
|
|
175 |
iDataManager->OpenDatabaseL(iDataMapCache);
|
|
176 |
iBURLock = EFalse;
|
|
177 |
}
|
|
178 |
}
|
|
179 |
|
|
180 |
// ---------------------------------------------------------------------------
|
|
181 |
// CCPServer::GetLock
|
|
182 |
// ---------------------------------------------------------------------------
|
|
183 |
//
|
|
184 |
TBool CCPServer::GetLock()
|
|
185 |
{
|
|
186 |
return iBURLock;
|
|
187 |
}
|
|
188 |
|
|
189 |
// -----------------------------------------------------------------------------
|
|
190 |
// CCPServer::GetNotifications
|
|
191 |
// -----------------------------------------------------------------------------
|
|
192 |
//
|
|
193 |
RPointerArray<CLiwDefaultList>& CCPServer::GetNotifications( )
|
|
194 |
{
|
|
195 |
return iNotifications;
|
|
196 |
}
|
|
197 |
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
// CCPServer::GetDataMapCache
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
//
|
|
202 |
TLiwVariant& CCPServer::GetDataMapCache()
|
|
203 |
{
|
|
204 |
return iDataMapCache;
|
|
205 |
}
|
|
206 |
|
|
207 |
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
// CCPServer::NewSessionL
|
|
210 |
// Create new session.
|
|
211 |
// -----------------------------------------------------------------------------
|
|
212 |
//
|
|
213 |
CSession2* CCPServer::NewSessionL( const TVersion& /*aVersion*/,
|
|
214 |
const RMessage2& /*aMessage*/) const
|
|
215 |
{
|
|
216 |
CP_DEBUG( _L8("CCPServer::NewSessionL()" ) );
|
|
217 |
TPointersForSession passer;
|
|
218 |
passer.iDataManager = iDataManager;
|
|
219 |
passer.iServer = const_cast<CCPServer*>(this);
|
|
220 |
passer.iActionHandlerThread = iActionHandlerThread;
|
|
221 |
return CCPServerSession::NewL( passer );
|
|
222 |
}
|
|
223 |
|
|
224 |
// -----------------------------------------------------------------------------
|
|
225 |
// CCPServer::RunError
|
|
226 |
// RunError is called when RunL leaves.
|
|
227 |
// -----------------------------------------------------------------------------
|
|
228 |
//
|
|
229 |
TInt CCPServer::RunError( TInt /*aError*/)
|
|
230 |
{
|
|
231 |
ReStart( );
|
|
232 |
return KErrNone;
|
|
233 |
}
|
|
234 |
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
// CCPServer::PanicClient
|
|
237 |
// Panic client.
|
|
238 |
// -----------------------------------------------------------------------------
|
|
239 |
//
|
|
240 |
void CCPServer::PanicClient( const RMessage2& aMessage, TCPServerPanic aPanic )
|
|
241 |
{
|
|
242 |
aMessage.Panic( KCPServerName, aPanic );
|
|
243 |
}
|
|
244 |
|
|
245 |
// -----------------------------------------------------------------------------
|
|
246 |
// CCPServer::PanicServer
|
|
247 |
// Panic server.
|
|
248 |
// -----------------------------------------------------------------------------
|
|
249 |
//
|
|
250 |
void CCPServer::PanicServer( TCPServerPanic aPanic )
|
|
251 |
{
|
|
252 |
User::Panic( KCPServerName, aPanic );
|
|
253 |
}
|
|
254 |
|
|
255 |
|
|
256 |
// -----------------------------------------------------------------------------
|
|
257 |
// CCPServer::SendNotificationL
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
//
|
|
260 |
void CCPServer::AppendNotificationL( CCPLiwMap* aMap )
|
|
261 |
{
|
|
262 |
aMap->InsertL( KType, TLiwVariant( KPublisher ) );
|
|
263 |
aMap->InsertL( KOperation, TLiwVariant( KOperationUpdate ) );
|
|
264 |
CLiwDefaultList* list = CLiwDefaultList::NewLC( );
|
|
265 |
list->AppendL( TLiwVariant( aMap ) );
|
|
266 |
iNotifications.AppendL( list );
|
|
267 |
CleanupStack::Pop( list );
|
|
268 |
}
|
|
269 |
|
|
270 |
// -----------------------------------------------------------------------------
|
|
271 |
// CCPServer::Stop
|
|
272 |
// Stop serwer
|
|
273 |
// -----------------------------------------------------------------------------
|
|
274 |
//
|
|
275 |
void CCPServer::Stop()
|
|
276 |
{
|
|
277 |
CP_DEBUG( _L8("CCPServer::Stop()" ) );
|
|
278 |
CActiveScheduler::Stop( );
|
|
279 |
}
|
|
280 |
|
|
281 |
// -----------------------------------------------------------------------------
|
|
282 |
// CCPServer::ThreadStart(void)
|
|
283 |
// Starts server.
|
|
284 |
// -----------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
TInt CCPServer::ThreadStart( void )
|
|
287 |
{
|
|
288 |
__UHEAP_MARK;
|
|
289 |
// Create the server, if one with this name does not already exist.
|
|
290 |
TFindServer findCountServer( KCPServerName );
|
|
291 |
TFullName name;
|
|
292 |
|
|
293 |
CTrapCleanup* trapCleanup = CTrapCleanup::New();
|
|
294 |
if ( !trapCleanup )
|
|
295 |
{
|
|
296 |
PanicServer( ECPServerSrvCreateServer );
|
|
297 |
}
|
|
298 |
CActiveScheduler* activeScheduler = new CActiveScheduler;
|
|
299 |
if ( !activeScheduler )
|
|
300 |
{
|
|
301 |
PanicServer( ECPServerSrvCreateServer );
|
|
302 |
}
|
|
303 |
CActiveScheduler::Install( activeScheduler );
|
|
304 |
|
|
305 |
// Need to check that the server exists.
|
|
306 |
if ( findCountServer.Next( name ) != KErrNone )
|
|
307 |
{
|
|
308 |
User::RenameThread( KCPServerName );
|
|
309 |
|
|
310 |
TRAPD( err, CreateAndRunServerL() );
|
|
311 |
if ( err != KErrNone )
|
|
312 |
{
|
|
313 |
PanicServer( ECPServerSrvCreateServer );
|
|
314 |
}
|
|
315 |
}
|
|
316 |
|
|
317 |
delete activeScheduler;
|
|
318 |
delete trapCleanup;
|
|
319 |
__UHEAP_MARKEND;
|
|
320 |
return KErrNone;
|
|
321 |
}
|
|
322 |
|
|
323 |
// -----------------------------------------------------------------------------
|
|
324 |
// CCPServer::CreateAndRunServerL(void)
|
|
325 |
// Creates and runs server.
|
|
326 |
// -----------------------------------------------------------------------------
|
|
327 |
//
|
|
328 |
void CCPServer::CreateAndRunServerL( void )
|
|
329 |
{
|
|
330 |
// Construct server
|
|
331 |
//
|
|
332 |
CCPServer* server = CCPServer::NewLC( );
|
|
333 |
// Initialisation complete, now signal the client
|
|
334 |
//
|
|
335 |
RProcess::Rendezvous( KErrNone );
|
|
336 |
CActiveScheduler::Start( );
|
|
337 |
CleanupStack::PopAndDestroy( server );
|
|
338 |
}
|
|
339 |
|
|
340 |
// -----------------------------------------------------------------------------
|
|
341 |
//
|
|
342 |
// -----------------------------------------------------------------------------
|
|
343 |
//
|
|
344 |
void CCPServer::DeactivatePublishersL()
|
|
345 |
{
|
|
346 |
CLiwGenericParamList* publishers = CLiwGenericParamList::NewLC( );
|
|
347 |
CCPLiwMap* map = CPublisherRegistryMap::NewLC( );
|
|
348 |
iDataManager->GetActivePublishersL( publishers );
|
|
349 |
TInt pos( 0 );
|
|
350 |
while( pos != KErrNotFound )
|
|
351 |
{
|
|
352 |
publishers->FindFirst( pos, KListMap );
|
|
353 |
|
|
354 |
if( pos != KErrNotFound )
|
|
355 |
{
|
|
356 |
TLiwVariant variant = ( *publishers )[pos++].Value( );
|
|
357 |
map->Reset( );
|
|
358 |
variant.Get( *map );
|
|
359 |
|
|
360 |
// update flag value in the database
|
|
361 |
TRAP_IGNORE( ResetAndUpdateFlagL( map ) );
|
|
362 |
|
|
363 |
//append update notification
|
|
364 |
TRAP_IGNORE( AppendNotificationL( map ) );
|
|
365 |
|
|
366 |
variant.Reset( );
|
|
367 |
}
|
|
368 |
}
|
|
369 |
CleanupStack::PopAndDestroy( map );
|
|
370 |
CleanupStack::PopAndDestroy( publishers );
|
|
371 |
}
|
|
372 |
|
|
373 |
// -----------------------------------------------------------------------------
|
|
374 |
// CCPServer::ResetAndUpdateFlagL
|
|
375 |
// Resets Activate flag and update item in the DB
|
|
376 |
// -----------------------------------------------------------------------------
|
|
377 |
//
|
|
378 |
void CCPServer::ResetAndUpdateFlagL( CCPLiwMap* aMap )
|
|
379 |
{
|
|
380 |
TInt32 flag(0);
|
|
381 |
if( !aMap->GetProperty( KFlag, flag ))
|
|
382 |
{
|
|
383 |
User::Leave(KErrNotFound);
|
|
384 |
}
|
|
385 |
aMap->Remove( KFlag );
|
|
386 |
flag &= 0xFFFFFFFE;
|
|
387 |
aMap->InsertL( KFlag, TLiwVariant( flag ) );
|
|
388 |
iDataManager->AddDataL( *aMap );
|
|
389 |
}
|
|
390 |
|
|
391 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
392 |
|
|
393 |
// -----------------------------------------------------------------------------
|
|
394 |
// E32Main entry point.
|
|
395 |
// Returns: KErrNone
|
|
396 |
// -----------------------------------------------------------------------------
|
|
397 |
//
|
|
398 |
TInt E32Main()
|
|
399 |
{
|
|
400 |
RAllocator* iAllocator = MemoryManager::SwitchToFastAllocator();
|
|
401 |
|
|
402 |
//Get the return value (needs to call CloseFastAllocator() before return)
|
|
403 |
TInt iReturnValue = CCPServer::ThreadStart( );
|
|
404 |
MemoryManager::CloseFastAllocator(iAllocator);
|
|
405 |
return iReturnValue;
|
|
406 |
}
|
|
407 |
|
|
408 |
// End of File
|