|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-1AAA88BB-19AD-5B8E-993C-11F4B7CD90EB" xml:lang="en"><title>Writing |
|
13 a MIME Recognizer</title><abstract><p>The Mime Recognizers provide the implementation for data type |
|
14 (MIME Type) recognition using the MIME recognition framework. </p><p>Each |
|
15 MIME recognizer specifies the MIME type it supports along with the priority |
|
16 and confidence of recognition. A MIME recognizer reads a small piece of data |
|
17 and identifies the data type. Once the data type is identified, it is passed |
|
18 to the <xref href="GUID-1578590A-FC00-5C3B-8BF9-F6E43CA9D9A0.dita">Application |
|
19 Architecture </xref> (AppArc). AppArc launches the application |
|
20 that best handles the identified data type. </p></abstract><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
21 <context id="GUID-6799E3F3-353E-5C00-A38C-D32F888392AA-GENID-1-8-1-11-1-1-6-1-6-1-4-1-3-1-3-1"><p>Symbian OS v9.1 |
|
22 and onwards, MIME recognizers are <xref href="GUID-9E92EE30-F2E2-5F28-BB2A-391C09EC69D2.dita">ECOM</xref> plug-ins. |
|
23 They are located in <b>\sys\bin\</b>. </p> <p>Each MIME recognizer is loaded |
|
24 by the <xref href="GUID-1578590A-FC00-5C3B-8BF9-F6E43CA9D9A0.dita">Application |
|
25 Architecture (AppArc)</xref> during the startup sequence. </p> </context> |
|
26 <steps id="GUID-45E4FFC7-5C92-5101-B21B-581C2AFB9CF0"> |
|
27 <step id="GUID-016BE2C1-DFB1-51B0-9A5C-C3A926C48E33"><cmd/> |
|
28 <info>Create a project file (<filepath>.mmp</filepath>) for the MIME recognizer |
|
29 and ensure the following parameters are set. </info> |
|
30 <stepxmp><table id="GUID-8A194C7E-8927-5A8A-B1EA-EB9D7A23CF0C"> |
|
31 <tgroup cols="3"><colspec colname="col0"/><colspec colname="col1"/><colspec colname="col2"/> |
|
32 <tbody> |
|
33 <row> |
|
34 <entry><p> <b>Variable Name</b> </p> </entry> |
|
35 <entry><p> <b>Value</b> </p> </entry> |
|
36 <entry><p> <b>Description</b> </p> </entry> |
|
37 </row> |
|
38 <row> |
|
39 <entry><p> <codeph>TargetType</codeph> </p> </entry> |
|
40 <entry><p> <codeph>plugin</codeph> </p> </entry> |
|
41 <entry><p>Specifies the type of binary. </p> </entry> |
|
42 </row> |
|
43 <row> |
|
44 <entry><p> <codeph>Resource</codeph> </p> </entry> |
|
45 <entry><p>Use the block <codeph>start resource ... end</codeph> </p> </entry> |
|
46 <entry><p>The variable <codeph>Resource</codeph> is set to the registration |
|
47 resource file (<filepath>.rss)</filepath>)of the MIME recognizer. </p> </entry> |
|
48 </row> |
|
49 <row> |
|
50 <entry><p> <codeph>UID</codeph> </p> </entry> |
|
51 <entry><p> <codeph>0x10009D8D</codeph> and the <codeph>DLL UID</codeph> </p> </entry> |
|
52 <entry><p>The variable <codeph>UID</codeph> requires two values. The first |
|
53 value is 0x10009D8D and is constant for all MIME recognizers. The second value |
|
54 is the UID of the DLL. </p> </entry> |
|
55 </row> |
|
56 <row> |
|
57 <entry><p> <codeph>Capability</codeph> </p> </entry> |
|
58 <entry><p> <codeph>Protserv</codeph> </p> </entry> |
|
59 <entry><p>The AppArc server has <codeph>protserv</codeph> capability.The MIME |
|
60 recognizers are loaded by the AppArc server on requirement. The MIME recognizers |
|
61 must have <codeph>protserv</codeph> capability to be loaded by the AppArc |
|
62 server. </p> </entry> |
|
63 </row> |
|
64 </tbody> |
|
65 </tgroup> |
|
66 </table> </stepxmp> |
|
67 <info>For more details, refer <xref href="GUID-641A276D-F618-50CE-BA5A-658DCC26BAB5.dita">Creating |
|
68 a Project File</xref>. </info> |
|
69 <info>The code below shows a sample <filepath>.mmp</filepath> file with the |
|
70 above parameters set. </info> |
|
71 <stepxmp><codeblock id="GUID-B21A3AEB-C21C-5C9B-8BE3-715336ECBFD0" xml:space="preserve">target exampleRecognizer.dll |
|
72 |
|
73 capability Protserv |
|
74 targettype plugin |
|
75 uid 0x10009d8d 0x1d1f75ed |
|
76 vendorid 0x70000001 |
|
77 |
|
78 sourcepath . |
|
79 source exampleRecognizer.cpp |
|
80 systeminclude \EPOC32\INCLUDE |
|
81 systeminclude \EPOC32\INCLUDE\ECOM |
|
82 |
|
83 library EUSER.LIB APMIME.LIB |
|
84 |
|
85 start resource 1d1f75ed.rss |
|
86 target exampleRecognizer.rsc |
|
87 end</codeblock> </stepxmp> |
|
88 </step> |
|
89 <step id="GUID-98A72A42-24D2-5A16-A0DE-15223FD1A685"><cmd/> |
|
90 <info>Export the factory code function of the MIME recognizer as shown below. |
|
91 This is required to create an instance of the MIME recognizer. </info> |
|
92 <info>The class <codeph>CExampleRecognizer</codeph> is derived from <xref href="GUID-EBE480D9-E377-32F4-9AE5-9C58684BEFF0.dita"><apiname>CApaDataRecognizerType</apiname></xref>. </info> |
|
93 <stepxmp><codeblock id="GUID-F61F7E5E-37E0-5F4B-8E9A-E4C106005554" xml:space="preserve">const TInt KImplementationUID = 0x101F7DA1; |
|
94 |
|
95 CApaDataRecognizerType* CExampleRecognizer::CreateRecognizerL() |
|
96 { |
|
97 return new (ELeave) CExampleRecognizer; |
|
98 } |
|
99 |
|
100 const TImplementationProxy ImplementationTable[] = |
|
101 { |
|
102 IMPLEMENTATION_PROXY_ENTRY(KImplementationUID,CExampleRecognizer::CreateRecognizerL); |
|
103 } |
|
104 |
|
105 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
106 { |
|
107 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
108 return ImplementationTable; |
|
109 } |
|
110 </codeblock> </stepxmp> |
|
111 <info>For more details refer <xref href="GUID-895A685E-83E8-51A3-A823-3A0E07B1E609.dita">Exporting |
|
112 Implementation Factories.</xref> </info> |
|
113 </step> |
|
114 <step id="GUID-B06E4D48-5CC2-5BEB-8C28-8DE5EFF62FE1"><cmd/> |
|
115 <info>Implement <codeph>CApaDataRecognizerType</codeph> polymorphic interface. </info> |
|
116 <substeps id="GUID-C29E1469-92CF-53D6-867F-FA73E223929C"> |
|
117 <substep id="GUID-B670112D-ACEB-5001-8F60-F16DF4240CE7"><cmd/> |
|
118 <info>The code below shows a sample constructor implementation. </info> |
|
119 <stepxmp><codeblock id="GUID-F8BD0190-4751-5731-BBF8-BD41644755F5" xml:space="preserve">const TUid KExampleUid = {0x1d1f75ed}; |
|
120 |
|
121 const TInt KNumDataTypes = 1; |
|
122 |
|
123 CExampleRecognizer::CExampleRecognizer() : CApaDataRecognizerType(KExampleUid,CApaDataRecognizerType::EHigh) |
|
124 |
|
125 { |
|
126 iCountDataTypes = KNumDataTypes; |
|
127 |
|
128 } |
|
129 |
|
130 </codeblock> </stepxmp> |
|
131 <info>Specify a UID (the <codeph>DLL UID</codeph> as specified in the plug-in |
|
132 project definition file) and a <xref href="GUID-EBD1242B-6BD9-5ABB-B471-24ABC78A918C.dita">priority</xref> in |
|
133 the constructor. </info> |
|
134 <info>The <codeph>iCountDataTypes</codeph> variable, represents the number |
|
135 of data types supported by the recognizer can also be set in the constructor. |
|
136 The value set for this variable should match the implementation of <xref href="GUID-EBE480D9-E377-32F4-9AE5-9C58684BEFF0.dita#GUID-EBE480D9-E377-32F4-9AE5-9C58684BEFF0/GUID-FBCE07F2-9566-3AD1-B943-2FFF5C5AAE67"><apiname>CApaDataRecognizerType::SupportedDataTypeL()</apiname></xref>. </info> |
|
137 </substep> |
|
138 <substep id="GUID-5F36C1F6-3EDA-5817-801D-9B5C6F9F4927"><cmd/> |
|
139 <info>Implement the pure virtual function <xref href="GUID-EBE480D9-E377-32F4-9AE5-9C58684BEFF0.dita#GUID-EBE480D9-E377-32F4-9AE5-9C58684BEFF0/GUID-FBCE07F2-9566-3AD1-B943-2FFF5C5AAE67"><apiname>CApaDataRecognizerType::SupportedDataTypeL()</apiname></xref>. |
|
140 It returns the MIME types that the recognizer is capable of recognizing. </info> |
|
141 <info>The code below shows a sample implementation of <codeph>SupportedDataTypeL()</codeph> for |
|
142 supporting MIME type/ subtype "text/example". </info> |
|
143 <stepxmp><codeblock id="GUID-D2DDF2A2-2897-544A-ACA7-DA3A60FB27E9" xml:space="preserve"> |
|
144 _LIT8(KExampleTextMimeType, "text/example"); |
|
145 |
|
146 |
|
147 TDataType CExampleRecognizer::SupportedDataTypeL(TInt aIndex) const |
|
148 |
|
149 { |
|
150 return TDataType(KExampleTextMimeType); |
|
151 |
|
152 }</codeblock> </stepxmp> |
|
153 </substep> |
|
154 <substep id="GUID-4C2CD90F-17AB-53B5-883A-7022E1231E2E"><cmd/> |
|
155 <info>Implement <xref href="GUID-EBE480D9-E377-32F4-9AE5-9C58684BEFF0.dita#GUID-EBE480D9-E377-32F4-9AE5-9C58684BEFF0/GUID-74ED8BEA-52AA-3AC4-92D9-5E4FB4F25DDD"><apiname>CApaDataRecognizerType::DoRecognizeL()</apiname></xref>. |
|
156 This function executes data type recognition. </info> |
|
157 <info>The code below shows a sample implementation of <codeph>DoRecognizeL()</codeph> for |
|
158 recognizing the MIME type <codeph>"/text/example"</codeph> contained in files |
|
159 with <filepath>.example</filepath> extension with maximum confidence. </info> |
|
160 <stepxmp><codeblock id="GUID-C8F82861-AF59-5E23-9F1D-8656B2D1EE54" xml:space="preserve">void CExampleRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer) |
|
161 { |
|
162 _LIT8(KExampleData, "example"); |
|
163 _LIT(KDotExample, ".Example"); |
|
164 |
|
165 TParse parse; |
|
166 parse.Set(aName,NULL,NULL); |
|
167 TPtrC ext=parse.Ext(); // extract the extension from the filename |
|
168 |
|
169 if (ext.CompareF(KDotExample)==0 && aBuffer.FindF(KExampleData)!=KErrNotFound) |
|
170 { |
|
171 iConfidence=ECertain; |
|
172 iDataType=TDataType(KExampleTextMimeType); |
|
173 } |
|
174 }</codeblock> </stepxmp> |
|
175 </substep> |
|
176 </substeps> |
|
177 </step> |
|
178 </steps> |
|
179 </taskbody></task> |