contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentdata.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2004-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 <caf/caf.h>
       
    20 #include "f32agentdata.h"
       
    21 #include "f32defaultattributes.h"
       
    22 #include "virtualpath.h"
       
    23 #include "f32agentui.h"
       
    24 
       
    25 using namespace ContentAccess;
       
    26 
       
    27 CF32AgentData* CF32AgentData::NewL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
       
    28 	{
       
    29 	CF32AgentData* self = new (ELeave) CF32AgentData;
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL(aVirtualPath, aShareMode);
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CF32AgentData* CF32AgentData::NewL(RFile& aFile, const TDesC& aUniqueId)
       
    37 	{
       
    38 	CF32AgentData* self = new (ELeave) CF32AgentData;
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL(aFile, aUniqueId);
       
    41 	CleanupStack::Pop(self);
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 CF32AgentData::CF32AgentData()
       
    46 	{
       
    47 	}
       
    48 
       
    49 CF32AgentData::~CF32AgentData()
       
    50 	{
       
    51 	// Tidy up RFile and RFs
       
    52 	iFile.Close();
       
    53 	if(iVirtualPath) // opened by name
       
    54 		{
       
    55 		iFs.Close();
       
    56 		}
       
    57 
       
    58 	delete iVirtualPath;
       
    59 	}
       
    60   
       
    61 void CF32AgentData::ConstructL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
       
    62 	{
       
    63 	iVirtualPath = CVirtualPath::NewL(aVirtualPath);
       
    64 	
       
    65 	// Check that the client hasn't specified some incorrect UniqueId
       
    66 	User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aVirtualPath.UniqueId()));
       
    67 
       
    68 	TUint mode = TF32DefaultAttributes::GetFileMode(aShareMode);
       
    69 	User::LeaveIfError(iFs.Connect());
       
    70 
       
    71 	// Make the file session shareable
       
    72 	User::LeaveIfError(iFs.ShareAuto());
       
    73 
       
    74 	User::LeaveIfError(iFile.Open(iFs, aVirtualPath.URI(), mode));
       
    75 	}
       
    76 
       
    77 void CF32AgentData::ConstructL(RFile& aFile, const TDesC& aUniqueId)
       
    78 	{
       
    79 	TInt pos = 0;
       
    80 
       
    81 	// Check that the client hasn't specified some incorrect UniqueId
       
    82 	User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aUniqueId));	
       
    83 	
       
    84 	// When creating a CData from a file handle we must duplicate the file handle
       
    85 	// before doing anything
       
    86 	User::LeaveIfError(iFile.Duplicate(aFile));
       
    87 	User::LeaveIfError(iFile.Seek(ESeekStart, pos));  // reset to start of file
       
    88 	}
       
    89 
       
    90 void CF32AgentData::DataSizeL(TInt &aSize)
       
    91 	{
       
    92 	User::LeaveIfError(iFile.Size(aSize));
       
    93 	}
       
    94 
       
    95 TInt CF32AgentData::EvaluateIntent(TIntent /*aIntent*/)
       
    96 	{
       
    97 	return KErrNone;
       
    98 	}
       
    99 
       
   100 TInt CF32AgentData::ExecuteIntent(TIntent /*aIntent*/)
       
   101 	{
       
   102 	return KErrNone;
       
   103 	}
       
   104 
       
   105 TInt CF32AgentData::Read(TDes8& aDes) 
       
   106 	{
       
   107 	return iFile.Read(aDes);
       
   108 	}
       
   109 
       
   110 TInt CF32AgentData::Read(TDes8& aDes,TInt aLength) 
       
   111 	{
       
   112 	return iFile.Read(aDes,aLength);
       
   113 	}
       
   114 
       
   115 void CF32AgentData::Read(TDes8& aDes,TRequestStatus& aStatus) 
       
   116 	{
       
   117 	iFile.Read(aDes, aStatus);
       
   118 	}
       
   119 
       
   120 void CF32AgentData::Read(TDes8& aDes,
       
   121 							 TInt aLength, 
       
   122 							 TRequestStatus& aStatus) 
       
   123 	{
       
   124 	iFile.Read(aDes, aLength, aStatus);
       
   125 	}
       
   126 	
       
   127 TInt CF32AgentData::Read(TInt aPos, TDes8& aDes,
       
   128 							 TInt aLength, 
       
   129 							 TRequestStatus& aStatus) 
       
   130 	{
       
   131 	iFile.Read(aPos, aDes, aLength, aStatus);
       
   132 	return KErrNone;
       
   133 	}
       
   134 	
       
   135 void CF32AgentData::ReadCancel(TRequestStatus& aStatus)
       
   136 {
       
   137 	iFile.ReadCancel(aStatus);
       
   138 }
       
   139 
       
   140 TInt CF32AgentData::Seek(TSeek aMode, TInt& aPos) 
       
   141 	{
       
   142 	return iFile.Seek(aMode, aPos);
       
   143 	}
       
   144 
       
   145 TInt CF32AgentData::SetProperty(TAgentProperty aProperty, TInt aValue)
       
   146 	{
       
   147 	
       
   148 	if(aProperty==EAgentPropertyAgentUI)
       
   149 		//	should only pass type EAgentPropertyAgentUI 
       
   150 		{
       
   151 		CF32AgentUi* ui = NULL;
       
   152 	
       
   153 		// get a pointer to the UI
       
   154 		TRAPD(err, ui = &AgentUiL());
       
   155 		if(err)
       
   156 			{
       
   157 			return err;
       
   158 			}
       
   159 		return ui->SetProperty(aProperty, aValue);
       
   160 		}
       
   161 	else
       
   162 		{
       
   163 		return KErrCANotSupported;
       
   164 		}
       
   165 	}
       
   166 
       
   167 TInt CF32AgentData::GetAttribute(TInt aAttribute, TInt& aValue)
       
   168 	{
       
   169 	if(iVirtualPath)
       
   170 		{
       
   171 		return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iVirtualPath->URI());
       
   172 		}
       
   173 	else
       
   174 		{
       
   175 		return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
       
   176 		}
       
   177 	}
       
   178 
       
   179 TInt CF32AgentData::GetAttributeSet(RAttributeSet& aAttributeSet)
       
   180 	{
       
   181 	if(iVirtualPath)
       
   182 		{
       
   183 		return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iVirtualPath->URI());
       
   184 		}	
       
   185 	else
       
   186 		{
       
   187 		return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
       
   188 		}	
       
   189 			
       
   190 	}
       
   191 
       
   192 TInt CF32AgentData::GetStringAttribute(TInt aAttribute, TDes& aValue)
       
   193 	{
       
   194 	if(iVirtualPath)
       
   195 		{
       
   196 		return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iVirtualPath->URI());
       
   197 		}
       
   198 	else
       
   199 		{
       
   200 		return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
       
   201 		}
       
   202 	}
       
   203 
       
   204 TInt CF32AgentData::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet)
       
   205 	{
       
   206 	if(iVirtualPath)
       
   207 		{
       
   208 		return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iVirtualPath->URI());
       
   209 		}
       
   210 	else
       
   211 		{
       
   212 		return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
       
   213 		}
       
   214 	}
       
   215 
       
   216 CF32AgentUi& CF32AgentData::AgentUiL()
       
   217 	{
       
   218 	if(!iAgentUi)
       
   219 		{
       
   220 		// load agent UI from f32AgentUi.dll
       
   221 		iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL();
       
   222 		}
       
   223 	return *iAgentUi;
       
   224 	}