dbcreator/commsdatcreatorrfsplugin/src/cdcprocesslauncher.cpp
changeset 0 5a93021fdf25
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:   Implementation of CCdcProcessLauncher class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "cdcprocesslauncher.h"
       
    21 #include "cdclogger.h"
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CCdcProcessLauncher::NewL
       
    27 // Two-phased constructor.
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CCdcProcessLauncher* CCdcProcessLauncher::NewL()
       
    31     {
       
    32     CCdcProcessLauncher* self = new( ELeave ) CCdcProcessLauncher();
       
    33 
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop( self );
       
    37 
       
    38     return self;
       
    39     }
       
    40 
       
    41 
       
    42 // Destructor
       
    43 CCdcProcessLauncher::~CCdcProcessLauncher()
       
    44     {
       
    45     iProcess.Close();
       
    46     Cancel();
       
    47     }
       
    48 
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CCdcProcessLauncher::Launch()
       
    52 //
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CCdcProcessLauncher::Launch()
       
    56     {
       
    57     CLOG_WRITE( "CCdcProcessLauncher::Launch" );
       
    58 
       
    59     // Exe name and empty parameters
       
    60 	_LIT( KProcess, "commsdatstartup.exe" );
       
    61     _LIT( KEmpty, "" );
       
    62     	
       
    63     TInt errorCode = iProcess.Create(KProcess, KEmpty); 
       
    64 
       
    65     CLOG_WRITE_FORMAT( "CCdcCommsDatCreatorRfsPlugin::process.Create result: %d", errorCode );
       
    66 	
       
    67     if ( errorCode == KErrNone )
       
    68         {
       
    69         LaunchProcess();
       
    70         }
       
    71     else
       
    72         {
       
    73         CLOG_WRITE( "Failed to creating process" );
       
    74         }
       
    75 
       
    76     CLOG_WRITE( "CCdcProcessLauncher::Launch" );
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCdcProcessLauncher::CCdcProcessLauncher
       
    82 // C++ default constructor can NOT contain any code, that
       
    83 // might leave.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CCdcProcessLauncher::CCdcProcessLauncher()
       
    87   : CActive( EPriorityStandard )
       
    88     {
       
    89     CActiveScheduler::Add( this );
       
    90     }
       
    91 
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CCdcProcessLauncher::ConstructL
       
    95 // Symbian 2nd phase constructor can leave.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CCdcProcessLauncher::ConstructL()
       
    99     {
       
   100     iProcess.SetHandle( NULL );
       
   101     }
       
   102 
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CCdcProcessLauncher::DoCancel
       
   106 //
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CCdcProcessLauncher::DoCancel()
       
   110     {
       
   111     CLOG_WRITE( "CCdcProcessLauncher::DoCancel" );
       
   112 
       
   113     if ( iProcess.Handle() )
       
   114         {
       
   115         iProcess.RendezvousCancel( iStatus );
       
   116         iProcess.Close();
       
   117         }
       
   118 
       
   119     iWait.AsyncStop();
       
   120 
       
   121     CLOG_WRITE( "CCdcProcessLauncher::DoCancel" );
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCdcProcessLauncher::RunL
       
   127 //
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CCdcProcessLauncher::RunL()
       
   131     {
       
   132     CLOG_WRITE( "CCdcProcessLauncher::RunL" );
       
   133     ASSERT( iProcess.Handle() );
       
   134 
       
   135     if ( iProcess.ExitType() == EExitPanic )
       
   136         {
       
   137         iProcess.ExitReason();
       
   138         }
       
   139     else
       
   140         {
       
   141         iStatus.Int();
       
   142         }
       
   143     
       
   144     iWait.AsyncStop();
       
   145 
       
   146     CLOG_WRITE( "CCdcProcessLauncher::RunL" );
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CCdcProcessLauncher::Launch()
       
   151 //
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CCdcProcessLauncher::LaunchProcess()
       
   155     {
       
   156     CLOG_WRITE( "CCdcProcessLauncher::Launch" );
       
   157 
       
   158     ASSERT( !IsActive() );
       
   159     ASSERT( iProcess.Handle() );
       
   160 
       
   161     iProcess.Rendezvous( iStatus );
       
   162 
       
   163     if( iStatus == KRequestPending )
       
   164         {
       
   165         CLOG_WRITE( "CCdcProcessLauncher::Resume" );
       
   166         iProcess.Resume();
       
   167         CLOG_WRITE( "CCdcProcessLauncher::SetActive" );
       
   168         SetActive();
       
   169         CLOG_WRITE( "CCdcProcessLauncher::Start waiter" );
       
   170         iWait.Start();
       
   171         }
       
   172     else
       
   173         {
       
   174         CLOG_WRITE( "Failed to make rendezvous with process, killing it" );
       
   175         iProcess.Kill( KErrGeneral );
       
   176         }
       
   177 
       
   178     CLOG_WRITE( "CCdcProcessLauncher::Launch end" );
       
   179     }
       
   180 
       
   181