|
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: Implementation of RGbaServerSession |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "GbaCommon.h" |
|
20 #include "GbaServerSession.h" |
|
21 #include "GBALogger.h" |
|
22 |
|
23 // Number of message slots to reserve for this client server session. |
|
24 // In this example we can have one asynchronous request outstanding |
|
25 // and one synchronous request in progress. |
|
26 static const TUint KDefaultMessageSlots = 2; |
|
27 static const TUid KServerUid3 = {0x20029F0A}; |
|
28 |
|
29 |
|
30 static TInt StartServer(); |
|
31 static TInt CreateServerProcess(); |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // RGbaServerSession::RGbaServerSession() |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 RGbaServerSession::RGbaServerSession() |
|
38 : RSessionBase(), iGbaInputBuffer(NULL, 0, 0), iGbaOutputBuffer(NULL, 0, 0) |
|
39 { |
|
40 // No implementation required. |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // RGbaServerSession::Connect() |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 TInt RGbaServerSession::Connect() |
|
48 { |
|
49 TInt error = ::StartServer(); |
|
50 GBA_TRACE_DEBUG(("RGbaServerSession::Connect")); |
|
51 if (KErrNone == error) |
|
52 { |
|
53 GBA_TRACE_DEBUG(("RGbaServerSession::Connect 1")); |
|
54 error = CreateSession(KGbaServerName, |
|
55 Version(), |
|
56 KDefaultMessageSlots); |
|
57 } |
|
58 |
|
59 return error; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // RGbaServerSession::Version() |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 TVersion RGbaServerSession::Version() const |
|
68 { |
|
69 return(TVersion(KGbaServMajorVersionNumber, |
|
70 KGbaServMinorVersionNumber, |
|
71 KGbaServBuildVersionNumber)); |
|
72 } |
|
73 |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // RGbaServerSession::RequestBootstrap() |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void RGbaServerSession::RequestBootstrap( TGBABootstrapInputParams& aInput, TGBABootstrapOutputParams& aOutput, TRequestStatus& aStatus) |
|
80 { |
|
81 iGbaInputBuffer.Set(reinterpret_cast <TUint8*>(&aInput), sizeof(TGBABootstrapInputParams), sizeof(TGBABootstrapInputParams)); |
|
82 iGbaOutputBuffer.Set(reinterpret_cast <TUint8*>(&aOutput), sizeof(TGBABootstrapOutputParams), sizeof(TGBABootstrapOutputParams)); |
|
83 TIpcArgs messageParameters(&iGbaInputBuffer, &iGbaOutputBuffer); |
|
84 SendReceive(EGbaServRequestBootstrap, messageParameters, aStatus); |
|
85 } |
|
86 |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // RGbaServerSession::CancelBootstrap() |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt RGbaServerSession::CancelBootstrap() const |
|
93 { |
|
94 return SendReceive(EGbaServCancelRequestBootstrap); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // RGbaServerSession::WriteOption() |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TInt RGbaServerSession::WriteOption(TUid optionUid, const TDesC8& aValue) const |
|
102 { |
|
103 TIpcArgs messageParameters(optionUid.iUid,&aValue); |
|
104 return SendReceive(EGbaServWriteOption,messageParameters); |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // RGbaServerSession::IsGBAUSupported() |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 TInt RGbaServerSession::IsGBAUSupported( TBool& aIsGBAUSupported ) |
|
113 { |
|
114 |
|
115 TPckg<TBool> pckg( aIsGBAUSupported ); |
|
116 TIpcArgs messageParameters( &pckg ); |
|
117 TInt err = SendReceive(EGbaServIsGBAUSupported,messageParameters); |
|
118 GBA_TRACE_DEBUG_NUM(("returned error is %d"), err ); |
|
119 return err; |
|
120 } |
|
121 |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // StartServer() |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 static TInt StartServer() |
|
128 { |
|
129 TInt result; |
|
130 |
|
131 TFindServer findGbaServer(KGbaServerName); |
|
132 TFullName name; |
|
133 |
|
134 result = findGbaServer.Next(name); |
|
135 if ( result == KErrNone ) |
|
136 { |
|
137 return KErrNone; |
|
138 } |
|
139 |
|
140 result = CreateServerProcess(); |
|
141 if ( result != KErrNone ) |
|
142 { |
|
143 return result; |
|
144 } |
|
145 |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CreateServerProcess() |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 static TInt CreateServerProcess() |
|
155 { |
|
156 TInt result; |
|
157 const TUidType serverUid(KNullUid, KNullUid, KServerUid3); |
|
158 RProcess server; |
|
159 result = server.Create( KGbaServerName, _L(""), serverUid ); |
|
160 if ( result != KErrNone ) |
|
161 { |
|
162 return result; |
|
163 } |
|
164 |
|
165 TRequestStatus stat; |
|
166 server.Rendezvous(stat); |
|
167 if (stat!=KRequestPending) |
|
168 { |
|
169 // abort startup |
|
170 server.Kill(0); |
|
171 } |
|
172 else |
|
173 { |
|
174 // logon OK - start the server |
|
175 server.Resume(); |
|
176 } |
|
177 // wait for start or death |
|
178 User::WaitForRequest(stat); |
|
179 // we can't use the 'exit reason' if the server panicked as this |
|
180 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
181 // from KErrNone |
|
182 TInt r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
183 server.Close(); |
|
184 |
|
185 return r; |
|
186 } |
|
187 |
|
188 |
|
189 //EOF |