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 "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: #include sl@0: #include sl@0: #include "RecMmf.h" sl@0: #include "mmfcontrollerpluginresolver.h" sl@0: sl@0: const TInt KMimeMmfRecognizerValue = 0x101F7C0C; sl@0: const TUid KUidMimeMmfRecognizer = {KMimeMmfRecognizerValue}; sl@0: const TInt KMmfRecognizerPriority = 10; // The recognizer priority is set to 10(a value between ENormal and EHigh) sl@0: sl@0: sl@0: // the minimum buffer size that will theoretically guarantee recognition sl@0: const TInt KPreferredBufSize = 256; sl@0: sl@0: // the granularity of the internal MIME type array sl@0: const TInt KMimeArrayGranularity = 4; sl@0: sl@0: // CApaMmfRecognizer sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Call base constructor with the recognizer's UID and confidence level sl@0: * The MMF recognizer priority is set to 10(a value between ENormal and EHigh) to allow sl@0: * third-party recognizers to specify high priority. sl@0: */ sl@0: CApaMmfRecognizer::CApaMmfRecognizer() sl@0: :CApaDataRecognizerType(KUidMimeMmfRecognizer,KMmfRecognizerPriority) sl@0: { sl@0: } sl@0: sl@0: CApaMmfRecognizer::~CApaMmfRecognizer() sl@0: { sl@0: delete iMmfRecognizer; sl@0: } sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Return the supposed minimum buffer size we need to sl@0: * successfully recognize the data sl@0: */ sl@0: TUint CApaMmfRecognizer::PreferredBufSize() sl@0: { sl@0: return KPreferredBufSize; sl@0: } sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Gets one of the data (MIME) types that the recognizer can recognize. sl@0: */ sl@0: TDataType CApaMmfRecognizer::SupportedDataTypeL(TInt aIndex) const sl@0: { sl@0: return (iMmfRecognizer->SupportedDataTypeL(aIndex)); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Attempt to recognize the data. sl@0: * This recognizer only attempts to match the data header on its own, sl@0: * or the data header plus the file suffix together. sl@0: * sl@0: * NB if the file is not recognized, this function should NOT leave : sl@0: * it should instead set iConfidence = ENotRecognized and return sl@0: * the function should only leave if there is an out-of-memory condition sl@0: */ sl@0: void CApaMmfRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer) sl@0: { sl@0: // assume Match will fail : sl@0: iConfidence = CApaDataRecognizerType::ENotRecognized; sl@0: sl@0: CMmfRecognizer::TMatchMethod matchMethod = iMmfRecognizer->MatchL(aName,aBuffer); sl@0: sl@0: // return whether the data was matched by setting iConfidence sl@0: // if matched the MIME type is returned in iDataType sl@0: if (matchMethod == CMmfRecognizer::ENotMatched) sl@0: { sl@0: iConfidence = CApaDataRecognizerType::ENotRecognized; sl@0: } sl@0: else sl@0: { sl@0: iDataType = iMmfRecognizer->MimeString(); sl@0: sl@0: //Match on data only sl@0: if (matchMethod == CMmfRecognizer::EBySignature) sl@0: iConfidence = CApaDataRecognizerType::EPossible; sl@0: else sl@0: {//Match on data and suffix sl@0: ASSERT(matchMethod == CMmfRecognizer::EByName); sl@0: iConfidence = CApaDataRecognizerType::EProbable; sl@0: } sl@0: sl@0: } sl@0: } sl@0: sl@0: void CApaMmfRecognizer::ConstructL() sl@0: { sl@0: iMmfRecognizer = CMmfRecognizer::NewL(); sl@0: iCountDataTypes = iMmfRecognizer->NumMimeTypes(); sl@0: } sl@0: sl@0: CApaMmfRecognizer* CApaMmfRecognizer::NewL() sl@0: { sl@0: CApaMmfRecognizer* self = new (ELeave) CApaMmfRecognizer(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: // CMmfRecognizer - the main utility class owner by CApaMmfRecognizer sl@0: sl@0: CMmfRecognizer::CMmfRecognizer() sl@0: { sl@0: } sl@0: sl@0: CMmfRecognizer::~CMmfRecognizer() sl@0: { sl@0: delete iMmfRecognizerUtil; sl@0: delete iMimeTypes; sl@0: } sl@0: sl@0: void CMmfRecognizer::ConstructL() sl@0: { sl@0: iMimeTypes = new (ELeave) CDesC8ArrayFlat(KMimeArrayGranularity); sl@0: BuildListL(); sl@0: iMmfRecognizerUtil = CMmfRecognizerUtil::NewL(); sl@0: } sl@0: sl@0: CMmfRecognizer* CMmfRecognizer::NewL() sl@0: { sl@0: CMmfRecognizer* self = new (ELeave) CMmfRecognizer(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Return the number of MIME types supported sl@0: */ sl@0: TInt CMmfRecognizer::NumMimeTypes() const sl@0: { sl@0: return(iMimeTypes->Count()); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Call into the MMF Controller Framework DLL to get sl@0: * a list of supported MIME types sl@0: */ sl@0: void CMmfRecognizer::BuildListL() sl@0: { sl@0: iMimeTypes->Reset(); sl@0: CMmfRecognizerUtil::GetMimeTypesL(iMimeTypes); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Get one of the data (MIME) types that MMF can recognize. sl@0: */ sl@0: const TPtrC8 CMmfRecognizer::SupportedDataTypeL(TInt aIndex) const sl@0: { sl@0: if ((aIndex < 0) || (aIndex >= iMimeTypes->Count())) sl@0: User::Leave(KErrArgument); sl@0: sl@0: return(iMimeTypes->MdcaPoint(aIndex)); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Get a reference to the last MIME type string successfully matched sl@0: */ sl@0: const TDesC8& CMmfRecognizer::MimeString() const sl@0: { sl@0: return iMimeString; sl@0: } sl@0: sl@0: /** sl@0: * @internalAll sl@0: * sl@0: * Attempt to recognize the data sl@0: */ sl@0: CMmfRecognizer::TMatchMethod CMmfRecognizer::MatchL(const TDesC& aFileName, const TDesC8& aBuffer) sl@0: { sl@0: CMmfRecognizerUtil::TMatchLevel matchLevel = CMmfRecognizerUtil::EMatchNone; sl@0: matchLevel = iMmfRecognizerUtil->GetMimeTypeL(aFileName, aBuffer, iMimeString); sl@0: sl@0: TMatchMethod bestMatchMethod = ENotMatched; sl@0: if(matchLevel==CMmfRecognizerUtil::EMatchData) sl@0: bestMatchMethod = EBySignature; sl@0: else if(matchLevel==CMmfRecognizerUtil::EMatchName) sl@0: bestMatchMethod = EByName; sl@0: sl@0: return bestMatchMethod; sl@0: } sl@0: sl@0: sl@0: #include sl@0: #include sl@0: sl@0: const TImplementationProxy ImplementationTable[] = sl@0: { sl@0: IMPLEMENTATION_PROXY_ENTRY(0x101F7C41, CApaMmfRecognizer::NewL) sl@0: }; sl@0: sl@0: sl@0: EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) sl@0: { sl@0: aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); sl@0: return ImplementationTable; sl@0: } sl@0: sl@0: