|
1 // Copyright (c) 2003-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 #include <f32file.h> |
|
17 #include <barsread.h> |
|
18 #include "RecMmf.h" |
|
19 #include "mmfcontrollerpluginresolver.h" |
|
20 |
|
21 const TInt KMimeMmfRecognizerValue = 0x101F7C0C; |
|
22 const TUid KUidMimeMmfRecognizer = {KMimeMmfRecognizerValue}; |
|
23 const TInt KMmfRecognizerPriority = 10; // The recognizer priority is set to 10(a value between ENormal and EHigh) |
|
24 |
|
25 |
|
26 // the minimum buffer size that will theoretically guarantee recognition |
|
27 const TInt KPreferredBufSize = 256; |
|
28 |
|
29 // the granularity of the internal MIME type array |
|
30 const TInt KMimeArrayGranularity = 4; |
|
31 |
|
32 // CApaMmfRecognizer |
|
33 |
|
34 /** |
|
35 * @internalAll |
|
36 * |
|
37 * Call base constructor with the recognizer's UID and confidence level |
|
38 * The MMF recognizer priority is set to 10(a value between ENormal and EHigh) to allow |
|
39 * third-party recognizers to specify high priority. |
|
40 */ |
|
41 CApaMmfRecognizer::CApaMmfRecognizer() |
|
42 :CApaDataRecognizerType(KUidMimeMmfRecognizer,KMmfRecognizerPriority) |
|
43 { |
|
44 } |
|
45 |
|
46 CApaMmfRecognizer::~CApaMmfRecognizer() |
|
47 { |
|
48 delete iMmfRecognizer; |
|
49 } |
|
50 |
|
51 /** |
|
52 * @internalAll |
|
53 * |
|
54 * Return the supposed minimum buffer size we need to |
|
55 * successfully recognize the data |
|
56 */ |
|
57 TUint CApaMmfRecognizer::PreferredBufSize() |
|
58 { |
|
59 return KPreferredBufSize; |
|
60 } |
|
61 |
|
62 /** |
|
63 * @internalAll |
|
64 * |
|
65 * Gets one of the data (MIME) types that the recognizer can recognize. |
|
66 */ |
|
67 TDataType CApaMmfRecognizer::SupportedDataTypeL(TInt aIndex) const |
|
68 { |
|
69 return (iMmfRecognizer->SupportedDataTypeL(aIndex)); |
|
70 } |
|
71 |
|
72 |
|
73 /** |
|
74 * @internalAll |
|
75 * |
|
76 * Attempt to recognize the data. |
|
77 * This recognizer only attempts to match the data header on its own, |
|
78 * or the data header plus the file suffix together. |
|
79 * |
|
80 * NB if the file is not recognized, this function should NOT leave : |
|
81 * it should instead set iConfidence = ENotRecognized and return |
|
82 * the function should only leave if there is an out-of-memory condition |
|
83 */ |
|
84 void CApaMmfRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer) |
|
85 { |
|
86 // assume Match will fail : |
|
87 iConfidence = CApaDataRecognizerType::ENotRecognized; |
|
88 |
|
89 CMmfRecognizer::TMatchMethod matchMethod = iMmfRecognizer->MatchL(aName,aBuffer); |
|
90 |
|
91 // return whether the data was matched by setting iConfidence |
|
92 // if matched the MIME type is returned in iDataType |
|
93 if (matchMethod == CMmfRecognizer::ENotMatched) |
|
94 { |
|
95 iConfidence = CApaDataRecognizerType::ENotRecognized; |
|
96 } |
|
97 else |
|
98 { |
|
99 iDataType = iMmfRecognizer->MimeString(); |
|
100 |
|
101 //Match on data only |
|
102 if (matchMethod == CMmfRecognizer::EBySignature) |
|
103 iConfidence = CApaDataRecognizerType::EPossible; |
|
104 else |
|
105 {//Match on data and suffix |
|
106 ASSERT(matchMethod == CMmfRecognizer::EByName); |
|
107 iConfidence = CApaDataRecognizerType::EProbable; |
|
108 } |
|
109 |
|
110 } |
|
111 } |
|
112 |
|
113 void CApaMmfRecognizer::ConstructL() |
|
114 { |
|
115 iMmfRecognizer = CMmfRecognizer::NewL(); |
|
116 iCountDataTypes = iMmfRecognizer->NumMimeTypes(); |
|
117 } |
|
118 |
|
119 CApaMmfRecognizer* CApaMmfRecognizer::NewL() |
|
120 { |
|
121 CApaMmfRecognizer* self = new (ELeave) CApaMmfRecognizer(); |
|
122 CleanupStack::PushL(self); |
|
123 self->ConstructL(); |
|
124 CleanupStack::Pop(self); |
|
125 return self; |
|
126 } |
|
127 |
|
128 // CMmfRecognizer - the main utility class owner by CApaMmfRecognizer |
|
129 |
|
130 CMmfRecognizer::CMmfRecognizer() |
|
131 { |
|
132 } |
|
133 |
|
134 CMmfRecognizer::~CMmfRecognizer() |
|
135 { |
|
136 delete iMmfRecognizerUtil; |
|
137 delete iMimeTypes; |
|
138 } |
|
139 |
|
140 void CMmfRecognizer::ConstructL() |
|
141 { |
|
142 iMimeTypes = new (ELeave) CDesC8ArrayFlat(KMimeArrayGranularity); |
|
143 BuildListL(); |
|
144 iMmfRecognizerUtil = CMmfRecognizerUtil::NewL(); |
|
145 } |
|
146 |
|
147 CMmfRecognizer* CMmfRecognizer::NewL() |
|
148 { |
|
149 CMmfRecognizer* self = new (ELeave) CMmfRecognizer(); |
|
150 CleanupStack::PushL(self); |
|
151 self->ConstructL(); |
|
152 CleanupStack::Pop(self); |
|
153 return self; |
|
154 } |
|
155 |
|
156 /** |
|
157 * @internalAll |
|
158 * |
|
159 * Return the number of MIME types supported |
|
160 */ |
|
161 TInt CMmfRecognizer::NumMimeTypes() const |
|
162 { |
|
163 return(iMimeTypes->Count()); |
|
164 } |
|
165 |
|
166 |
|
167 /** |
|
168 * @internalAll |
|
169 * |
|
170 * Call into the MMF Controller Framework DLL to get |
|
171 * a list of supported MIME types |
|
172 */ |
|
173 void CMmfRecognizer::BuildListL() |
|
174 { |
|
175 iMimeTypes->Reset(); |
|
176 CMmfRecognizerUtil::GetMimeTypesL(iMimeTypes); |
|
177 } |
|
178 |
|
179 |
|
180 /** |
|
181 * @internalAll |
|
182 * |
|
183 * Get one of the data (MIME) types that MMF can recognize. |
|
184 */ |
|
185 const TPtrC8 CMmfRecognizer::SupportedDataTypeL(TInt aIndex) const |
|
186 { |
|
187 if ((aIndex < 0) || (aIndex >= iMimeTypes->Count())) |
|
188 User::Leave(KErrArgument); |
|
189 |
|
190 return(iMimeTypes->MdcaPoint(aIndex)); |
|
191 } |
|
192 |
|
193 |
|
194 /** |
|
195 * @internalAll |
|
196 * |
|
197 * Get a reference to the last MIME type string successfully matched |
|
198 */ |
|
199 const TDesC8& CMmfRecognizer::MimeString() const |
|
200 { |
|
201 return iMimeString; |
|
202 } |
|
203 |
|
204 /** |
|
205 * @internalAll |
|
206 * |
|
207 * Attempt to recognize the data |
|
208 */ |
|
209 CMmfRecognizer::TMatchMethod CMmfRecognizer::MatchL(const TDesC& aFileName, const TDesC8& aBuffer) |
|
210 { |
|
211 CMmfRecognizerUtil::TMatchLevel matchLevel = CMmfRecognizerUtil::EMatchNone; |
|
212 matchLevel = iMmfRecognizerUtil->GetMimeTypeL(aFileName, aBuffer, iMimeString); |
|
213 |
|
214 TMatchMethod bestMatchMethod = ENotMatched; |
|
215 if(matchLevel==CMmfRecognizerUtil::EMatchData) |
|
216 bestMatchMethod = EBySignature; |
|
217 else if(matchLevel==CMmfRecognizerUtil::EMatchName) |
|
218 bestMatchMethod = EByName; |
|
219 |
|
220 return bestMatchMethod; |
|
221 } |
|
222 |
|
223 |
|
224 #include <ecom/ecom.h> |
|
225 #include <ecom/implementationproxy.h> |
|
226 |
|
227 const TImplementationProxy ImplementationTable[] = |
|
228 { |
|
229 IMPLEMENTATION_PROXY_ENTRY(0x101F7C41, CApaMmfRecognizer::NewL) |
|
230 }; |
|
231 |
|
232 |
|
233 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
234 { |
|
235 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
236 return ImplementationTable; |
|
237 } |
|
238 |
|
239 |