32
|
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 |
* Client implementation for FlexTimerServerMonitor
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
/*
|
|
20 |
* %version: 1 %
|
|
21 |
*/
|
|
22 |
#include "rflextimerservermonitor.h"
|
|
23 |
#include "flextimerservermonitorcommon.h"
|
|
24 |
#include "OstTraceDefinitions.h"
|
|
25 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
26 |
#include "rflextimerservermonitorTraces.h"
|
|
27 |
#endif
|
|
28 |
|
|
29 |
// ======== MEMBER FUNCTIONS ========
|
|
30 |
// ---------------------------------------------------------------------------
|
|
31 |
// Constructs the object.
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
//
|
|
34 |
EXPORT_C RFlexTimerServerMonitor::RFlexTimerServerMonitor()
|
|
35 |
{
|
|
36 |
}
|
|
37 |
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
// Destructs the object.
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
EXPORT_C RFlexTimerServerMonitor::~RFlexTimerServerMonitor()
|
|
43 |
{
|
|
44 |
Close();
|
|
45 |
}
|
|
46 |
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
// Connects to the server and create a session.
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
EXPORT_C TInt RFlexTimerServerMonitor::Connect()
|
|
52 |
{
|
|
53 |
// Starts the server, if it does not already exist in the system.
|
|
54 |
TInt ret = StartServer();
|
|
55 |
|
|
56 |
if ( ret == KErrNone )
|
|
57 |
{ // No session, create it
|
|
58 |
ret = CreateSession(
|
|
59 |
KFlexTimerServerMonitorServerName,
|
|
60 |
Version(),
|
|
61 |
KFlexTimerServerMonitorServerMessageSlots );
|
|
62 |
}
|
|
63 |
return ret;
|
|
64 |
}
|
|
65 |
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
// Start monitoring FlexTimer server crashes
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
EXPORT_C TInt RFlexTimerServerMonitor::StartMonitoring()
|
|
71 |
{
|
|
72 |
return SendReceive( EFlexTimerServerMonitorStartMonitoring );
|
|
73 |
}
|
|
74 |
|
|
75 |
// ---------------------------------------------------------------------------
|
|
76 |
// Get the status of the monitoring; has FlexTimer server crashed while
|
|
77 |
// monitoring or not.
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
EXPORT_C TInt RFlexTimerServerMonitor::GetStatus( TBool& aHasServerCrashed )
|
|
81 |
{
|
|
82 |
TPckgBuf<TBool> pckg;
|
|
83 |
TIpcArgs args( &pckg );
|
|
84 |
|
|
85 |
TInt ret = SendReceive( EFlexTimerServerMonitorHasServerCrashed, args );
|
|
86 |
|
|
87 |
// Extract the value returned from the server.
|
|
88 |
aHasServerCrashed = pckg();
|
|
89 |
return ret;
|
|
90 |
}
|
|
91 |
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
// Stop monitoring FlexTimer server crashes
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
EXPORT_C TInt RFlexTimerServerMonitor::StopMonitoring()
|
|
97 |
{
|
|
98 |
return SendReceive( EFlexTimerServerMonitorStopMonitoring );
|
|
99 |
}
|
|
100 |
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
// Gets the version number.
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
TVersion RFlexTimerServerMonitor::Version() const
|
|
106 |
{
|
|
107 |
return ( TVersion( KFlexTimerServerMonitorMajorVersionNumber,
|
|
108 |
KFlexTimerServerMonitorMinorVersionNumber,
|
|
109 |
KFlexTimerServerMonitorBuildVersionNumber ) );
|
|
110 |
}
|
|
111 |
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
// Connects to the server. If server does not exist, it is created.
|
|
114 |
// ---------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
TInt RFlexTimerServerMonitor::StartServer()
|
|
117 |
{
|
|
118 |
TFindServer findServer( KFlexTimerServerMonitorServerName );
|
|
119 |
TFullName serverName;
|
|
120 |
|
|
121 |
// See if the server is already started.
|
|
122 |
TInt ret = findServer.Next( serverName );
|
|
123 |
|
|
124 |
if ( ret != KErrNone )
|
|
125 |
{
|
|
126 |
//Server was not found so create one.
|
|
127 |
RProcess serverProcess;
|
|
128 |
TBuf<1> serverParameters;
|
|
129 |
|
|
130 |
// Load the executable for the server.
|
|
131 |
ret = serverProcess.Create( KFlexTimerServerMonitorServerExe,
|
|
132 |
serverParameters,
|
|
133 |
EOwnerThread );
|
|
134 |
|
|
135 |
if ( ret == KErrNone )
|
|
136 |
{
|
|
137 |
// Server has been created successfully. It is initially
|
|
138 |
// in suspended state. Now resume the server process.
|
|
139 |
|
|
140 |
// Wait until the server process has been started.
|
|
141 |
TRequestStatus status;
|
|
142 |
|
|
143 |
serverProcess.Rendezvous( status );
|
|
144 |
serverProcess.Resume();
|
|
145 |
User::WaitForRequest( status );
|
|
146 |
|
|
147 |
// Check if server has panicked during initialization.
|
|
148 |
ret = serverProcess.ExitType();
|
|
149 |
if ( ret == EExitPanic )
|
|
150 |
{
|
|
151 |
ret = KErrServerTerminated;
|
|
152 |
}
|
|
153 |
else
|
|
154 |
{
|
|
155 |
ret = status.Int();
|
|
156 |
}
|
|
157 |
|
|
158 |
// The server process stands on its own. This handle can
|
|
159 |
// be closed.
|
|
160 |
serverProcess.Close();
|
|
161 |
}
|
|
162 |
}
|
|
163 |
return ret;
|
|
164 |
}
|