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