|
1 /* |
|
2 * Copyright (c) 2004 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: DRMClockServer manages the all operation to the DRMClock |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include "DRMClockServer.h" |
|
23 #include "drmlog.h" |
|
24 #include "drmclockclientserver.h" |
|
25 #include "drmcommonclientserver.h" |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 // CONSTANTS |
|
30 // MACROS |
|
31 |
|
32 |
|
33 // LOCAL CONSTANTS AND MACROS |
|
34 const TUint8 KMaxStartTries = 3; |
|
35 const TInt KWaitingTime = 100000; // 1 secs |
|
36 _LIT( KClockThread, "DRMClockServer" ); |
|
37 |
|
38 // MODULE DATA STRUCTURES |
|
39 using DRMClock::KServerMajorVersion; |
|
40 using DRMClock::KServerMinorVersion; |
|
41 using DRMClock::KServerBuildVersion; |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 LOCAL_C TInt StartClockServer( RSemaphore& aClientSem ); |
|
45 |
|
46 // FORWARD DECLARATIONS |
|
47 |
|
48 // ============================= LOCAL FUNCTIONS =============================== |
|
49 |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // Function StartClockServer(). |
|
53 // This function starts the actual server under TRAP harness and starts |
|
54 // waiting for connections. This function returns only if there has been |
|
55 // errors during server startup or the server is stopped for some reason. |
|
56 // |
|
57 // Returns: TInt: Symbian OS error code. |
|
58 // ----------------------------------------------------------------------------- |
|
59 LOCAL_C TInt StartClockServer( RSemaphore& aClientSem ) |
|
60 |
|
61 { |
|
62 TInt error = KErrNone; |
|
63 CDRMClockServer* server = NULL; |
|
64 |
|
65 TUint8 count = 0; |
|
66 |
|
67 do |
|
68 { |
|
69 DRMLOG2( _L( "unipertar.exe: StartClockServer: %d" ), error ); |
|
70 |
|
71 ++count; |
|
72 |
|
73 TRAP( error, ( server = CDRMClockServer::NewL() ) ); |
|
74 |
|
75 if ( error ) |
|
76 { |
|
77 User::After( TTimeIntervalMicroSeconds32(KWaitingTime) ); |
|
78 } |
|
79 |
|
80 } while( error && ( count <= KMaxStartTries ) ); |
|
81 |
|
82 if( error ) |
|
83 { |
|
84 // Failed |
|
85 return error; |
|
86 } |
|
87 |
|
88 // Release the semaphore... |
|
89 aClientSem.Signal(); |
|
90 |
|
91 // and close it. Otherwise there will be an unused handle to the semaphore |
|
92 // until the phone is switched off. |
|
93 aClientSem.Close(); |
|
94 |
|
95 DRMLOG( _L( "unipertar.exe: StartClockServer: starting..." ) ); |
|
96 |
|
97 // Start waiting for connections |
|
98 CActiveScheduler::Start(); |
|
99 |
|
100 // Dying. |
|
101 |
|
102 DRMLOG( _L( "unipertar.exe: StartClockServer: dying" ) ); |
|
103 |
|
104 delete server; |
|
105 |
|
106 return KErrNone; |
|
107 } |
|
108 |
|
109 // ============================ MEMBER FUNCTIONS =============================== |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CDRMClockServer::NewLC |
|
113 // Two-phased constructor. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CDRMClockServer* CDRMClockServer::NewL() |
|
117 { |
|
118 CDRMClockServer* self = new( ELeave ) CDRMClockServer(); |
|
119 |
|
120 CleanupStack::PushL( self ); |
|
121 |
|
122 self->ConstructL(); |
|
123 |
|
124 CleanupStack::Pop( self ); |
|
125 |
|
126 return self; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // Destructor |
|
131 // ----------------------------------------------------------------------------- |
|
132 CDRMClockServer::~CDRMClockServer() |
|
133 { |
|
134 if( iDRMClock ) |
|
135 { |
|
136 delete iDRMClock; |
|
137 iDRMClock = 0; |
|
138 } |
|
139 |
|
140 DRMLOG( _L( "CDRMClockServer::~" ) ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CDRMClockServer::RunErrorL |
|
145 // From CActive. Complete the request and restart the scheduler. |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 TInt CDRMClockServer::RunError( TInt aError ) |
|
149 { |
|
150 DRMLOG2( _L( "CDRMClockServer::RunError: %d" ), aError ); |
|
151 |
|
152 // Inform the client. |
|
153 Message().Complete( aError ); |
|
154 |
|
155 // Restart the scheduler. |
|
156 ReStart(); |
|
157 |
|
158 // Error handled. |
|
159 return KErrNone; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CDRMClockServer::NewSessionL |
|
164 // Called when a client requires a new instance. |
|
165 // ----------------------------------------------------------------------------- |
|
166 CSession2* CDRMClockServer::NewSessionL( |
|
167 const TVersion& aVersion, |
|
168 const RMessage2& /*aMessage*/ ) const |
|
169 { |
|
170 DRMLOG( _L( "CDRMClockServer::NewSessionL" ) ); |
|
171 |
|
172 // Check that the versions are compatible. |
|
173 if ( ! User::QueryVersionSupported( TVersion( KServerMajorVersion, |
|
174 KServerMinorVersion, |
|
175 KServerBuildVersion ), |
|
176 aVersion ) ) |
|
177 { |
|
178 // Sorry, no can do. |
|
179 User::Leave( KErrNotSupported ); |
|
180 } |
|
181 |
|
182 DRMLOG( _L( "CDRMClockServer::NewSessionL: Creating a new session" ) ); |
|
183 |
|
184 return CDRMClockSession::NewL( iDRMClock ); |
|
185 } |
|
186 |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CDRMClockServer::CDRMClockServer |
|
190 // C++ default constructor can NOT contain any code, that |
|
191 // might leave. |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 CDRMClockServer::CDRMClockServer() : |
|
195 CServer2( EPriorityStandard ) |
|
196 { |
|
197 // Nothing |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CDRMClockServer::ConstructL |
|
202 // Symbian 2nd phase constructor can leave. |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CDRMClockServer::ConstructL() |
|
206 { |
|
207 DRMLOG( _L( "CDRMClockServer::ConstructL" ) ); |
|
208 |
|
209 // Ignore errors |
|
210 User::LeaveIfError( User::RenameThread( KClockThread ) ); |
|
211 |
|
212 iDRMClock = CDRMClock::NewL(); |
|
213 |
|
214 DRMLOG( _L( "CDRMClockServer::clock Server started." ) ); |
|
215 |
|
216 // Add the server to the scheduler. |
|
217 StartL( DRMClock::KServerName ); |
|
218 } |
|
219 |
|
220 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
221 // ----------------------------------------------------------------------------- |
|
222 // Function StartupClock(). |
|
223 // This function starts the actual DRM Notifier |
|
224 // the cleanup stack and active scheduler. |
|
225 // Returns: TInt: Symbian OS error code. |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 |
|
229 TInt StartupClock( TAny* ) |
|
230 { |
|
231 DRMLOG( _L( "unipertar.exe: StartupClock" ) ); |
|
232 TInt error = KErrNone; |
|
233 CTrapCleanup* trap = CTrapCleanup::New(); |
|
234 |
|
235 // Check that memory allocation was successful. |
|
236 __ASSERT_ALWAYS( trap, User::Invariant() ); |
|
237 |
|
238 DRMLOG( _L( "unipertar.exe: StartupClock: active scheduler" ) ); |
|
239 |
|
240 CActiveScheduler* scheduler = new CActiveScheduler(); |
|
241 |
|
242 __ASSERT_ALWAYS( scheduler, User::Invariant() ); |
|
243 |
|
244 CActiveScheduler::Install( scheduler ); |
|
245 |
|
246 // Reusing semaphore |
|
247 RSemaphore clientSem; |
|
248 __ASSERT_ALWAYS( !( clientSem.OpenGlobal( KDRMEngCommonSemaphore ) ), |
|
249 User::Invariant() ); |
|
250 |
|
251 error = StartClockServer( clientSem ); |
|
252 |
|
253 if ( error ) { |
|
254 // Server creation failed. Release the semaphore. |
|
255 // In case of successful startup, CDRMClockServer |
|
256 // releases the semaphore. |
|
257 clientSem.Signal(); |
|
258 clientSem.Close(); |
|
259 } |
|
260 |
|
261 delete scheduler; |
|
262 scheduler = NULL; |
|
263 |
|
264 delete trap; |
|
265 trap = NULL; |
|
266 |
|
267 DRMLOG2( _L( "unipertar.exe: StartupClock exits with %d" ), error ); |
|
268 |
|
269 return error; |
|
270 } |
|
271 |
|
272 // End of File |