hti/HtiAutoStart/src/HtiAutoStart.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 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 "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:  HtiAutoStart implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "HtiAutoStart.h"
       
    21 #include <apmrec.h>
       
    22 #include <ecom/implementationproxy.h>
       
    23 
       
    24 // CONSTANTS
       
    25 const static TUint KHtiAutoStartImplUid = 0x10210CC5;
       
    26 const static TUid KHtiAutoStartUid = {0x10210CC4};
       
    27 _LIT( KHtiFrameworkExe, "HtiFramework.exe" );
       
    28 _LIT( KHtiMatchPattern, "HtiFramework*" );
       
    29 
       
    30 const TImplementationProxy ImplementationTable[] =
       
    31     {
       
    32     IMPLEMENTATION_PROXY_ENTRY( KHtiAutoStartImplUid,
       
    33                                 CHtiAutostart::CreateRecognizerL )
       
    34     };
       
    35 
       
    36 // MACROS
       
    37 #ifdef __ENABLE_LOGGING__
       
    38 
       
    39 #include <flogger.h>
       
    40 _LIT( KLogFolder, "hti" );
       
    41 _LIT( KLogFile,   "htiautostart.txt" );
       
    42 
       
    43 #define HTI_LOG_TEXT(a1) {_LIT(temp, a1); RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, temp);}
       
    44 #define HTI_LOG_DES(a1) {RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, a1);}
       
    45 #define HTI_LOG_FORMAT(a1,a2) {_LIT(temp, a1); RFileLogger::WriteFormat(KLogFolder, KLogFile, EFileLoggingModeAppend, temp, (a2));}
       
    46 
       
    47 #else   // !__ENABLE_LOGGING__
       
    48 
       
    49 #define HTI_LOG_TEXT(a1)
       
    50 #define HTI_LOG_DES(a1)
       
    51 #define HTI_LOG_FORMAT(a1,a2)
       
    52 
       
    53 #endif // __ENABLE_LOGGING__
       
    54 
       
    55 // LOCAL CONSTANTS AND MACROS
       
    56 
       
    57 // MODULE DATA STRUCTURES
       
    58 
       
    59 // LOCAL FUNCTION PROTOTYPES
       
    60 
       
    61 // FORWARD DECLARATIONS
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
    67     {
       
    68     HTI_LOG_TEXT( "ImplementationGroupProxy" );
       
    69     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    70     return ImplementationTable;
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 CApaDataRecognizerType* CHtiAutostart::CreateRecognizerL()
       
    75     {
       
    76     HTI_LOG_TEXT( "CreateRecognizerL" );
       
    77     CApaDataRecognizerType* recognizer = new CHtiAutostart();
       
    78     CHtiAutostart::StartThread();
       
    79     return recognizer;
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 CHtiAutostart::CHtiAutostart()
       
    84     :CApaDataRecognizerType( KHtiAutoStartUid, CApaDataRecognizerType::ENormal )
       
    85     {
       
    86     HTI_LOG_TEXT( "CHtiAutostart constructor" );
       
    87     iCountDataTypes = 1;
       
    88     }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 TUint CHtiAutostart::PreferredBufSize()
       
    92     {
       
    93     HTI_LOG_TEXT( "PreferredBufSize" );
       
    94     return 0;
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 TDataType CHtiAutostart::SupportedDataTypeL( TInt /*aIndex*/ ) const
       
    99     {
       
   100     HTI_LOG_TEXT( "SupportedDataTypeL" );
       
   101     return TDataType();
       
   102     }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 void CHtiAutostart::DoRecognizeL( const TDesC& /*aName*/,
       
   106                                   const TDesC8& /*aBuffer*/ )
       
   107     {
       
   108     HTI_LOG_TEXT( "DoRecognizeL" );
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 void CHtiAutostart::StartThread()
       
   113     {
       
   114     HTI_LOG_TEXT( "StartThread" );
       
   115     //create a new thread for starting our application
       
   116     RThread* startAppThread = new RThread();
       
   117 
       
   118     User::LeaveIfError( startAppThread->Create(
       
   119         _L( "HtiAutostart" ),
       
   120         CHtiAutostart::StartAppThreadFunction,
       
   121         KDefaultStackSize,
       
   122         KMinHeapSize,
       
   123         KMinHeapSize,
       
   124         NULL,
       
   125         EOwnerThread ) );
       
   126 
       
   127     startAppThread->SetPriority( EPriorityNormal );
       
   128     startAppThread->Resume();
       
   129     startAppThread->Close();
       
   130     delete startAppThread;
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 TInt CHtiAutostart::StartAppThreadFunction( TAny* /*aParam*/ )
       
   135     {
       
   136     HTI_LOG_TEXT( "StartAppThreadFunction" );
       
   137     // create a TRAP cleanup
       
   138     CTrapCleanup * cleanup = CTrapCleanup::New();
       
   139     TInt err;
       
   140     if ( cleanup == NULL )
       
   141         {
       
   142         err = KErrNoMemory;
       
   143         }
       
   144     else
       
   145         {
       
   146         TRAP( err, StartAppThreadFunctionL() );
       
   147         }
       
   148     delete cleanup;
       
   149 
       
   150     if ( err != KErrNone )
       
   151         {
       
   152         HTI_LOG_FORMAT( "StartAppThreadFunctionL leave %d", err );
       
   153         User::Panic( _L( "HtiAutostart" ), err );
       
   154         }
       
   155 
       
   156     return err;
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 void CHtiAutostart::StartAppThreadFunctionL()
       
   161     {
       
   162     HTI_LOG_TEXT( "StartAppThreadFunctionL" );
       
   163     // Check if HtiFramework is already running
       
   164     TFullName processName;
       
   165     TFindProcess finder( KHtiMatchPattern );
       
   166     TInt err = finder.Next( processName );
       
   167     if ( err == KErrNone )
       
   168         {
       
   169         HTI_LOG_TEXT( "HtiFramework.exe already running, nothing to do" );
       
   170         return;
       
   171         }
       
   172 
       
   173     RProcess prs;
       
   174     err = prs.Create( KHtiFrameworkExe, KNullDesC );
       
   175     if ( err == KErrNone )
       
   176         {
       
   177         prs.Resume();
       
   178         prs.Close();
       
   179         HTI_LOG_TEXT( "HtiFramework.exe process created" );
       
   180         }
       
   181     else
       
   182         {
       
   183         HTI_LOG_FORMAT( "HtiFramework.exe process creation failed %d", err );
       
   184         User::Leave( err );
       
   185         }
       
   186     }
       
   187 
       
   188 // End of File