85
|
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: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
// INCLUDE FILES
|
86
|
18 |
#include <sqldb.h>
|
85
|
19 |
#include <eikenv.h>
|
|
20 |
#include <eikappui.h>
|
|
21 |
#include "casrv.h"
|
|
22 |
#include "casrvdef.h"
|
|
23 |
#include "casrvsession.h"
|
|
24 |
#include "casrvengutils.h"
|
|
25 |
#include "castorageproxy.h"
|
|
26 |
#include "casrvmanager.h"
|
|
27 |
|
|
28 |
// ==================== LOCAL FUNCTIONS ====================
|
|
29 |
|
|
30 |
/**
|
|
31 |
* Create a server.
|
|
32 |
* @param Pointer to created server (if created) returned here.
|
|
33 |
* @return Error code.
|
|
34 |
*/
|
|
35 |
LOCAL_C TInt CreateServer( CCaSrv*& aServer )
|
|
36 |
{
|
|
37 |
// The TRAP is not working in the same stack frame where the
|
|
38 |
// CTrapCleanup was created. This is why we need this function.
|
|
39 |
TRAPD( err, aServer = CCaSrv::NewL() );
|
|
40 |
return err;
|
|
41 |
}
|
|
42 |
|
|
43 |
// ==================== GLOBAL FUNCTIONS ====================
|
|
44 |
|
|
45 |
// ---------------------------------------------------------
|
86
|
46 |
//
|
85
|
47 |
// ---------------------------------------------------------
|
|
48 |
//
|
|
49 |
EXPORT_C TInt RunCaServer()
|
|
50 |
{
|
|
51 |
__UHEAP_MARK;
|
|
52 |
CTrapCleanup* trapCleanup = NULL;
|
|
53 |
CActiveScheduler* activeScheduler = NULL;
|
|
54 |
CCaSrv* server = NULL;
|
|
55 |
|
|
56 |
TInt err = User::RenameThread( KCaSrvName );
|
|
57 |
if( !err )
|
|
58 |
{
|
|
59 |
// Create a trap cleanup, make and install an active scheduler.
|
|
60 |
err = KErrNoMemory;
|
|
61 |
trapCleanup = CTrapCleanup::New();
|
|
62 |
if( trapCleanup )
|
|
63 |
{
|
|
64 |
activeScheduler = new CActiveScheduler();
|
|
65 |
if( activeScheduler )
|
|
66 |
{
|
|
67 |
CActiveScheduler::Install( activeScheduler );
|
|
68 |
err = CreateServer( server ); // Not pushed (no leaving).
|
|
69 |
if( !err )
|
|
70 |
{
|
|
71 |
err = server->Start( KCaSrvName );
|
|
72 |
}
|
|
73 |
}
|
|
74 |
else
|
|
75 |
{
|
|
76 |
err = KErrNoMemory;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
}
|
|
80 |
// Let the caller know how it went.
|
|
81 |
RProcess::Rendezvous( err );
|
|
82 |
if( !err )
|
|
83 |
{
|
|
84 |
CActiveScheduler::Start(); // Start off. Exit timer will stop it.
|
|
85 |
}
|
|
86 |
CActiveScheduler::Install( NULL );
|
|
87 |
delete activeScheduler;
|
|
88 |
delete server;
|
|
89 |
delete trapCleanup;
|
|
90 |
__UHEAP_MARKEND;
|
|
91 |
return err;
|
|
92 |
}
|
|
93 |
|
|
94 |
// ==================== MEMBER FUNCTIONS ====================
|
|
95 |
|
|
96 |
// ---------------------------------------------------------
|
86
|
97 |
//
|
85
|
98 |
// ---------------------------------------------------------
|
|
99 |
//
|
|
100 |
CCaSrv* CCaSrv::NewL()
|
|
101 |
{
|
|
102 |
CCaSrv* srv = new ( ELeave ) CCaSrv();
|
|
103 |
CleanupStack::PushL( srv );
|
|
104 |
srv->ConstructL();
|
|
105 |
CleanupStack::Pop( srv );
|
|
106 |
return srv;
|
|
107 |
}
|
|
108 |
|
|
109 |
// ---------------------------------------------------------
|
86
|
110 |
//
|
85
|
111 |
// ---------------------------------------------------------
|
|
112 |
//
|
|
113 |
CCaSrv::~CCaSrv()
|
|
114 |
{
|
|
115 |
// Cancel requests and delete all sessions first.
|
|
116 |
// Base class would do it for us but that's too late - our sessions
|
|
117 |
// call the server back (SessionClosed, RemoveContainer, etc.).
|
|
118 |
Cancel();
|
|
119 |
CSession2* session;
|
|
120 |
iSessionIter.SetToFirst();
|
|
121 |
while( ( session = iSessionIter++ ) != NULL )
|
|
122 |
{
|
|
123 |
delete session;
|
|
124 |
}
|
|
125 |
delete iSrvManager;
|
|
126 |
delete iSrvEngUtils;
|
|
127 |
delete iStorageProxy;
|
|
128 |
}
|
|
129 |
|
|
130 |
// ---------------------------------------------------------
|
86
|
131 |
//
|
85
|
132 |
// ---------------------------------------------------------
|
|
133 |
//
|
|
134 |
CCaStorageProxy* CCaSrv::GetStorageProxy()
|
|
135 |
{
|
|
136 |
return iStorageProxy;
|
|
137 |
}
|
|
138 |
|
|
139 |
// ---------------------------------------------------------
|
86
|
140 |
//
|
85
|
141 |
// ---------------------------------------------------------
|
|
142 |
//
|
|
143 |
CCaSrv::CCaSrv() :
|
|
144 |
CServer2( EPriorityNormal, CServer2::TServerType( EIpcSession_Sharable ) )
|
|
145 |
{
|
|
146 |
}
|
|
147 |
|
|
148 |
// ---------------------------------------------------------
|
86
|
149 |
//
|
85
|
150 |
// ---------------------------------------------------------
|
|
151 |
//
|
|
152 |
void CCaSrv::ConstructL()
|
|
153 |
{
|
|
154 |
iSessionCount = 0;
|
|
155 |
iStorageProxy = CCaStorageProxy::NewL();
|
|
156 |
iSrvEngUtils = CCaSrvEngUtils::NewL();
|
94
|
157 |
iSrvManager = CCaSrvManager::NewL(*iStorageProxy, iSrvEngUtils);
|
|
158 |
TInt errCode = iSrvManager->LoadOperationErrorCodeL();
|
|
159 |
if( KSqlErrNotDb <= errCode && errCode <= KSqlErrGeneral )
|
86
|
160 |
{
|
|
161 |
//problem in loading one of plugins, probably data base is corrupted
|
|
162 |
//lets load it from ROM and try again
|
94
|
163 |
delete iSrvManager;
|
|
164 |
iSrvManager = NULL;
|
86
|
165 |
iStorageProxy->LoadDataBaseFromRomL();
|
|
166 |
iSrvManager = CCaSrvManager::NewL( *iStorageProxy, iSrvEngUtils );
|
|
167 |
}
|
85
|
168 |
}
|
|
169 |
|
|
170 |
// ---------------------------------------------------------
|
86
|
171 |
//
|
85
|
172 |
// ---------------------------------------------------------
|
|
173 |
//
|
|
174 |
CSession2* CCaSrv::NewSessionL( const TVersion& aVersion,
|
|
175 |
const RMessage2& /*aMessage*/) const
|
|
176 |
{
|
|
177 |
TVersion version( KCaMajorVersion, KCaMinorVersion, KCaBuild );
|
|
178 |
if( !User::QueryVersionSupported( version, aVersion ) )
|
|
179 |
{
|
|
180 |
User::Leave( KErrNotSupported );
|
|
181 |
}
|
|
182 |
CSession2* session;
|
|
183 |
session = CCaSrvSession::NewL( const_cast<CCaSrv&> ( *this ) );
|
|
184 |
return session;
|
|
185 |
}
|
|
186 |
|
|
187 |
// ---------------------------------------------------------
|
86
|
188 |
//
|
85
|
189 |
// ---------------------------------------------------------
|
|
190 |
//
|
|
191 |
void CCaSrv::IncreaseSessionCount()
|
|
192 |
{
|
|
193 |
iSessionCount++;
|
|
194 |
}
|
|
195 |
|
|
196 |
// ---------------------------------------------------------
|
86
|
197 |
//
|
85
|
198 |
// ---------------------------------------------------------
|
|
199 |
//
|
|
200 |
void CCaSrv::DecreaseSessionCount()
|
|
201 |
{
|
|
202 |
iSessionCount--;
|
|
203 |
}
|
|
204 |
|
|
205 |
// End of File
|