williamr@2
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@2
|
4 |
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@2
|
6 |
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
//
|
williamr@2
|
15 |
|
williamr@2
|
16 |
#if !defined(__APMREC_H__)
|
williamr@2
|
17 |
#define __APMREC_H__
|
williamr@2
|
18 |
|
williamr@2
|
19 |
#if !defined(__E32BASE_H__)
|
williamr@2
|
20 |
#include <e32base.h>
|
williamr@2
|
21 |
#endif
|
williamr@2
|
22 |
|
williamr@2
|
23 |
#if !defined(__APMSTD_H__)
|
williamr@2
|
24 |
#include <apmstd.h>
|
williamr@2
|
25 |
#endif
|
williamr@2
|
26 |
|
williamr@2
|
27 |
// classes defined
|
williamr@2
|
28 |
class CApaDataRecognizerType;
|
williamr@2
|
29 |
// classes referenced
|
williamr@2
|
30 |
class RFs;
|
williamr@2
|
31 |
class RFile;
|
williamr@2
|
32 |
class TDataToRecognize;
|
williamr@2
|
33 |
class CDataRecognizerExtension;
|
williamr@2
|
34 |
|
williamr@2
|
35 |
/** Creates an interface object for a abstract base class for a recognizer.
|
williamr@2
|
36 |
|
williamr@2
|
37 |
@publishedAll
|
williamr@2
|
38 |
@released
|
williamr@2
|
39 |
*/
|
williamr@2
|
40 |
typedef CApaDataRecognizerType* (*CreateCApaDataRecognizerType)();
|
williamr@2
|
41 |
|
williamr@2
|
42 |
class TDataRecognitionResult
|
williamr@2
|
43 |
/** The result of an attempt to recognize data.
|
williamr@2
|
44 |
|
williamr@2
|
45 |
The class contains a data (MIME) type and a confidence rating.
|
williamr@2
|
46 |
|
williamr@2
|
47 |
An object of this type is passed to the Application Architecture server when
|
williamr@2
|
48 |
making a request to recognize data.
|
williamr@2
|
49 |
|
williamr@2
|
50 |
@publishedAll
|
williamr@2
|
51 |
@released
|
williamr@2
|
52 |
@see RApaLsSession::RecognizeData() */
|
williamr@2
|
53 |
{
|
williamr@2
|
54 |
public:
|
williamr@2
|
55 |
IMPORT_C void Reset();
|
williamr@2
|
56 |
public:
|
williamr@2
|
57 |
/** The data type. */
|
williamr@2
|
58 |
TDataType iDataType;
|
williamr@2
|
59 |
/** The confidence rating associated with the data (EMIME) type. */
|
williamr@2
|
60 |
TInt iConfidence;
|
williamr@2
|
61 |
};
|
williamr@2
|
62 |
|
williamr@2
|
63 |
/**
|
williamr@2
|
64 |
@internalComponent
|
williamr@2
|
65 |
*/
|
williamr@2
|
66 |
const TInt KDataArrayGranularity=5;
|
williamr@2
|
67 |
|
williamr@2
|
68 |
/**
|
williamr@2
|
69 |
@publishedAll
|
williamr@2
|
70 |
@released
|
williamr@2
|
71 |
*/
|
williamr@2
|
72 |
typedef CArrayFixFlat<TDataType> CDataTypeArray;
|
williamr@2
|
73 |
|
williamr@2
|
74 |
class CApaDataRecognizer : public CBase
|
williamr@2
|
75 |
/**
|
williamr@2
|
76 |
@internalTechnology
|
williamr@2
|
77 |
*/
|
williamr@2
|
78 |
{
|
williamr@2
|
79 |
public:
|
williamr@2
|
80 |
IMPORT_C TDataRecognitionResult RecognizeL(const TDesC& aName, const TDesC8& aBuffer);
|
williamr@2
|
81 |
IMPORT_C TDataRecognitionResult RecognizeL(RFile& aFile, TInt aPreferredBufSize);
|
williamr@2
|
82 |
IMPORT_C TBool RecognizeL(const TDesC& aName, const TDesC8& aBuffer, const TDataType& aDataType);
|
williamr@2
|
83 |
IMPORT_C TBool RecognizeL(RFile& aFile, TInt aPreferredBufSize, const TDataType& aDataType);
|
williamr@2
|
84 |
IMPORT_C ~CApaDataRecognizer();
|
williamr@2
|
85 |
IMPORT_C TInt PreferredBufSize() const;
|
williamr@2
|
86 |
IMPORT_C void DataTypeL(CDataTypeArray& aArray);
|
williamr@2
|
87 |
IMPORT_C void UpdateDataTypesL();
|
williamr@2
|
88 |
IMPORT_C TInt AcceptedConfidence() const;
|
williamr@2
|
89 |
IMPORT_C void SetAcceptedConfidence(TInt aConfidence);
|
williamr@2
|
90 |
inline void SetFilePassedByHandle(RFile* aFilePassedByHandle) {iFilePassedByHandle=aFilePassedByHandle;}
|
williamr@2
|
91 |
inline RFile* FilePassedByHandle() {return iFilePassedByHandle;}
|
williamr@2
|
92 |
protected:
|
williamr@2
|
93 |
IMPORT_C CApaDataRecognizer(RFs& aFs);
|
williamr@2
|
94 |
IMPORT_C void AddDataRecognizerTypeL(CApaDataRecognizerType* aDataRecognizerType);
|
williamr@2
|
95 |
inline void AddDataRecognizerType(CApaDataRecognizerType* aDataRecognizerType);
|
williamr@2
|
96 |
IMPORT_C TInt RemoveDataRecognizerType(const CApaDataRecognizerType* aDataRecognizerType);
|
williamr@2
|
97 |
IMPORT_C void DestroyRecognizerList();
|
williamr@2
|
98 |
private:
|
williamr@2
|
99 |
void AddDataTypeL(const TDataType& aDataType);
|
williamr@2
|
100 |
TDataRecognitionResult RecognizeL(TDataToRecognize& aDataToRecognize);
|
williamr@2
|
101 |
TBool RecognizeL(TDataToRecognize& aDataToRecognize, const TDataType& aDataType);
|
williamr@2
|
102 |
TBool DoRecognize(CApaDataRecognizerType* aDataRecognizerType, TDataToRecognize& aDataToRecognize, const TDataType& aDataType, TInt& aError);
|
williamr@2
|
103 |
protected:
|
williamr@2
|
104 |
RFs& iFs;
|
williamr@2
|
105 |
// iMaxBufferSize is mutable to allow modification by PreferredBufSize() which is const.
|
williamr@2
|
106 |
mutable TInt iMaxBufferSize;
|
williamr@2
|
107 |
private:
|
williamr@2
|
108 |
IMPORT_C virtual void CApaDataRecognizer_Reserved_1(); // shouldn't be necessary as the class is @internalTechnology
|
williamr@2
|
109 |
private:
|
williamr@2
|
110 |
RPointerArray<CApaDataRecognizerType> iDataRecognizerList;
|
williamr@2
|
111 |
RArray<TDataType> iDataArray;
|
williamr@2
|
112 |
TInt iAcceptedConfidence;
|
williamr@2
|
113 |
TDataRecognitionResult iResult;
|
williamr@2
|
114 |
RFile* iFilePassedByHandle;
|
williamr@2
|
115 |
};
|
williamr@2
|
116 |
|
williamr@2
|
117 |
class CApaDataRecognizerType : public CBase
|
williamr@2
|
118 |
/** Abstract base class for a recognizer.
|
williamr@2
|
119 |
|
williamr@2
|
120 |
Concrete recognizers need to define and implement a derived class; specifically,
|
williamr@2
|
121 |
they need to provide an implementation of the DoRecognizeL(), SupportedDataTypeL()
|
williamr@2
|
122 |
and PreferredBufSize() functions.
|
williamr@2
|
123 |
|
williamr@2
|
124 |
The class is implemented as part of a DLL. The ordinal 1 function of the DLL
|
williamr@2
|
125 |
must construct an instance of, and return a pointer to, a CApaDataRecognizerType
|
williamr@2
|
126 |
derived class.
|
williamr@2
|
127 |
|
williamr@2
|
128 |
@publishedAll
|
williamr@2
|
129 |
@released */
|
williamr@2
|
130 |
{
|
williamr@2
|
131 |
friend class TDataToRecognize; // so that it can call the overloads of DoRecognizeL
|
williamr@2
|
132 |
public:
|
williamr@2
|
133 |
/** A set of values used to indicate the probability that the recognizer will successfully
|
williamr@2
|
134 |
identify data. The Application Architecture framework uses this set to determine
|
williamr@2
|
135 |
the order in which recognizers are invoked.
|
williamr@2
|
136 |
|
williamr@2
|
137 |
@see CApaDataRecognizerType()
|
williamr@2
|
138 |
@see Priority() */
|
williamr@2
|
139 |
enum TRecognizerPriority
|
williamr@2
|
140 |
{
|
williamr@2
|
141 |
/** The highest recognizer priority. Recognizers with this priority are invoked
|
williamr@2
|
142 |
before those with any other priority. */
|
williamr@2
|
143 |
EHigh=100,
|
williamr@2
|
144 |
/** The normal recognizer priority. Recognizers with this priority are invoked
|
williamr@2
|
145 |
after those with a EHigh priority but before those with a ELow priority. */
|
williamr@2
|
146 |
ENormal=0,
|
williamr@2
|
147 |
/** The lowest recognizer priority. */
|
williamr@2
|
148 |
ELow=-100
|
williamr@2
|
149 |
};
|
williamr@2
|
150 |
/** A set of values describing the probability that the recognizer assigns to its
|
williamr@2
|
151 |
belief that the most recently sampled data is of the type ascribed to it. */
|
williamr@2
|
152 |
enum TRecognitionConfidence
|
williamr@2
|
153 |
{
|
williamr@2
|
154 |
/** The data is definitely of the data type. */
|
williamr@2
|
155 |
ECertain=KMaxTInt,
|
williamr@2
|
156 |
/** A level of confidence between ECertain and EPossible. */
|
williamr@2
|
157 |
EProbable=100,
|
williamr@2
|
158 |
/** The data is possibly of the data type. */
|
williamr@2
|
159 |
EPossible=0,
|
williamr@2
|
160 |
/** A level of confidence between EPossible and ENotRecognized. */
|
williamr@2
|
161 |
EUnlikely=-100,
|
williamr@2
|
162 |
/** The data is not recognized. */
|
williamr@2
|
163 |
ENotRecognized=KMinTInt
|
williamr@2
|
164 |
};
|
williamr@2
|
165 |
public:
|
williamr@2
|
166 |
inline TInt MimeTypesCount() const;
|
williamr@2
|
167 |
inline TUid TypeUid() const;
|
williamr@2
|
168 |
inline TInt Priority() const;
|
williamr@2
|
169 |
inline TInt Confidence() const;
|
williamr@2
|
170 |
inline TInt Locked() const;
|
williamr@2
|
171 |
IMPORT_C TDataRecognitionResult RecognizeL(const TDesC& aName, const TDesC8& aBuffer);
|
williamr@2
|
172 |
TDataRecognitionResult RecognizeL(TDataToRecognize& aDataToRecognize);
|
williamr@2
|
173 |
IMPORT_C TDataType MimeType();
|
williamr@2
|
174 |
IMPORT_C void Lock();
|
williamr@2
|
175 |
IMPORT_C void Unlock();
|
williamr@2
|
176 |
IMPORT_C void UpdateDataTypesL();
|
williamr@2
|
177 |
IMPORT_C ~CApaDataRecognizerType();
|
williamr@2
|
178 |
IMPORT_C virtual TUint PreferredBufSize();
|
williamr@2
|
179 |
/** Gets one of the data (MIME) types that the recognizer can recognize.
|
williamr@2
|
180 |
|
williamr@2
|
181 |
@param aIndex An index that identifies the data type. Typically, the minimum
|
williamr@2
|
182 |
value is zero and the maximum value is the value of MimeTypesCount() - 1.
|
williamr@2
|
183 |
@return The data (MIME) type. */
|
williamr@2
|
184 |
IMPORT_C virtual TDataType SupportedDataTypeL(TInt aIndex) const = 0;
|
williamr@2
|
185 |
protected:
|
williamr@2
|
186 |
IMPORT_C CApaDataRecognizerType(TUid aUid, TInt aPriority);
|
williamr@2
|
187 |
IMPORT_C RFile* FilePassedByHandleL();
|
williamr@2
|
188 |
private:
|
williamr@2
|
189 |
IMPORT_C virtual void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
|
williamr@2
|
190 |
// Reserved virtual functions...
|
williamr@2
|
191 |
IMPORT_C virtual void Reserved_1();
|
williamr@2
|
192 |
public:
|
williamr@2
|
193 |
IMPORT_C static CApaDataRecognizerType* CreateDataRecognizerL(TUid aImplUid);
|
williamr@2
|
194 |
CDataRecognizerExtension* DataRecognizerExtension();
|
williamr@2
|
195 |
protected:
|
williamr@2
|
196 |
const TUid iTypeUid;
|
williamr@2
|
197 |
const TInt iPriority;
|
williamr@2
|
198 |
/** The number of data (MIME) types supported by this recognizer. Typically, this
|
williamr@2
|
199 |
is set during construction of an instance of the derived class.
|
williamr@2
|
200 |
|
williamr@2
|
201 |
Users of the derived class use MimeTypesCount() to get this value. */
|
williamr@2
|
202 |
TInt iCountDataTypes;
|
williamr@2
|
203 |
/** The recognizer's confidence rating of the most recently recognized data.
|
williamr@2
|
204 |
|
williamr@2
|
205 |
Users of the derived class use Confidence() to get this value. */
|
williamr@2
|
206 |
TInt iConfidence;
|
williamr@2
|
207 |
/** The data (MIME) type of the most recently recognized data.
|
williamr@2
|
208 |
|
williamr@2
|
209 |
Users of the derived class use MimeType() to get this value. */
|
williamr@2
|
210 |
TDataType iDataType;
|
williamr@2
|
211 |
private:
|
williamr@2
|
212 |
TInt iLock;
|
williamr@2
|
213 |
CDataRecognizerExtension* iDataRecognizerExtn;
|
williamr@2
|
214 |
};
|
williamr@2
|
215 |
|
williamr@2
|
216 |
#include <apmrec.inl>
|
williamr@2
|
217 |
|
williamr@2
|
218 |
#endif
|