First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include <caf/agentinterface.h>
23 #include "agentinfo.h"
24 #include <caf/agentfactory.h>
25 #include <caf/attributeset.h>
26 #include <caf/virtualpath.h>
28 #include "agentinfo.h"
31 using namespace ContentAccess;
33 EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
35 CData *self = CData::NewLC(aVirtualPath, aIntent, aShareMode);
36 CleanupStack::Pop(self);
40 EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
42 CData *self = new (ELeave) CData;
43 CleanupStack::PushL(self);
44 self->ConstructL(aVirtualPath, aIntent, aShareMode);
48 EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
50 CData *self = CData::NewLC(aFile, aUniqueId, aIntent);
51 CleanupStack::Pop(self);
55 EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
57 CData *self = new (ELeave) CData;
58 CleanupStack::PushL(self);
59 self->ConstructL(aFile, aUniqueId, aIntent);
64 EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
66 CData *self = CData::NewLC(aVirtualPath, aShareMode);
67 CleanupStack::Pop(self);
71 EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
73 CData *self = new (ELeave) CData;
74 CleanupStack::PushL(self);
75 self->ConstructL(aVirtualPath, aShareMode);
79 EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId)
81 CData *self = CData::NewLC(aFile, aUniqueId);
82 CleanupStack::Pop(self);
86 EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId)
88 CData *self = new (ELeave) CData;
89 CleanupStack::PushL(self);
90 self->ConstructL(aFile, aUniqueId);
95 CData* CData::NewLC(TUid aUid,
96 const TVirtualPathPtr& aVirtualPath,
98 TContentShareMode aShareMode)
100 CData* self = new(ELeave) CData();
101 CleanupStack::PushL(self);
102 self->ConstructL(aUid, aVirtualPath, aIntent, aShareMode);
106 CData* CData::NewLC(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
108 CData* self = new (ELeave) CData();
109 CleanupStack::PushL(self);
110 self->ConstructL(aUid, aFile, aUniqueId, aIntent);
114 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
116 EXPORT_C CData* CData::NewL(const TDesC8& aHeaderData)
118 CData* self = CData::NewLC(aHeaderData);
119 CleanupStack::Pop(self);
123 EXPORT_C CData* CData::NewL(const TDesC8& aHeaderData, TIntent aIntent)
125 CData* self = CData::NewLC(aHeaderData, aIntent);
126 CleanupStack::Pop(self);
130 EXPORT_C CData* CData::NewLC(const TDesC8& aHeaderData)
132 CData* self = new (ELeave) CData();
133 CleanupStack::PushL(self);
134 self->ConstructL(aHeaderData);
138 EXPORT_C CData* CData::NewLC(const TDesC8& aHeaderData, TIntent aIntent)
140 CData* self = new (ELeave) CData();
141 CleanupStack::PushL(self);
142 self->ConstructL(aHeaderData, aIntent);
146 CData* CData::NewLC(TUid aAgentUid, const TDesC8& aHeaderData, TIntent aIntent)
148 CData* self = new (ELeave) CData();
149 CleanupStack::PushL(self);
150 self->ConstructL(aAgentUid, aHeaderData, aIntent);
154 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
162 // Destroy the agent implementation
165 // close ECOM session, may result in the unloading of the DLL
166 delete iAgentFactory;
167 REComSession::FinalClose();
171 void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
173 // Create the agent resolver which will contains a reference to
174 // the agent responsible for this piece of content
175 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
177 // Create a temporary buffer used to store the translated version of the URI
178 HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
179 TPtr uri = actualUri->Des();
181 // Find the agent who handles the file and translate the URI if it is pointing to a private directory
182 CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode);
184 // Figure out the Uid of the agent
185 TUid agentUid = agentInfo.Agent().ImplementationUid();
187 // call internal CData::NewL()
188 CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aIntent, aShareMode);
190 CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver
193 void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
195 // Create the agent resolver which will contains a reference to
196 // the agent responsible for this piece of content
197 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
199 // Create a temporary buffer used to store the translated version of the URI
200 HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
201 TPtr uri = actualUri->Des();
203 // Find the agent who handles the file and translate the URI if it is pointing to a private directory
204 CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode);
206 // Figure out the Uid of the agent
207 TUid agentUid = agentInfo.Agent().ImplementationUid();
209 // call internal CData::NewL()
210 CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aShareMode);
212 CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver
215 void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
217 // Find the agent who handles the file
218 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
219 CAgentInfo& agentInfo = resolver->ResolveFileL(aFile);
221 // Figure out the Uid of the agent
222 TUid agentUid = agentInfo.Agent().ImplementationUid();
224 // call other constructL now that we have the Uid
225 CData::ConstructL(agentUid, aFile, aUniqueId, aIntent);
227 // Cleanup resolver after creating CData to unnecessary
228 // unloading and loading of agent plug-ins
229 CleanupStack::PopAndDestroy(resolver);
232 void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId)
234 // Find the agent who handles the file
235 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
236 CAgentInfo& agentInfo = resolver->ResolveFileL(aFile);
238 // Figure out the Uid of the agent
239 TUid agentUid = agentInfo.Agent().ImplementationUid();
241 // call other constructL now that we have the Uid
242 CData::ConstructL(agentUid, aFile, aUniqueId);
244 // Cleanup resolver after creating CData to unnecessary
245 // unloading and loading of agent plug-ins
246 CleanupStack::PopAndDestroy(resolver);
249 void CData::ConstructL(TUid aUid,
250 const TVirtualPathPtr& aVirtualPath,
252 TContentShareMode aShareMode)
254 CData::ConstructL(aUid, aVirtualPath, aShareMode);
256 // Ensure that client's intent is possible
257 User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
260 void CData::ConstructL(TUid aUid,
261 const TVirtualPathPtr& aVirtualPath,
262 TContentShareMode aShareMode)
266 // create our own agent factory (de-facto session handle for ECOM)
267 iAgentFactory = CAgentFactory::NewL(iAgentUid);
269 // Create an instance of the Agent's CAgentData
270 iAgentData = iAgentFactory->CreateDataConsumerL(aVirtualPath, aShareMode);
274 void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
276 CData::ConstructL(aUid, aFile, aUniqueId);
278 // Ensure that client's intent is possible
279 User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
282 void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId)
286 // create our own agent factory (de-facto session handle for ECOM)
287 iAgentFactory = CAgentFactory::NewL(iAgentUid);
289 // Create an instance of the agent's CAgentData
290 // The agent must make a duplicate of the file handle
291 iAgentData = iAgentFactory->CreateDataConsumerL(aFile, aUniqueId);
294 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
296 void CData::ConstructL(const TDesC8& aHeaderData)
298 // Find the agent who handles the file
299 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
300 CAgentInfo& agentInfo = resolver->ResolveFileL(aHeaderData);
302 // Figure out the Uid of the agent
303 TUid agentUid = agentInfo.Agent().ImplementationUid();
304 CData::ConstructL(agentUid, aHeaderData);
306 // Cleanup resolver after creating CData to unnecessary
307 // unloading and loading of agent plug-ins
308 CleanupStack::PopAndDestroy(resolver);
311 void CData::ConstructL(const TDesC8& aHeaderData, TIntent aIntent)
313 CData::ConstructL(aHeaderData);
315 // Ensure that client's intent is possible
316 User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
319 void CData::ConstructL(TUid aAgentUid, const TDesC8& aHeaderData)
321 iAgentUid = aAgentUid;
323 iAgentFactory = CAgentFactory::NewL(iAgentUid);
324 // create an instance of agent's CAgentStreamData.
325 iAgentData = iAgentFactory->CreateDataConsumerL(aHeaderData);
328 void CData::ConstructL(TUid aUid, const TDesC8& aHeaderData, TIntent aIntent)
330 CData::ConstructL(aUid, aHeaderData);
332 // Ensure that client's intent is possible
333 User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
336 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
338 EXPORT_C void CData::DataSizeL(TInt& aSize)
340 // ask the agent for the data size of the current content object
341 iAgentData->DataSizeL(aSize);
344 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
345 EXPORT_C void CData::DataSize64L(TInt64& aSize)
347 // ask the agent for the data size of the current content object
348 TRAPD(err, iAgentData->DataSize64L(aSize));
349 if(err == KErrCANotSupported)
351 //fallback to 32bit API
353 iAgentData->DataSizeL(size32);
357 User::LeaveIfError(err);
359 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
361 EXPORT_C TInt CData::EvaluateIntent(TIntent aIntent)
363 // ask the agent to re-evaluate the intent on the current content object
364 return iAgentData->EvaluateIntent(aIntent);
367 EXPORT_C TInt CData::ExecuteIntent(TIntent aIntent)
369 // ask the agent to re-evaluate the intent on the current content object
370 return iAgentData->ExecuteIntent(aIntent);
373 EXPORT_C TInt CData::Read(TDes8& aDes) const
375 // ask the agent to read plaintext from the content object
376 return iAgentData->Read(aDes);
379 EXPORT_C TInt CData::Read(TDes8& aDes, TInt aLength) const
381 // ask the agent to read plaintext from the content object
382 return iAgentData->Read(aDes, aLength);
385 EXPORT_C void CData::Read(TDes8& aDes,
386 TRequestStatus& aStatus) const
388 // ask the agent to read plaintext from the content object
389 iAgentData->Read(aDes, aStatus);
392 EXPORT_C void CData::Read(TDes8& aDes,
394 TRequestStatus& aStatus) const
396 // ask the agent to read plaintext from the content object
397 iAgentData->Read(aDes, aLength, aStatus);
400 EXPORT_C void CData::ReadCancel(TRequestStatus &aStatus) const
402 iAgentData->ReadCancel(aStatus);
405 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
407 EXPORT_C TInt CData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputPacket) const
409 return iAgentData->Read(aEncryptedInputDataPacket, aDecryptedOutputPacket);
412 EXPORT_C void CData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputPacket, TRequestStatus& aStatus) const
414 iAgentData->Read(aEncryptedInputDataPacket, aDecryptedOutputPacket, aStatus);
417 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
419 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
420 EXPORT_C TInt CData::Read_Unused(TInt aPos, TDes8& aDes,
421 TInt aLength, TRequestStatus& aStatus) const
423 EXPORT_C TInt CData::Read(TInt aPos, TDes8& aDes,
424 TInt aLength, TRequestStatus& aStatus) const
427 // ask the agent to read plaintext from the content object
430 return iAgentData->Read(aPos, aDes, aLength, aStatus);
433 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
434 EXPORT_C TInt CData::Read(TInt64 aPos, TDes8& aDes,
435 TInt aLength, TRequestStatus& aStatus) const
437 // If agent does not support 64bit Read, a fallback to 32bit Read is provided automatically
438 // The above API method signature allows error codes to be returned
439 // via two different routes (return code & aStatus). Should the async request
440 // dispatch fail then an error code is returned immediately via the
441 // aStatus parameter rather than via the return code of the function.
443 // NOTE: it is not generally not recommended for functions to be able to return
444 // error codes in two different ways as this places a bigger error-checking
445 // burden on clients.
449 TInt rval = iAgentData->Read64(aPos, aDes, aLength, aStatus);
450 return (rval == KErrCANotSupported? iAgentData->Read((TInt)aPos, aDes, aLength, aStatus) : rval );
452 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
454 EXPORT_C TInt CData::Seek(TSeek aMode,TInt& aPos) const
456 // ask the agent to seek witin the plaintext
457 return iAgentData->Seek(aMode, aPos);
460 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
461 EXPORT_C TInt CData::Seek64(TSeek aMode,TInt64& aPos) const
463 // ask the agent to seek witin the plaintext
464 TInt rval64 = iAgentData->Seek64(aMode, aPos);
465 if(rval64 == KErrCANotSupported)
467 //fallback to 32bit API
468 TInt pos32 = I64INT(aPos);
469 TInt rval32 = iAgentData->Seek(aMode, pos32);
475 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
477 EXPORT_C TInt CData::SetProperty(TAgentProperty aProperty, TInt aValue)
479 // Set a property within the agent
480 return iAgentData->SetProperty(aProperty, aValue);
483 EXPORT_C TInt CData::GetAttribute(TInt aAttribute, TInt& aValue) const
485 // Get an attribute related to this content object
486 return iAgentData->GetAttribute(aAttribute, aValue);
489 EXPORT_C TInt CData::GetAttributeSet(RAttributeSet& aAttributeSet) const
491 // Get a set of attributes related to this content object
492 return iAgentData->GetAttributeSet(aAttributeSet);
495 EXPORT_C TInt CData::GetStringAttribute(TInt aAttribute, TDes& aValue) const
497 // Get a string attribute related to this content object
498 return iAgentData->GetStringAttribute(aAttribute, aValue);
501 EXPORT_C TInt CData::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const
503 // Get a set of string attributes related to this content object
504 return iAgentData->GetStringAttributeSet(aStringAttributeSet);
508 EXPORT_C void CData::SetQosL(TQosAttribute aQosAttr, TInt aValue)
510 if(aQosAttr == EQosBufferSize)
512 User::LeaveIfError(iAgentData->SetProperty(EAgentPropertyBufferSize, aValue));
516 EXPORT_C TBool CData::GetMimeTypeL(TDes8& aMimeType) const
518 TBuf16 <KMaxDataTypeLength> mimeType;
520 if(iAgentUid != KF32AgentImplUid)
522 err = iAgentData->GetStringAttribute(EMimeType, mimeType);
523 if(err == KErrNone && mimeType.Length() != 0)
525 aMimeType.Copy(mimeType);
531 #endif // REMOVE_CAF1