|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #if !defined(__APMREC_H__) |
|
17 #define __APMREC_H__ |
|
18 |
|
19 #if !defined(__E32BASE_H__) |
|
20 #include <e32base.h> |
|
21 #endif |
|
22 |
|
23 #if !defined(__APMSTD_H__) |
|
24 #include <apmstd.h> |
|
25 #endif |
|
26 |
|
27 // classes defined |
|
28 class CApaDataRecognizerType; |
|
29 // classes referenced |
|
30 class RFs; |
|
31 class RFile; |
|
32 class TDataToRecognize; |
|
33 class CDataRecognizerExtension; |
|
34 |
|
35 /** Creates an interface object for a abstract base class for a recognizer. |
|
36 |
|
37 @publishedAll |
|
38 @released |
|
39 */ |
|
40 typedef CApaDataRecognizerType* (*CreateCApaDataRecognizerType)(); |
|
41 |
|
42 class TDataRecognitionResult |
|
43 /** The result of an attempt to recognize data. |
|
44 |
|
45 The class contains a data (MIME) type and a confidence rating. |
|
46 |
|
47 An object of this type is passed to the Application Architecture server when |
|
48 making a request to recognize data. |
|
49 |
|
50 @publishedAll |
|
51 @released |
|
52 @see RApaLsSession::RecognizeData() */ |
|
53 { |
|
54 public: |
|
55 IMPORT_C void Reset(); |
|
56 public: |
|
57 /** The data type. */ |
|
58 TDataType iDataType; |
|
59 /** The confidence rating associated with the data (EMIME) type. */ |
|
60 TInt iConfidence; |
|
61 }; |
|
62 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
63 /** |
|
64 @internalComponent |
|
65 */ |
|
66 const TInt KDataArrayGranularity=5; |
|
67 |
|
68 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
69 /** |
|
70 @publishedAll |
|
71 @released |
|
72 */ |
|
73 typedef CArrayFixFlat<TDataType> CDataTypeArray; |
|
74 |
|
75 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
76 |
|
77 class CApaDataRecognizer : public CBase |
|
78 /** |
|
79 @internalTechnology |
|
80 */ |
|
81 { |
|
82 public: |
|
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;} |
|
95 protected: |
|
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(); |
|
101 private: |
|
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); |
|
106 protected: |
|
107 RFs& iFs; |
|
108 // iMaxBufferSize is mutable to allow modification by PreferredBufSize() which is const. |
|
109 mutable TInt iMaxBufferSize; |
|
110 private: |
|
111 IMPORT_C virtual void CApaDataRecognizer_Reserved_1(); // shouldn't be necessary as the class is @internalTechnology |
|
112 private: |
|
113 RPointerArray<CApaDataRecognizerType> iDataRecognizerList; |
|
114 RArray<TDataType> iDataArray; |
|
115 TInt iAcceptedConfidence; |
|
116 TDataRecognitionResult iResult; |
|
117 RFile* iFilePassedByHandle; |
|
118 }; |
|
119 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
120 |
|
121 class CApaDataRecognizerType : public CBase |
|
122 /** Abstract base class for a recognizer. |
|
123 |
|
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. |
|
127 |
|
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 |
|
130 derived class. |
|
131 |
|
132 @publishedAll |
|
133 @released */ |
|
134 { |
|
135 friend class TDataToRecognize; // so that it can call the overloads of DoRecognizeL |
|
136 public: |
|
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. |
|
140 |
|
141 @see CApaDataRecognizerType() |
|
142 @see Priority() */ |
|
143 enum TRecognizerPriority |
|
144 { |
|
145 /** The highest recognizer priority. Recognizers with this priority are invoked |
|
146 before those with any other priority. */ |
|
147 EHigh=100, |
|
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. */ |
|
150 ENormal=0, |
|
151 /** The lowest recognizer priority. */ |
|
152 ELow=-100 |
|
153 }; |
|
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 |
|
157 { |
|
158 /** The data is definitely of the data type. */ |
|
159 ECertain=KMaxTInt, |
|
160 /** A level of confidence between ECertain and EPossible. */ |
|
161 EProbable=100, |
|
162 /** The data is possibly of the data type. */ |
|
163 EPossible=0, |
|
164 /** A level of confidence between EPossible and ENotRecognized. */ |
|
165 EUnlikely=-100, |
|
166 /** The data is not recognized. */ |
|
167 ENotRecognized=KMinTInt |
|
168 }; |
|
169 public: |
|
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. |
|
184 |
|
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; |
|
189 protected: |
|
190 IMPORT_C CApaDataRecognizerType(TUid aUid, TInt aPriority); |
|
191 IMPORT_C RFile* FilePassedByHandleL(); |
|
192 private: |
|
193 IMPORT_C virtual void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer); |
|
194 // Reserved virtual functions... |
|
195 IMPORT_C virtual void Reserved_1(); |
|
196 public: |
|
197 IMPORT_C static CApaDataRecognizerType* CreateDataRecognizerL(TUid aImplUid); |
|
198 CDataRecognizerExtension* DataRecognizerExtension(); |
|
199 protected: |
|
200 const TUid iTypeUid; |
|
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. |
|
204 |
|
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. |
|
208 |
|
209 Users of the derived class use Confidence() to get this value. */ |
|
210 TInt iConfidence; |
|
211 /** The data (MIME) type of the most recently recognized data. |
|
212 |
|
213 Users of the derived class use MimeType() to get this value. */ |
|
214 TDataType iDataType; |
|
215 private: |
|
216 TInt iLock; |
|
217 CDataRecognizerExtension* iDataRecognizerExtn; |
|
218 }; |
|
219 |
|
220 #include <apmrec.inl> |
|
221 |
|
222 #endif |