|
1 // Copyright (c) 2008-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 // sd_apiextension.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #include "sd_apiextensionclient.h" |
|
24 #include "sd_apiextensionipc.h" |
|
25 |
|
26 |
|
27 #ifdef _DEBUG |
|
28 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
29 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
30 _LIT(KSpecAssert_ElemSvrDenApiXCC, "ElemSvrDenApiXCC"); |
|
31 #endif |
|
32 |
|
33 using namespace Den; |
|
34 using namespace Elements; |
|
35 |
|
36 |
|
37 _LIT(KDenApiExtPanic, "API Extension Interface"); |
|
38 /** |
|
39 API extension interface panic codes |
|
40 |
|
41 @internalTechnology |
|
42 */ |
|
43 |
|
44 enum TDenApiExtPanic |
|
45 { |
|
46 EDenApiExtBadSessionHandle = 0, //< The session handle of the extension interface is invalid |
|
47 EDenApiExtBadSubSessionHandle, //< The subsession handle of the extension interface is invalid |
|
48 EDenApiExtBadHandle, //< The session handle of the extension interface is invalid |
|
49 EDenApiExtMetaOverflow, //< Storing a message into a descriptor has overflowed |
|
50 }; |
|
51 |
|
52 |
|
53 // Implementation interface id for messages |
|
54 static const TInt KApiExtMsgImplementationUid = 0x10285c89; |
|
55 |
|
56 enum |
|
57 { |
|
58 EApiExtReqMsg = 1, |
|
59 EApiExtSubSessionReqMsg, |
|
60 EApiExtSessionReqMsg, |
|
61 EApiExtRespMsg |
|
62 }; |
|
63 |
|
64 // |
|
65 //TApiExtRespMsg |
|
66 //EXPORT_REGISTER_TYPEID(TApiExtReqMsg, KReqMsgImplementationUid, EApiExtReqMsg) |
|
67 |
|
68 // |
|
69 //TApiExtSubSessionReqMsg |
|
70 |
|
71 EXPORT_REGISTER_TYPEID(TApiExtSubSessionReqMsg, KApiExtMsgImplementationUid, EApiExtSubSessionReqMsg) |
|
72 |
|
73 // |
|
74 //TApiExtHostRoutingReqMsg |
|
75 |
|
76 EXPORT_REGISTER_TYPEID(TApiExtSessionReqMsg, KApiExtMsgImplementationUid, EApiExtSessionReqMsg) |
|
77 |
|
78 |
|
79 // |
|
80 //TApiExtRespMsg |
|
81 EXPORT_C TApiExtRespMsg* TApiExtRespMsg::NewL(const Meta::STypeId& aTypeId) |
|
82 { |
|
83 return static_cast<TApiExtRespMsg*>(Meta::SMetaDataECom::NewInstanceL(aTypeId)); |
|
84 } |
|
85 |
|
86 EXPORT_C TApiExtRespMsg* TApiExtRespMsg::NewL(const TDesC8& aMsgBuffer) |
|
87 { |
|
88 TPtrC8 buf(aMsgBuffer.Ptr(), aMsgBuffer.Length()); |
|
89 return static_cast<TApiExtRespMsg*>(Meta::SMetaDataECom::LoadL(buf)); |
|
90 } |
|
91 |
|
92 EXPORT_REGISTER_TYPEID(TApiExtRespMsg, KApiExtMsgImplementationUid, EApiExtRespMsg) |
|
93 |
|
94 // |
|
95 //RApiExtBase |
|
96 TInt RApiExtCommonBase::PrepareForSending(TApiExtReqMsg& aRequestMsg, TRBuf8*& aBuffer) const |
|
97 { |
|
98 //clean up all used up buffers |
|
99 for (TInt index = iBuffers.Count() - 1; index >= 0; --index) |
|
100 { |
|
101 if (iBuffers[index]->Length()==0) |
|
102 { |
|
103 delete iBuffers[index]; |
|
104 iBuffers.Remove(index); |
|
105 } |
|
106 } |
|
107 TInt error = KErrNoMemory; |
|
108 TRBuf8* buffer = TRBuf8::New(aRequestMsg.Length()); |
|
109 if (buffer!=NULL) |
|
110 { |
|
111 error = iBuffers.Append(buffer); //stick new buffer into the array |
|
112 if (error!=KErrNone) |
|
113 { |
|
114 delete buffer; |
|
115 buffer = NULL; |
|
116 } |
|
117 else |
|
118 { |
|
119 error = aRequestMsg.Store(*buffer); |
|
120 if (error!=KErrNone) |
|
121 { |
|
122 __ASSERT_DEBUG(iBuffers[iBuffers.Count()-1]==buffer, User::Panic(KSpecAssert_ElemSvrDenApiXCC, 1)); //make sure we are removing what we believe we are removing |
|
123 iBuffers.Remove(iBuffers.Count()-1); //remove the buffer |
|
124 delete buffer; |
|
125 buffer = NULL; |
|
126 } |
|
127 else |
|
128 { |
|
129 aBuffer = buffer; |
|
130 } |
|
131 } |
|
132 } |
|
133 return error; |
|
134 } |
|
135 |
|
136 void RApiExtCommonBase::Close() |
|
137 { |
|
138 #if defined( _DEBUG ) |
|
139 for (TInt index = iBuffers.Count() - 1; index >= 0; --index) |
|
140 { |
|
141 if (iBuffers[index]->Length()!=0) |
|
142 { |
|
143 User::Invariant(); //The request has not been processed by the server yet |
|
144 } |
|
145 } |
|
146 #endif |
|
147 |
|
148 iBuffers.ResetAndDestroy(); |
|
149 iIdentification=TApiExtIdentification(0,0); |
|
150 } |
|
151 |
|
152 // |
|
153 //RApiExtSubSessionBase |
|
154 EXPORT_C TInt RApiExtSubSessionBase::Open(RExtendableSubSessionBase& aExtendableInterface, TInt aInterfaceId) |
|
155 { |
|
156 __ASSERT_ALWAYS(aExtendableInterface.SubSessionHandle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSessionHandle)); |
|
157 |
|
158 TApiExtIdentification identification(aInterfaceId); |
|
159 TInt error = aExtendableInterface.SendReceive(EIpcSubSessionApiExtIfaceOpen, TIpcArgs(&identification)); |
|
160 if (error == KErrNone) |
|
161 { |
|
162 iSubSession = aExtendableInterface; |
|
163 iIdentification = identification; |
|
164 } |
|
165 return error; |
|
166 } |
|
167 |
|
168 EXPORT_C void RApiExtSubSessionBase::Close() |
|
169 { |
|
170 if (!iSubSession.SubSessionHandle()) |
|
171 return; |
|
172 |
|
173 iSubSession.SendReceive(EIpcSubSessionApiExtIfaceClose, TIpcArgs(&iIdentification)); |
|
174 RApiExtCommonBase::Close(); |
|
175 } |
|
176 |
|
177 //Calling this function, the client is responsible for providing a buffer |
|
178 //that is big enough to store first the request message and then the response message. |
|
179 EXPORT_C void RApiExtSubSessionBase::SendReceive(TApiExtReqMsg& aMsg, TDes8& aReqAndRespBuf, TRequestStatus& aStatus) const |
|
180 { |
|
181 __ASSERT_ALWAYS(iSubSession.SubSessionHandle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
182 aReqAndRespBuf.Zero(); |
|
183 TInt error = aMsg.Store(aReqAndRespBuf); |
|
184 if (error==KErrNone) |
|
185 { |
|
186 iSubSession.SendReceive(EIpcSubSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, &aReqAndRespBuf), aStatus); |
|
187 } |
|
188 else |
|
189 { |
|
190 TRequestStatus* status = &aStatus; |
|
191 User::RequestComplete(status,error); |
|
192 } |
|
193 } |
|
194 |
|
195 EXPORT_C void RApiExtSubSessionBase::SendReceive(TApiExtReqMsg& aMsg, TDes8& aReqAndRespBuf, TDes8& aReqAndRespBuf2, TRequestStatus& aStatus) const |
|
196 { |
|
197 __ASSERT_ALWAYS(iSubSession.SubSessionHandle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
198 aReqAndRespBuf.Zero(); |
|
199 TInt error = aMsg.Store(aReqAndRespBuf); |
|
200 if (error==KErrNone) |
|
201 { |
|
202 iSubSession.SendReceive(EIpcSubSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, &aReqAndRespBuf, &aReqAndRespBuf2), aStatus); |
|
203 } |
|
204 else |
|
205 { |
|
206 TRequestStatus* status = &aStatus; |
|
207 User::RequestComplete(status,error); |
|
208 } |
|
209 } |
|
210 |
|
211 //Calling this function, the client does not have to be concerned about the |
|
212 //buffer management that happens underneath |
|
213 EXPORT_C void RApiExtSubSessionBase::Send(TApiExtReqMsg& aMsg, TRequestStatus& aStatus) const |
|
214 { |
|
215 __ASSERT_ALWAYS(iSubSession.SubSessionHandle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
216 TRBuf8* buffer = NULL; |
|
217 TInt error = RApiExtCommonBase::PrepareForSending(aMsg, buffer); |
|
218 if (error==KErrNone) |
|
219 { |
|
220 iSubSession.SendReceive(EIpcSubSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, buffer), aStatus); |
|
221 } |
|
222 else |
|
223 { |
|
224 TRequestStatus* status = &aStatus; |
|
225 User::RequestComplete(status,error); |
|
226 } |
|
227 } |
|
228 |
|
229 EXPORT_C void RApiExtSubSessionBase::Send(TApiExtReqMsg& aMsg, TDes8& aReqAndRespBuf2, TRequestStatus& aStatus) const |
|
230 { |
|
231 __ASSERT_ALWAYS(iSubSession.SubSessionHandle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
232 TRBuf8* buffer = NULL; |
|
233 TInt error = RApiExtCommonBase::PrepareForSending(aMsg, buffer); |
|
234 if (error==KErrNone) |
|
235 { |
|
236 iSubSession.SendReceive(EIpcSubSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, buffer, &aReqAndRespBuf2), aStatus); |
|
237 } |
|
238 else |
|
239 { |
|
240 TRequestStatus* status = &aStatus; |
|
241 User::RequestComplete(status,error); |
|
242 } |
|
243 } |
|
244 |
|
245 EXPORT_C void RApiExtSubSessionBase::Send(TApiExtReqMsg& aMsg, const RHandleBase& aHandleBase, TRequestStatus& aStatus) const |
|
246 { |
|
247 __ASSERT_ALWAYS(iSubSession.SubSessionHandle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
248 TRBuf8* buffer = NULL; |
|
249 TInt error = RApiExtCommonBase::PrepareForSending(aMsg, buffer); |
|
250 if (error==KErrNone) |
|
251 { |
|
252 iSubSession.SendReceive(EIpcSubSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, buffer, aHandleBase), aStatus); |
|
253 } |
|
254 else |
|
255 { |
|
256 TRequestStatus* status = &aStatus; |
|
257 User::RequestComplete(status,error); |
|
258 } |
|
259 } |
|
260 |
|
261 // |
|
262 //RApiExtSessionBase |
|
263 EXPORT_C TInt RApiExtSessionBase::Open(RExtendableSessionBase& aExtendableInterface, TInt aInterfaceId) |
|
264 { |
|
265 __ASSERT_ALWAYS(aExtendableInterface.Handle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
266 |
|
267 TApiExtIdentification identification(aInterfaceId); |
|
268 TInt error = aExtendableInterface.SendReceive(EIpcSessionApiExtIfaceOpen, TIpcArgs(&identification)); |
|
269 if (error == KErrNone) |
|
270 { |
|
271 iSession = aExtendableInterface; |
|
272 iIdentification = identification; |
|
273 } |
|
274 return error; |
|
275 } |
|
276 |
|
277 EXPORT_C void RApiExtSessionBase::Close() |
|
278 { |
|
279 if (!iSession.Handle()) |
|
280 return; |
|
281 |
|
282 iSession.SendReceive(EIpcSessionApiExtIfaceClose, TIpcArgs(&iIdentification)); |
|
283 RApiExtCommonBase::Close(); |
|
284 } |
|
285 |
|
286 //Calling this function, the client is responsible for providing a buffer |
|
287 //that is big enough to store first the request message and then the response message. |
|
288 EXPORT_C void RApiExtSessionBase::SendReceive(TApiExtReqMsg& aMsg, TDes8& aReqAndRespBuf, TRequestStatus& aStatus) const |
|
289 { |
|
290 __ASSERT_ALWAYS(iSession.Handle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
291 aReqAndRespBuf.Zero(); |
|
292 TInt error = aMsg.Store(aReqAndRespBuf); |
|
293 if (error==KErrNone) |
|
294 { |
|
295 iSession.SendReceive(EIpcSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, &aReqAndRespBuf), aStatus); |
|
296 } |
|
297 else |
|
298 { |
|
299 TRequestStatus* status = &aStatus; |
|
300 User::RequestComplete(status,error); |
|
301 } |
|
302 } |
|
303 |
|
304 EXPORT_C void RApiExtSessionBase::SendReceive(TApiExtReqMsg& aMsg, TDes8& aReqAndRespBuf, TDes8& aReqAndRespBuf2, TRequestStatus& aStatus) const |
|
305 { |
|
306 __ASSERT_ALWAYS(iSession.Handle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
307 aReqAndRespBuf.Zero(); |
|
308 TInt error = aMsg.Store(aReqAndRespBuf); |
|
309 if (error==KErrNone) |
|
310 { |
|
311 iSession.SendReceive(EIpcSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, &aReqAndRespBuf, &aReqAndRespBuf2), aStatus); |
|
312 } |
|
313 else |
|
314 { |
|
315 TRequestStatus* status = &aStatus; |
|
316 User::RequestComplete(status,error); |
|
317 } |
|
318 } |
|
319 |
|
320 //Calling this function, the client does not have to be concerned about the |
|
321 //buffer management that happens underneath |
|
322 EXPORT_C void RApiExtSessionBase::Send(TApiExtReqMsg& aMsg, TRequestStatus& aStatus) const |
|
323 { |
|
324 __ASSERT_ALWAYS(iSession.Handle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
325 |
|
326 TRBuf8* buffer = NULL; |
|
327 TInt error = RApiExtCommonBase::PrepareForSending(aMsg, buffer); |
|
328 if (error==KErrNone) |
|
329 { |
|
330 iSession.SendReceive(EIpcSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, buffer), aStatus); |
|
331 } |
|
332 else |
|
333 { |
|
334 TRequestStatus* status = &aStatus; |
|
335 User::RequestComplete(status,error); |
|
336 } |
|
337 } |
|
338 |
|
339 EXPORT_C void RApiExtSessionBase::Send(TApiExtReqMsg& aMsg, TDes8& aReqAndRespBuf2, TRequestStatus& aStatus) const |
|
340 { |
|
341 __ASSERT_ALWAYS(iSession.Handle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
342 |
|
343 TRBuf8* buffer = NULL; |
|
344 TInt error = RApiExtCommonBase::PrepareForSending(aMsg, buffer); |
|
345 if (error==KErrNone) |
|
346 { |
|
347 iSession.SendReceive(EIpcSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, buffer, &aReqAndRespBuf2), aStatus); |
|
348 } |
|
349 else |
|
350 { |
|
351 TRequestStatus* status = &aStatus; |
|
352 User::RequestComplete(status,error); |
|
353 } |
|
354 } |
|
355 |
|
356 EXPORT_C void RApiExtSessionBase::Send(TApiExtReqMsg& aMsg, const RHandleBase& aHandleBase, TRequestStatus& aStatus) const |
|
357 { |
|
358 __ASSERT_ALWAYS(iSession.Handle(), User::Panic(KDenApiExtPanic, EDenApiExtBadSubSessionHandle)); |
|
359 |
|
360 TRBuf8* buffer = NULL; |
|
361 TInt error = RApiExtCommonBase::PrepareForSending(aMsg, buffer); |
|
362 if (error==KErrNone) |
|
363 { |
|
364 iSession.SendReceive(EIpcSessionApiExtIfaceSendReceive, TIpcArgs(&iIdentification, buffer, aHandleBase), aStatus); |
|
365 } |
|
366 else |
|
367 { |
|
368 TRequestStatus* status = &aStatus; |
|
369 User::RequestComplete(status,error); |
|
370 } |
|
371 } |
|
372 |
|
373 |