|
1 /* |
|
2 * Copyright (c) 2007 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: Power save mode server main class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 #include "psmsrvserver.h" |
|
21 #include "psmmanager.h" // CPsmManager |
|
22 #include "psmsrvsession.h" // CPsmSession |
|
23 #include "psmsrvshutdown.h" |
|
24 #include "psmtrace.h" |
|
25 #include "psmdefines.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CPsmSrvServer::NewL |
|
29 // Two-phased constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CPsmSrvServer* CPsmSrvServer::NewL() |
|
33 { |
|
34 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::NewL()" ) ) ); |
|
35 |
|
36 CPsmSrvServer* self = CPsmSrvServer::NewLC(); |
|
37 CleanupStack::Pop( self ); |
|
38 |
|
39 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::NewL - return 0x%x" ), self ) ); |
|
40 |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CPsmSrvServer::NewLC |
|
46 // Two-phased constructor. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CPsmSrvServer* CPsmSrvServer::NewLC() |
|
50 { |
|
51 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::NewLC()" ) ) ); |
|
52 |
|
53 CPsmSrvServer* self = new( ELeave ) CPsmSrvServer( EUnsharableSessions ); |
|
54 |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 |
|
58 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::NewLC - return 0x%x" ), self ) ); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPsmSrvServer::CPsmSrvServer |
|
65 // C++ default constructor can NOT contain any code, that |
|
66 // might leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CPsmSrvServer::CPsmSrvServer( const TServerType aType ) |
|
70 : CPolicyServer( CActive::EPriorityStandard, KPsmSrvPolicy, aType ) |
|
71 { |
|
72 // Nothing to do |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CPsmSrvServer::ConstructL |
|
77 // Symbian 2nd phase constructor can leave. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CPsmSrvServer::ConstructL() |
|
81 { |
|
82 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::ConstructL()" ) ) ); |
|
83 |
|
84 // Add server to active scheduler before doing anything else so there won't |
|
85 // be synchronization problems with multiple clients. |
|
86 StartL( KPsmProcessName ); |
|
87 |
|
88 // Create an instance of the manager class |
|
89 iPsmManager = CPsmManager::NewL(); |
|
90 |
|
91 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::ConstructL - return" ) ) ); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // Destructor |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CPsmSrvServer::~CPsmSrvServer() |
|
99 { |
|
100 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::~CPsmSrvServer()" ) ) ); |
|
101 |
|
102 delete iPsmManager; |
|
103 delete iShutdown; |
|
104 |
|
105 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::~CPsmSrvServer - return") ) ); |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CPsmSrvServer::NewSessionL |
|
110 // Creates a new CSession2 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CSession2* CPsmSrvServer::NewSessionL( const TVersion& aVersion, |
|
114 const RMessage2& /*aMessage*/ ) const |
|
115 { |
|
116 #if defined(_DEBUG) && defined(COMPONENT_TRACE_FLAG) |
|
117 TVersionName name = aVersion.Name(); |
|
118 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::NewSessionL(%S)" ), &name) ); |
|
119 #endif |
|
120 |
|
121 if ( !User::QueryVersionSupported( TVersion( KPsmVersionMajor, |
|
122 KPsmVersionMinor, |
|
123 KPsmVersionBuild ), |
|
124 aVersion ) ) |
|
125 { |
|
126 User::Leave( KErrNotSupported ); |
|
127 } |
|
128 |
|
129 CSession2* session = CPsmSession::NewL( *const_cast<CPsmManager*>(iPsmManager ), |
|
130 *const_cast<CPsmSrvServer*>(this ) ); |
|
131 |
|
132 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::NewSessionL - return 0x%x" ), session ) ); |
|
133 |
|
134 return( session ); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CPsmSrvServer::SessionClosed |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CPsmSrvServer::SessionClosed() |
|
142 { |
|
143 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::SessionClosed()" ) ) ); |
|
144 |
|
145 if ( !iShutdown ) |
|
146 { |
|
147 iShutdown = new CPsmSrvShutdown( *this ); |
|
148 // Start shutdown |
|
149 if ( iShutdown ) |
|
150 { |
|
151 iShutdown->Start(); |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 iShutdown->Restart(); |
|
157 } |
|
158 |
|
159 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::SessionClosed - return" ) ) ); |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CPsmSrvServer::ShutdownServer |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CPsmSrvServer::ShutdownServer() |
|
167 { |
|
168 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::ShutdownServer()" ) ) ); |
|
169 |
|
170 iSessionIter.SetToFirst(); |
|
171 CPsmSession* session = NULL; |
|
172 session = static_cast<CPsmSession*>(iSessionIter++); |
|
173 |
|
174 TInt returnValue; |
|
175 |
|
176 if ( !session ) |
|
177 { |
|
178 CActiveScheduler::Stop(); |
|
179 returnValue = KErrNone; |
|
180 } |
|
181 else |
|
182 { |
|
183 returnValue = KErrNotReady; |
|
184 } |
|
185 |
|
186 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSrvServer::ShutdownServer - return: %d" ), returnValue ) ); |
|
187 return returnValue; |
|
188 } |
|
189 |
|
190 // End of file |