codhandler/ddrecog/src/DdRecog.cpp
changeset 0 dd21522fd290
child 26 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *      Implementation of class CDdRecog.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <s32std.h>
       
    24 #include <apmrec.h>
       
    25 #include <apmstd.h>
       
    26 #include <f32file.h>
       
    27 #include <CodDefs.h>
       
    28 #include <CharConv.h>
       
    29 #include <ImplementationProxy.h>
       
    30 #include "DdRecog.h"
       
    31 #include "DdRecogLogger.h"
       
    32 
       
    33 // ================= CONSTANTS =======================
       
    34 
       
    35 /// UID of DD Viewer Application.
       
    36 LOCAL_D const TUid KDdUidDdViewerApp = { DD_VIEWER_UID };
       
    37 /// Preferred recognition buffer size.
       
    38 const TInt KPreferedBufferSize = 1024;
       
    39 /// DD MIME type string.
       
    40 _LIT8( KDdMimeType, DD_MIME_TYPE );
       
    41 /// DD file extension.
       
    42 _LIT( KDdExt,".dd" );
       
    43 /// DD content recognition pattern (8 bit).
       
    44 _LIT8( KDd8,"<media");
       
    45 /// DD content recognition pattern (16 bit).
       
    46 _LIT( KDd16,"<media");
       
    47 
       
    48 /// DD recog ecom plugin implementation UID.
       
    49 LOCAL_D const TInt KDdRecogImplementationUid = 0x10008d55;
       
    50 /// ECOM implementation table.
       
    51 LOCAL_D const TImplementationProxy ImplementationTable[] =
       
    52     {
       
    53     IMPLEMENTATION_PROXY_ENTRY\
       
    54         ( KDdRecogImplementationUid, CDdRecog::CreateRecognizerL )
       
    55     };
       
    56 
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CDdRecog::CDdRecog()
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 CDdRecog::CDdRecog()
       
    65 : CApaDataRecognizerType( KDdUidDdViewerApp, CApaDataRecognizerType::ENormal )
       
    66     {
       
    67     iCountDataTypes = 1;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CDdRecog::PreferredBufSize()
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 TUint CDdRecog::PreferredBufSize()
       
    75     {
       
    76     return KPreferedBufferSize;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CDdRecog::SupportedDataTypeL()
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 TDataType CDdRecog::SupportedDataTypeL( TInt aIndex ) const
       
    84     {
       
    85     switch ( aIndex )
       
    86         {
       
    87         case 0:
       
    88             {
       
    89             return TDataType( KDdMimeType );
       
    90             }
       
    91 
       
    92         default:
       
    93             {
       
    94             return TDataType();
       
    95             }
       
    96         }
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CDdRecog::CreateRecognizerL()
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 CApaDataRecognizerType* CDdRecog::CreateRecognizerL()
       
   104     {
       
   105     return new (ELeave) CDdRecog();
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CDdRecog::DoRecognizeL()
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 void CDdRecog::DoRecognizeL( const TDesC& aName, const TDesC8& aBuffer )
       
   113     {
       
   114     CLOG_ENTERFN( "CDdRecog::DoRecognizeL" );
       
   115     CLOG_WRITE_FORMAT( "DoRecognize: name: %S", &aName );
       
   116 
       
   117     iConfidence = ENotRecognized;
       
   118 
       
   119     // Check extension. We cannot use TParse* classes, as the recog is
       
   120     // called with generated filenames which contain invalid chars and
       
   121     // panic TParsePtrC.
       
   122     TInt len( KDdExt().Length() );
       
   123     if( aName.Length() >= len && !aName.Right( len ).CompareF( KDdExt ) )
       
   124         {
       
   125         CLOG_WRITE( "DoRecognize: extension is '.dd'" );
       
   126         // Named ".dd"
       
   127         iDataType = TDataType( KDdMimeType );
       
   128         iConfidence = ECertain;
       
   129         }
       
   130     else
       
   131         {
       
   132         CLOG_WRITE( "DoRecognize: pattern search" );
       
   133         // Not named ".dd". Recognition by pattern-matching.
       
   134         // Prepare pointers to buffer (both 8 and 16 bits).
       
   135         TPtrC8 buf8( aBuffer );
       
   136         if ( aBuffer.Length() > KPreferedBufferSize )
       
   137             {
       
   138             buf8.Set( aBuffer.Left( KPreferedBufferSize ) );
       
   139             }
       
   140         TPtrC buf16( (TText*)buf8.Ptr(), buf8.Length() / 2 );
       
   141         // Find DD-specific pattern in buffer (both 8 and 16 bits).
       
   142         if ( buf8.FindF( KDd8 ) >= 0 || buf16.FindF( KDd16 ) >= 0 )
       
   143             {
       
   144             iDataType = TDataType( KDdMimeType );
       
   145             iConfidence = ECertain;
       
   146             }
       
   147         }
       
   148     CLOG_WRITE_FORMAT( "DoRecognize: confidence: %d", iConfidence );
       
   149     CLOG_LEAVEFN( "CDdRecog::DoRecognizeL" );
       
   150     }
       
   151 
       
   152 /**
       
   153 * Implementation group proxy.
       
   154 * @param aTableCount Table count is returned here.
       
   155 * @return Implementation table is returned here.
       
   156 */
       
   157 EXPORT_C const TImplementationProxy* ImplementationGroupProxy
       
   158 ( TInt& aTableCount )
       
   159     {
       
   160     aTableCount =
       
   161         sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   162     return ImplementationTable;
       
   163     }