examples/ForumNokia/Document_Handler_Example/RecognizerDll/src/RecognizerEx.cpp

00001 /*
00002  * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 // INCLUDE FILES
00031 #include <apmrec.h>
00032 #include <apmstd.h>
00033 //#ifdef __SERIES60_3X__
00034     #include <ImplementationProxy.h>
00035 //#endif
00036 #include "RecognizerEx.h"
00037 
00038 // CONSTANTS
00039 const TUid KUidRecognizerEx={0x101FF1ec};
00040 const TInt KMaxBufferLength=4;                  // maximum amount of buffer space we will ever use
00041 const TInt KRecRtFileExtensionsMightBeValid=4;  // If the file name length > 4, the file extension might be valid
00042 
00043 _LIT(KExtension1, ".new");
00044 
00045 _LIT8(KDataType,"application/something-totally-new");
00046 
00047 // ================= MEMBER FUNCTIONS =======================
00048 
00049 // ---------------------------------------------------------
00050 // RecognizerEx::RecognizerEx()
00051 // constructs the object
00052 // ---------------------------------------------------------
00053 //
00054 CApaRecognizerEx::CApaRecognizerEx()
00055     : CApaDataRecognizerType(KUidRecognizerEx, CApaDataRecognizerType::ENormal)
00056     {
00057     iCountDataTypes=1;
00058     }
00059 
00060 // ---------------------------------------------------------
00061 // RecognizerEx::~RecognizerEx()
00062 // Destroys the object
00063 // ---------------------------------------------------------
00064 //
00065 CApaRecognizerEx::~CApaRecognizerEx()
00066     {
00067     // Do nothing
00068     }
00069 
00070 // ---------------------------------------------------------
00071 // RecognizerEx::PreferredBufSize()
00072 // Returns preferred buffer size
00073 // ---------------------------------------------------------
00074 //
00075 TUint CApaRecognizerEx::PreferredBufSize()
00076     {
00077     return KMaxBufferLength;
00078     }
00079 
00080 // ---------------------------------------------------------
00081 // RecognizerEx::SupportedDataTypeL()
00082 // Returns supported mime type
00083 // ---------------------------------------------------------
00084 //
00085 TDataType CApaRecognizerEx::SupportedDataTypeL(TInt /*aIndex*/) const
00086     {
00087     return TDataType(KDataType);
00088     }
00089 
00090 // ---------------------------------------------------------
00091 // RecognizerEx::DoRecognizeL()
00092 // Recognizes the file by name and/or head buffer
00093 // ---------------------------------------------------------
00094 //
00095 void CApaRecognizerEx::DoRecognizeL(const TDesC& aName, const TDesC8& /*aBuffer*/)
00096     {
00097     // To keep code simple, we only check file name extension
00098     if (aName.Length()>KRecRtFileExtensionsMightBeValid)
00099     {
00100         if (aName.Right(KRecRtFileExtensionsMightBeValid).CompareF(KExtension1)==0)
00101         {
00102             iConfidence=ECertain;   // is certainly something totally new
00103             iDataType=TDataType(KDataType);
00104             return;
00105         }
00106     }
00107     }
00108 
00109 
00110 
00111 // ================= OTHER EXPORTED FUNCTIONS ==============
00112 
00113 //#ifdef __SERIES60_3X__
00114 
00115 // ---------------------------------------------------------
00116 // RecognizerEx::CreateRecognizerL()
00117 // Returns pointer to the new object
00118 // ---------------------------------------------------------
00119 //
00120 CApaDataRecognizerType* CApaRecognizerEx::CreateRecognizerL()
00121     {
00122     return new (ELeave) CApaRecognizerEx();
00123     }
00124 
00125 const TImplementationProxy ImplementationTable[] =
00126     {
00127     IMPLEMENTATION_PROXY_ENTRY(KRecognizerExImplementationUid, CApaRecognizerEx::CreateRecognizerL)
00128     };
00129 
00130 // ---------------------------------------------------------
00131 // ImplementationGroupProxy
00132 // Provides access to the implementationtable
00133 // ---------------------------------------------------------
00134 //
00135 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
00136     {
00137     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
00138     return ImplementationTable;
00139     }
00140 /*
00141 #else
00142 EXPORT_C CApaDataRecognizerType* CreateRecognizer()
00143     {
00144     CApaDataRecognizerType* thing=new CApaRecognizerEx();
00145     return thing; // NULL if new failed
00146     }
00147 
00148 GLDEF_C TInt E32Dll(TDllReason aReason)
00149     {
00150     return KErrNone;
00151     }
00152 #endif
00153 */

Generated by  doxygen 1.6.2