|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "../../public/clientServerShared.h" |
|
19 #include "classControllerClientSession.h" |
|
20 |
|
21 |
|
22 /** |
|
23 * Function used by RClassControllerClient::Connect member function. |
|
24 * It exists to create a new process which contains the server side code. |
|
25 * |
|
26 * @return Value of error code created |
|
27 */ |
|
28 static TInt StartServer() |
|
29 { |
|
30 const TUidType serverUid(KNullUid, KNullUid, KObexCCUid); |
|
31 RProcess server; |
|
32 TInt err = server.Create(KServerExe, KNullDesC, serverUid); |
|
33 if ( err != KErrNone ) |
|
34 { |
|
35 return err; |
|
36 } |
|
37 |
|
38 TRequestStatus stat; |
|
39 server.Rendezvous(stat); |
|
40 |
|
41 if ( stat != KRequestPending ) |
|
42 { |
|
43 server.Kill(0); // abort startup |
|
44 } |
|
45 else |
|
46 { |
|
47 server.Resume(); // logon OK - start the server |
|
48 } |
|
49 |
|
50 User::WaitForRequest(stat); // wait for start or death |
|
51 |
|
52 // we can't use the 'exit reason' if the server paniced as this |
|
53 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
54 // from KErrNone |
|
55 err = (server.ExitType() == EExitPanic) ? KErrServerTerminated : stat.Int(); |
|
56 |
|
57 server.Close(); |
|
58 |
|
59 return err; |
|
60 } |
|
61 |
|
62 |
|
63 |
|
64 /** |
|
65 * Function that creates a session with the server and then returns the appropriate error code. |
|
66 * Then calls StartServer to start the process with the server side code. |
|
67 * |
|
68 * @return Value of error code produced |
|
69 */ |
|
70 |
|
71 EXPORT_C TInt RClassControllerClient::Connect() |
|
72 { |
|
73 TInt retry = 2; |
|
74 |
|
75 FOREVER |
|
76 { |
|
77 //Create Session, With server name from shared header |
|
78 //And lowest version number of the server with which this client is compatible. |
|
79 //Number of message slots available, -1 for meessages from global free pool |
|
80 |
|
81 TInt err = CreateSession(KServerName, TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber), KMessageSlots); |
|
82 |
|
83 if ((err != KErrNotFound) && (err != KErrServerTerminated)) |
|
84 { |
|
85 return err; |
|
86 } |
|
87 |
|
88 if (--retry == 0) |
|
89 { |
|
90 return err; |
|
91 } |
|
92 |
|
93 err = StartServer(); |
|
94 |
|
95 if ((err != KErrNone) && (err != KErrAlreadyExists)) |
|
96 { |
|
97 return err; |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 /** |
|
103 * Function that sends a message to the server to initiate the start |
|
104 * of an Obex Service. On completion, TRequestStatus contains error code. |
|
105 * |
|
106 * @return Value of TRequestStatus |
|
107 */ |
|
108 EXPORT_C TInt RClassControllerClient::StartService() |
|
109 { |
|
110 return (SendReceive(EStartClassContServer)); |
|
111 } |
|
112 |
|
113 /** |
|
114 * Function that sends a message to the server to initiate the stop |
|
115 * of an Obex Service. On completion, TRequestStatus contains error code. |
|
116 * |
|
117 * @return Value of TRequestStatus |
|
118 */ |
|
119 EXPORT_C TInt RClassControllerClient::StopService() |
|
120 { |
|
121 return (SendReceive(EStopClassContServer)); |
|
122 } |
|
123 |
|
124 |