First public contribution.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include "mmfcontrollerpluginresolver.h"
21 const TInt KMimeMmfRecognizerValue = 0x101F7C0C;
22 const TUid KUidMimeMmfRecognizer = {KMimeMmfRecognizerValue};
23 const TInt KMmfRecognizerPriority = 10; // The recognizer priority is set to 10(a value between ENormal and EHigh)
26 // the minimum buffer size that will theoretically guarantee recognition
27 const TInt KPreferredBufSize = 256;
29 // the granularity of the internal MIME type array
30 const TInt KMimeArrayGranularity = 4;
37 * Call base constructor with the recognizer's UID and confidence level
38 * The MMF recognizer priority is set to 10(a value between ENormal and EHigh) to allow
39 * third-party recognizers to specify high priority.
41 CApaMmfRecognizer::CApaMmfRecognizer()
42 :CApaDataRecognizerType(KUidMimeMmfRecognizer,KMmfRecognizerPriority)
46 CApaMmfRecognizer::~CApaMmfRecognizer()
48 delete iMmfRecognizer;
54 * Return the supposed minimum buffer size we need to
55 * successfully recognize the data
57 TUint CApaMmfRecognizer::PreferredBufSize()
59 return KPreferredBufSize;
65 * Gets one of the data (MIME) types that the recognizer can recognize.
67 TDataType CApaMmfRecognizer::SupportedDataTypeL(TInt aIndex) const
69 return (iMmfRecognizer->SupportedDataTypeL(aIndex));
76 * Attempt to recognize the data.
77 * This recognizer only attempts to match the data header on its own,
78 * or the data header plus the file suffix together.
80 * NB if the file is not recognized, this function should NOT leave :
81 * it should instead set iConfidence = ENotRecognized and return
82 * the function should only leave if there is an out-of-memory condition
84 void CApaMmfRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
86 // assume Match will fail :
87 iConfidence = CApaDataRecognizerType::ENotRecognized;
89 CMmfRecognizer::TMatchMethod matchMethod = iMmfRecognizer->MatchL(aName,aBuffer);
91 // return whether the data was matched by setting iConfidence
92 // if matched the MIME type is returned in iDataType
93 if (matchMethod == CMmfRecognizer::ENotMatched)
95 iConfidence = CApaDataRecognizerType::ENotRecognized;
99 iDataType = iMmfRecognizer->MimeString();
102 if (matchMethod == CMmfRecognizer::EBySignature)
103 iConfidence = CApaDataRecognizerType::EPossible;
105 {//Match on data and suffix
106 ASSERT(matchMethod == CMmfRecognizer::EByName);
107 iConfidence = CApaDataRecognizerType::EProbable;
113 void CApaMmfRecognizer::ConstructL()
115 iMmfRecognizer = CMmfRecognizer::NewL();
116 iCountDataTypes = iMmfRecognizer->NumMimeTypes();
119 CApaMmfRecognizer* CApaMmfRecognizer::NewL()
121 CApaMmfRecognizer* self = new (ELeave) CApaMmfRecognizer();
122 CleanupStack::PushL(self);
124 CleanupStack::Pop(self);
128 // CMmfRecognizer - the main utility class owner by CApaMmfRecognizer
130 CMmfRecognizer::CMmfRecognizer()
134 CMmfRecognizer::~CMmfRecognizer()
136 delete iMmfRecognizerUtil;
140 void CMmfRecognizer::ConstructL()
142 iMimeTypes = new (ELeave) CDesC8ArrayFlat(KMimeArrayGranularity);
144 iMmfRecognizerUtil = CMmfRecognizerUtil::NewL();
147 CMmfRecognizer* CMmfRecognizer::NewL()
149 CMmfRecognizer* self = new (ELeave) CMmfRecognizer();
150 CleanupStack::PushL(self);
152 CleanupStack::Pop(self);
159 * Return the number of MIME types supported
161 TInt CMmfRecognizer::NumMimeTypes() const
163 return(iMimeTypes->Count());
170 * Call into the MMF Controller Framework DLL to get
171 * a list of supported MIME types
173 void CMmfRecognizer::BuildListL()
176 CMmfRecognizerUtil::GetMimeTypesL(iMimeTypes);
183 * Get one of the data (MIME) types that MMF can recognize.
185 const TPtrC8 CMmfRecognizer::SupportedDataTypeL(TInt aIndex) const
187 if ((aIndex < 0) || (aIndex >= iMimeTypes->Count()))
188 User::Leave(KErrArgument);
190 return(iMimeTypes->MdcaPoint(aIndex));
197 * Get a reference to the last MIME type string successfully matched
199 const TDesC8& CMmfRecognizer::MimeString() const
207 * Attempt to recognize the data
209 CMmfRecognizer::TMatchMethod CMmfRecognizer::MatchL(const TDesC& aFileName, const TDesC8& aBuffer)
211 CMmfRecognizerUtil::TMatchLevel matchLevel = CMmfRecognizerUtil::EMatchNone;
212 matchLevel = iMmfRecognizerUtil->GetMimeTypeL(aFileName, aBuffer, iMimeString);
214 TMatchMethod bestMatchMethod = ENotMatched;
215 if(matchLevel==CMmfRecognizerUtil::EMatchData)
216 bestMatchMethod = EBySignature;
217 else if(matchLevel==CMmfRecognizerUtil::EMatchName)
218 bestMatchMethod = EByName;
220 return bestMatchMethod;
224 #include <ecom/ecom.h>
225 #include <ecom/implementationproxy.h>
227 const TImplementationProxy ImplementationTable[] =
229 IMPLEMENTATION_PROXY_ENTRY(0x101F7C41, CApaMmfRecognizer::NewL)
233 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
235 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
236 return ImplementationTable;