sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include "agentinfo.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "resolver.h" sl@0: #include "agentinfo.h" sl@0: #include sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode) sl@0: { sl@0: CData *self = CData::NewLC(aVirtualPath, aIntent, aShareMode); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode) sl@0: { sl@0: CData *self = new (ELeave) CData; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aVirtualPath, aIntent, aShareMode); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent) sl@0: { sl@0: CData *self = CData::NewLC(aFile, aUniqueId, aIntent); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent) sl@0: { sl@0: CData *self = new (ELeave) CData; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aFile, aUniqueId, aIntent); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode) sl@0: { sl@0: CData *self = CData::NewLC(aVirtualPath, aShareMode); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode) sl@0: { sl@0: CData *self = new (ELeave) CData; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aVirtualPath, aShareMode); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId) sl@0: { sl@0: CData *self = CData::NewLC(aFile, aUniqueId); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId) sl@0: { sl@0: CData *self = new (ELeave) CData; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aFile, aUniqueId); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CData* CData::NewLC(TUid aUid, sl@0: const TVirtualPathPtr& aVirtualPath, sl@0: TIntent aIntent, sl@0: TContentShareMode aShareMode) sl@0: { sl@0: CData* self = new(ELeave) CData(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aUid, aVirtualPath, aIntent, aShareMode); sl@0: return self; sl@0: } sl@0: sl@0: CData* CData::NewLC(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent) sl@0: { sl@0: CData* self = new (ELeave) CData(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aUid, aFile, aUniqueId, aIntent); sl@0: return self; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: EXPORT_C CData* CData::NewL(const TDesC8& aHeaderData) sl@0: { sl@0: CData* self = CData::NewLC(aHeaderData); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewL(const TDesC8& aHeaderData, TIntent aIntent) sl@0: { sl@0: CData* self = CData::NewLC(aHeaderData, aIntent); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewLC(const TDesC8& aHeaderData) sl@0: { sl@0: CData* self = new (ELeave) CData(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aHeaderData); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CData* CData::NewLC(const TDesC8& aHeaderData, TIntent aIntent) sl@0: { sl@0: CData* self = new (ELeave) CData(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aHeaderData, aIntent); sl@0: return self; sl@0: } sl@0: sl@0: CData* CData::NewLC(TUid aAgentUid, const TDesC8& aHeaderData, TIntent aIntent) sl@0: { sl@0: CData* self = new (ELeave) CData(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aAgentUid, aHeaderData, aIntent); sl@0: return self; sl@0: } sl@0: sl@0: #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: CData::CData() sl@0: { sl@0: } sl@0: sl@0: CData::~CData() sl@0: { sl@0: // Destroy the agent implementation sl@0: delete iAgentData; sl@0: sl@0: // close ECOM session, may result in the unloading of the DLL sl@0: delete iAgentFactory; sl@0: REComSession::FinalClose(); sl@0: } sl@0: sl@0: sl@0: void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode) sl@0: { sl@0: // Create the agent resolver which will contains a reference to sl@0: // the agent responsible for this piece of content sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: sl@0: // Create a temporary buffer used to store the translated version of the URI sl@0: HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength); sl@0: TPtr uri = actualUri->Des(); sl@0: sl@0: // Find the agent who handles the file and translate the URI if it is pointing to a private directory sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode); sl@0: sl@0: // Figure out the Uid of the agent sl@0: TUid agentUid = agentInfo.Agent().ImplementationUid(); sl@0: sl@0: // call internal CData::NewL() sl@0: CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aIntent, aShareMode); sl@0: sl@0: CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver sl@0: } sl@0: sl@0: void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode) sl@0: { sl@0: // Create the agent resolver which will contains a reference to sl@0: // the agent responsible for this piece of content sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: sl@0: // Create a temporary buffer used to store the translated version of the URI sl@0: HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength); sl@0: TPtr uri = actualUri->Des(); sl@0: sl@0: // Find the agent who handles the file and translate the URI if it is pointing to a private directory sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode); sl@0: sl@0: // Figure out the Uid of the agent sl@0: TUid agentUid = agentInfo.Agent().ImplementationUid(); sl@0: sl@0: // call internal CData::NewL() sl@0: CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aShareMode); sl@0: sl@0: CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver sl@0: } sl@0: sl@0: void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent) sl@0: { sl@0: // Find the agent who handles the file sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(aFile); sl@0: sl@0: // Figure out the Uid of the agent sl@0: TUid agentUid = agentInfo.Agent().ImplementationUid(); sl@0: sl@0: // call other constructL now that we have the Uid sl@0: CData::ConstructL(agentUid, aFile, aUniqueId, aIntent); sl@0: sl@0: // Cleanup resolver after creating CData to unnecessary sl@0: // unloading and loading of agent plug-ins sl@0: CleanupStack::PopAndDestroy(resolver); sl@0: } sl@0: sl@0: void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId) sl@0: { sl@0: // Find the agent who handles the file sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(aFile); sl@0: sl@0: // Figure out the Uid of the agent sl@0: TUid agentUid = agentInfo.Agent().ImplementationUid(); sl@0: sl@0: // call other constructL now that we have the Uid sl@0: CData::ConstructL(agentUid, aFile, aUniqueId); sl@0: sl@0: // Cleanup resolver after creating CData to unnecessary sl@0: // unloading and loading of agent plug-ins sl@0: CleanupStack::PopAndDestroy(resolver); sl@0: } sl@0: sl@0: void CData::ConstructL(TUid aUid, sl@0: const TVirtualPathPtr& aVirtualPath, sl@0: TIntent aIntent, sl@0: TContentShareMode aShareMode) sl@0: { sl@0: CData::ConstructL(aUid, aVirtualPath, aShareMode); sl@0: sl@0: // Ensure that client's intent is possible sl@0: User::LeaveIfError(iAgentData->EvaluateIntent(aIntent)); sl@0: } sl@0: sl@0: void CData::ConstructL(TUid aUid, sl@0: const TVirtualPathPtr& aVirtualPath, sl@0: TContentShareMode aShareMode) sl@0: { sl@0: iAgentUid = aUid; sl@0: sl@0: // create our own agent factory (de-facto session handle for ECOM) sl@0: iAgentFactory = CAgentFactory::NewL(iAgentUid); sl@0: sl@0: // Create an instance of the Agent's CAgentData sl@0: iAgentData = iAgentFactory->CreateDataConsumerL(aVirtualPath, aShareMode); sl@0: sl@0: } sl@0: sl@0: void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent) sl@0: { sl@0: CData::ConstructL(aUid, aFile, aUniqueId); sl@0: sl@0: // Ensure that client's intent is possible sl@0: User::LeaveIfError(iAgentData->EvaluateIntent(aIntent)); sl@0: } sl@0: sl@0: void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId) sl@0: { sl@0: iAgentUid = aUid; sl@0: sl@0: // create our own agent factory (de-facto session handle for ECOM) sl@0: iAgentFactory = CAgentFactory::NewL(iAgentUid); sl@0: sl@0: // Create an instance of the agent's CAgentData sl@0: // The agent must make a duplicate of the file handle sl@0: iAgentData = iAgentFactory->CreateDataConsumerL(aFile, aUniqueId); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: void CData::ConstructL(const TDesC8& aHeaderData) sl@0: { sl@0: // Find the agent who handles the file sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(aHeaderData); sl@0: sl@0: // Figure out the Uid of the agent sl@0: TUid agentUid = agentInfo.Agent().ImplementationUid(); sl@0: CData::ConstructL(agentUid, aHeaderData); sl@0: sl@0: // Cleanup resolver after creating CData to unnecessary sl@0: // unloading and loading of agent plug-ins sl@0: CleanupStack::PopAndDestroy(resolver); sl@0: } sl@0: sl@0: void CData::ConstructL(const TDesC8& aHeaderData, TIntent aIntent) sl@0: { sl@0: CData::ConstructL(aHeaderData); sl@0: sl@0: // Ensure that client's intent is possible sl@0: User::LeaveIfError(iAgentData->EvaluateIntent(aIntent)); sl@0: } sl@0: sl@0: void CData::ConstructL(TUid aAgentUid, const TDesC8& aHeaderData) sl@0: { sl@0: iAgentUid = aAgentUid; sl@0: sl@0: iAgentFactory = CAgentFactory::NewL(iAgentUid); sl@0: // create an instance of agent's CAgentStreamData. sl@0: iAgentData = iAgentFactory->CreateDataConsumerL(aHeaderData); sl@0: } sl@0: sl@0: void CData::ConstructL(TUid aUid, const TDesC8& aHeaderData, TIntent aIntent) sl@0: { sl@0: CData::ConstructL(aUid, aHeaderData); sl@0: sl@0: // Ensure that client's intent is possible sl@0: User::LeaveIfError(iAgentData->EvaluateIntent(aIntent)); sl@0: } sl@0: sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: EXPORT_C void CData::DataSizeL(TInt& aSize) sl@0: { sl@0: // ask the agent for the data size of the current content object sl@0: iAgentData->DataSizeL(aSize); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: EXPORT_C void CData::DataSize64L(TInt64& aSize) sl@0: { sl@0: // ask the agent for the data size of the current content object sl@0: TRAPD(err, iAgentData->DataSize64L(aSize)); sl@0: if(err == KErrCANotSupported) sl@0: { sl@0: //fallback to 32bit API sl@0: TInt size32; sl@0: iAgentData->DataSizeL(size32); sl@0: aSize = size32; sl@0: } sl@0: else sl@0: User::LeaveIfError(err); sl@0: } sl@0: #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: EXPORT_C TInt CData::EvaluateIntent(TIntent aIntent) sl@0: { sl@0: // ask the agent to re-evaluate the intent on the current content object sl@0: return iAgentData->EvaluateIntent(aIntent); sl@0: } sl@0: sl@0: EXPORT_C TInt CData::ExecuteIntent(TIntent aIntent) sl@0: { sl@0: // ask the agent to re-evaluate the intent on the current content object sl@0: return iAgentData->ExecuteIntent(aIntent); sl@0: } sl@0: sl@0: EXPORT_C TInt CData::Read(TDes8& aDes) const sl@0: { sl@0: // ask the agent to read plaintext from the content object sl@0: return iAgentData->Read(aDes); sl@0: } sl@0: sl@0: EXPORT_C TInt CData::Read(TDes8& aDes, TInt aLength) const sl@0: { sl@0: // ask the agent to read plaintext from the content object sl@0: return iAgentData->Read(aDes, aLength); sl@0: } sl@0: sl@0: EXPORT_C void CData::Read(TDes8& aDes, sl@0: TRequestStatus& aStatus) const sl@0: { sl@0: // ask the agent to read plaintext from the content object sl@0: iAgentData->Read(aDes, aStatus); sl@0: } sl@0: sl@0: EXPORT_C void CData::Read(TDes8& aDes, sl@0: TInt aLength, sl@0: TRequestStatus& aStatus) const sl@0: { sl@0: // ask the agent to read plaintext from the content object sl@0: iAgentData->Read(aDes, aLength, aStatus); sl@0: } sl@0: sl@0: EXPORT_C void CData::ReadCancel(TRequestStatus &aStatus) const sl@0: { sl@0: iAgentData->ReadCancel(aStatus); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: EXPORT_C TInt CData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputPacket) const sl@0: { sl@0: return iAgentData->Read(aEncryptedInputDataPacket, aDecryptedOutputPacket); sl@0: } sl@0: sl@0: EXPORT_C void CData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputPacket, TRequestStatus& aStatus) const sl@0: { sl@0: iAgentData->Read(aEncryptedInputDataPacket, aDecryptedOutputPacket, aStatus); sl@0: } sl@0: sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: EXPORT_C TInt CData::Read_Unused(TInt aPos, TDes8& aDes, sl@0: TInt aLength, TRequestStatus& aStatus) const sl@0: #else sl@0: EXPORT_C TInt CData::Read(TInt aPos, TDes8& aDes, sl@0: TInt aLength, TRequestStatus& aStatus) const sl@0: #endif sl@0: { sl@0: // ask the agent to read plaintext from the content object sl@0: if(aPos<0) sl@0: return KErrArgument; sl@0: return iAgentData->Read(aPos, aDes, aLength, aStatus); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: EXPORT_C TInt CData::Read(TInt64 aPos, TDes8& aDes, sl@0: TInt aLength, TRequestStatus& aStatus) const sl@0: { sl@0: // If agent does not support 64bit Read, a fallback to 32bit Read is provided automatically sl@0: // The above API method signature allows error codes to be returned sl@0: // via two different routes (return code & aStatus). Should the async request sl@0: // dispatch fail then an error code is returned immediately via the sl@0: // aStatus parameter rather than via the return code of the function. sl@0: sl@0: // NOTE: it is not generally not recommended for functions to be able to return sl@0: // error codes in two different ways as this places a bigger error-checking sl@0: // burden on clients. sl@0: if(aPos<0) sl@0: return KErrArgument; sl@0: sl@0: TInt rval = iAgentData->Read64(aPos, aDes, aLength, aStatus); sl@0: return (rval == KErrCANotSupported? iAgentData->Read((TInt)aPos, aDes, aLength, aStatus) : rval ); sl@0: } sl@0: #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: EXPORT_C TInt CData::Seek(TSeek aMode,TInt& aPos) const sl@0: { sl@0: // ask the agent to seek witin the plaintext sl@0: return iAgentData->Seek(aMode, aPos); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: EXPORT_C TInt CData::Seek64(TSeek aMode,TInt64& aPos) const sl@0: { sl@0: // ask the agent to seek witin the plaintext sl@0: TInt rval64 = iAgentData->Seek64(aMode, aPos); sl@0: if(rval64 == KErrCANotSupported) sl@0: { sl@0: //fallback to 32bit API sl@0: TInt pos32 = I64INT(aPos); sl@0: TInt rval32 = iAgentData->Seek(aMode, pos32); sl@0: aPos = pos32; sl@0: return rval32; sl@0: } sl@0: return rval64; sl@0: } sl@0: #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: EXPORT_C TInt CData::SetProperty(TAgentProperty aProperty, TInt aValue) sl@0: { sl@0: // Set a property within the agent sl@0: return iAgentData->SetProperty(aProperty, aValue); sl@0: } sl@0: sl@0: EXPORT_C TInt CData::GetAttribute(TInt aAttribute, TInt& aValue) const sl@0: { sl@0: // Get an attribute related to this content object sl@0: return iAgentData->GetAttribute(aAttribute, aValue); sl@0: } sl@0: sl@0: EXPORT_C TInt CData::GetAttributeSet(RAttributeSet& aAttributeSet) const sl@0: { sl@0: // Get a set of attributes related to this content object sl@0: return iAgentData->GetAttributeSet(aAttributeSet); sl@0: } sl@0: sl@0: EXPORT_C TInt CData::GetStringAttribute(TInt aAttribute, TDes& aValue) const sl@0: { sl@0: // Get a string attribute related to this content object sl@0: return iAgentData->GetStringAttribute(aAttribute, aValue); sl@0: } sl@0: sl@0: EXPORT_C TInt CData::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const sl@0: { sl@0: // Get a set of string attributes related to this content object sl@0: return iAgentData->GetStringAttributeSet(aStringAttributeSet); sl@0: } sl@0: sl@0: #ifndef REMOVE_CAF1 sl@0: EXPORT_C void CData::SetQosL(TQosAttribute aQosAttr, TInt aValue) sl@0: { sl@0: if(aQosAttr == EQosBufferSize) sl@0: { sl@0: User::LeaveIfError(iAgentData->SetProperty(EAgentPropertyBufferSize, aValue)); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TBool CData::GetMimeTypeL(TDes8& aMimeType) const sl@0: { sl@0: TBuf16 mimeType; sl@0: TInt err = KErrNone; sl@0: if(iAgentUid != KF32AgentImplUid) sl@0: { sl@0: err = iAgentData->GetStringAttribute(EMimeType, mimeType); sl@0: if(err == KErrNone && mimeType.Length() != 0) sl@0: { sl@0: aMimeType.Copy(mimeType); sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: #endif // REMOVE_CAF1