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