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: Client side session to the Location Centre server. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 |
|
21 // USER INCLUDES |
|
22 #include "lcclientsession.h" |
|
23 |
|
24 // CONSTANT DEFINTIONS |
|
25 const TInt KNumofConnectAttempts = 200; |
|
26 |
|
27 // ----- Member funtions for RLcClientSession --------------------------------- |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // RLcClientSession::RLcClientSession |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 RLcClientSession::RLcClientSession() |
|
34 { |
|
35 // C++ Default constructor. No allocations or functions which can Leave |
|
36 // should be called from here. |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // RLcClientSession::~RLcClientSession |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 RLcClientSession::~RLcClientSession() |
|
44 { |
|
45 // C++ Destructor. Free all resources associated with this class. |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // RLcClientSession::~RLcClientSession |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 TInt RLcClientSession::CreateSession() |
|
53 { |
|
54 TInt error = KErrNone; |
|
55 |
|
56 // Attempt KNumofConnectAttempts to make a connection to the server |
|
57 for ( TInt i = 0; i <= KNumofConnectAttempts; i++ ) |
|
58 { |
|
59 error = RSessionBase::CreateSession( |
|
60 KLocationCentreServerName, |
|
61 TVersion( KLcServerMajorVersionNumber, |
|
62 KLcServerMinorVersionNumber, |
|
63 KLcServerBuildVersionNumber ), |
|
64 8); |
|
65 if ( error != KErrNotFound && error != KErrServerTerminated ) |
|
66 { |
|
67 // If the Create session returns an error code other than |
|
68 // KErrNotFound or KErrServerTerminated, then the request |
|
69 // is terminated immediately with the error code. |
|
70 // If it is any of these error codes then the server is |
|
71 // not running. In this case, try to start the server |
|
72 return error; |
|
73 } |
|
74 |
|
75 error = StartServer(); |
|
76 if ( error != KErrAlreadyExists && error != KErrNone) |
|
77 { |
|
78 // Server returned error code other than KErrAlreadyExists |
|
79 // or KErrNone. The request is terminated with this |
|
80 // error code. |
|
81 // If the error code is one of these then the server is |
|
82 // up and running. Now try to establish the connection. |
|
83 return error; |
|
84 } |
|
85 } |
|
86 return error; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // RLcClientSession::~RLcClientSession |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void RLcClientSession::Close() |
|
94 { |
|
95 RHandleBase::Close(); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // RLcClientSession::SendReceive |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void RLcClientSession::SendReceive( TLcServerMsgType aMsgType, |
|
103 const TIpcArgs& aArgs, |
|
104 TRequestStatus& aStatus ) const |
|
105 { |
|
106 return RSessionBase::SendReceive( aMsgType, |
|
107 aArgs, |
|
108 aStatus ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // RLcClientSession::SendReceive |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 TInt RLcClientSession::SendReceive( TLcServerMsgType aMsgType, |
|
116 const TIpcArgs& aArgs ) const |
|
117 { |
|
118 return RSessionBase::SendReceive( aMsgType, |
|
119 aArgs ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // RLcClientSession::SendReceive |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void RLcClientSession::SendReceive( TLcServerMsgType aMsgType, |
|
127 TRequestStatus& aStatus ) const |
|
128 { |
|
129 return RSessionBase::SendReceive( aMsgType, aStatus ); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // RLcClientSession::SendReceive |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 TInt RLcClientSession::SendReceive( TLcServerMsgType aMsgType ) const |
|
137 { |
|
138 return RSessionBase::SendReceive( aMsgType ); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // RLcClientSession::StartServer |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 TInt RLcClientSession::StartServer() |
|
146 { |
|
147 // Create a new server process. |
|
148 // If the server is already running then the function fails with |
|
149 // KErrAlreadyExists |
|
150 RProcess server; |
|
151 TInt error = server.Create( KLocationCentreServerExe, |
|
152 KNullDesC ); |
|
153 if ( !error ) |
|
154 { |
|
155 TRequestStatus died; |
|
156 server.Rendezvous( died ); |
|
157 if ( died != KRequestPending ) |
|
158 { |
|
159 // Logon failed - Server is not yet running, so cannot have terminated |
|
160 User::WaitForRequest( died ); // Eat signal |
|
161 server.Kill( 0 ); // Abort startup |
|
162 } |
|
163 else |
|
164 { |
|
165 server.Resume(); |
|
166 User::WaitForRequest( died ); // Wait for start or death |
|
167 } |
|
168 |
|
169 // We can't use the 'exit reason' if the server panicked as this |
|
170 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
171 // from KErrNone |
|
172 error = ( server.ExitType() == EExitPanic ) ? KErrGeneral : died.Int(); |
|
173 server.Close(); |
|
174 } |
|
175 return error; |
|
176 } |
|
177 // End of File |
|