1 /* |
|
2 * Copyright (c) 2006-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: obexservicemanager client class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "obexsmclient.h" |
|
21 #include <e32std.h> |
|
22 #include "debug.h" |
|
23 |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KServerConnectRetries = 2; // How many times client tries to make connection to server |
|
27 |
|
28 // ======== LOCAL FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------- |
|
31 // StartThread |
|
32 // |
|
33 // Create the server thread/process depending on the framework. |
|
34 // This function is exported from the DLL and called from the client |
|
35 // RObexSMServer::Connect() -method. |
|
36 // Returns: TInt: Error Code |
|
37 // |
|
38 // --------------------------------------------------------- |
|
39 |
|
40 TInt StartThread() |
|
41 { |
|
42 TRACE_FUNC |
|
43 |
|
44 TInt retVal = KErrNone; |
|
45 // create server - if one of this name does not already exist |
|
46 TFindServer findSrcs(KSrcsName); |
|
47 TFullName name; |
|
48 |
|
49 if ( findSrcs.Next( name ) != KErrNone ) // we don't exist already |
|
50 { |
|
51 TRequestStatus started; |
|
52 //TSrcsStart start( started ); |
|
53 const TUidType serverUid( KNullUid,KNullUid,KSrcsUid ); |
|
54 |
|
55 // Then we have to create the server |
|
56 // This depends on if we are in WINS or target HW environment. |
|
57 |
|
58 TRACE_INFO(_L("[SRCS]\tclient\tSrcs StartThread(): create the server")); |
|
59 // We are on target HW or EKA2 WINS. |
|
60 // New process has to be created for the SRCS |
|
61 RProcess server; |
|
62 retVal=server.Create(KSrcsName, // Full path to SRCS |
|
63 KNullDesC, // Descriptor of parameters |
|
64 serverUid); // Triplet UID of executable |
|
65 |
|
66 // Check the return value of process creation |
|
67 if ( retVal != KErrNone ) |
|
68 { |
|
69 // Loading failed. |
|
70 TRACE_ERROR((_L("[SRCS]\tclient\tSrcs StartThread(): process creation failed %d"), retVal)); |
|
71 return retVal; |
|
72 } |
|
73 |
|
74 TRACE_INFO(_L("[SRCS]\tclient\tSrcs StartThread(): Process created successfully")); |
|
75 |
|
76 |
|
77 // Process/Thread has been created |
|
78 // Now logon to the server |
|
79 TRequestStatus stat; |
|
80 //server.Logon(died); |
|
81 server.Rendezvous(stat); |
|
82 |
|
83 if (stat!=KRequestPending) |
|
84 { |
|
85 server.Kill(0); // abort startup |
|
86 //FTRACE(FPrint(_L("c\tclient\tSrcs abort startup.\n"))); |
|
87 } |
|
88 else |
|
89 { |
|
90 server.Resume(); // logon OK - start the server |
|
91 //FTRACE(FPrint(_L("c\tclient\tSrcs Resumed.\n"))); |
|
92 } |
|
93 |
|
94 // Then wait the start or death of the server. |
|
95 User::WaitForRequest(stat); |
|
96 |
|
97 // we can't use the 'exit reason' if the server panicked as this |
|
98 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
99 // from KErrNone |
|
100 TRACE_INFO((_L("[SRCS]\tclient\tSrcs Server started, code %d (0=>success)\n"), stat.Int())); |
|
101 retVal=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
102 |
|
103 server.Close(); |
|
104 TRACE_INFO(_L("[SRCS]\tclient\tSrcs server handle closed.")); |
|
105 } |
|
106 |
|
107 return retVal; |
|
108 } |
|
109 |
|
110 // ================= MEMBER FUNCTIONS ======================= |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // Default constructor |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 RObexSMServer::RObexSMServer() |
|
117 { |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------- |
|
122 // Connect |
|
123 // Handles connection to server( creates session ) |
|
124 // --------------------------------------------------------- |
|
125 // |
|
126 TInt RObexSMServer::Connect() |
|
127 { |
|
128 TRACE_FUNC |
|
129 |
|
130 // IF there is allready a session handle, |
|
131 // no other session is created. |
|
132 if ( Handle() ) |
|
133 { |
|
134 return KErrAlreadyExists; |
|
135 } |
|
136 |
|
137 // Else try to create a new session with server |
|
138 TInt retry= KServerConnectRetries; |
|
139 |
|
140 FOREVER |
|
141 { |
|
142 // Try to make session with server |
|
143 TInt retVal=CreateSession(KSrcsName,Version()); |
|
144 TRACE_INFO((_L("[SRCS]\tclient\tRSrcs: create Session returned: %d"), retVal)); |
|
145 if ( retVal != KErrNotFound && retVal != KErrServerTerminated ) |
|
146 { |
|
147 // Error which can't be handled happened. |
|
148 return retVal; |
|
149 } |
|
150 // Decrease count |
|
151 --retry; |
|
152 if ( retry == 0 ) |
|
153 { |
|
154 return retVal; |
|
155 } |
|
156 |
|
157 // Try to start the server |
|
158 TRACE_INFO(_L("[SRCS]\tclient\tRSrcs::Connect(): try to start server")); |
|
159 retVal=StartThread(); |
|
160 TRACE_INFO((_L("[SRCS]\tclient\tRSrcs: StartThread returned: %d"), retVal)); |
|
161 |
|
162 if ( retVal != KErrNone && retVal != KErrAlreadyExists ) |
|
163 { |
|
164 // Error can't be handled. |
|
165 return retVal; |
|
166 } |
|
167 } |
|
168 |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // Version |
|
173 // Defines server version number |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 TVersion RObexSMServer::Version() const |
|
177 { |
|
178 TRACE_FUNC |
|
179 return( TVersion( KSrcsMajorVersionNumber, |
|
180 KSrcsMinorVersionNumber, |
|
181 KSrcsBuildVersionNumber )); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // ManageServices |
|
186 // Sends Manage services command to SRCS. |
|
187 // --------------------------------------------------------- |
|
188 // |
|
189 TInt RObexSMServer::ManageServices(TLocodBearer aBearer, TBool aBearStatus,TRequestStatus &aStatus ) |
|
190 { |
|
191 TRACE_FUNC |
|
192 TInt retVal = KErrNone; |
|
193 |
|
194 TPckgBuf<TInt> pckg; |
|
195 TIpcArgs args( &pckg, NULL, NULL ); |
|
196 TSrcsServRequest request; |
|
197 |
|
198 switch(aBearer) |
|
199 { |
|
200 case ELocodBearerBT: |
|
201 { |
|
202 if(aBearStatus) |
|
203 { |
|
204 request=ESrcsBTServicesON; |
|
205 } |
|
206 else |
|
207 { |
|
208 request=ESrcsBTServicesOFF; |
|
209 } |
|
210 } |
|
211 break; |
|
212 case ELocodBearerIR: |
|
213 { |
|
214 if(aBearStatus) |
|
215 { |
|
216 request=ESrcsIrDAServicesON; |
|
217 } |
|
218 else |
|
219 { |
|
220 request=ESrcsIrDAServicesOFF; |
|
221 } |
|
222 } |
|
223 break; |
|
224 case ELocodBearerUSB: |
|
225 { |
|
226 if(aBearStatus) |
|
227 { |
|
228 request=ESrcsStartUSB; |
|
229 } |
|
230 else |
|
231 { |
|
232 request=ESrcsStopUSB; |
|
233 } |
|
234 } |
|
235 break; |
|
236 default: |
|
237 { |
|
238 TRACE_ERROR(_L("[SRCS]\tclient\tRSrcs Manageservice: Bad bearer")); |
|
239 return KErrArgument; |
|
240 } |
|
241 } |
|
242 if ( Handle() ) |
|
243 { |
|
244 SendReceive( request, args, aStatus ); |
|
245 } |
|
246 else |
|
247 { |
|
248 TRACE_ERROR(_L("[SRCS]\tclient\tRSrcs ManageBTServices. No Handle")); |
|
249 retVal = KErrBadHandle; |
|
250 } |
|
251 return retVal; |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------- |
|
255 // CancelRequest |
|
256 // --------------------------------------------------------- |
|
257 // |
|
258 void RObexSMServer::CancelRequest() |
|
259 { |
|
260 TPckgBuf<TInt> pckg; |
|
261 TIpcArgs args( &pckg, NULL, NULL ); |
|
262 TSrcsServRequest request; |
|
263 request=ESrcsCancelRequest; |
|
264 if ( Handle() ) |
|
265 { |
|
266 SendReceive( request, args ); |
|
267 } |
|
268 |
|
269 } |
|
270 //end of file |
|
271 |
|