os/mm/mmlibs/mmfw/Recogniser/src/mmruf.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef MMRUF_H
    17 #define MMRUF_H
    18 
    19 #include <e32cons.h>
    20 #include <apmrec.h>
    21 #include <ecom/ecom.h>
    22 #include <ecom/implementationproxy.h>
    23 #include "constants.h"
    24 
    25 //
    26 // This class is used to store the results of a match.
    27 // iConfidence - the confidence of the match
    28 // iMime - the matched mime-type.
    29 //
    30 class TMatch
    31 	{
    32 public:
    33 	TMatch()
    34 	  : iConfidence(CApaDataRecognizerType::ENotRecognized),
    35 	 	iMime(NULL)
    36 		{
    37 		}
    38 		
    39 	TMatch(TInt aConfidence, const TText8* aMime)
    40 	  : iConfidence(aConfidence),
    41 	    iMime(aMime)
    42 		{
    43 		}
    44 	
    45 	void Reset()
    46 		{
    47 		iConfidence = KConfNotRecognised;
    48 		iMime = NULL;
    49 		}
    50 		
    51 	TInt iConfidence;
    52 	const TText8* iMime;
    53 	};
    54 
    55 
    56 // 
    57 // Function prototype for custom format recogniser functions.
    58 // Forward declaration of CReader required.
    59 //
    60 class CReader;
    61 typedef void (*TCustomProc)(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
    62 
    63 
    64 //
    65 // These macros are used when creating the KSigs table.
    66 // CUSTOM_SIG - this is to be used when a format cannot be identified
    67 //              from a known header pattern. It takes the MIME-type it
    68 //              tries to identify and a pointer to a function that
    69 //              does the identification.
    70 // HEADER_SIG - this is to be used when a format can be identified
    71 //              from a known header pattern.
    72 //
    73 #define CUSTOM_SIG(mime, funcPtr)		{NULL, (mime), (TAny*)(funcPtr), 0}
    74 #define HEADER_SIG(mime, ext, header) 	{(ext), (mime), (TAny*)_S8(header), sizeof(header) - 1}
    75 
    76 
    77 //
    78 // This structure tells the recogniser how to match a format.
    79 // iExt - the standard file extension for the format.
    80 // iMime - the defined MIME-type for the format.
    81 // iHeaderOrProc - a pointer to either a header signature pattern
    82 //                 (if iHeaderLen = 0) or a function that carries
    83 //                 out in-depth parsing of the file (if iHeaderLen > 0)
    84 // iHeaderLen - the length of the header signature in characters, or zero
    85 //              if iHeaderOrProc is a pointer to a function.
    86 //
    87 typedef struct
    88 	{
    89 	const TText* iExt;
    90 	const TText8* iMime;
    91 	TAny* iHeaderOrProc;
    92 	TInt iHeaderLen;
    93 	}
    94 TSignature;
    95 
    96 
    97 // UIDs taken from Multimedia Allocation Table.
    98 static const TInt KRecogniserUID = 0x1027381A;
    99 static const TUid KMMRUFDLLUid = {0x102825F6};
   100 
   101 // The amount of file data wanted from the AppArc framework.
   102 static const TInt KPreferredBufSize = 256;
   103 
   104 // The recogniser priority.
   105 static const TInt KRecogniserPriority = CApaDataRecognizerType::ENormal;
   106 
   107 
   108 //
   109 // This class does the recognising.
   110 //
   111 class CMMRUF : public CApaDataRecognizerType
   112   	{
   113 public:
   114 	static CMMRUF* NewL();
   115 	virtual ~CMMRUF();
   116 	TDataType SupportedDataTypeL(TInt aIndex) const;
   117 	TDataType SupportedDataTypeL(const TText8* aMime) const;
   118 	TUint PreferredBufSize();
   119 
   120 protected:
   121 	void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
   122 	void SetDataTypeL(TInt aConfidence, const TText8* aMime);
   123 	TUint8 MatchExtension(const TDesC& aFileName, const TText* aExt) const;
   124 	TUint8 MatchHeader(const TDesC8& aBuffer, const TDesC8& aHeader) const;
   125 	
   126 private:
   127 	CMMRUF();
   128 	};
   129 
   130 	
   131 #endif