os/mm/mmlibs/mmfw/src/Recognizer/RecMmf.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <f32file.h>
sl@0
    17
#include <barsread.h>
sl@0
    18
#include "RecMmf.h"
sl@0
    19
#include "mmfcontrollerpluginresolver.h"
sl@0
    20
sl@0
    21
const TInt KMimeMmfRecognizerValue = 0x101F7C0C;
sl@0
    22
const TUid KUidMimeMmfRecognizer = {KMimeMmfRecognizerValue};
sl@0
    23
const TInt KMmfRecognizerPriority = 10; // The recognizer priority is set to 10(a value between ENormal and EHigh)
sl@0
    24
sl@0
    25
sl@0
    26
// the minimum buffer size that will theoretically guarantee recognition 
sl@0
    27
const TInt KPreferredBufSize = 256;
sl@0
    28
sl@0
    29
// the granularity of the internal MIME type array 
sl@0
    30
const TInt KMimeArrayGranularity = 4;
sl@0
    31
sl@0
    32
// CApaMmfRecognizer
sl@0
    33
sl@0
    34
/**
sl@0
    35
 * @internalAll
sl@0
    36
 *
sl@0
    37
 * Call base constructor with the recognizer's UID and confidence level
sl@0
    38
 * The MMF recognizer priority is set to 10(a value between ENormal and EHigh) to allow 
sl@0
    39
 * third-party recognizers to specify high priority.
sl@0
    40
 */
sl@0
    41
CApaMmfRecognizer::CApaMmfRecognizer()
sl@0
    42
	:CApaDataRecognizerType(KUidMimeMmfRecognizer,KMmfRecognizerPriority)
sl@0
    43
	{
sl@0
    44
	}
sl@0
    45
sl@0
    46
CApaMmfRecognizer::~CApaMmfRecognizer()
sl@0
    47
	{
sl@0
    48
	delete iMmfRecognizer;
sl@0
    49
	}
sl@0
    50
sl@0
    51
/**
sl@0
    52
 * @internalAll
sl@0
    53
 *
sl@0
    54
 * Return the supposed minimum buffer size we need to 
sl@0
    55
 * successfully recognize the data
sl@0
    56
 */
sl@0
    57
TUint CApaMmfRecognizer::PreferredBufSize()
sl@0
    58
	{
sl@0
    59
	return KPreferredBufSize;
sl@0
    60
	}
sl@0
    61
sl@0
    62
/**
sl@0
    63
 * @internalAll
sl@0
    64
 *
sl@0
    65
 * Gets one of the data (MIME) types that the recognizer can recognize.
sl@0
    66
 */
sl@0
    67
TDataType CApaMmfRecognizer::SupportedDataTypeL(TInt aIndex) const
sl@0
    68
	{
sl@0
    69
	return (iMmfRecognizer->SupportedDataTypeL(aIndex));
sl@0
    70
	}
sl@0
    71
sl@0
    72
sl@0
    73
/**
sl@0
    74
 * @internalAll
sl@0
    75
 *
sl@0
    76
 * Attempt to recognize the data.
sl@0
    77
 * This recognizer only attempts to match the data header on its own,
sl@0
    78
 * or the data header plus the file suffix together.
sl@0
    79
 *
sl@0
    80
 * NB if the file is not recognized, this function should NOT leave :
sl@0
    81
 * it should instead set iConfidence = ENotRecognized and return
sl@0
    82
 * the function should only leave if there is an out-of-memory condition
sl@0
    83
 */
sl@0
    84
void CApaMmfRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
sl@0
    85
	{
sl@0
    86
	// assume Match will fail :
sl@0
    87
	iConfidence = CApaDataRecognizerType::ENotRecognized;
sl@0
    88
sl@0
    89
	CMmfRecognizer::TMatchMethod matchMethod = iMmfRecognizer->MatchL(aName,aBuffer);
sl@0
    90
	
sl@0
    91
	// return whether the data was matched by setting iConfidence
sl@0
    92
	// if matched the MIME type is returned in iDataType
sl@0
    93
	if (matchMethod == CMmfRecognizer::ENotMatched)
sl@0
    94
		{	
sl@0
    95
		iConfidence = CApaDataRecognizerType::ENotRecognized;
sl@0
    96
		}
sl@0
    97
	else
sl@0
    98
		{
sl@0
    99
		iDataType = iMmfRecognizer->MimeString();
sl@0
   100
sl@0
   101
		//Match on data only
sl@0
   102
		if (matchMethod == CMmfRecognizer::EBySignature)
sl@0
   103
			iConfidence = CApaDataRecognizerType::EPossible;
sl@0
   104
		else
sl@0
   105
			{//Match on data and suffix
sl@0
   106
			ASSERT(matchMethod == CMmfRecognizer::EByName);
sl@0
   107
			iConfidence = CApaDataRecognizerType::EProbable;
sl@0
   108
			}
sl@0
   109
sl@0
   110
		}
sl@0
   111
	}
sl@0
   112
sl@0
   113
void CApaMmfRecognizer::ConstructL()
sl@0
   114
	{
sl@0
   115
	iMmfRecognizer = CMmfRecognizer::NewL();
sl@0
   116
    iCountDataTypes = iMmfRecognizer->NumMimeTypes();
sl@0
   117
	}
sl@0
   118
sl@0
   119
CApaMmfRecognizer* CApaMmfRecognizer::NewL()
sl@0
   120
	{
sl@0
   121
	CApaMmfRecognizer* self = new (ELeave) CApaMmfRecognizer();   
sl@0
   122
	CleanupStack::PushL(self);
sl@0
   123
	self->ConstructL();
sl@0
   124
	CleanupStack::Pop(self);
sl@0
   125
	return self;
sl@0
   126
	}
sl@0
   127
sl@0
   128
// CMmfRecognizer - the main utility class owner by CApaMmfRecognizer
sl@0
   129
sl@0
   130
CMmfRecognizer::CMmfRecognizer()
sl@0
   131
	{
sl@0
   132
	}
sl@0
   133
sl@0
   134
CMmfRecognizer::~CMmfRecognizer()
sl@0
   135
	{
sl@0
   136
	delete iMmfRecognizerUtil;
sl@0
   137
	delete iMimeTypes;
sl@0
   138
	}
sl@0
   139
sl@0
   140
void CMmfRecognizer::ConstructL()
sl@0
   141
	{
sl@0
   142
	iMimeTypes = new (ELeave) CDesC8ArrayFlat(KMimeArrayGranularity);
sl@0
   143
	BuildListL();
sl@0
   144
	iMmfRecognizerUtil = CMmfRecognizerUtil::NewL();
sl@0
   145
	}
sl@0
   146
sl@0
   147
CMmfRecognizer* CMmfRecognizer::NewL()
sl@0
   148
	{
sl@0
   149
	CMmfRecognizer* self = new (ELeave) CMmfRecognizer();   
sl@0
   150
	CleanupStack::PushL(self);
sl@0
   151
	self->ConstructL();
sl@0
   152
	CleanupStack::Pop(self);
sl@0
   153
	return self;
sl@0
   154
	}
sl@0
   155
sl@0
   156
/**
sl@0
   157
 * @internalAll
sl@0
   158
 *
sl@0
   159
 * Return the number of MIME types supported 
sl@0
   160
 */
sl@0
   161
TInt CMmfRecognizer::NumMimeTypes() const
sl@0
   162
	{
sl@0
   163
	return(iMimeTypes->Count());
sl@0
   164
	}
sl@0
   165
sl@0
   166
sl@0
   167
/**
sl@0
   168
 * @internalAll
sl@0
   169
 *
sl@0
   170
 * Call into the MMF Controller Framework DLL to get
sl@0
   171
 * a list of supported MIME types
sl@0
   172
 */
sl@0
   173
void CMmfRecognizer::BuildListL()
sl@0
   174
	{
sl@0
   175
	iMimeTypes->Reset();
sl@0
   176
	CMmfRecognizerUtil::GetMimeTypesL(iMimeTypes);
sl@0
   177
	}
sl@0
   178
sl@0
   179
sl@0
   180
/**
sl@0
   181
 * @internalAll
sl@0
   182
 *
sl@0
   183
 * Get one of the data (MIME) types that MMF can recognize.
sl@0
   184
 */
sl@0
   185
const TPtrC8 CMmfRecognizer::SupportedDataTypeL(TInt aIndex) const
sl@0
   186
	{
sl@0
   187
	if ((aIndex < 0) || (aIndex >= iMimeTypes->Count()))
sl@0
   188
		User::Leave(KErrArgument);
sl@0
   189
sl@0
   190
	return(iMimeTypes->MdcaPoint(aIndex));
sl@0
   191
	}
sl@0
   192
sl@0
   193
sl@0
   194
/**
sl@0
   195
 * @internalAll
sl@0
   196
 *
sl@0
   197
 * Get a reference to the last MIME type string successfully matched
sl@0
   198
 */
sl@0
   199
const TDesC8& CMmfRecognizer::MimeString() const
sl@0
   200
	{
sl@0
   201
	return iMimeString;
sl@0
   202
	}
sl@0
   203
sl@0
   204
/**
sl@0
   205
 * @internalAll
sl@0
   206
 *
sl@0
   207
 * Attempt to recognize the data
sl@0
   208
 */
sl@0
   209
CMmfRecognizer::TMatchMethod CMmfRecognizer::MatchL(const TDesC& aFileName, const TDesC8& aBuffer)
sl@0
   210
	{
sl@0
   211
	CMmfRecognizerUtil::TMatchLevel matchLevel = CMmfRecognizerUtil::EMatchNone;
sl@0
   212
	matchLevel = iMmfRecognizerUtil->GetMimeTypeL(aFileName, aBuffer, iMimeString);
sl@0
   213
	
sl@0
   214
	TMatchMethod bestMatchMethod = ENotMatched;
sl@0
   215
	if(matchLevel==CMmfRecognizerUtil::EMatchData)
sl@0
   216
		bestMatchMethod = EBySignature;
sl@0
   217
	else if(matchLevel==CMmfRecognizerUtil::EMatchName)
sl@0
   218
		bestMatchMethod = EByName;
sl@0
   219
sl@0
   220
	return bestMatchMethod;
sl@0
   221
	}
sl@0
   222
sl@0
   223
sl@0
   224
#include <ecom/ecom.h>
sl@0
   225
#include <ecom/implementationproxy.h>
sl@0
   226
sl@0
   227
const TImplementationProxy ImplementationTable[] = 
sl@0
   228
	{
sl@0
   229
	IMPLEMENTATION_PROXY_ENTRY(0x101F7C41, CApaMmfRecognizer::NewL)
sl@0
   230
	};
sl@0
   231
sl@0
   232
sl@0
   233
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0
   234
    {
sl@0
   235
    aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0
   236
    return ImplementationTable;
sl@0
   237
    }
sl@0
   238
sl@0
   239