1 // Copyright (c) 1997-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.
16 #if !defined(__APMREC_H__)
19 #if !defined(__E32BASE_H__)
23 #if !defined(__APMSTD_H__)
28 class CApaDataRecognizerType;
32 class TDataToRecognize;
33 class CDataRecognizerExtension;
35 /** Creates an interface object for a abstract base class for a recognizer.
40 typedef CApaDataRecognizerType* (*CreateCApaDataRecognizerType)();
42 class TDataRecognitionResult
43 /** The result of an attempt to recognize data.
45 The class contains a data (MIME) type and a confidence rating.
47 An object of this type is passed to the Application Architecture server when
48 making a request to recognize data.
52 @see RApaLsSession::RecognizeData() */
55 IMPORT_C void Reset();
59 /** The confidence rating associated with the data (EMIME) type. */
62 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
66 const TInt KDataArrayGranularity=5;
68 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
73 typedef CArrayFixFlat<TDataType> CDataTypeArray;
75 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
77 class CApaDataRecognizer : public CBase
83 IMPORT_C TDataRecognitionResult RecognizeL(const TDesC& aName, const TDesC8& aBuffer);
84 IMPORT_C TDataRecognitionResult RecognizeL(RFile& aFile, TInt aPreferredBufSize);
85 IMPORT_C TBool RecognizeL(const TDesC& aName, const TDesC8& aBuffer, const TDataType& aDataType);
86 IMPORT_C TBool RecognizeL(RFile& aFile, TInt aPreferredBufSize, const TDataType& aDataType);
87 IMPORT_C ~CApaDataRecognizer();
88 IMPORT_C TInt PreferredBufSize() const;
89 IMPORT_C void DataTypeL(CDataTypeArray& aArray);
90 IMPORT_C void UpdateDataTypesL();
91 IMPORT_C TInt AcceptedConfidence() const;
92 IMPORT_C void SetAcceptedConfidence(TInt aConfidence);
93 inline void SetFilePassedByHandle(RFile* aFilePassedByHandle) {iFilePassedByHandle=aFilePassedByHandle;}
94 inline RFile* FilePassedByHandle() {return iFilePassedByHandle;}
96 IMPORT_C CApaDataRecognizer(RFs& aFs);
97 IMPORT_C void AddDataRecognizerTypeL(CApaDataRecognizerType* aDataRecognizerType);
98 inline void AddDataRecognizerType(CApaDataRecognizerType* aDataRecognizerType);
99 IMPORT_C TInt RemoveDataRecognizerType(const CApaDataRecognizerType* aDataRecognizerType);
100 IMPORT_C void DestroyRecognizerList();
102 void AddDataTypeL(const TDataType& aDataType);
103 TDataRecognitionResult RecognizeL(TDataToRecognize& aDataToRecognize);
104 TBool RecognizeL(TDataToRecognize& aDataToRecognize, const TDataType& aDataType);
105 TBool DoRecognize(CApaDataRecognizerType* aDataRecognizerType, TDataToRecognize& aDataToRecognize, const TDataType& aDataType, TInt& aError);
108 // iMaxBufferSize is mutable to allow modification by PreferredBufSize() which is const.
109 mutable TInt iMaxBufferSize;
111 IMPORT_C virtual void CApaDataRecognizer_Reserved_1(); // shouldn't be necessary as the class is @internalTechnology
113 RPointerArray<CApaDataRecognizerType> iDataRecognizerList;
114 RArray<TDataType> iDataArray;
115 TInt iAcceptedConfidence;
116 TDataRecognitionResult iResult;
117 RFile* iFilePassedByHandle;
119 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
121 class CApaDataRecognizerType : public CBase
122 /** Abstract base class for a recognizer.
124 Concrete recognizers need to define and implement a derived class; specifically,
125 they need to provide an implementation of the DoRecognizeL(), SupportedDataTypeL()
126 and PreferredBufSize() functions.
128 The class is implemented as part of a DLL. The ordinal 1 function of the DLL
129 must construct an instance of, and return a pointer to, a CApaDataRecognizerType
135 friend class TDataToRecognize; // so that it can call the overloads of DoRecognizeL
137 /** A set of values used to indicate the probability that the recognizer will successfully
138 identify data. The Application Architecture framework uses this set to determine
139 the order in which recognizers are invoked.
141 @see CApaDataRecognizerType()
143 enum TRecognizerPriority
145 /** The highest recognizer priority. Recognizers with this priority are invoked
146 before those with any other priority. */
148 /** The normal recognizer priority. Recognizers with this priority are invoked
149 after those with a EHigh priority but before those with a ELow priority. */
151 /** The lowest recognizer priority. */
154 /** A set of values describing the probability that the recognizer assigns to its
155 belief that the most recently sampled data is of the type ascribed to it. */
156 enum TRecognitionConfidence
158 /** The data is definitely of the data type. */
160 /** A level of confidence between ECertain and EPossible. */
162 /** The data is possibly of the data type. */
164 /** A level of confidence between EPossible and ENotRecognized. */
166 /** The data is not recognized. */
167 ENotRecognized=KMinTInt
170 inline TInt MimeTypesCount() const;
171 inline TUid TypeUid() const;
172 inline TInt Priority() const;
173 inline TInt Confidence() const;
174 inline TInt Locked() const;
175 IMPORT_C TDataRecognitionResult RecognizeL(const TDesC& aName, const TDesC8& aBuffer);
176 TDataRecognitionResult RecognizeL(TDataToRecognize& aDataToRecognize);
177 IMPORT_C TDataType MimeType();
178 IMPORT_C void Lock();
179 IMPORT_C void Unlock();
180 IMPORT_C void UpdateDataTypesL();
181 IMPORT_C ~CApaDataRecognizerType();
182 IMPORT_C virtual TUint PreferredBufSize();
183 /** Gets one of the data (MIME) types that the recognizer can recognize.
185 @param aIndex An index that identifies the data type. Typically, the minimum
186 value is zero and the maximum value is the value of MimeTypesCount() - 1.
187 @return The data (MIME) type. */
188 IMPORT_C virtual TDataType SupportedDataTypeL(TInt aIndex) const = 0;
190 IMPORT_C CApaDataRecognizerType(TUid aUid, TInt aPriority);
191 IMPORT_C RFile* FilePassedByHandleL();
193 IMPORT_C virtual void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
194 // Reserved virtual functions...
195 IMPORT_C virtual void Reserved_1();
197 IMPORT_C static CApaDataRecognizerType* CreateDataRecognizerL(TUid aImplUid);
198 CDataRecognizerExtension* DataRecognizerExtension();
201 const TInt iPriority;
202 /** The number of data (MIME) types supported by this recognizer. Typically, this
203 is set during construction of an instance of the derived class.
205 Users of the derived class use MimeTypesCount() to get this value. */
206 TInt iCountDataTypes;
207 /** The recognizer's confidence rating of the most recently recognized data.
209 Users of the derived class use Confidence() to get this value. */
211 /** The data (MIME) type of the most recently recognized data.
213 Users of the derived class use MimeType() to get this value. */
217 CDataRecognizerExtension* iDataRecognizerExtn;
220 #include <apmrec.inl>