os/mm/mmlibs/mmfw/src/Recognizer/RecMmf.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/src/Recognizer/RecMmf.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,239 @@
     1.4 +// Copyright (c) 2003-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 <barsread.h>
    1.21 +#include "RecMmf.h"
    1.22 +#include "mmfcontrollerpluginresolver.h"
    1.23 +
    1.24 +const TInt KMimeMmfRecognizerValue = 0x101F7C0C;
    1.25 +const TUid KUidMimeMmfRecognizer = {KMimeMmfRecognizerValue};
    1.26 +const TInt KMmfRecognizerPriority = 10; // The recognizer priority is set to 10(a value between ENormal and EHigh)
    1.27 +
    1.28 +
    1.29 +// the minimum buffer size that will theoretically guarantee recognition 
    1.30 +const TInt KPreferredBufSize = 256;
    1.31 +
    1.32 +// the granularity of the internal MIME type array 
    1.33 +const TInt KMimeArrayGranularity = 4;
    1.34 +
    1.35 +// CApaMmfRecognizer
    1.36 +
    1.37 +/**
    1.38 + * @internalAll
    1.39 + *
    1.40 + * Call base constructor with the recognizer's UID and confidence level
    1.41 + * The MMF recognizer priority is set to 10(a value between ENormal and EHigh) to allow 
    1.42 + * third-party recognizers to specify high priority.
    1.43 + */
    1.44 +CApaMmfRecognizer::CApaMmfRecognizer()
    1.45 +	:CApaDataRecognizerType(KUidMimeMmfRecognizer,KMmfRecognizerPriority)
    1.46 +	{
    1.47 +	}
    1.48 +
    1.49 +CApaMmfRecognizer::~CApaMmfRecognizer()
    1.50 +	{
    1.51 +	delete iMmfRecognizer;
    1.52 +	}
    1.53 +
    1.54 +/**
    1.55 + * @internalAll
    1.56 + *
    1.57 + * Return the supposed minimum buffer size we need to 
    1.58 + * successfully recognize the data
    1.59 + */
    1.60 +TUint CApaMmfRecognizer::PreferredBufSize()
    1.61 +	{
    1.62 +	return KPreferredBufSize;
    1.63 +	}
    1.64 +
    1.65 +/**
    1.66 + * @internalAll
    1.67 + *
    1.68 + * Gets one of the data (MIME) types that the recognizer can recognize.
    1.69 + */
    1.70 +TDataType CApaMmfRecognizer::SupportedDataTypeL(TInt aIndex) const
    1.71 +	{
    1.72 +	return (iMmfRecognizer->SupportedDataTypeL(aIndex));
    1.73 +	}
    1.74 +
    1.75 +
    1.76 +/**
    1.77 + * @internalAll
    1.78 + *
    1.79 + * Attempt to recognize the data.
    1.80 + * This recognizer only attempts to match the data header on its own,
    1.81 + * or the data header plus the file suffix together.
    1.82 + *
    1.83 + * NB if the file is not recognized, this function should NOT leave :
    1.84 + * it should instead set iConfidence = ENotRecognized and return
    1.85 + * the function should only leave if there is an out-of-memory condition
    1.86 + */
    1.87 +void CApaMmfRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
    1.88 +	{
    1.89 +	// assume Match will fail :
    1.90 +	iConfidence = CApaDataRecognizerType::ENotRecognized;
    1.91 +
    1.92 +	CMmfRecognizer::TMatchMethod matchMethod = iMmfRecognizer->MatchL(aName,aBuffer);
    1.93 +	
    1.94 +	// return whether the data was matched by setting iConfidence
    1.95 +	// if matched the MIME type is returned in iDataType
    1.96 +	if (matchMethod == CMmfRecognizer::ENotMatched)
    1.97 +		{	
    1.98 +		iConfidence = CApaDataRecognizerType::ENotRecognized;
    1.99 +		}
   1.100 +	else
   1.101 +		{
   1.102 +		iDataType = iMmfRecognizer->MimeString();
   1.103 +
   1.104 +		//Match on data only
   1.105 +		if (matchMethod == CMmfRecognizer::EBySignature)
   1.106 +			iConfidence = CApaDataRecognizerType::EPossible;
   1.107 +		else
   1.108 +			{//Match on data and suffix
   1.109 +			ASSERT(matchMethod == CMmfRecognizer::EByName);
   1.110 +			iConfidence = CApaDataRecognizerType::EProbable;
   1.111 +			}
   1.112 +
   1.113 +		}
   1.114 +	}
   1.115 +
   1.116 +void CApaMmfRecognizer::ConstructL()
   1.117 +	{
   1.118 +	iMmfRecognizer = CMmfRecognizer::NewL();
   1.119 +    iCountDataTypes = iMmfRecognizer->NumMimeTypes();
   1.120 +	}
   1.121 +
   1.122 +CApaMmfRecognizer* CApaMmfRecognizer::NewL()
   1.123 +	{
   1.124 +	CApaMmfRecognizer* self = new (ELeave) CApaMmfRecognizer();   
   1.125 +	CleanupStack::PushL(self);
   1.126 +	self->ConstructL();
   1.127 +	CleanupStack::Pop(self);
   1.128 +	return self;
   1.129 +	}
   1.130 +
   1.131 +// CMmfRecognizer - the main utility class owner by CApaMmfRecognizer
   1.132 +
   1.133 +CMmfRecognizer::CMmfRecognizer()
   1.134 +	{
   1.135 +	}
   1.136 +
   1.137 +CMmfRecognizer::~CMmfRecognizer()
   1.138 +	{
   1.139 +	delete iMmfRecognizerUtil;
   1.140 +	delete iMimeTypes;
   1.141 +	}
   1.142 +
   1.143 +void CMmfRecognizer::ConstructL()
   1.144 +	{
   1.145 +	iMimeTypes = new (ELeave) CDesC8ArrayFlat(KMimeArrayGranularity);
   1.146 +	BuildListL();
   1.147 +	iMmfRecognizerUtil = CMmfRecognizerUtil::NewL();
   1.148 +	}
   1.149 +
   1.150 +CMmfRecognizer* CMmfRecognizer::NewL()
   1.151 +	{
   1.152 +	CMmfRecognizer* self = new (ELeave) CMmfRecognizer();   
   1.153 +	CleanupStack::PushL(self);
   1.154 +	self->ConstructL();
   1.155 +	CleanupStack::Pop(self);
   1.156 +	return self;
   1.157 +	}
   1.158 +
   1.159 +/**
   1.160 + * @internalAll
   1.161 + *
   1.162 + * Return the number of MIME types supported 
   1.163 + */
   1.164 +TInt CMmfRecognizer::NumMimeTypes() const
   1.165 +	{
   1.166 +	return(iMimeTypes->Count());
   1.167 +	}
   1.168 +
   1.169 +
   1.170 +/**
   1.171 + * @internalAll
   1.172 + *
   1.173 + * Call into the MMF Controller Framework DLL to get
   1.174 + * a list of supported MIME types
   1.175 + */
   1.176 +void CMmfRecognizer::BuildListL()
   1.177 +	{
   1.178 +	iMimeTypes->Reset();
   1.179 +	CMmfRecognizerUtil::GetMimeTypesL(iMimeTypes);
   1.180 +	}
   1.181 +
   1.182 +
   1.183 +/**
   1.184 + * @internalAll
   1.185 + *
   1.186 + * Get one of the data (MIME) types that MMF can recognize.
   1.187 + */
   1.188 +const TPtrC8 CMmfRecognizer::SupportedDataTypeL(TInt aIndex) const
   1.189 +	{
   1.190 +	if ((aIndex < 0) || (aIndex >= iMimeTypes->Count()))
   1.191 +		User::Leave(KErrArgument);
   1.192 +
   1.193 +	return(iMimeTypes->MdcaPoint(aIndex));
   1.194 +	}
   1.195 +
   1.196 +
   1.197 +/**
   1.198 + * @internalAll
   1.199 + *
   1.200 + * Get a reference to the last MIME type string successfully matched
   1.201 + */
   1.202 +const TDesC8& CMmfRecognizer::MimeString() const
   1.203 +	{
   1.204 +	return iMimeString;
   1.205 +	}
   1.206 +
   1.207 +/**
   1.208 + * @internalAll
   1.209 + *
   1.210 + * Attempt to recognize the data
   1.211 + */
   1.212 +CMmfRecognizer::TMatchMethod CMmfRecognizer::MatchL(const TDesC& aFileName, const TDesC8& aBuffer)
   1.213 +	{
   1.214 +	CMmfRecognizerUtil::TMatchLevel matchLevel = CMmfRecognizerUtil::EMatchNone;
   1.215 +	matchLevel = iMmfRecognizerUtil->GetMimeTypeL(aFileName, aBuffer, iMimeString);
   1.216 +	
   1.217 +	TMatchMethod bestMatchMethod = ENotMatched;
   1.218 +	if(matchLevel==CMmfRecognizerUtil::EMatchData)
   1.219 +		bestMatchMethod = EBySignature;
   1.220 +	else if(matchLevel==CMmfRecognizerUtil::EMatchName)
   1.221 +		bestMatchMethod = EByName;
   1.222 +
   1.223 +	return bestMatchMethod;
   1.224 +	}
   1.225 +
   1.226 +
   1.227 +#include <ecom/ecom.h>
   1.228 +#include <ecom/implementationproxy.h>
   1.229 +
   1.230 +const TImplementationProxy ImplementationTable[] = 
   1.231 +	{
   1.232 +	IMPLEMENTATION_PROXY_ENTRY(0x101F7C41, CApaMmfRecognizer::NewL)
   1.233 +	};
   1.234 +
   1.235 +
   1.236 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   1.237 +    {
   1.238 +    aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   1.239 +    return ImplementationTable;
   1.240 +    }
   1.241 +
   1.242 +