|
1 // Copyright (c) 1997-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 @file |
|
18 */ |
|
19 |
|
20 #include <comms-infras/es_api_ext.h> |
|
21 #include <comms-infras/es_connectionservermessages.h> |
|
22 #include <comms-infras/api_ext_msg.h> |
|
23 #include <comms-infras/sockmes.h> |
|
24 |
|
25 |
|
26 #ifdef _DEBUG |
|
27 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
28 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
29 _LIT(KSpecAssert_ESockCSockcsp_xt, "ESockCSockcsp_xt"); |
|
30 #endif |
|
31 |
|
32 using namespace Elements; |
|
33 |
|
34 |
|
35 CCommsSessionApiExtProvider::CCommsSessionApiExtProvider(RCommsSession& session) |
|
36 : iSession(session) |
|
37 { |
|
38 } |
|
39 |
|
40 CCommsSessionApiExtProvider *CCommsSessionApiExtProvider::Open( |
|
41 RCommsSession& aExtensionProvider, TSupportedCommsApiExt aInterfaceId, TInt &error) |
|
42 { |
|
43 __ASSERT_ALWAYS(aExtensionProvider.Handle(), User::Panic(KApiExtPanic, EApiExtBadHandle)); |
|
44 CCommsSessionApiExtProvider *provider = new CCommsSessionApiExtProvider(aExtensionProvider); |
|
45 if (!provider) |
|
46 { |
|
47 error = KErrNoMemory; |
|
48 return NULL; |
|
49 } |
|
50 |
|
51 error = aExtensionProvider.SendReceive(ECMApiExtBindIface, TIpcArgs(aInterfaceId)); |
|
52 |
|
53 if (KErrNone != error) |
|
54 { |
|
55 delete provider; |
|
56 return NULL; |
|
57 } |
|
58 return provider; |
|
59 } |
|
60 |
|
61 TInt CCommsSessionApiExtProvider::Close(const TIpcArgs& aArgs) const |
|
62 { |
|
63 return iSession.SendReceive(ECMApiExtIfaceClose, aArgs); |
|
64 } |
|
65 |
|
66 TInt CCommsSessionApiExtProvider::Handle() const |
|
67 { |
|
68 return iSession.Handle(); |
|
69 } |
|
70 |
|
71 TInt CCommsSessionApiExtProvider::Send(const TIpcArgs& aArgs) const |
|
72 { |
|
73 return iSession.SendReceive(ECMApiExtIfaceSend, aArgs); |
|
74 } |
|
75 |
|
76 void CCommsSessionApiExtProvider::SendReceive(const TIpcArgs& aArgs,TRequestStatus& aStatus) const |
|
77 { |
|
78 iSession.SendReceive(ECMApiExtIfaceSendReceive, aArgs, aStatus); |
|
79 } |
|
80 |
|
81 void CCommsSessionApiExtProvider::Release() |
|
82 { |
|
83 delete this; |
|
84 } |
|
85 |
|
86 CCommsSubSessionApiExtProvider::CCommsSubSessionApiExtProvider(RCommsSubSession& subsession) |
|
87 : iSubSession(subsession) |
|
88 { |
|
89 } |
|
90 |
|
91 CCommsSubSessionApiExtProvider *CCommsSubSessionApiExtProvider::Open( |
|
92 RCommsSubSession& aExtensionProvider, TSupportedCommsApiExt aInterfaceId, TInt &error) |
|
93 { |
|
94 __ASSERT_ALWAYS(aExtensionProvider.SubSessionHandle(), User::Panic(KApiExtPanic, EApiExtBadHandle)); |
|
95 CCommsSubSessionApiExtProvider *provider = new CCommsSubSessionApiExtProvider(aExtensionProvider); |
|
96 if (!provider) |
|
97 { |
|
98 error = KErrNoMemory; |
|
99 return NULL; |
|
100 } |
|
101 |
|
102 error = aExtensionProvider.SendReceive(ECommsApiExtBindIface, TIpcArgs(aInterfaceId)); |
|
103 |
|
104 if (KErrNone != error) |
|
105 { |
|
106 delete provider; |
|
107 return NULL; |
|
108 } |
|
109 return provider; |
|
110 } |
|
111 |
|
112 TInt CCommsSubSessionApiExtProvider::Close(const TIpcArgs& aArgs) const |
|
113 { |
|
114 return iSubSession.SendReceive(ECommsApiExtIfaceClose, aArgs); |
|
115 } |
|
116 |
|
117 TInt CCommsSubSessionApiExtProvider::Handle() const |
|
118 { |
|
119 return iSubSession.SubSessionHandle(); |
|
120 } |
|
121 |
|
122 TInt CCommsSubSessionApiExtProvider::Send(const TIpcArgs& aArgs) const |
|
123 { |
|
124 return iSubSession.SendReceive(ECommsApiExtIfaceSend, aArgs); |
|
125 } |
|
126 |
|
127 void CCommsSubSessionApiExtProvider::SendReceive(const TIpcArgs& aArgs,TRequestStatus& aStatus) const |
|
128 { |
|
129 iSubSession.SendReceive(ECommsApiExtIfaceSendReceive, aArgs, aStatus); |
|
130 } |
|
131 |
|
132 void CCommsSubSessionApiExtProvider::Release() |
|
133 { |
|
134 delete this; |
|
135 } |
|
136 |
|
137 |
|
138 EXPORT_C RCommsApiExtensionBase::RCommsApiExtensionBase() |
|
139 : iProvider(0) |
|
140 { |
|
141 } |
|
142 |
|
143 EXPORT_C TInt RCommsApiExtensionBase::Open(RCommsSession& aExtensionProvider, TSupportedCommsApiExt aInterfaceId) |
|
144 { |
|
145 if (iProvider) |
|
146 { |
|
147 return KErrInUse; |
|
148 } |
|
149 |
|
150 TInt error = KErrNone; |
|
151 iProvider = CCommsSessionApiExtProvider::Open(aExtensionProvider, aInterfaceId, error); |
|
152 |
|
153 if (error == KErrNone) |
|
154 { |
|
155 iInterfaceId = aInterfaceId; |
|
156 } |
|
157 return error; |
|
158 } |
|
159 |
|
160 EXPORT_C TInt RCommsApiExtensionBase::Open(RCommsSubSession& aExtensionProvider, TSupportedCommsApiExt aInterfaceId) |
|
161 { |
|
162 if (iProvider) |
|
163 { |
|
164 return KErrInUse; |
|
165 } |
|
166 |
|
167 TInt error = KErrNone; |
|
168 iProvider = CCommsSubSessionApiExtProvider::Open(aExtensionProvider, aInterfaceId, error); |
|
169 |
|
170 if (error == KErrNone) |
|
171 { |
|
172 iInterfaceId = aInterfaceId; |
|
173 } |
|
174 return error; |
|
175 } |
|
176 |
|
177 |
|
178 EXPORT_C void RCommsApiExtensionBase::Close() |
|
179 { |
|
180 if (iProvider && iProvider->Handle()) |
|
181 { |
|
182 iProvider->Close(TIpcArgs(iInterfaceId)); |
|
183 iProvider->Release(); |
|
184 iProvider = NULL; |
|
185 } |
|
186 |
|
187 #if defined( _DEBUG ) |
|
188 for (TInt index = iBuffers.Count() - 1; index >= 0; --index) |
|
189 { |
|
190 if (iBuffers[index]->Length()!=0) |
|
191 { |
|
192 User::Invariant(); //The request has not been processed by the server yet |
|
193 } |
|
194 } |
|
195 #endif |
|
196 |
|
197 iBuffers.ResetAndDestroy(); |
|
198 } |
|
199 |
|
200 EXPORT_C void RCommsApiExtensionBase::SendRequest(TCommsApiExtReqMsg& aRequestMsg, TDes8& aResponseBuf, TRequestStatus& aStatus) |
|
201 { |
|
202 __ASSERT_ALWAYS(iProvider && iProvider->Handle(), User::Panic(KApiExtPanic, EApiExtBadHandle)); |
|
203 |
|
204 //clean up all used up buffers |
|
205 for (TInt index = iBuffers.Count() - 1; index >= 0; --index) |
|
206 { |
|
207 if (iBuffers[index]->Length()==0) |
|
208 { |
|
209 delete iBuffers[index]; |
|
210 iBuffers.Remove(index); |
|
211 } |
|
212 } |
|
213 |
|
214 TInt error = KErrNoMemory; |
|
215 TRBuf8* buffer = TRBuf8::New(aRequestMsg.Length()); |
|
216 if (buffer!=NULL) |
|
217 { |
|
218 error = iBuffers.Append(buffer); //stick new buffer into the array |
|
219 if (error==KErrNone) |
|
220 { |
|
221 error = aRequestMsg.Store(*buffer); |
|
222 if (error==KErrNone) |
|
223 { |
|
224 iProvider->SendReceive(TIpcArgs(iInterfaceId,buffer,&aResponseBuf), aStatus); |
|
225 } |
|
226 else |
|
227 { |
|
228 __ASSERT_DEBUG(iBuffers[iBuffers.Count()-1]==buffer, User::Panic(KSpecAssert_ESockCSockcsp_xt, 1)); //make sure we are removing what we believe we are removing |
|
229 iBuffers.Remove(iBuffers.Count()-1); //remove the buffer |
|
230 delete buffer; |
|
231 buffer = NULL; |
|
232 } |
|
233 } |
|
234 else |
|
235 { |
|
236 delete buffer; |
|
237 buffer = NULL; |
|
238 } |
|
239 } |
|
240 |
|
241 if (error!=KErrNone) |
|
242 { |
|
243 TRequestStatus* status = &aStatus; |
|
244 User::RequestComplete(status,error); |
|
245 return; |
|
246 } |
|
247 } |
|
248 |
|
249 EXPORT_C void RCommsApiExtensionBase::SendMessage(TCommsApiExtReqMsg& aRequestMsg) |
|
250 { |
|
251 __ASSERT_ALWAYS(iProvider && iProvider->Handle(), User::Panic(KApiExtPanic, EApiExtBadHandle)); |
|
252 __ASSERT_ALWAYS((aRequestMsg.Length() <= KMaxExtApiIpcMsgLength), User::Panic(KApiExtPanic, EApiExtMetaOverflow)); |
|
253 |
|
254 TBuf8<KMaxExtApiIpcMsgLength> buffer; |
|
255 if (aRequestMsg.Store(buffer) != KErrNone) |
|
256 { |
|
257 User::Panic(KApiExtPanic, EApiExtMetaOverflow); |
|
258 } |
|
259 |
|
260 iProvider->Send(TIpcArgs(iInterfaceId, &buffer)); |
|
261 } |
|
262 |