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