homescreenapp/hsapplicationlauncher/src/hsapplicationlauncher.cpp
author hgs
Fri, 09 Jul 2010 14:36:01 +0300
changeset 63 52b0f64eeb51
child 87 b19f22d9e323
child 90 3ac3aaebaee5
permissions -rw-r--r--
201027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description: application class.                 
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <e32property.h>
hgs
parents:
diff changeset
    19
#include <e32debug.h>
hgs
parents:
diff changeset
    20
#include "hsapplicationlauncher.h"
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
// ========================= DECLARATIONS ==================================
hgs
parents:
diff changeset
    23
_LIT( KHsExeName, "hsapplication.exe" );
hgs
parents:
diff changeset
    24
_LIT( KHsProcessName, "hsapplication.exe" );
hgs
parents:
diff changeset
    25
const TInt KSleepOnRetry = 250000; // 250ms
hgs
parents:
diff changeset
    26
const TUid KPSCategoryUid = TUid::Uid( 0x20022F36 );
hgs
parents:
diff changeset
    27
const TInt KPSCrashCountKey = 1;
hgs
parents:
diff changeset
    28
_LIT_SECURITY_POLICY_C1( KPSReadPolicy, ECapabilityReadDeviceData );
hgs
parents:
diff changeset
    29
_LIT_SECURITY_POLICY_C1( KPSWritePolicy, ECapabilityWriteDeviceData );
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
// ========================= LOCAL FUNCTIONS ==================================
hgs
parents:
diff changeset
    32
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
    33
#pragma CTC SKIP
hgs
parents:
diff changeset
    34
#endif //COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
    35
void RunAppL()
hgs
parents:
diff changeset
    36
    {
hgs
parents:
diff changeset
    37
    // Construct active scheduler.
hgs
parents:
diff changeset
    38
    CActiveScheduler* activeScheduler = new ( ELeave )CActiveScheduler();
hgs
parents:
diff changeset
    39
    CleanupStack::PushL( activeScheduler );
hgs
parents:
diff changeset
    40
    CActiveScheduler::Install( activeScheduler );
hgs
parents:
diff changeset
    41
hgs
parents:
diff changeset
    42
    // Construct app.
hgs
parents:
diff changeset
    43
    CHsLaunch* app = CHsLaunch::NewL();
hgs
parents:
diff changeset
    44
    CleanupStack::PushL( app );
hgs
parents:
diff changeset
    45
    
hgs
parents:
diff changeset
    46
    app->Activate();
hgs
parents:
diff changeset
    47
    
hgs
parents:
diff changeset
    48
    // Signal startup.
hgs
parents:
diff changeset
    49
    RProcess::Rendezvous(KErrNone);
hgs
parents:
diff changeset
    50
    
hgs
parents:
diff changeset
    51
    // Start active scheduler.
hgs
parents:
diff changeset
    52
    CActiveScheduler::Start();
hgs
parents:
diff changeset
    53
    
hgs
parents:
diff changeset
    54
    User::LeaveIfError( app->ApplicationReturnValue() );
hgs
parents:
diff changeset
    55
    
hgs
parents:
diff changeset
    56
    // Cleanup.
hgs
parents:
diff changeset
    57
    CleanupStack::PopAndDestroy( app );
hgs
parents:
diff changeset
    58
    CleanupStack::PopAndDestroy( activeScheduler );
hgs
parents:
diff changeset
    59
    }
hgs
parents:
diff changeset
    60
hgs
parents:
diff changeset
    61
#ifndef HOMESCREEN_TEST
hgs
parents:
diff changeset
    62
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    63
// E32Main
hgs
parents:
diff changeset
    64
// entry-point
hgs
parents:
diff changeset
    65
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    66
//
hgs
parents:
diff changeset
    67
TInt E32Main()
hgs
parents:
diff changeset
    68
    {            
hgs
parents:
diff changeset
    69
    TInt error = KErrNone;
hgs
parents:
diff changeset
    70
    
hgs
parents:
diff changeset
    71
    __UHEAP_MARK;    
hgs
parents:
diff changeset
    72
    
hgs
parents:
diff changeset
    73
    // Construct cleanup stack.
hgs
parents:
diff changeset
    74
    CTrapCleanup* cleanupstack = CTrapCleanup::New();
hgs
parents:
diff changeset
    75
    if( !cleanupstack )
hgs
parents:
diff changeset
    76
        {
hgs
parents:
diff changeset
    77
        error  = KErrNoMemory;
hgs
parents:
diff changeset
    78
        }
hgs
parents:
diff changeset
    79
    
hgs
parents:
diff changeset
    80
    // Call next phase of startup.
hgs
parents:
diff changeset
    81
    if( !error )
hgs
parents:
diff changeset
    82
        {
hgs
parents:
diff changeset
    83
        TRAP( error, RunAppL() );
hgs
parents:
diff changeset
    84
        }
hgs
parents:
diff changeset
    85
    
hgs
parents:
diff changeset
    86
    // Cleanup.
hgs
parents:
diff changeset
    87
    delete cleanupstack;
hgs
parents:
diff changeset
    88
    cleanupstack = NULL;
hgs
parents:
diff changeset
    89
    
hgs
parents:
diff changeset
    90
    __UHEAP_MARKEND;
hgs
parents:
diff changeset
    91
    
hgs
parents:
diff changeset
    92
    return error;
hgs
parents:
diff changeset
    93
    }
hgs
parents:
diff changeset
    94
#endif //HOMESCREEN_TEST
hgs
parents:
diff changeset
    95
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
    96
#pragma CTC ENDSKIP
hgs
parents:
diff changeset
    97
#endif //COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
    98
// ========================= MEMBER FUNCTIONS ==================================
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   101
// CHsLaunch::NewL()
hgs
parents:
diff changeset
   102
// Two-phased constructor.
hgs
parents:
diff changeset
   103
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   104
CHsLaunch* CHsLaunch::NewL()
hgs
parents:
diff changeset
   105
    {
hgs
parents:
diff changeset
   106
    CHsLaunch* self = new ( ELeave ) CHsLaunch();
hgs
parents:
diff changeset
   107
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
   108
    self->ConstructL();
hgs
parents:
diff changeset
   109
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
   110
    return self;
hgs
parents:
diff changeset
   111
    }
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   114
// CHsLaunch::ConstructL()
hgs
parents:
diff changeset
   115
// Symbian 2nd phase constructor can leave.
hgs
parents:
diff changeset
   116
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   117
//
hgs
parents:
diff changeset
   118
void CHsLaunch::ConstructL()
hgs
parents:
diff changeset
   119
    {
hgs
parents:
diff changeset
   120
    iRepository = CRepository::NewL(TUid::Uid(0x2002b3aa));
hgs
parents:
diff changeset
   121
    
hgs
parents:
diff changeset
   122
    iShutdownMonitor = CHsShutdownMonitor::NewL( *this );
hgs
parents:
diff changeset
   123
    iShutdownMonitor->StartMonitor();
hgs
parents:
diff changeset
   124
    
hgs
parents:
diff changeset
   125
    // Create property to pub/sub.    
hgs
parents:
diff changeset
   126
    TInt error = RProperty::Define( KPSCrashCountKey,
hgs
parents:
diff changeset
   127
                                    RProperty::EInt,
hgs
parents:
diff changeset
   128
                                    KPSReadPolicy,
hgs
parents:
diff changeset
   129
                                    KPSWritePolicy );    
hgs
parents:
diff changeset
   130
    if( error == KErrNone )
hgs
parents:
diff changeset
   131
        {
hgs
parents:
diff changeset
   132
        // Init it to zero.
hgs
parents:
diff changeset
   133
        error = RProperty::Set( KPSCategoryUid, KPSCrashCountKey, 0 );
hgs
parents:
diff changeset
   134
        }                
hgs
parents:
diff changeset
   135
    else if( error == KErrAlreadyExists )
hgs
parents:
diff changeset
   136
        {
hgs
parents:
diff changeset
   137
        error = KErrNone;        
hgs
parents:
diff changeset
   138
        }        
hgs
parents:
diff changeset
   139
    
hgs
parents:
diff changeset
   140
    User::LeaveIfError( error );
hgs
parents:
diff changeset
   141
    }
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   144
// CHsLaunch::CHsLaunch()
hgs
parents:
diff changeset
   145
// C++ default constructor can NOT contain any code, that might leave.
hgs
parents:
diff changeset
   146
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   147
CHsLaunch::CHsLaunch() :
hgs
parents:
diff changeset
   148
        CActive( EPriorityStandard ),
hgs
parents:
diff changeset
   149
        iApplicationReturnValue( KErrNone )
hgs
parents:
diff changeset
   150
    {
hgs
parents:
diff changeset
   151
    CActiveScheduler::Add( this );
hgs
parents:
diff changeset
   152
    }
hgs
parents:
diff changeset
   153
hgs
parents:
diff changeset
   154
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   155
// CHsLaunch::~CHsLaunch()
hgs
parents:
diff changeset
   156
// Destructor.
hgs
parents:
diff changeset
   157
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   158
//
hgs
parents:
diff changeset
   159
CHsLaunch::~CHsLaunch()
hgs
parents:
diff changeset
   160
    {
hgs
parents:
diff changeset
   161
    Cancel();
hgs
parents:
diff changeset
   162
    
hgs
parents:
diff changeset
   163
    delete iRepository;
hgs
parents:
diff changeset
   164
    iRepository = NULL;
hgs
parents:
diff changeset
   165
    
hgs
parents:
diff changeset
   166
    delete iProcessMonitor;
hgs
parents:
diff changeset
   167
    iProcessMonitor = NULL;
hgs
parents:
diff changeset
   168
    
hgs
parents:
diff changeset
   169
    delete iShutdownMonitor;
hgs
parents:
diff changeset
   170
    iShutdownMonitor = NULL;
hgs
parents:
diff changeset
   171
    }
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   174
// CHsLaunch::Activate()
hgs
parents:
diff changeset
   175
// Set active object to be ran
hgs
parents:
diff changeset
   176
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   177
//
hgs
parents:
diff changeset
   178
void CHsLaunch::Activate()
hgs
parents:
diff changeset
   179
    {   
hgs
parents:
diff changeset
   180
    SetActive();
hgs
parents:
diff changeset
   181
    TRequestStatus* tmp = &iStatus;
hgs
parents:
diff changeset
   182
    User::RequestComplete( tmp, KErrNone );
hgs
parents:
diff changeset
   183
    }
hgs
parents:
diff changeset
   184
hgs
parents:
diff changeset
   185
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   186
// CHsLaunch::ApplicationReturnValue()
hgs
parents:
diff changeset
   187
// Get application return value
hgs
parents:
diff changeset
   188
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   189
//
hgs
parents:
diff changeset
   190
TInt CHsLaunch::ApplicationReturnValue()
hgs
parents:
diff changeset
   191
    {
hgs
parents:
diff changeset
   192
    return iApplicationReturnValue;
hgs
parents:
diff changeset
   193
    }
hgs
parents:
diff changeset
   194
hgs
parents:
diff changeset
   195
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   196
// CHsLaunch::RunL
hgs
parents:
diff changeset
   197
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   198
//
hgs
parents:
diff changeset
   199
void CHsLaunch::RunL()
hgs
parents:
diff changeset
   200
    {
hgs
parents:
diff changeset
   201
#if defined( __WINS__ )
hgs
parents:
diff changeset
   202
    StartHomeScreen();
hgs
parents:
diff changeset
   203
#else 
hgs
parents:
diff changeset
   204
    if (IsLanguageSelectedL()) 
hgs
parents:
diff changeset
   205
        {
hgs
parents:
diff changeset
   206
        StartHomeScreen();
hgs
parents:
diff changeset
   207
        } 
hgs
parents:
diff changeset
   208
    else 
hgs
parents:
diff changeset
   209
        {
hgs
parents:
diff changeset
   210
        StartListeningLanguageSelectionL();
hgs
parents:
diff changeset
   211
        }
hgs
parents:
diff changeset
   212
#endif //__WINS__
hgs
parents:
diff changeset
   213
    }
hgs
parents:
diff changeset
   214
hgs
parents:
diff changeset
   215
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   216
// CHsLaunch::DoCancel()
hgs
parents:
diff changeset
   217
// From CActive.
hgs
parents:
diff changeset
   218
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   219
//
hgs
parents:
diff changeset
   220
void CHsLaunch::DoCancel()
hgs
parents:
diff changeset
   221
    {
hgs
parents:
diff changeset
   222
    if( iProcessMonitor )
hgs
parents:
diff changeset
   223
        {
hgs
parents:
diff changeset
   224
        iProcessMonitor->Cancel();
hgs
parents:
diff changeset
   225
        }
hgs
parents:
diff changeset
   226
    
hgs
parents:
diff changeset
   227
    if( iShutdownMonitor )
hgs
parents:
diff changeset
   228
        {
hgs
parents:
diff changeset
   229
        iShutdownMonitor->Cancel();
hgs
parents:
diff changeset
   230
        }
hgs
parents:
diff changeset
   231
    }      
hgs
parents:
diff changeset
   232
hgs
parents:
diff changeset
   233
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   234
// CHsLaunch::RunError()
hgs
parents:
diff changeset
   235
// From CActive.
hgs
parents:
diff changeset
   236
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   237
//
hgs
parents:
diff changeset
   238
TInt CHsLaunch::RunError( TInt aError )
hgs
parents:
diff changeset
   239
    {
hgs
parents:
diff changeset
   240
    /* Shutdown. This application
hgs
parents:
diff changeset
   241
     * will be restarted by startup sw. */
hgs
parents:
diff changeset
   242
    ShutdownApp( KErrGeneral );
hgs
parents:
diff changeset
   243
    return KErrNone;
hgs
parents:
diff changeset
   244
    } 
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   247
// CHsLaunch::HandleNotifyInt()
hgs
parents:
diff changeset
   248
// From MCenRepNotifyHandlerCallback
hgs
parents:
diff changeset
   249
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   250
//
hgs
parents:
diff changeset
   251
void CHsLaunch::HandleNotifyInt(TUint32 aId, TInt aNewValue)
hgs
parents:
diff changeset
   252
{
hgs
parents:
diff changeset
   253
    if (aId == 0x00000007 && aNewValue) 
hgs
parents:
diff changeset
   254
        {
hgs
parents:
diff changeset
   255
        StopListeningLanguageSelection();
hgs
parents:
diff changeset
   256
        StartHomeScreen();
hgs
parents:
diff changeset
   257
        }
hgs
parents:
diff changeset
   258
}
hgs
parents:
diff changeset
   259
hgs
parents:
diff changeset
   260
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   261
// CHsLaunch::ProcessEndedL()
hgs
parents:
diff changeset
   262
// From MHsProcessMonitorObserver
hgs
parents:
diff changeset
   263
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   264
//
hgs
parents:
diff changeset
   265
void CHsLaunch::ProcessEnded( const TExitType& aExitType,
hgs
parents:
diff changeset
   266
                              const TInt aExitReason,
hgs
parents:
diff changeset
   267
                              const TExitCategoryName& /*aExitCategory*/ )
hgs
parents:
diff changeset
   268
    {    
hgs
parents:
diff changeset
   269
    TInt crashCount = 0;
hgs
parents:
diff changeset
   270
    TInt error = RProperty::Get( KPSCategoryUid,
hgs
parents:
diff changeset
   271
                                 KPSCrashCountKey,
hgs
parents:
diff changeset
   272
                                 crashCount );
hgs
parents:
diff changeset
   273
    
hgs
parents:
diff changeset
   274
    // increment crash count in cenrep if the process has panic'd or killed with
hgs
parents:
diff changeset
   275
    // an error code
hgs
parents:
diff changeset
   276
    if( aExitType == EExitPanic ||
hgs
parents:
diff changeset
   277
        ( aExitType == EExitKill && aExitReason != KErrNone ) )
hgs
parents:
diff changeset
   278
        {
hgs
parents:
diff changeset
   279
        if( error == KErrNone )
hgs
parents:
diff changeset
   280
            {
hgs
parents:
diff changeset
   281
            crashCount++;
hgs
parents:
diff changeset
   282
            error = RProperty::Set( KPSCategoryUid,
hgs
parents:
diff changeset
   283
                                    KPSCrashCountKey,
hgs
parents:
diff changeset
   284
                                    crashCount );                          
hgs
parents:
diff changeset
   285
            }
hgs
parents:
diff changeset
   286
        
hgs
parents:
diff changeset
   287
        if( error == KErrNone )
hgs
parents:
diff changeset
   288
            {      
hgs
parents:
diff changeset
   289
            User::After( KSleepOnRetry ); 
hgs
parents:
diff changeset
   290
            Activate();
hgs
parents:
diff changeset
   291
            }
hgs
parents:
diff changeset
   292
        else
hgs
parents:
diff changeset
   293
            {           
hgs
parents:
diff changeset
   294
            ShutdownApp( error );
hgs
parents:
diff changeset
   295
            }
hgs
parents:
diff changeset
   296
        }
hgs
parents:
diff changeset
   297
    }
hgs
parents:
diff changeset
   298
hgs
parents:
diff changeset
   299
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   300
// CHsLaunch::ProcessMonitoringErrorL()
hgs
parents:
diff changeset
   301
// From MHsProcessMonitorObserver
hgs
parents:
diff changeset
   302
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   303
//
hgs
parents:
diff changeset
   304
void CHsLaunch::ProcessMonitoringError( TInt aError )
hgs
parents:
diff changeset
   305
    {
hgs
parents:
diff changeset
   306
    /* Error in this method is critical and it might cause
hgs
parents:
diff changeset
   307
     * endless active scheduler loop if no active objects are
hgs
parents:
diff changeset
   308
     * not triggered. Therefore shutdown. This application
hgs
parents:
diff changeset
   309
     * will be restarted by startup sw. */
hgs
parents:
diff changeset
   310
    ShutdownApp( aError );
hgs
parents:
diff changeset
   311
    }
hgs
parents:
diff changeset
   312
hgs
parents:
diff changeset
   313
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   314
// CHsLaunch::SystemShutdownEvent()
hgs
parents:
diff changeset
   315
// From MHsShutdownMonitorObserver
hgs
parents:
diff changeset
   316
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   317
//
hgs
parents:
diff changeset
   318
void CHsLaunch::SystemShutdownEvent()
hgs
parents:
diff changeset
   319
    {
hgs
parents:
diff changeset
   320
    // Do not shut down app. Startup app would try to restart this app.
hgs
parents:
diff changeset
   321
    // Just deactivate all active objects and wait for power off.
hgs
parents:
diff changeset
   322
    if( IsActive() )
hgs
parents:
diff changeset
   323
        {
hgs
parents:
diff changeset
   324
        Cancel();
hgs
parents:
diff changeset
   325
        }
hgs
parents:
diff changeset
   326
    else
hgs
parents:
diff changeset
   327
        {
hgs
parents:
diff changeset
   328
        DoCancel();
hgs
parents:
diff changeset
   329
        }    
hgs
parents:
diff changeset
   330
    }
hgs
parents:
diff changeset
   331
hgs
parents:
diff changeset
   332
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   333
// CHsLaunch::InitProcessMonitorL()
hgs
parents:
diff changeset
   334
// Initialize process monitor
hgs
parents:
diff changeset
   335
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   336
//
hgs
parents:
diff changeset
   337
void CHsLaunch::InitProcessMonitorL( const TInt aProcessId )
hgs
parents:
diff changeset
   338
    {
hgs
parents:
diff changeset
   339
    if( iProcessMonitor )
hgs
parents:
diff changeset
   340
        {
hgs
parents:
diff changeset
   341
        delete iProcessMonitor;
hgs
parents:
diff changeset
   342
        iProcessMonitor = NULL;
hgs
parents:
diff changeset
   343
        }
hgs
parents:
diff changeset
   344
    iProcessMonitor = CHsProcessMonitor::NewL( aProcessId, *this );    
hgs
parents:
diff changeset
   345
    User::LeaveIfError( iProcessMonitor->StartMonitor() );
hgs
parents:
diff changeset
   346
    }
hgs
parents:
diff changeset
   347
hgs
parents:
diff changeset
   348
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   349
// CHsLaunch::ShutdownApp()
hgs
parents:
diff changeset
   350
// Shut down application
hgs
parents:
diff changeset
   351
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   352
//
hgs
parents:
diff changeset
   353
void CHsLaunch::ShutdownApp( const TInt aApplicationReturnValue )
hgs
parents:
diff changeset
   354
    {
hgs
parents:
diff changeset
   355
    if( IsActive() )
hgs
parents:
diff changeset
   356
        {
hgs
parents:
diff changeset
   357
        Cancel();
hgs
parents:
diff changeset
   358
        }
hgs
parents:
diff changeset
   359
    else
hgs
parents:
diff changeset
   360
        {
hgs
parents:
diff changeset
   361
        DoCancel();
hgs
parents:
diff changeset
   362
        }
hgs
parents:
diff changeset
   363
    
hgs
parents:
diff changeset
   364
    iApplicationReturnValue = aApplicationReturnValue;
hgs
parents:
diff changeset
   365
#ifndef HOMESCREEN_TEST    
hgs
parents:
diff changeset
   366
    CActiveScheduler::Stop();
hgs
parents:
diff changeset
   367
#endif //HOMESCREEN_TEST
hgs
parents:
diff changeset
   368
    }
hgs
parents:
diff changeset
   369
hgs
parents:
diff changeset
   370
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   371
// CHsLaunch::StartHomeScreen()
hgs
parents:
diff changeset
   372
// Starts the homescreen application.
hgs
parents:
diff changeset
   373
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   374
//
hgs
parents:
diff changeset
   375
void CHsLaunch::StartHomeScreen()
hgs
parents:
diff changeset
   376
    {
hgs
parents:
diff changeset
   377
    // Create app or connect to existing.
hgs
parents:
diff changeset
   378
    TInt processExisted = EFalse;
hgs
parents:
diff changeset
   379
    
hgs
parents:
diff changeset
   380
    RProcess process;
hgs
parents:
diff changeset
   381
    TInt processError = process.Create( KHsExeName, KNullDesC );    
hgs
parents:
diff changeset
   382
    if( processError == KErrAlreadyExists )
hgs
parents:
diff changeset
   383
        {        
hgs
parents:
diff changeset
   384
        processError = process.Open( KHsProcessName, EOwnerProcess );
hgs
parents:
diff changeset
   385
        processExisted = ETrue;
hgs
parents:
diff changeset
   386
        }
hgs
parents:
diff changeset
   387
    TInt monitorError = KErrNone;
hgs
parents:
diff changeset
   388
    if( processError == KErrNone )
hgs
parents:
diff changeset
   389
        {
hgs
parents:
diff changeset
   390
        TRAP( monitorError, InitProcessMonitorL( process.Id() ) );
hgs
parents:
diff changeset
   391
        }
hgs
parents:
diff changeset
   392
    
hgs
parents:
diff changeset
   393
    if( processError == KErrNone &&
hgs
parents:
diff changeset
   394
        !processExisted )
hgs
parents:
diff changeset
   395
        {
hgs
parents:
diff changeset
   396
        // Make sure process is started even if monitor startup
hgs
parents:
diff changeset
   397
        // fails. This will assure that process is not left in
hgs
parents:
diff changeset
   398
        // suspended state. Resume can not be called for
hgs
parents:
diff changeset
   399
        // already running process (will cause KERN-EXEC 46).
hgs
parents:
diff changeset
   400
        process.Resume();
hgs
parents:
diff changeset
   401
        }
hgs
parents:
diff changeset
   402
                     
hgs
parents:
diff changeset
   403
    process.Close();
hgs
parents:
diff changeset
   404
    
hgs
parents:
diff changeset
   405
    if( processError != KErrNone ||
hgs
parents:
diff changeset
   406
        monitorError != KErrNone )
hgs
parents:
diff changeset
   407
        {
hgs
parents:
diff changeset
   408
        /* Error in this method is critical and it might cause
hgs
parents:
diff changeset
   409
         * endless active scheduler loop if no active objects are
hgs
parents:
diff changeset
   410
         * not triggered. Therefore shutdown. This application
hgs
parents:
diff changeset
   411
         * will be restarted by startup sw. */
hgs
parents:
diff changeset
   412
        ShutdownApp( KErrGeneral );
hgs
parents:
diff changeset
   413
        }
hgs
parents:
diff changeset
   414
    }
hgs
parents:
diff changeset
   415
        
hgs
parents:
diff changeset
   416
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   417
// CHsLaunch::IsLanguageSelected()
hgs
parents:
diff changeset
   418
// Checks if the language is selected.
hgs
parents:
diff changeset
   419
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   420
//  
hgs
parents:
diff changeset
   421
TBool CHsLaunch::IsLanguageSelectedL()
hgs
parents:
diff changeset
   422
    {
hgs
parents:
diff changeset
   423
    TInt value;
hgs
parents:
diff changeset
   424
    User::LeaveIfError(iRepository->Get(0x00000007, value));
hgs
parents:
diff changeset
   425
    return value;
hgs
parents:
diff changeset
   426
    }
hgs
parents:
diff changeset
   427
hgs
parents:
diff changeset
   428
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   429
// CHsLaunch::StartListeningLanguageSelection()
hgs
parents:
diff changeset
   430
// Starts to listen repository notifications.
hgs
parents:
diff changeset
   431
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   432
//  
hgs
parents:
diff changeset
   433
void CHsLaunch::StartListeningLanguageSelectionL()
hgs
parents:
diff changeset
   434
    {
hgs
parents:
diff changeset
   435
    iCenRepNotifyHandler = CCenRepNotifyHandler::NewL(
hgs
parents:
diff changeset
   436
            *this, *iRepository, CCenRepNotifyHandler::EIntKey, 0x00000007);
hgs
parents:
diff changeset
   437
    iCenRepNotifyHandler->StartListeningL();
hgs
parents:
diff changeset
   438
    }
hgs
parents:
diff changeset
   439
        
hgs
parents:
diff changeset
   440
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   441
// CHsLaunch::StopListeningLanguageSelection()
hgs
parents:
diff changeset
   442
// Stops to listen repository notifications.
hgs
parents:
diff changeset
   443
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   444
//      
hgs
parents:
diff changeset
   445
void CHsLaunch::StopListeningLanguageSelection()
hgs
parents:
diff changeset
   446
    {
hgs
parents:
diff changeset
   447
    iCenRepNotifyHandler->StopListening();
hgs
parents:
diff changeset
   448
    delete iCenRepNotifyHandler;
hgs
parents:
diff changeset
   449
    iCenRepNotifyHandler = NULL;
hgs
parents:
diff changeset
   450
    }
hgs
parents:
diff changeset
   451
hgs
parents:
diff changeset
   452
// End of File