1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/src/Plugin/StdSourceAndSink/fileaccess.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,355 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <f32file.h>
1.20 +#include <f32file64.h>
1.21 +#include <e32std.h>
1.22 +#include <caf/attribute.h>
1.23 +#include <caf/bitset.h>
1.24 +#include <caf/content.h>
1.25 +#include <caf/data.h>
1.26 +using namespace ContentAccess;
1.27 +#include <f32file.h>
1.28 +
1.29 +#include "FileAccess.h"
1.30 +
1.31 +CF32File::~CF32File()
1.32 + {
1.33 + if (!iFileHandle)
1.34 + iFile.Close();
1.35 + delete iFilePath;
1.36 + }
1.37 +
1.38 +CF32File* CF32File::NewL(RFs& aSession, TDesC& aFilePath, TUint aMode)
1.39 + {
1.40 + CF32File* self = new (ELeave) CF32File;
1.41 + CleanupStack::PushL(self);
1.42 + self->ConstructL(aSession, aFilePath, aMode);
1.43 + CleanupStack::Pop(self);
1.44 + return self;
1.45 + }
1.46 +
1.47 +
1.48 +void CF32File::ConstructL(RFs& aSession, TDesC& aPath, TUint aFileMode)
1.49 + {
1.50 + iSession = &aSession;
1.51 + iFilePath = aPath.AllocL();
1.52 + TUint attributes = 0;
1.53 + TInt err = iSession->Att(*iFilePath, attributes);
1.54 + if (err == KErrNone)
1.55 + {
1.56 + if ( attributes & KEntryAttReadOnly )
1.57 + User::LeaveIfError(iFile.Open(*iSession, *iFilePath, EFileShareReadersOnly )) ;
1.58 + else //if ( !( attributes & KEntryAttReadOnly ) )
1.59 + User::LeaveIfError(iFile.Open(*iSession, *iFilePath, aFileMode)) ;
1.60 + }
1.61 + else if ((err == KErrNotFound) && (aFileMode & EFileWrite))
1.62 + {
1.63 + User::LeaveIfError(iFile.Create(*iSession, *iFilePath, aFileMode )) ;
1.64 + }
1.65 + else
1.66 + {
1.67 + User::Leave(err);
1.68 + }
1.69 + }
1.70 +
1.71 +
1.72 +RFile& CF32File::FileL()
1.73 + {
1.74 + return iFile;
1.75 + }
1.76 +
1.77 +TInt CF32File::Data(CData*& /*aData*/)
1.78 + {
1.79 + return KErrNotSupported;
1.80 + }
1.81 +
1.82 +TInt CF32File::Seek(TSeek aSeekMode, TInt aPos)
1.83 + {
1.84 + return iFile.Seek(aSeekMode, aPos);
1.85 + }
1.86 +
1.87 +TInt CF32File::Read(TDes8& aDes,TInt aLength)
1.88 + {
1.89 + return iFile.Read(aDes, aLength);
1.90 + }
1.91 +
1.92 +void CF32File::Read(TDes8& aDes, TInt aLength, TRequestStatus& aStatus)
1.93 + {
1.94 + iFile.Read(aDes, aLength, aStatus);
1.95 + }
1.96 +
1.97 +TInt CF32File::Write(const TDesC8& aDes,TInt aLength)
1.98 + {
1.99 + return iFile.Write(aDes, aLength);
1.100 + }
1.101 +
1.102 +void CF32File::Write(const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus)
1.103 + {
1.104 + iFile.Write(aDes, aLength, aStatus);
1.105 + }
1.106 +
1.107 +TInt CF32File::Size(TInt& aSize)
1.108 + {
1.109 + return iFile.Size(aSize);
1.110 + }
1.111 +
1.112 +TInt CF32File::SetSize(TInt aSize)
1.113 + {
1.114 + TInt err = iFile.SetSize(aSize);
1.115 + if(err == KErrNone)
1.116 + iFileSize = aSize;
1.117 + else
1.118 + iFileSize = -1;
1.119 +
1.120 + return err;
1.121 + }
1.122 +
1.123 +TInt CF32File::EvaluateIntent(TIntent /*aIntent*/) const
1.124 + {
1.125 + return KErrNone;
1.126 + }
1.127 +
1.128 +
1.129 +TInt CF32File::ExecuteIntent(TIntent /*aIntent*/)
1.130 + {
1.131 + return KErrNone;
1.132 + }
1.133 +
1.134 +TBool CF32File::IsProtected() const
1.135 + {
1.136 + return EFalse;
1.137 + }
1.138 +
1.139 +TInt CF32File::Read(TInt aPosition, TDes8& aDes, TInt aLength, TRequestStatus& aStatus)
1.140 + {
1.141 + iFile.Read(aPosition, aDes, aLength, aStatus);
1.142 + return KErrNone;
1.143 + }
1.144 +
1.145 +TInt CF32File::SetAgentProperty(TAgentProperty /*aProperty*/, TInt /*aValue*/)
1.146 + {
1.147 + // not an error to set this if not supported, just wont do anything
1.148 + return KErrNone;
1.149 + }
1.150 +
1.151 +CContentFile::~CContentFile()
1.152 + {
1.153 + delete iData;
1.154 +
1.155 + iLegacyFile.Close();
1.156 + iFile64.Close(); //For defect EASA-84ZC6J
1.157 +
1.158 + delete iFilePath;
1.159 + }
1.160 +
1.161 +
1.162 +CContentFile* CContentFile::NewL(RFs& aSession, const TDesC& aFilePath, const TDesC& aUniqueId, TUint aMode, TBool aEnableUI)
1.163 + {
1.164 + CContentFile* self = new (ELeave) CContentFile;
1.165 + CleanupStack::PushL(self);
1.166 + self->ConstructL(aSession, aFilePath, aUniqueId, aMode, aEnableUI);
1.167 + CleanupStack::Pop(self);
1.168 + return self;
1.169 + }
1.170 +
1.171 +void CContentFile::ConstructL(RFs& aSession, const TDesC& aPath, const TDesC& aUniqueId, TUint /*aMode*/, TBool aEnableUI)
1.172 + {
1.173 + iSession = &aSession;
1.174 + iFilePath = aPath.AllocL();
1.175 +
1.176 + // Assume that we want the content to be shared and read-only.
1.177 + if (aUniqueId.Length() > 0)
1.178 + {
1.179 + iData = CData::NewL(TVirtualPathPtr(*iFilePath, aUniqueId), EContentShareReadWrite);
1.180 + }
1.181 + else
1.182 + {
1.183 + iData = CData::NewL(TVirtualPathPtr(*iFilePath), EContentShareReadWrite);
1.184 + }
1.185 +
1.186 + TInt err = iData->SetProperty(EAgentPropertyAgentUI, aEnableUI);
1.187 + if (err != KErrNone && err != KErrCANotSupported)
1.188 + {
1.189 + User::Leave(err);
1.190 + }
1.191 + User::LeaveIfError(iData->EvaluateIntent(EPeek));
1.192 + }
1.193 +
1.194 +
1.195 +
1.196 +TInt CContentFile::EvaluateIntent(TIntent aIntent) const
1.197 + {
1.198 + ASSERT(iData);
1.199 + return iData->EvaluateIntent(aIntent);
1.200 + }
1.201 +
1.202 +
1.203 +TInt CContentFile::ExecuteIntent(TIntent aIntent)
1.204 + {
1.205 + ASSERT(iData);
1.206 + return iData->ExecuteIntent(aIntent);
1.207 + }
1.208 +
1.209 +TBool CContentFile::IsProtected() const
1.210 + {
1.211 + ASSERT(iData);
1.212 + TInt value = 0;
1.213 + TInt err =iData->GetAttribute(EIsProtected, value);
1.214 + return (err == KErrNone && value);
1.215 + }
1.216 +
1.217 +TInt CContentFile::SetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue)
1.218 + {
1.219 + ASSERT(iData);
1.220 + return iData->SetProperty(aProperty, aValue);
1.221 + }
1.222 +
1.223 +TInt CContentFile::Seek(TSeek aSeekMode, TInt aPos)
1.224 + {
1.225 + ASSERT(iData);
1.226 + return iData->Seek(aSeekMode, aPos);
1.227 + }
1.228 +
1.229 +TInt CContentFile::Read(TDes8& aDes,TInt aLength)
1.230 + {
1.231 + ASSERT(iData);
1.232 + return iData->Read(aDes,aLength);
1.233 + }
1.234 +
1.235 +void CContentFile::Read(TDes8& aDes, TInt aLength, TRequestStatus& aStatus)
1.236 + {
1.237 + ASSERT(iData);
1.238 + iData->Read(aDes, aLength, aStatus);
1.239 + }
1.240 +
1.241 +TInt CContentFile::Write(const TDesC8& /*aDes*/,TInt /*aLength*/)
1.242 + {
1.243 + return KErrAccessDenied;
1.244 + }
1.245 +void CContentFile::Write(const TDesC8& /*aDes*/, TInt /*aLength*/, TRequestStatus& aStatus)
1.246 + {
1.247 + TRequestStatus* status = &aStatus;
1.248 + User::RequestComplete(status, KErrAccessDenied);
1.249 + }
1.250 +
1.251 +TInt CContentFile::SetSize(TInt /*aSize*/)
1.252 + {
1.253 + // Only a source is implemented, hence this cannot be allowed
1.254 + return KErrAccessDenied;
1.255 + }
1.256 +
1.257 +
1.258 +// Get the size of file
1.259 +// this method opens a new, read-only, RFile the first time this method is called
1.260 +
1.261 +TInt CContentFile::Size(TInt& aSize)
1.262 + {
1.263 + ASSERT(iData);
1.264 + TRAPD(err, iData->DataSizeL(aSize));
1.265 + return err;
1.266 + }
1.267 +
1.268 +/**
1.269 + * return a RFile for the legacy RFile method
1.270 + * this method opens a new, read-only, RFile the first time this method is called
1.271 + * @internalTechnology
1.272 + * @return Reference to RFile handle to current file
1.273 + */
1.274 +RFile& CContentFile::FileL()
1.275 + {
1.276 + if (!iLegacyFileOpen)
1.277 + {//For defect EASA-84ZC6J
1.278 + TInt error = iLegacyFile.Open(*iSession, *iFilePath, EFileRead | EFileStream | EFileShareReadersOrWriters);
1.279 + if ( error == KErrTooBig )
1.280 + {
1.281 + User::LeaveIfError(iFile64.Open(*iSession, *iFilePath, EFileRead | EFileStream | EFileShareReadersOrWriters));
1.282 + iLegacyFileOpen = ETrue;
1.283 + return iFile64;
1.284 + }
1.285 +
1.286 + else if (error == KErrNone)
1.287 + {
1.288 + iLegacyFileOpen = ETrue;
1.289 + return iLegacyFile;
1.290 + }
1.291 +
1.292 + else
1.293 + {
1.294 + User::Leave(error);
1.295 + }
1.296 + }
1.297 + if(iLegacyFile.SubSessionHandle())
1.298 + {
1.299 + return iLegacyFile;
1.300 + }
1.301 + else
1.302 + {
1.303 + return iFile64;
1.304 + }
1.305 +}
1.306 +
1.307 +TInt CContentFile::Data(CData*& aData)
1.308 + {
1.309 + if (iData==NULL)
1.310 + {
1.311 + return KErrNotReady;
1.312 + }
1.313 + else
1.314 + {
1.315 + aData = iData;
1.316 + return KErrNone;
1.317 + }
1.318 + }
1.319 +
1.320 +CF32File* CF32File::NewL(RFile& aFile)
1.321 + {
1.322 + CF32File* self = new (ELeave) CF32File;
1.323 + CleanupStack::PushL(self);
1.324 + self->ConstructL(aFile);
1.325 + CleanupStack::Pop(self);
1.326 + return self;
1.327 + }
1.328 +
1.329 +void CF32File::ConstructL(RFile& aFile)
1.330 + {
1.331 + iFile = aFile;
1.332 + iFileHandle = ETrue;
1.333 + }
1.334 +
1.335 +CContentFile* CContentFile::NewL(RFile& aFile, const TDesC& aUniqueId, TBool aEnableUI)
1.336 + {
1.337 + CContentFile* self = new (ELeave) CContentFile;
1.338 + CleanupStack::PushL(self);
1.339 + self->ConstructL(aFile, aUniqueId, aEnableUI);
1.340 + CleanupStack::Pop(self);
1.341 + return self;
1.342 + }
1.343 +
1.344 +void CContentFile::ConstructL(RFile& aFile, const TDesC& aUniqueId, TBool aEnableUI)
1.345 + {
1.346 + iData = CData::NewL(aFile, aUniqueId);
1.347 + TInt err = iData->SetProperty(EAgentPropertyAgentUI, aEnableUI);
1.348 + if (err != KErrNone && err != KErrCANotSupported)
1.349 + {
1.350 + User::Leave(err);
1.351 + }
1.352 + User::LeaveIfError(iData->EvaluateIntent(EPeek));
1.353 + }
1.354 +
1.355 +TInt CContentFile::Read(TInt aPosition, TDes8& aDes, TInt aLength, TRequestStatus& aStatus)
1.356 + {
1.357 + return iData->Read(aPosition, aDes, aLength, aStatus);
1.358 + }