contentmgmt/contentaccessfwfordrm/source/caf/data.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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 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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <apmstd.h>
       
    20 
       
    21 #include "data.h"
       
    22 #include "agentinterface.h"
       
    23 #include "agentinfo.h"
       
    24 #include "agentfactory.h"
       
    25 #include "attributeset.h"
       
    26 #include "virtualpath.h"
       
    27 #include "resolver.h"
       
    28 #include "agentinfo.h"
       
    29 
       
    30 using namespace ContentAccess;
       
    31 
       
    32 EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
       
    33 	{
       
    34 	CData *self = CData::NewLC(aVirtualPath, aIntent, aShareMode);
       
    35 	CleanupStack::Pop(self);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
       
    40 	{
       
    41 	CData *self = new (ELeave) CData;
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL(aVirtualPath, aIntent, aShareMode);
       
    44 	return self;
       
    45 	}
       
    46 
       
    47 EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
       
    48 	{
       
    49 	CData *self = CData::NewLC(aFile, aUniqueId, aIntent);
       
    50 	CleanupStack::Pop(self);
       
    51 	return self;
       
    52 	}
       
    53 		
       
    54 EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
       
    55 	{
       
    56 	CData *self = new (ELeave) CData;
       
    57 	CleanupStack::PushL(self);
       
    58 	self->ConstructL(aFile, aUniqueId, aIntent);
       
    59 	return self;
       
    60 	}
       
    61 
       
    62 
       
    63 EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
       
    64 	{
       
    65 	CData *self = CData::NewLC(aVirtualPath, aShareMode);
       
    66 	CleanupStack::Pop(self);
       
    67 	return self;
       
    68 	}
       
    69 
       
    70 EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
       
    71 	{
       
    72 	CData *self = new (ELeave) CData;
       
    73 	CleanupStack::PushL(self);
       
    74 	self->ConstructL(aVirtualPath, aShareMode);
       
    75 	return self;
       
    76 	}
       
    77 
       
    78 EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId)
       
    79 	{
       
    80 	CData *self = CData::NewLC(aFile, aUniqueId);
       
    81 	CleanupStack::Pop(self);
       
    82 	return self;
       
    83 	}
       
    84 		
       
    85 EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId)
       
    86 	{
       
    87 	CData *self = new (ELeave) CData;
       
    88 	CleanupStack::PushL(self);
       
    89 	self->ConstructL(aFile, aUniqueId);
       
    90 	return self;
       
    91 	}
       
    92 
       
    93 
       
    94 CData* CData::NewLC(TUid aUid,
       
    95 					const TVirtualPathPtr& aVirtualPath,
       
    96 					TIntent aIntent,
       
    97 					TContentShareMode aShareMode)
       
    98 	{
       
    99 	CData* self = new(ELeave) CData();
       
   100 	CleanupStack::PushL(self);
       
   101 	self->ConstructL(aUid, aVirtualPath, aIntent, aShareMode);
       
   102 	return self;
       
   103 	}
       
   104 
       
   105 CData* CData::NewLC(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
       
   106 	{
       
   107 	CData* self = new (ELeave) CData();
       
   108 	CleanupStack::PushL(self);
       
   109 	self->ConstructL(aUid, aFile, aUniqueId, aIntent);
       
   110 	return self;
       
   111 	}
       
   112 
       
   113 CData::CData()
       
   114 	{ 
       
   115 	}
       
   116 
       
   117 CData::~CData() 
       
   118 	{ 
       
   119 	// Destroy the agent implementation
       
   120 	delete iAgentData;
       
   121 	
       
   122 	// close ECOM session, may result in the unloading of the DLL
       
   123 	delete iAgentFactory;
       
   124 	REComSession::FinalClose();
       
   125 	}
       
   126 
       
   127 
       
   128 void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
       
   129 	{
       
   130 	// Create the agent resolver which will contains a reference to
       
   131 	// the agent responsible for this piece of content
       
   132 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
       
   133 	
       
   134 	// Create a temporary buffer used to store the translated version of the URI
       
   135 	HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
       
   136 	TPtr uri = actualUri->Des();
       
   137 	
       
   138 	// Find the agent who handles the file and translate the URI if it is pointing to a private directory 
       
   139 	CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode);
       
   140 
       
   141 	// Figure out the Uid of the agent
       
   142 	TUid agentUid = agentInfo.Agent().ImplementationUid();
       
   143 	
       
   144 	// call internal CData::NewL()
       
   145 	CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aIntent, aShareMode);
       
   146 	
       
   147 	CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver
       
   148 	}
       
   149 
       
   150 void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
       
   151 	{
       
   152 	// Create the agent resolver which will contains a reference to
       
   153 	// the agent responsible for this piece of content
       
   154 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
       
   155 	
       
   156 	// Create a temporary buffer used to store the translated version of the URI
       
   157 	HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
       
   158 	TPtr uri = actualUri->Des();
       
   159 	
       
   160 	// Find the agent who handles the file and translate the URI if it is pointing to a private directory 
       
   161 	CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode);
       
   162 
       
   163 	// Figure out the Uid of the agent
       
   164 	TUid agentUid = agentInfo.Agent().ImplementationUid();
       
   165 	
       
   166 	// call internal CData::NewL()
       
   167 	CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aShareMode);
       
   168 	
       
   169 	CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver
       
   170 	}
       
   171 
       
   172 void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
       
   173 	{
       
   174 	// Find the agent who handles the file
       
   175 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
       
   176 	CAgentInfo& agentInfo = resolver->ResolveFileL(aFile);
       
   177 
       
   178 	// Figure out the Uid of the agent
       
   179 	TUid agentUid = agentInfo.Agent().ImplementationUid();
       
   180 
       
   181 	// call other constructL now that we have the Uid
       
   182 	CData::ConstructL(agentUid, aFile, aUniqueId, aIntent);
       
   183 
       
   184 	// Cleanup resolver after creating CData to unnecessary 
       
   185 	// unloading and loading of agent plug-ins
       
   186 	CleanupStack::PopAndDestroy(resolver); 
       
   187 	}
       
   188 
       
   189 void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId)
       
   190 	{
       
   191 	// Find the agent who handles the file
       
   192 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
       
   193 	CAgentInfo& agentInfo = resolver->ResolveFileL(aFile);
       
   194 
       
   195 	// Figure out the Uid of the agent
       
   196 	TUid agentUid = agentInfo.Agent().ImplementationUid();
       
   197 
       
   198 	// call other constructL now that we have the Uid
       
   199 	CData::ConstructL(agentUid, aFile, aUniqueId);
       
   200 
       
   201 	// Cleanup resolver after creating CData to unnecessary 
       
   202 	// unloading and loading of agent plug-ins
       
   203 	CleanupStack::PopAndDestroy(resolver); 
       
   204 	}
       
   205 
       
   206 void CData::ConstructL(TUid aUid,
       
   207 					   const TVirtualPathPtr& aVirtualPath,
       
   208 					   TIntent aIntent,
       
   209 					   TContentShareMode aShareMode)
       
   210 	{
       
   211 	CData::ConstructL(aUid, aVirtualPath, aShareMode);
       
   212 
       
   213 	// Ensure that client's intent is possible
       
   214 	User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
       
   215 	}
       
   216 
       
   217 void CData::ConstructL(TUid aUid,
       
   218 					   const TVirtualPathPtr& aVirtualPath,
       
   219 					   TContentShareMode aShareMode)
       
   220 	{
       
   221 	iAgentUid = aUid;
       
   222 
       
   223 	// create our own agent factory (de-facto session handle for ECOM)
       
   224 	iAgentFactory = CAgentFactory::NewL(iAgentUid);
       
   225 
       
   226 	// Create an instance of the Agent's CAgentData
       
   227 	iAgentData = iAgentFactory->CreateDataConsumerL(aVirtualPath, aShareMode);
       
   228 
       
   229 	}
       
   230 
       
   231 void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
       
   232 	{
       
   233 	CData::ConstructL(aUid, aFile, aUniqueId);
       
   234 
       
   235 	// Ensure that client's intent is possible
       
   236 	User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
       
   237 	}
       
   238 
       
   239 void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId)
       
   240 	{
       
   241 	iAgentUid = aUid;
       
   242 
       
   243 	// create our own agent factory (de-facto session handle for ECOM)
       
   244 	iAgentFactory = CAgentFactory::NewL(iAgentUid);
       
   245 
       
   246 	// Create an instance of the agent's CAgentData
       
   247 	// The agent must make a duplicate of the file handle
       
   248 	iAgentData = iAgentFactory->CreateDataConsumerL(aFile, aUniqueId);
       
   249 
       
   250 	}
       
   251 
       
   252 
       
   253 EXPORT_C void CData::DataSizeL(TInt& aSize)
       
   254 	{
       
   255 	// ask the agent for the data size of the current content object
       
   256 	iAgentData->DataSizeL(aSize);
       
   257 	}
       
   258 
       
   259 EXPORT_C TInt CData::EvaluateIntent(TIntent aIntent)
       
   260 	{
       
   261 	// ask the agent to re-evaluate the intent on the current content object
       
   262 	return iAgentData->EvaluateIntent(aIntent);
       
   263 	}
       
   264 
       
   265 EXPORT_C TInt CData::ExecuteIntent(TIntent aIntent)
       
   266 	{
       
   267 	// ask the agent to re-evaluate the intent on the current content object
       
   268 	return iAgentData->ExecuteIntent(aIntent);
       
   269 	}
       
   270 
       
   271 EXPORT_C TInt CData::Read(TDes8& aDes) const
       
   272 	{
       
   273 	// ask the agent to read plaintext from the content object 
       
   274 	return iAgentData->Read(aDes);
       
   275 	}
       
   276 
       
   277 EXPORT_C TInt CData::Read(TDes8& aDes, TInt aLength) const
       
   278 	{
       
   279 	// ask the agent to read plaintext from the content object 
       
   280 	return iAgentData->Read(aDes, aLength);
       
   281 	}
       
   282 
       
   283 EXPORT_C void CData::Read(TDes8& aDes, 
       
   284 						  TRequestStatus& aStatus) const
       
   285 	{
       
   286 	// ask the agent to read plaintext from the content object 
       
   287 	iAgentData->Read(aDes, aStatus);
       
   288 	}
       
   289 
       
   290 EXPORT_C void CData::Read(TDes8& aDes, 
       
   291 						  TInt aLength, 
       
   292 						  TRequestStatus& aStatus) const
       
   293 	{
       
   294 	// ask the agent to read plaintext from the content object 
       
   295 	iAgentData->Read(aDes, aLength, aStatus);
       
   296 	}
       
   297 	
       
   298 EXPORT_C void CData::ReadCancel(TRequestStatus &aStatus) const
       
   299 	{
       
   300 	iAgentData->ReadCancel(aStatus);
       
   301 	}
       
   302 EXPORT_C TInt CData::Read(TInt aPos, TDes8& aDes,
       
   303 						  TInt aLength, TRequestStatus& aStatus) const
       
   304 	{
       
   305 	// The above API method signature allows error codes to be returned
       
   306 	// via two different routes (return code & aStatus). Should the async request 
       
   307 	// dispatch fail then an error code is returned immediately via the 
       
   308 	// aStatus parameter rather than via the return code of the function.	
       
   309 
       
   310 	// NOTE: it is not generally not recommended for functions to be able to return
       
   311 	// error codes in two different ways as this places a bigger error-checking
       
   312 	// burden on clients.
       
   313 	
       
   314 	
       
   315 	// ask the agent to read plaintext from the content object 
       
   316 	if(aPos<0)
       
   317 		return KErrArgument;
       
   318 	return iAgentData->Read(aPos, aDes, aLength, aStatus);
       
   319 	}
       
   320 
       
   321 
       
   322 EXPORT_C TInt CData::Seek(TSeek aMode,TInt& aPos) const
       
   323 	{
       
   324 	// ask the agent to seek witin the plaintext 
       
   325 	return iAgentData->Seek(aMode, aPos);
       
   326 	}
       
   327 
       
   328 EXPORT_C TInt CData::SetProperty(TAgentProperty aProperty, TInt aValue)
       
   329 	{
       
   330 	// Set a property within the agent
       
   331 	return iAgentData->SetProperty(aProperty, aValue);
       
   332 	}
       
   333 
       
   334 EXPORT_C TInt CData::GetAttribute(TInt aAttribute, TInt& aValue) const
       
   335 	{
       
   336 	// Get an attribute related to this content object
       
   337 	return iAgentData->GetAttribute(aAttribute, aValue);
       
   338 	}
       
   339 
       
   340 EXPORT_C TInt CData::GetAttributeSet(RAttributeSet& aAttributeSet) const
       
   341 	{
       
   342 	// Get a set of attributes related to this content object
       
   343 	return iAgentData->GetAttributeSet(aAttributeSet);
       
   344 	}
       
   345 
       
   346 EXPORT_C TInt CData::GetStringAttribute(TInt aAttribute, TDes& aValue) const
       
   347 	{
       
   348 	// Get a string attribute related to this content object
       
   349 	return iAgentData->GetStringAttribute(aAttribute, aValue);
       
   350 	}
       
   351 
       
   352 EXPORT_C TInt CData::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const
       
   353 	{
       
   354 	// Get a set of string attributes related to this content object
       
   355 	return iAgentData->GetStringAttributeSet(aStringAttributeSet);
       
   356 	}
       
   357 
       
   358 #ifndef REMOVE_CAF1
       
   359 EXPORT_C void CData::SetQosL(TQosAttribute aQosAttr, TInt aValue)
       
   360 	{
       
   361 	if(aQosAttr == EQosBufferSize)
       
   362 		{
       
   363 		User::LeaveIfError(iAgentData->SetProperty(EAgentPropertyBufferSize, aValue));
       
   364 		}
       
   365 	}
       
   366 
       
   367 EXPORT_C TBool CData::GetMimeTypeL(TDes8& aMimeType) const
       
   368 	{
       
   369 	TBuf16 <KMaxDataTypeLength> mimeType;
       
   370 	TInt err = KErrNone;
       
   371 	if(iAgentUid != KF32AgentImplUid)
       
   372 		{
       
   373 		err = iAgentData->GetStringAttribute(EMimeType, mimeType);
       
   374 		if(err == KErrNone && mimeType.Length() != 0)
       
   375 			{
       
   376 			aMimeType.Copy(mimeType);
       
   377 			return ETrue;
       
   378 			}
       
   379 		}
       
   380 	return EFalse;
       
   381 	}
       
   382 #endif // REMOVE_CAF1