|
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 session retry implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mpxsessionretry.h" |
|
19 |
|
20 |
|
21 enum { EFunctionType_SendReceive1, EFunctionType_SendReceive2}; |
|
22 |
|
23 // ============================== LOCAL FUNCTIONS ============================= |
|
24 |
|
25 // ---------------------------------------------------------------------------- |
|
26 // Start server process |
|
27 // ---------------------------------------------------------------------------- |
|
28 // |
|
29 LOCAL_C TInt StartServer(const TDesC& aImage) |
|
30 { |
|
31 RProcess server; |
|
32 |
|
33 TInt r = server.Create(aImage,KNullDesC); |
|
34 if (r != KErrNone) |
|
35 { |
|
36 return r; |
|
37 } |
|
38 |
|
39 TRequestStatus s; |
|
40 server.Rendezvous(s); |
|
41 if (s != KRequestPending) |
|
42 { |
|
43 server.Kill(0); |
|
44 } |
|
45 else |
|
46 { |
|
47 server.Resume(); |
|
48 } |
|
49 |
|
50 User::WaitForRequest(s); |
|
51 |
|
52 r = (server.ExitType()==EExitPanic) ? KErrGeneral : s.Int(); |
|
53 server.Close(); |
|
54 |
|
55 return r; |
|
56 } |
|
57 |
|
58 // ============================== MEMBER FUNCTIONS ============================ |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // Return the version info |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 TVersion RMPXSessionRetry::Version() const |
|
65 { |
|
66 return iVersion; |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // Connect to server |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 TInt RMPXSessionRetry::Connect(const TDesC& aServer, |
|
74 const TDesC& aImage, |
|
75 const TVersion& aVersion) |
|
76 { |
|
77 iVersion = aVersion; |
|
78 iServer = aServer; |
|
79 iImage = aImage; |
|
80 |
|
81 TInt r = RSessionBase::CreateSession(iServer, iVersion, 2); |
|
82 |
|
83 if (r == KErrNotFound || r == KErrServerTerminated) |
|
84 { |
|
85 r = Reconnect(); |
|
86 } |
|
87 |
|
88 return r; |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // Reconnect to server |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 TInt RMPXSessionRetry::Reconnect() |
|
96 { |
|
97 // make sure the current session is closed; it does no harm to close |
|
98 // a session that is already closed |
|
99 Close(); |
|
100 |
|
101 TInt r = StartServer(iImage); |
|
102 |
|
103 if (r == KErrNone || r == KErrAlreadyExists) |
|
104 { |
|
105 r = RSessionBase::CreateSession(iServer, iVersion, 2); |
|
106 } |
|
107 |
|
108 return r; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // Send a message |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 TInt RMPXSessionRetry::SendReceiveL(TInt aFunction) |
|
116 { |
|
117 TInt retVal = RSessionBase::SendReceive(aFunction); |
|
118 |
|
119 if (KErrServerTerminated == retVal) |
|
120 { |
|
121 Reconnect(); // try again in case IAD took down the server to replace it |
|
122 retVal = RSessionBase::SendReceive(aFunction); |
|
123 } |
|
124 |
|
125 return User::LeaveIfError(retVal); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // Send a message |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt RMPXSessionRetry::SendReceiveL(TInt aFunction, const TIpcArgs& aArgs) |
|
133 { |
|
134 TInt retVal = RSessionBase::SendReceive(aFunction,aArgs); |
|
135 |
|
136 if (KErrServerTerminated == retVal) |
|
137 { |
|
138 Reconnect(); // try again in case IAD took down the server to replace it |
|
139 retVal = RSessionBase::SendReceive(aFunction,aArgs); |
|
140 } |
|
141 |
|
142 return User::LeaveIfError(retVal); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // Send a message |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void RMPXSessionRetry::SendReceive(TInt aFunction, |
|
150 TRequestStatus& aStatus) |
|
151 { |
|
152 RSessionBase::SendReceive(aFunction, aStatus); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // Send a message |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void RMPXSessionRetry::SendReceive(TInt aFunction, |
|
160 const TIpcArgs& aArgs, |
|
161 TRequestStatus& aStatus) |
|
162 { |
|
163 RSessionBase::SendReceive(aFunction, aArgs, aStatus); |
|
164 } |