omadrm/drmengine/utils/src/procwatcher.cpp
changeset 0 95b198f216e5
child 84 b09186059647
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2005 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 the process watcher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32def.h>
       
    20 #include <e32base.h>
       
    21 #include <f32file.h>
       
    22 #include <sysutil.h>
       
    23 #include "procwatcher.h"
       
    24 #include "drmlog.h"
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 void CProcWatcher::ConstructL( const TDesC& aProcess, const TDesC& aFile )
       
    29     {
       
    30     DRMLOG( _L( "CProcWatcher::ConstructL <-" ) );
       
    31 
       
    32     iProcessName.Copy( aProcess );
       
    33     iFileName.Copy( aFile );
       
    34     CActiveScheduler::Add( this );
       
    35     
       
    36     DRMLOG( _L( "CProcWatcher::ConstructL ->" ) );
       
    37     }
       
    38 
       
    39 CProcWatcher* CProcWatcher::NewL( MWatcherObserver& aObserver, const TDesC& aProcess, const TDesC& aFile )
       
    40     {
       
    41     CProcWatcher* self = new( ELeave ) CProcWatcher( aObserver);
       
    42     self->ConstructL( aProcess, aFile );
       
    43     return self;
       
    44     }
       
    45 
       
    46 CProcWatcher::CProcWatcher( MWatcherObserver& aObserver ):
       
    47     CActive( EPriorityStandard ),
       
    48     iObserver( aObserver )
       
    49     {
       
    50     DRMLOG( _L( "CProcWatcher::CProcWatcher ->" ) );
       
    51     DRMLOG( _L( "CProcWatcher::CProcWatcher <-" ) );
       
    52     }
       
    53 
       
    54 CProcWatcher::~CProcWatcher()
       
    55     {
       
    56     DRMLOG( _L( "CProcWatcher::~CProcWatcher ->" ) );
       
    57     
       
    58     Cancel();
       
    59     
       
    60     DRMLOG( _L( "CProcWatcher::~CProcWatcher <-" ) );
       
    61     }
       
    62 
       
    63 TInt CProcWatcher::StartWatching()
       
    64     {
       
    65     TFullName name;
       
    66     TFindProcess finder( iProcessName );
       
    67     TInt r = KErrNone;
       
    68     
       
    69     DRMLOG( _L( "CProcWatcher::StartWatching ->" ) );
       
    70     DRMLOG( iProcessName );
       
    71     
       
    72     r = finder.Next( name );
       
    73     if ( r != KErrNone )
       
    74         {
       
    75         r = iProcess.Create( iFileName, KNullDesC );
       
    76         if ( r == KErrNone )
       
    77             {
       
    78             iProcess.Resume();
       
    79             }
       
    80         }
       
    81     else
       
    82         {
       
    83         iProcessName.Copy( name );
       
    84         DRMLOG( iProcessName );
       
    85         r = iProcess.Open( iProcessName );
       
    86         }
       
    87         
       
    88     if ( r == KErrNone )
       
    89         {
       
    90         iProcess.Logon( iStatus );
       
    91         SetActive();
       
    92         DRMLOG( _L( "Active " ) );
       
    93         }
       
    94 
       
    95     DRMLOG( _L( "CProcWatcher::StartWatching <-" ) );
       
    96     return r;
       
    97     }
       
    98     
       
    99 void CProcWatcher::DoCancel()
       
   100     {
       
   101     DRMLOG( _L( "CProcWatcher::DoCancel ->" ) );
       
   102     
       
   103     DRMLOG( _L( "CProcWatcher::DoCancel <-" ) );
       
   104     }
       
   105     
       
   106 void CProcWatcher::RunL()
       
   107     {
       
   108     TBuf<256> logBuffer;
       
   109     TFileName object;
       
   110     
       
   111     DRMLOG( _L( "CProcWatcher::RunL ->" ) );
       
   112     
       
   113     DRMLOG( iProcessName );
       
   114     logBuffer.AppendNum( iStatus.Int() );
       
   115     logBuffer.Append( ' ' );
       
   116     logBuffer.AppendNum( iProcess.ExitType() );
       
   117     DRMLOG( logBuffer );
       
   118     if ( iProcess.ExitType() != EExitPending )
       
   119         {
       
   120         object.Copy( KProcIdentifier );
       
   121         object.Append( iProcessName );
       
   122         iObserver.WatchedObjectChangedL( object );
       
   123         }
       
   124     else
       
   125         {
       
   126         if ( iProcess.Open( iProcessName ) == KErrNone )
       
   127             {
       
   128             iProcess.Logon( iStatus );
       
   129             }
       
   130         }
       
   131     SetActive();
       
   132     
       
   133     DRMLOG( _L( "CProcWatcher::RunL <-" ) );
       
   134     }