|
1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * Server implementation for FlexTimerServerMonitor |
|
16 */ |
|
17 /* |
|
18 * %version: 2 % |
|
19 */ |
|
20 |
|
21 #include "flextimerservermonitorserver.h" |
|
22 #include "flextimerservermonitorcommon.h" |
|
23 #include "flextimerservermonitorsession.h" |
|
24 #include "OstTraceDefinitions.h" |
|
25 #ifdef OST_TRACE_COMPILER_IN_USE |
|
26 #include "flextimerservermonitorserverTraces.h" |
|
27 #endif |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // -------------------------------------------------------------------------- |
|
32 // Construction |
|
33 // -------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CFlexTimerServerMonitorServer* CFlexTimerServerMonitorServer::NewL( |
|
36 CActive::TPriority aPriority ) |
|
37 { |
|
38 return new ( ELeave ) CFlexTimerServerMonitorServer( aPriority ); |
|
39 } |
|
40 |
|
41 // -------------------------------------------------------------------------- |
|
42 // Destructor |
|
43 // -------------------------------------------------------------------------- |
|
44 // |
|
45 CFlexTimerServerMonitorServer::~CFlexTimerServerMonitorServer() |
|
46 { |
|
47 iFlexTimer.Close(); |
|
48 } |
|
49 |
|
50 // -------------------------------------------------------------------------- |
|
51 // Creation of new sessions, called by server framework |
|
52 // -------------------------------------------------------------------------- |
|
53 // |
|
54 CSession2* CFlexTimerServerMonitorServer::NewSessionL( |
|
55 const TVersion& aVersion , |
|
56 const RMessage2& /* aMessage */ ) const |
|
57 { |
|
58 |
|
59 if ( aVersion.iMajor > KFlexTimerServerMonitorMajorVersionNumber ) |
|
60 { |
|
61 User::Leave( KErrNotSupported ); |
|
62 } |
|
63 |
|
64 // Create and return session |
|
65 return CFlexTimerServerMonitorSession::NewL(); |
|
66 } |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // Connect to FlexTimer service |
|
70 // -------------------------------------------------------------------------- |
|
71 // |
|
72 TInt CFlexTimerServerMonitorServer::StartMonitoring() |
|
73 { |
|
74 if ( iIsMonitoringOn ) |
|
75 { |
|
76 return KErrAlreadyExists; |
|
77 } |
|
78 iIsMonitoringOn = ETrue; |
|
79 return iFlexTimer.Connect(); |
|
80 } |
|
81 |
|
82 // -------------------------------------------------------------------------- |
|
83 // Close connection to FlexTimer service |
|
84 // -------------------------------------------------------------------------- |
|
85 // |
|
86 TInt CFlexTimerServerMonitorServer::StopMonitoring() |
|
87 { |
|
88 if ( !iIsMonitoringOn ) |
|
89 { |
|
90 return KErrNotFound; |
|
91 } |
|
92 iIsMonitoringOn = EFalse; |
|
93 iFlexTimer.Close(); |
|
94 return KErrNone; |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // Get status of the monitored process |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 TInt CFlexTimerServerMonitorServer::GetStatus( TBool& aHasServerCrashed ) |
|
102 { |
|
103 if ( !iIsMonitoringOn ) |
|
104 { |
|
105 return KErrNotFound; |
|
106 } |
|
107 |
|
108 // Check has the FlexTimerServer crashed by trying to configure |
|
109 // the timer. If the server has crashed, it fails. Usually, in case of |
|
110 // server crash this will return KErrServerTerminated (-15). |
|
111 TInt ret = iFlexTimer.Configure( TTimeIntervalMicroSeconds( 1000000 ) ); |
|
112 |
|
113 if ( ret == KErrNone ) |
|
114 { // No crash. |
|
115 aHasServerCrashed = EFalse; |
|
116 } |
|
117 else |
|
118 { // Crash has happened. |
|
119 aHasServerCrashed = ETrue; |
|
120 } |
|
121 |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // Thread start function, loops in active scheduler |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 void CFlexTimerServerMonitorServer::StartServerL() |
|
130 { |
|
131 // Called when thread is created, create active scheduler |
|
132 CActiveScheduler* scheduler = new CActiveScheduler; |
|
133 User::LeaveIfNull( scheduler ); |
|
134 |
|
135 // Add active scheduler object to cleanup stack before installing it. |
|
136 // It will be deleted, if any of the next operations fails. |
|
137 CleanupStack::PushL( scheduler ); |
|
138 CActiveScheduler::Install( scheduler ); |
|
139 |
|
140 // Create server object and start it |
|
141 CFlexTimerServerMonitorServer* server( NULL ); |
|
142 server = CFlexTimerServerMonitorServer::NewL( EPriorityStandard ); |
|
143 |
|
144 // Push the server object to cleanup stack before starting it |
|
145 CleanupStack::PushL( server ); |
|
146 |
|
147 User::LeaveIfError( server->Start( KFlexTimerServerMonitorServerName ) ); |
|
148 |
|
149 // Complete open rendezvous in this process (syncs with creator) |
|
150 RProcess::Rendezvous( KErrNone ); |
|
151 |
|
152 // Active scheduler start will not leave, thus pop added objects |
|
153 // from the cleanup stack. They will be deleted once the execution |
|
154 // returns from the active scheduler (application is exiting) |
|
155 CleanupStack::Pop( server ); |
|
156 CleanupStack::Pop( scheduler ); |
|
157 |
|
158 // Start active scheduler, thread stays in active scheduler loop |
|
159 CActiveScheduler::Start(); |
|
160 |
|
161 // Delete allocated resources |
|
162 delete server; |
|
163 delete scheduler; |
|
164 } |
|
165 |
|
166 // -------------------------------------------------------------------------- |
|
167 // Constructor |
|
168 // -------------------------------------------------------------------------- |
|
169 // |
|
170 CFlexTimerServerMonitorServer::CFlexTimerServerMonitorServer( |
|
171 CActive::TPriority aPriority ) : |
|
172 CServer2( aPriority ), iIsMonitoringOn( EFalse ) |
|
173 { |
|
174 } |
|
175 |
|
176 // ======== GLOBAL FUNCTIONS ======== |
|
177 |
|
178 // -------------------------------------------------------------------------- |
|
179 // Main function of the server executable. |
|
180 // -------------------------------------------------------------------------- |
|
181 // |
|
182 GLDEF_C TInt E32Main() |
|
183 { |
|
184 // Mark memory allocation check |
|
185 __UHEAP_MARK; |
|
186 |
|
187 // Create cleanup stack |
|
188 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
189 __ASSERT_ALWAYS( |
|
190 cleanup != NULL, |
|
191 User::Panic( KFlexTimerServerMonitorPanicCategory, |
|
192 ECleanupStackCreationFailed ) ); |
|
193 |
|
194 // Start server |
|
195 TRAPD( panicCode, CFlexTimerServerMonitorServer::StartServerL() ); |
|
196 |
|
197 delete cleanup; |
|
198 if ( panicCode != KErrNone ) |
|
199 { |
|
200 User::Panic( KFlexTimerServerMonitorPanicCategory, panicCode ); |
|
201 } |
|
202 |
|
203 // Memory allocation check, panic in UDEB case of memory leak |
|
204 __UHEAP_MARKEND; |
|
205 |
|
206 return KErrNone; |
|
207 } |