sl@0: // Copyright (c) 2006-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: #ifndef MMRUF_H sl@0: #define MMRUF_H sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "constants.h" sl@0: sl@0: // sl@0: // This class is used to store the results of a match. sl@0: // iConfidence - the confidence of the match sl@0: // iMime - the matched mime-type. sl@0: // sl@0: class TMatch sl@0: { sl@0: public: sl@0: TMatch() sl@0: : iConfidence(CApaDataRecognizerType::ENotRecognized), sl@0: iMime(NULL) sl@0: { sl@0: } sl@0: sl@0: TMatch(TInt aConfidence, const TText8* aMime) sl@0: : iConfidence(aConfidence), sl@0: iMime(aMime) sl@0: { sl@0: } sl@0: sl@0: void Reset() sl@0: { sl@0: iConfidence = KConfNotRecognised; sl@0: iMime = NULL; sl@0: } sl@0: sl@0: TInt iConfidence; sl@0: const TText8* iMime; sl@0: }; sl@0: sl@0: sl@0: // sl@0: // Function prototype for custom format recogniser functions. sl@0: // Forward declaration of CReader required. sl@0: // sl@0: class CReader; sl@0: typedef void (*TCustomProc)(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch); sl@0: sl@0: sl@0: // sl@0: // These macros are used when creating the KSigs table. sl@0: // CUSTOM_SIG - this is to be used when a format cannot be identified sl@0: // from a known header pattern. It takes the MIME-type it sl@0: // tries to identify and a pointer to a function that sl@0: // does the identification. sl@0: // HEADER_SIG - this is to be used when a format can be identified sl@0: // from a known header pattern. sl@0: // sl@0: #define CUSTOM_SIG(mime, funcPtr) {NULL, (mime), (TAny*)(funcPtr), 0} sl@0: #define HEADER_SIG(mime, ext, header) {(ext), (mime), (TAny*)_S8(header), sizeof(header) - 1} sl@0: sl@0: sl@0: // sl@0: // This structure tells the recogniser how to match a format. sl@0: // iExt - the standard file extension for the format. sl@0: // iMime - the defined MIME-type for the format. sl@0: // iHeaderOrProc - a pointer to either a header signature pattern sl@0: // (if iHeaderLen = 0) or a function that carries sl@0: // out in-depth parsing of the file (if iHeaderLen > 0) sl@0: // iHeaderLen - the length of the header signature in characters, or zero sl@0: // if iHeaderOrProc is a pointer to a function. sl@0: // sl@0: typedef struct sl@0: { sl@0: const TText* iExt; sl@0: const TText8* iMime; sl@0: TAny* iHeaderOrProc; sl@0: TInt iHeaderLen; sl@0: } sl@0: TSignature; sl@0: sl@0: sl@0: // UIDs taken from Multimedia Allocation Table. sl@0: static const TInt KRecogniserUID = 0x1027381A; sl@0: static const TUid KMMRUFDLLUid = {0x102825F6}; sl@0: sl@0: // The amount of file data wanted from the AppArc framework. sl@0: static const TInt KPreferredBufSize = 256; sl@0: sl@0: // The recogniser priority. sl@0: static const TInt KRecogniserPriority = CApaDataRecognizerType::ENormal; sl@0: sl@0: sl@0: // sl@0: // This class does the recognising. sl@0: // sl@0: class CMMRUF : public CApaDataRecognizerType sl@0: { sl@0: public: sl@0: static CMMRUF* NewL(); sl@0: virtual ~CMMRUF(); sl@0: TDataType SupportedDataTypeL(TInt aIndex) const; sl@0: TDataType SupportedDataTypeL(const TText8* aMime) const; sl@0: TUint PreferredBufSize(); sl@0: sl@0: protected: sl@0: void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer); sl@0: void SetDataTypeL(TInt aConfidence, const TText8* aMime); sl@0: TUint8 MatchExtension(const TDesC& aFileName, const TText* aExt) const; sl@0: TUint8 MatchHeader(const TDesC8& aBuffer, const TDesC8& aHeader) const; sl@0: sl@0: private: sl@0: CMMRUF(); sl@0: }; sl@0: sl@0: sl@0: #endif