|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include "SendProxyClient.h" |
|
18 #include <e32debug.h> |
|
19 |
|
20 |
|
21 TInt StartSendProxyServer(void) |
|
22 { |
|
23 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
|
24 #ifdef __SENDPROXYSERVER_NO_PROCESSES__ |
|
25 // |
|
26 // In EKA1 WINS the server is a DLL, the exported entrypoint returns a TInt |
|
27 // which represents the real entry-point for the server thread |
|
28 // |
|
29 RLibrary lib; |
|
30 TInt r=lib.Load(KSendProxyServerImg,serverUid); |
|
31 if (r!=KErrNone) |
|
32 return r; |
|
33 TLibraryFunction ordinal1=lib.Lookup(1); |
|
34 TThreadFunction serverFunc=reinterpret_cast<TThreadFunction>(ordinal1()); |
|
35 // |
|
36 // To deal with the unique thread (+semaphore!) naming in EPOC, and that we may |
|
37 // be trying to restart a server that has just exited we attempt to create a |
|
38 // unique thread name for the server. |
|
39 // This uses Math::Random() to generate a 32-bit random number for the name |
|
40 // |
|
41 TName name(KSendProxyServerName); |
|
42 name.AppendNum(Math::Random(),EHex); |
|
43 RThread server; |
|
44 r=server.Create(name,serverFunc, |
|
45 KSendProxyServerStackSize, |
|
46 NULL,&lib,NULL, |
|
47 KSendProxyServerInitHeapSize,KSendProxyServerMaxHeapSize,EOwnerProcess); |
|
48 lib.Close(); // if successful, server thread has handle to library now |
|
49 #else |
|
50 // |
|
51 // EPOC and EKA2 is easy, we just create a new server process. Simultaneous |
|
52 // launching of two such processes should be detected when the second one |
|
53 // attempts to create the server object, failing with KErrAlreadyExists. |
|
54 // |
|
55 RProcess server; |
|
56 TInt r=server.Create(KSendProxyServerImg,KNullDesC,serverUid); |
|
57 |
|
58 |
|
59 #endif |
|
60 if (r!=KErrNone) |
|
61 { |
|
62 return r; |
|
63 } |
|
64 |
|
65 TRequestStatus stat; |
|
66 server.Rendezvous(stat); |
|
67 if (stat!=KRequestPending) |
|
68 server.Kill(0); // abort startup |
|
69 else |
|
70 server.Resume(); // logon OK - start the server |
|
71 User::WaitForRequest(stat); // wait for start or death |
|
72 // we can't use the 'exit reason' if the server panicked as this |
|
73 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
74 // from KErrNone |
|
75 |
|
76 r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
77 server.Close(); |
|
78 return r; |
|
79 |
|
80 } |
|
81 |
|
82 |
|
83 EXPORT_C TInt RProxyServerSession::Connect() |
|
84 // |
|
85 // Connect to the server, attempting to start it if necessary |
|
86 // |
|
87 { |
|
88 TInt retry=2; |
|
89 for (;;) |
|
90 { |
|
91 TInt r=CreateSession(KSendProxyServerName,TVersion(0,0,0),1); |
|
92 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
93 return r; |
|
94 if (--retry==0) |
|
95 return r; |
|
96 r=StartSendProxyServer(); |
|
97 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
98 return r; |
|
99 } |
|
100 } |
|
101 |
|
102 |
|
103 |
|
104 EXPORT_C TInt RProxyServerSession::SendReceive(TInt aCommand, const TIpcArgs& aTIpcArgs) |
|
105 { |
|
106 |
|
107 |
|
108 CPackServerData packServerData(aCommand, &aTIpcArgs); |
|
109 TPckg<CPackServerData> pack(packServerData); |
|
110 TIpcArgs tipcArgs(ESend, aTIpcArgs.iFlags); |
|
111 |
|
112 TInt err = RSessionBase::SendReceive(ESendData , tipcArgs); |
|
113 // We need to indicate how the buffers will be created and these are indicated by the |
|
114 // flags in aTIpcArgs. Should never fail to get this info across. |
|
115 if (err<0) |
|
116 { |
|
117 return err; |
|
118 } |
|
119 |
|
120 return RSessionBase::SendReceive(aCommand , aTIpcArgs ); |
|
121 // Same as parent call, except that we have got the data to build the dummy args in the proxy. |
|
122 |
|
123 } |
|
124 |
|
125 |
|
126 EXPORT_C TInt RProxyServerSession::SendReceiveProxyAsync(TInt aCommand, const TIpcArgs& aTIpcArgs ) |
|
127 { |
|
128 |
|
129 CPackServerData packServerData(aCommand, &aTIpcArgs); |
|
130 TPckg<CPackServerData> pack(packServerData); |
|
131 TIpcArgs tipcArgs(ESendAsyncWait, aTIpcArgs.iFlags); |
|
132 |
|
133 TInt err = RSessionBase::SendReceive(ESendData , tipcArgs); |
|
134 // We need to indicate how the buffers will be created and these are indicated by the |
|
135 // flags in aTIpcArgs. Should never fail to get this info across. |
|
136 if (err<0) |
|
137 { |
|
138 return err; |
|
139 } |
|
140 |
|
141 return RSessionBase::SendReceive(aCommand , aTIpcArgs ); |
|
142 // Same as parent call, except that we have got the data to build the dummy args in the proxy. |
|
143 |
|
144 } |
|
145 |
|
146 |
|
147 |
|
148 EXPORT_C TInt RProxyServerSession::SendReceive(TInt aCommand) |
|
149 { |
|
150 |
|
151 TIpcArgs aTIpcArgs; |
|
152 |
|
153 CPackServerData packServerData(aCommand, &aTIpcArgs); |
|
154 TPckg<CPackServerData> pack(packServerData); |
|
155 TIpcArgs tipcArgs(ESend, aTIpcArgs.iFlags); |
|
156 |
|
157 TInt err = RSessionBase::SendReceive(ESendData , tipcArgs); |
|
158 // We need to indicate how the buffers will be created and these are indicated by the |
|
159 // flags in aTIpcArgs. Should never fail to get this info across. |
|
160 if (err<0) |
|
161 { |
|
162 return err; |
|
163 } |
|
164 |
|
165 return RSessionBase::SendReceive(aCommand , aTIpcArgs ); |
|
166 // Same as parent call, except that we have got the data to build the dummy args in the proxy. |
|
167 |
|
168 } |
|
169 |
|
170 |
|
171 |
|
172 EXPORT_C TInt RProxyServerSession::SendReceiveProxyAsync(TInt aCommand ) |
|
173 { |
|
174 TIpcArgs aTIpcArgs; |
|
175 |
|
176 CPackServerData packServerData(aCommand, &aTIpcArgs); |
|
177 TPckg<CPackServerData> pack(packServerData); |
|
178 TIpcArgs tipcArgs(ESendAsyncWait, aTIpcArgs.iFlags); |
|
179 |
|
180 TInt err = RSessionBase::SendReceive(ESendData , tipcArgs); |
|
181 // We need to indicate how the buffers will be created and these are indicated by the |
|
182 // flags in aTIpcArgs. Should never fail to get this info across. |
|
183 |
|
184 if (err<0) |
|
185 { |
|
186 return err; |
|
187 } |
|
188 |
|
189 return RSessionBase::SendReceive(aCommand , aTIpcArgs ); |
|
190 // Same as parent call, except that we have got the data to build the dummy args in the proxy. |
|
191 |
|
192 |
|
193 } |
|
194 |
|
195 |
|
196 |
|
197 EXPORT_C TInt RProxyServerSession::GetServerSecureId( TSecureId& p ) |
|
198 { |
|
199 TPckg<TSecureId> buf(p); |
|
200 TIpcArgs send(&buf); |
|
201 |
|
202 TInt ret= RSessionBase::SendReceive(EGetServerSecureId, send); |
|
203 |
|
204 return ret; |
|
205 } |
|
206 |
|
207 |
|
208 |
|
209 EXPORT_C TInt RProxyServerSession::GetServerCapabilities( TInt32& p ) |
|
210 { |
|
211 TPckg<TInt32> buf(p); |
|
212 TIpcArgs send(&buf); |
|
213 |
|
214 TInt ret= RSessionBase::SendReceive(EGetServerCapabilities, send); |
|
215 |
|
216 return ret; |
|
217 } |
|
218 |
|
219 |