Recognizers
Article Metadata
Contents |
Description
Plug-in code that can examine sample data, and return, if recognized, its data type. A data type is also commonly known as a MIME type.
The plug-in recognizer architecture allows additional data recognizers to be created and added.
Loading
Before Symbian OS v9.1, data recognizers were plug-in DLLs with a .mdl extension and a UID2 of 0x10003A19. They were located in the \System\Recogs\ folder on any drive.
In Symbian OS v9.1 and onwards, recognizers are ECOM plugins, located under \sys\bin\. Each ECOM data recognizer is loaded by the application architecture (apparc) during the OS startup sequence.
Handling the Data
After a recognizer has been selected, apparc attempts to find the application that can best handle the selected data type. And it is not guaranteed that an application will be available to handle a data type, even if it was successfully recognized.
Recognizers List
The recognizer framework maintains an up to date list of all data recognizers that exist in the system. The list is ordered by recognizer priority.
FrameWork
CApaDataRecognizer is an internal class that represents the recognizer framework.Although CApaDataRecognizer is internal, clients can access most of its properties through the RApaLsSession API.
class CApaDataRecognizerType : public CBase;
Interface
All recognizers must implement CApaDataRecognizerType::DoRecognizeL(). This is the function that is called to do the data recognition. It is not pure virtual, but the implementation in CApaDataRecognizerType does not do anything apart from setting CApaDataRecognizerType::iDataType to a default value. Implementations should set iDataType to the MIME type it considers the data to belong to and iConfidence to indicate how confident it is. The decision is based on the two parameters, aName and aBuffer.
The following code recognizes with maximum confidence the word "example" contained in files with a .example extension.
void CExampleRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
{
_LIT8(KExampleData, "example");
_LIT(KDotExample, ".Example");
TParse parse;
parse.Set(aName,NULL,NULL);
TPtrC ext=parse.Ext(); // extract the extension from the filename
if (ext.CompareF(KDotExample)==0 && aBuffer.FindF(KExampleData)!=KErrNotFound)
{
iConfidence=ECertain;
iDataType=TDataType(KExampleTextMimeType);
}
}
This is located in apmrec.h and should be linked against apmime.lib in mmp file.
Function Members of CApaDataRecognizerType
CApaDataRecognizerType(), ~CApaDataRecognizerType(), Confidence(), CreateDataRecognizerL(), FilePassedByHandleL(), Lock(), Locked(), MimeType(), MimeTypesCount(), PreferredBufSize(), Priority(), RecognizeL(), SupportedDataTypeL(), TRecognitionConfidence, TRecognizerPriority, TypeUid(), Unlock(), UpdateDataTypesL().
Related:
- Recognizing file types
- Example by Third Party (NewLC)
- Document Handler Example
- Don't want to implement your own recognizer just now but still want your data type to be recognized. Write a simple text file instead and use the Data Type Registry.
--


(no comments yet)