dbgagents/trkagent/toolsstarter/toolsstarterserver/autolaunch/src/toolsstarteruiobserver.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32debug.h>
       
    20 #include <ActiveIdle2DomainPSKeys.h>
       
    21 #include <e32property.h>
       
    22 
       
    23 #include "logging.h"
       
    24 #include "toolsstarteruiobserver.h"
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // Constructor
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 CToolsStarterIdleObserver::CToolsStarterIdleObserver(MToolsStarterIdleObserver& aObserver) :
       
    36     CActive(EPriorityStandard), // Standard priority
       
    37     iObserver(aObserver)
       
    38     {
       
    39     }
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // Two-phased constructor
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 CToolsStarterIdleObserver* CToolsStarterIdleObserver::NewL(MToolsStarterIdleObserver& aObserver)
       
    46     {
       
    47     CToolsStarterIdleObserver* self = new(ELeave) CToolsStarterIdleObserver(aObserver);
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop(self);
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // 2nd phase construction
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 void CToolsStarterIdleObserver::ConstructL()
       
    59     {
       
    60     CActiveScheduler::Add(this);
       
    61     
       
    62     // attach to the property which listens the idle state
       
    63     User::LeaveIfError( iProperty.Attach( KPSUidAiInformation, KActiveIdleState ) );
       
    64     
       
    65     LOG_MSG("CToolsStarterIdleObserver::ConstructL succesfully attached to property");
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // Destructor
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CToolsStarterIdleObserver::~CToolsStarterIdleObserver()
       
    73     {
       
    74     Cancel();
       
    75     iProperty.Close();
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // Starts listening for events
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 void CToolsStarterIdleObserver::StartL()
       
    83     {
       
    84     Cancel();
       
    85     
       
    86     // subscribe to the property
       
    87     iProperty.Subscribe(iStatus);
       
    88     SetActive();
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // Implements cancellation of an outstanding request.
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 void CToolsStarterIdleObserver::DoCancel()
       
    96     {
       
    97     iProperty.Cancel();
       
    98     }
       
    99 
       
   100 // ----------------------------------------------------------------------------
       
   101 // Handles an active object's request completion event.
       
   102 // ----------------------------------------------------------------------------
       
   103 //
       
   104 void CToolsStarterIdleObserver::RunL()
       
   105     {
       
   106     // check the status
       
   107     TInt idleStatus(KErrNotFound);
       
   108     TInt err( iStatus.Int() );
       
   109     
       
   110     if (err == KErrNone)
       
   111         {
       
   112         // resubscribe before processing new value to prevent missing updates
       
   113         StartL();
       
   114         err = iProperty.Get( KPSUidAiInformation, KActiveIdleState, idleStatus );
       
   115         
       
   116         if (err == KErrNone && idleStatus == EPSAiForeground) 
       
   117             {
       
   118             LOG_MSG("CToolsStarterIdleObserver::RunL idle foreground state detected");
       
   119 
       
   120             // idle state is active so notify the observer and no need to wait anymore
       
   121             iObserver.IdleStateActivated();
       
   122             Cancel();
       
   123             }
       
   124         else
       
   125             {
       
   126             LOG_MSG2("CToolsStarterIdleObserver::RunL unknown state %d", idleStatus);
       
   127             }
       
   128         }
       
   129 
       
   130     else if (err != KErrCancel)
       
   131         {
       
   132         // try again..
       
   133         StartL();
       
   134         } 
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 
       
   139 // End of File