|
1 /* |
|
2 * Copyright (c) 2002-2005 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 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 #include "senwsiplugin.h" |
|
26 #include "MSenServiceDescription.h" |
|
27 #include "SenServiceConnection.h" // framework IDs, error codes |
|
28 #include "msencoreservicemanager.h" |
|
29 #include "senbasicwebservicesession.h" |
|
30 #include "sendebug.h" |
|
31 #include "SenFacet.h" |
|
32 #include "senlogger.h" |
|
33 |
|
34 #include <SenTransportProperties.h> |
|
35 #include <SenSoapConstants.h> |
|
36 |
|
37 namespace |
|
38 { |
|
39 _LIT8(KFrameworkLocalname, "Framework"); |
|
40 #ifdef _SENDEBUG |
|
41 const TInt KFLATBUFSIZE = 64; |
|
42 #endif // _SENDEBUG |
|
43 } |
|
44 |
|
45 // Create instance of concrete ECOM interface implementation |
|
46 CSenWsiPlugin* CSenWsiPlugin::NewL(TAny* aManager) |
|
47 { |
|
48 MSenCoreServiceManager* manager = |
|
49 reinterpret_cast<MSenCoreServiceManager*>(aManager); |
|
50 |
|
51 CSenWsiPlugin* self = new (ELeave) CSenWsiPlugin(*manager); |
|
52 CleanupStack::PushL (self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // Constructor |
|
59 CSenWsiPlugin::CSenWsiPlugin(MSenCoreServiceManager& aManager) |
|
60 : iManager(aManager) |
|
61 { |
|
62 } |
|
63 |
|
64 CSenWsiPlugin::~CSenWsiPlugin() |
|
65 { |
|
66 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("CSenWsiPlugin::~CSenWsiPlugin()"))); |
|
67 } |
|
68 |
|
69 // Second phase construction. |
|
70 void CSenWsiPlugin::ConstructL() |
|
71 { |
|
72 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("CSenWsiPlugin::ConstructL"))); |
|
73 |
|
74 BaseConstructL(KWsiFrameworkXMLNS, KFrameworkLocalname); |
|
75 } |
|
76 /* |
|
77 RFileLogger* CSenWsiPlugin::Log() const |
|
78 { |
|
79 return iManager.Log(); |
|
80 } |
|
81 */ |
|
82 |
|
83 TInt CSenWsiPlugin::RegisterServiceDescriptionL( MSenServiceDescription& aServiceDescription ) |
|
84 { |
|
85 TInt retVal(KErrNone); |
|
86 |
|
87 #ifdef _SENDEBUG |
|
88 TPtrC8 contract = aServiceDescription.Contract(); |
|
89 TPtrC8 endpoint = aServiceDescription.Endpoint(); |
|
90 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenWsiPlugin::RegisterServiceDescriptionL"); |
|
91 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel," - creating session from description."); |
|
92 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8(" - Endpoint: '%S'"), &endpoint)); |
|
93 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8(" - Contract: '%S'"), &contract)); |
|
94 #endif // _SENDEBUG |
|
95 |
|
96 if( aServiceDescription.Endpoint().Length() == 0 ) |
|
97 { |
|
98 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel," - Endpoint is zero-lenght(!), cannot register such SD."); |
|
99 return KErrSenNoEndpoint; |
|
100 } |
|
101 |
|
102 |
|
103 // WS-I sessions are matched by consumer id. |
|
104 // This way we can avoid session sharing/multiple consumers |
|
105 |
|
106 CSenBasicWebServiceSession* pSession = CSenBasicWebServiceSession::NewLC(*this); |
|
107 retVal = pSession->InitializeFromL(aServiceDescription); |
|
108 |
|
109 if( retVal == KErrNone ) |
|
110 { |
|
111 // Takes the ownership of this session |
|
112 retVal = Manager().AddServiceDescriptionL(pSession); |
|
113 CleanupStack::Pop(pSession); |
|
114 } |
|
115 else |
|
116 { |
|
117 CleanupStack::PopAndDestroy( pSession ); |
|
118 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenWsiPlugin::RegisterServiceDescriptionL:"); |
|
119 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("- Session->InitializeFromL failed: %d"), retVal)); |
|
120 } |
|
121 return retVal; |
|
122 } |
|
123 |
|
124 TInt CSenWsiPlugin::UnregisterServiceDescriptionL( MSenServiceDescription& aServiceDescription ) |
|
125 { |
|
126 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenWsiPlugin::UnregisterServiceDescriptionL"); |
|
127 TInt retVal(KErrNone); |
|
128 |
|
129 if(aServiceDescription.DescriptionClassType() == MSenServiceDescription::EBasicWebServiceSession) |
|
130 { |
|
131 CSenBasicWebServiceSession* pSession = |
|
132 (CSenBasicWebServiceSession*) &aServiceDescription; |
|
133 retVal = Manager().RemoveServiceDescriptionL(*pSession); |
|
134 } |
|
135 |
|
136 return retVal; |
|
137 } |
|
138 |
|
139 |
|
140 const TDesC8& CSenWsiPlugin::Id() |
|
141 { |
|
142 return KDefaultBasicWebServicesFrameworkID(); // "WS-I" |
|
143 } |
|
144 |
|
145 TInt CSenWsiPlugin::AddServiceDescriptionL(MSenServiceDescription& aPattern, |
|
146 MSenRemoteServiceConsumer& /* aRemoteConsumer */, |
|
147 HBufC8*& /* aErrorMsg */) |
|
148 { |
|
149 // Currently, accept only SDs, which explicitly declare WS-I framework ID. |
|
150 if(aPattern.FrameworkId() != KDefaultBasicWebServicesFrameworkID) |
|
151 { |
|
152 return 0; |
|
153 } |
|
154 |
|
155 TPtrC8 endpoint = aPattern.Endpoint(); |
|
156 if( endpoint.Length() > 0 ) |
|
157 { |
|
158 CSenBasicWebServiceSession* pNewSession = |
|
159 (CSenBasicWebServiceSession*) NewServiceDescriptionL(); |
|
160 CleanupStack::PushL(pNewSession); |
|
161 |
|
162 // InitializeFromL call copies the contract and endpoint: |
|
163 TInt retVal = pNewSession->InitializeFromL(aPattern); |
|
164 if( retVal != KErrNone ) |
|
165 { |
|
166 CleanupStack::PopAndDestroy(); |
|
167 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenWsiPlugin::AddServiceDescriptionL:"); |
|
168 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("- New session->InitializeFromL failed: %d"), retVal)); |
|
169 return 0; |
|
170 } |
|
171 else // init ok |
|
172 { |
|
173 // Core / XML DAO takes ownership of new session: |
|
174 // - if duplicate (equal primary keys) exists, it is deleted |
|
175 Manager().AddServiceDescriptionL( pNewSession ); |
|
176 CleanupStack::Pop( pNewSession ); |
|
177 return 1; // one new session added |
|
178 } |
|
179 } |
|
180 else |
|
181 { |
|
182 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel," - No endpoint; new session could not be added."); |
|
183 return 0; // zero added |
|
184 } |
|
185 } |
|
186 |
|
187 TInt CSenWsiPlugin::CreateServiceSessionL( MSenServiceDescription& aServiceDescription, |
|
188 MSenServiceDescription& /* aPattern */, |
|
189 CSenServiceSession*& aNewSession, |
|
190 MSenRemoteServiceConsumer& /* aRemoteConsumer */, |
|
191 HBufC8*& /* pErrorMsg */ ) |
|
192 { |
|
193 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenWsiPlugin::CreateServiceSessionL"); |
|
194 |
|
195 CSenBasicWebServiceSession* pNewSession = NULL; |
|
196 TInt retVal(KErrNone); |
|
197 if(aServiceDescription.DescriptionClassType() == MSenServiceDescription::EBasicWebServiceSession) |
|
198 { |
|
199 pNewSession = (CSenBasicWebServiceSession*) &aServiceDescription; |
|
200 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"- Service description is already a basic web service (WS-I) session"); |
|
201 //pNewSession->CopyFacetsFromL(aPattern); // not performed with WS-I |
|
202 retVal = KErrNone; |
|
203 } |
|
204 else |
|
205 { |
|
206 TPtrC8 endpoint = aServiceDescription.Endpoint(); |
|
207 if(endpoint.Length()>0) |
|
208 { |
|
209 pNewSession = (CSenBasicWebServiceSession*) NewServiceDescriptionL(); |
|
210 CleanupStack::PushL(pNewSession); |
|
211 |
|
212 // InitializeFromL call copies the contract and endpoint: |
|
213 retVal = pNewSession->InitializeFromL(aServiceDescription); |
|
214 |
|
215 #ifdef _SENDEBUG |
|
216 CBufFlat* pBuf = CBufFlat::NewL(KFLATBUFSIZE); |
|
217 CleanupStack::PushL(pBuf); |
|
218 RBufWriteStream writeStream; |
|
219 writeStream.Open(*pBuf); |
|
220 CleanupClosePushL(writeStream); |
|
221 pNewSession->WriteAsXMLToL(writeStream); |
|
222 TPtr8 ptr = pBuf->Ptr(0); |
|
223 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"- New WS-I service session as XML:"); |
|
224 TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase , KMaxLogLevel,( ptr )); |
|
225 CleanupStack::PopAndDestroy(2); // writeStream.Close(), pBuf |
|
226 #endif // _SENDEBUG |
|
227 |
|
228 if( retVal == KErrNone ) // initialize from pattern OK |
|
229 { |
|
230 // NOTE: Core ALWAYS takes ownership of new session: |
|
231 // - if some session with equal primary keys exists, it is deleted |
|
232 TInt retVal = Manager().AddServiceDescriptionL(pNewSession); |
|
233 CleanupStack::Pop(pNewSession); |
|
234 #ifdef _SENDEBUG |
|
235 if(retVal!=KErrNone) |
|
236 { |
|
237 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenBasicWsiPlugin::CreateServiceSessionL"); |
|
238 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KNormalLogLevel, _L8(" - CoreServiceMngr::AddServiceDescriptionL returned: %d"), retVal)); |
|
239 } |
|
240 #endif // _SENDEBUG |
|
241 } |
|
242 else // initialize from pattern failed! |
|
243 { |
|
244 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenWsiPlugin::CreateServiceSessionL:"); |
|
245 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("- New session->InitializeFromL failed: %d"), retVal)); |
|
246 CleanupStack::PopAndDestroy(pNewSession); |
|
247 } |
|
248 } |
|
249 else |
|
250 { |
|
251 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel," - No endpoint; returning KErrSenNoEndpoint"); |
|
252 retVal = KErrSenNoEndpoint; // no endpoint for basic web service session |
|
253 } |
|
254 } |
|
255 aNewSession = pNewSession; |
|
256 return retVal; |
|
257 } |
|
258 |
|
259 TInt CSenWsiPlugin::OnEvent(const TInt /* aEvent */, TAny* /* apArgument */) |
|
260 { |
|
261 // LOG_WRITE_L("CSenBasicWsiPlugin::OnEvent"); |
|
262 // LOG_WRITEFORMAT((_L8("-event code: %d"), aEvent)); |
|
263 TInt retVal(KErrNone); |
|
264 |
|
265 return retVal; |
|
266 } |
|
267 |
|
268 TAny* CSenWsiPlugin::ExtendedInterface() |
|
269 { |
|
270 // There is no extended interface in Basic WS framework at the moment |
|
271 return NULL; |
|
272 } |
|
273 |
|
274 CSenWSDescription* CSenWsiPlugin::NewServiceDescriptionL() |
|
275 { |
|
276 CSenBasicWebServiceSession* pSD = |
|
277 CSenBasicWebServiceSession::NewLC(*this); |
|
278 pSD->SetFrameworkIdL(KDefaultBasicWebServicesFrameworkID); |
|
279 CSenFacet* pCompleteOn = CSenFacet::NewL(); |
|
280 CleanupStack::PushL(pCompleteOn); |
|
281 pCompleteOn->SetNameL(KCompleteMessagesFacet); |
|
282 pSD->SetFacetL(*pCompleteOn); |
|
283 CleanupStack::PopAndDestroy(pCompleteOn); |
|
284 CleanupStack::Pop(pSD); |
|
285 return pSD; |
|
286 } |
|
287 |
|
288 /** |
|
289 * Return the ServiceManager for which this instance is working. |
|
290 * This is used by the ServiceSession instances created by this framework. |
|
291 * |
|
292 * Note, in Sen, MSenCoreServiceManager so all Frameworks |
|
293 * return their "owner" - i.e. - the only service manager in Sen Framework |
|
294 * |
|
295 * @return (MSenCoreServiceManager) |
|
296 */ |
|
297 |
|
298 MSenCoreServiceManager& CSenWsiPlugin::Manager() |
|
299 { |
|
300 return iManager; |
|
301 } |
|
302 |
|
303 /** |
|
304 * Set the ServiceManager to which this instance reports. |
|
305 * The (singleton) ServiceManager calls this method when |
|
306 * it instantiates a framework. |
|
307 * |
|
308 * @param aServiceManager The singleton ServiceManager in the system. |
|
309 */ |
|
310 void CSenWsiPlugin::SetManager(MSenCoreServiceManager& aServiceManager) |
|
311 { |
|
312 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,_L("CSenWsiPlugin::SetManager(.)")); |
|
313 iManager = aServiceManager; |
|
314 } |
|
315 |
|
316 /** |
|
317 * Return an object that can do SAX based parsing of a XML fragment |
|
318 * that contains framework specific configuration information. |
|
319 * The ServiceManager asks for this BaseFragment upon startup |
|
320 * in order to give this framework a chance to read its configuration |
|
321 * information from the central ServiceManager configuration document. |
|
322 * |
|
323 * @return (CSenBaseFragment) |
|
324 */ |
|
325 CSenBaseFragment& CSenWsiPlugin::ConfigParser() |
|
326 { |
|
327 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("CSenWsiPlugin::ConfigParser()"))); |
|
328 return *this; |
|
329 } |
|
330 |
|
331 /** |
|
332 * Write the ServiceInvocationFramework configuration as XML to a HBufC8. |
|
333 * |
|
334 * This method is invoked by the ServiceManager when it saves |
|
335 * its state and/or configuration. |
|
336 * |
|
337 * Upon startup the chunk of XML that is written will be passed back to |
|
338 * the configuation parser of the framework. |
|
339 * |
|
340 * The "schema" that shall be adhered to is: |
|
341 * <pre> |
|
342 * <element name="Framework"> |
|
343 * <any/><!-- this is where implementations write additional |
|
344 * information --> |
|
345 * <attribute name="class" type="String"> |
|
346 * <!-- In Symbian the class attribute is used as cue for |
|
347 * the ECOM Resolver --> |
|
348 * </element> |
|
349 * </pre> |
|
350 * |
|
351 * @param aTo - a HBufC8 to which the framework should write its configuration |
|
352 */ |
|
353 |
|
354 |
|
355 void CSenWsiPlugin::EndElementL(const TDesC8& aNsUri, |
|
356 const TDesC8& aLocalName, |
|
357 const TDesC8& aQName) |
|
358 { |
|
359 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("WS-I plugin @ end of element: %S (xmlns='%S', localname='%S')"), |
|
360 &aQName, &aNsUri, &aLocalName)); |
|
361 CSIF::EndElementL(aNsUri,aLocalName,aQName); |
|
362 } |
|
363 |
|
364 // over-ride CSenBaseFragment |
|
365 HBufC* CSenWsiPlugin::AsXmlUnicodeL() |
|
366 { |
|
367 HBufC8* pUtf8 = AsXmlL(); |
|
368 CleanupStack::PushL(pUtf8); |
|
369 HBufC* pAsXmlInUnicode = SenXmlUtils::ToUnicodeLC(*pUtf8); |
|
370 CleanupStack::Pop(pAsXmlInUnicode); |
|
371 CleanupStack::PopAndDestroy(pUtf8); |
|
372 return pAsXmlInUnicode; |
|
373 } |
|
374 |
|
375 HBufC8* CSenWsiPlugin::AsXmlL() |
|
376 { |
|
377 _LIT8(KLessFramework,"<Framework ");//CodeScannerWarning |
|
378 _LIT8(KXmlns,"xmlns=\""); |
|
379 _LIT8(KQuot,"\" "); |
|
380 _LIT8(KClassQuot,"class=\""); |
|
381 _LIT8(KQuotNewLine,"\"/>\n"); |
|
382 HBufC8* retVal = HBufC8::NewLC(256); |
|
383 TPtr8 ptr = retVal->Des(); |
|
384 ptr.Append(KLessFramework); |
|
385 ptr.Append(KXmlns); |
|
386 ptr.Append(KWsiFrameworkXMLNS); |
|
387 ptr.Append(KQuot); |
|
388 |
|
389 ptr.Append(KClassQuot); |
|
390 ptr.Append(KWsiFrameworkCue); |
|
391 ptr.Append(KQuotNewLine); |
|
392 CleanupStack::Pop(); // retVal |
|
393 return retVal; |
|
394 } |
|
395 |
|
396 // New methods |
|
397 |
|
398 TInt CSenWsiPlugin::SetTransportPropertiesL(MSenTransport& aTransport) |
|
399 { |
|
400 //CSenHttpTransportProperties* pProps = CSenHttpTransportProperties::NewLC(); |
|
401 CSenTransportProperties* pProps = CSenTransportProperties::NewLC(); |
|
402 pProps->SetPropertyL(KSenSoapActionHeaderName, KSenSoapActionHeaderValueEmpty, KHttpHeaderType); |
|
403 HBufC8* pPropsAsXml = pProps->AsUtf8L(); |
|
404 CleanupStack::PopAndDestroy(pProps); |
|
405 CleanupStack::PushL( pPropsAsXml ); |
|
406 TInt retVal = aTransport.SetPropertiesL( *pPropsAsXml, MSenLayeredProperties::ESenFrameworkLayer, NULL ); |
|
407 CleanupStack::PopAndDestroy( pPropsAsXml ); |
|
408 return retVal; |
|
409 } |
|
410 // END OF FILE |
|
411 |
|
412 |