|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Server connection handler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32math.h> |
|
22 #include <e32uid.h> |
|
23 #include "PhCltTypes.h" |
|
24 #include "RPhCltServer.h" |
|
25 #include "PhCltClientServer.h" |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // Information of Phone Server Startup failure, used in panic call. |
|
30 _LIT( PH_SRV_SU_FAILURE, "PhSrvStartUp" ); |
|
31 |
|
32 // The number of Phone Server startup attempts. |
|
33 const TInt KPhCltNumberOfRetryAttempts = 4; |
|
34 |
|
35 // The phase were the Phone Server failure happened. |
|
36 // Useful in debug purposes if Phone Server startup fails. |
|
37 enum |
|
38 { |
|
39 EPhSrvStartupFailurePhase1, // First phase |
|
40 EPhSrvStartupFailurePhase2 // Second phase |
|
41 }; |
|
42 |
|
43 |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // RPhCltServer::RPhCltServer |
|
50 // C++ constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C RPhCltServer::RPhCltServer() |
|
55 : RSessionBase() |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // RPhCltServer::Version |
|
61 // |
|
62 // Returns version. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 TVersion RPhCltServer::Version() const |
|
66 { |
|
67 return TVersion( KPhoneServerMajorVersionNumber, |
|
68 KPhoneServerMinorVersionNumber, |
|
69 KPhoneServerBuildVersionNumber ); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // RPhCltServer::Connect |
|
74 // |
|
75 // Creates connection to the server. If server is not running, |
|
76 // it is also launched. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C TInt RPhCltServer::Connect( TInt aMessageSlots ) |
|
80 { |
|
81 TInt err = KErrGeneral; |
|
82 TInt count = KPhCltNumberOfRetryAttempts; |
|
83 FOREVER |
|
84 { |
|
85 err = CreateSession( PHONE_SERVER_NAME, Version(), aMessageSlots ); |
|
86 if ( err != KErrNotFound && err != KErrServerTerminated ) |
|
87 { |
|
88 break; |
|
89 } |
|
90 // Need to restart server |
|
91 if ( --count < 0 ) |
|
92 { |
|
93 break; |
|
94 } |
|
95 err = StartServer(); |
|
96 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
97 { |
|
98 if ( err != KErrNotFound ) |
|
99 { |
|
100 break; |
|
101 } |
|
102 Panic( EPhCltPanicServerUnexpectedServerNotFound ); |
|
103 } |
|
104 } |
|
105 return err; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // RPhCltServer::CreateAll |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C void RPhCltServer::CreateAll( TRequestStatus& aStatus ) |
|
113 { |
|
114 SendReceive( |
|
115 EPhoneCreateAll, |
|
116 TIpcArgs(), |
|
117 aStatus ); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // RPhCltServer::StartServer |
|
122 // |
|
123 // Launches the phone server, which is assumed to be not |
|
124 // already running. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 TInt RPhCltServer::StartServer() |
|
128 { |
|
129 // The uid of the DLL/EXE - used to identify the correct target |
|
130 const TUidType KPhServerUidType( |
|
131 KExecutableImageUid, |
|
132 KSharedLibraryUid, |
|
133 KPhCltServerUid ); |
|
134 |
|
135 |
|
136 ////////////////////////////////////////////////////////////////////////// |
|
137 // On MARM, the server is an exe, so it is run inside its own process. |
|
138 // The server itself takes care of creating a thread and finalizing the |
|
139 // construction of the server. We pass the signalling object via the |
|
140 // command line. |
|
141 ////////////////////////////////////////////////////////////////////////// |
|
142 |
|
143 RProcess serverUnitOfExecution; |
|
144 |
|
145 TFileName pathName( KPhCltServerZDrive ); |
|
146 pathName.Append( KDC_PROGRAMS_DIR ); |
|
147 pathName.Append( KPhServerPathAndNameMARM ); |
|
148 pathName.ZeroTerminate(); |
|
149 |
|
150 TInt err = serverUnitOfExecution.Create( |
|
151 pathName, |
|
152 KNullDesC, |
|
153 KPhServerUidType ); |
|
154 |
|
155 if ( err != KErrNone ) |
|
156 { |
|
157 User::Panic( PH_SRV_SU_FAILURE, err ); |
|
158 } |
|
159 serverUnitOfExecution.SetPriority( EPriorityHigh ); |
|
160 |
|
161 |
|
162 // Now wait for the server to start up, and also observe if the server |
|
163 // thread dies for any reason. |
|
164 |
|
165 |
|
166 TRequestStatus stat; |
|
167 serverUnitOfExecution.Rendezvous( stat ); |
|
168 if ( stat != KRequestPending ) |
|
169 { |
|
170 User::Panic( PH_SRV_SU_FAILURE, EPhSrvStartupFailurePhase1 ); |
|
171 |
|
172 serverUnitOfExecution.Kill( KErrAbort ); // abort startup |
|
173 } |
|
174 else |
|
175 { |
|
176 serverUnitOfExecution.Resume(); // logon ok |
|
177 } |
|
178 |
|
179 // wait for start or death |
|
180 User::WaitForRequest( stat ); |
|
181 // we can't use the 'exit reason' if the server panicked as this |
|
182 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
183 // from KErrNone |
|
184 err = ( serverUnitOfExecution.ExitType() == EExitPanic ) |
|
185 ? KErrGeneral : stat.Int(); |
|
186 |
|
187 serverUnitOfExecution.Close(); |
|
188 |
|
189 |
|
190 return err; |
|
191 } |
|
192 |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // RPhCltServer::Panic |
|
196 // |
|
197 // Panics the client thread |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void RPhCltServer::Panic( TPhCltPanicTypes aPanic ) |
|
201 { |
|
202 User::Panic( KPhClientPanicCategory, aPanic ); |
|
203 } |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 // End of File |