imagehandlingutilities/thumbnailmanager/tmcommon/src/tmactivitymanager.cpp
branchRCL_3
changeset 22 9d4d3445ce6e
parent 21 6257223ede8a
equal deleted inserted replaced
21:6257223ede8a 22:9d4d3445ce6e
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "tmactivitymanager.h"
    18 #include "tmactivitymanager.h"
    19 #include "thumbnaillog.h"
    19 #include "thumbnaillog.h"
    20 #include "OstTraceDefinitions.h"
       
    21 #ifdef OST_TRACE_COMPILER_IN_USE
       
    22 #include "tmactivitymanagerTraces.h"
       
    23 #endif
       
    24 
    20 
    25 // ---------------------------------------------------------------------------
    21 // ---------------------------------------------------------------------------
    26 // CTMActivityManager::NewL()
    22 // CTMActivityManager::NewL()
    27 // ---------------------------------------------------------------------------
    23 // ---------------------------------------------------------------------------
    28 //
    24 //
    29 CTMActivityManager* CTMActivityManager::NewL(MTMActivityManagerObserver* aObserver, TInt aTimeout)
    25 CTMActivityManager* CTMActivityManager::NewL(MTMActivityManagerObserver* aObserver, TInt aTimeout)
    30     {
    26     {
    31     TN_DEBUG1( "CTMActivityManager::NewL()");
    27     TN_DEBUG1( "CTMActivityManager::NewL()");
    32     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_NEWL, "CTMActivityManager::NewL" );
       
    33     
    28     
    34     CTMActivityManager* self = new (ELeave) CTMActivityManager(aObserver, aTimeout);
    29     CTMActivityManager* self = new (ELeave) CTMActivityManager(aObserver, aTimeout);
    35     CleanupStack::PushL(self);
    30     CleanupStack::PushL(self);
    36     self->ConstructL();
    31     self->ConstructL();
    37     CleanupStack::Pop(self);
    32     CleanupStack::Pop(self);
    44 //
    39 //
    45 CTMActivityManager::CTMActivityManager(MTMActivityManagerObserver* aObserver, TInt aTimeout)
    40 CTMActivityManager::CTMActivityManager(MTMActivityManagerObserver* aObserver, TInt aTimeout)
    46 : CActive(CActive::EPriorityHigh), iObserver(aObserver), iTimeout(aTimeout), iPreviousStatus(KErrNotFound)
    41 : CActive(CActive::EPriorityHigh), iObserver(aObserver), iTimeout(aTimeout), iPreviousStatus(KErrNotFound)
    47     {
    42     {
    48     TN_DEBUG1( "CTMActivityManager::CTMActivityManager()");
    43     TN_DEBUG1( "CTMActivityManager::CTMActivityManager()");
    49     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_CTMACTIVITYMANAGER, "CTMActivityManager::CTMActivityManager" );
       
    50     
    44     
    51     CActiveScheduler::Add(this);
    45     CActiveScheduler::Add(this);
    52     }
    46     }
    53 
    47 
    54 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    56 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    57 //
    51 //
    58 CTMActivityManager::~CTMActivityManager()
    52 CTMActivityManager::~CTMActivityManager()
    59     {
    53     {
    60     TN_DEBUG1( "CTMActivityManager::~CTMActivityManager()");
    54     TN_DEBUG1( "CTMActivityManager::~CTMActivityManager()");
    61     OstTrace0( TRACE_NORMAL, DUP1_CTMACTIVITYMANAGER_CTMACTIVITYMANAGER, "CTMActivityManager::~CTMActivityManager" );
       
    62     
    55     
    63     iObserver = NULL;
    56     iObserver = NULL;
    64     Cancel();
    57     Cancel();
    65     
    58     
    66 #ifdef MONITOR_LIGHTS
    59 #ifdef MONITOR_LIGHTS
    77 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    78 //
    71 //
    79 void CTMActivityManager::ConstructL()
    72 void CTMActivityManager::ConstructL()
    80     {
    73     {
    81     TN_DEBUG1( "CTMActivityManager::ConstructL()");
    74     TN_DEBUG1( "CTMActivityManager::ConstructL()");
    82     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_CONSTRUCTL, "CTMActivityManager::ConstructL" );
       
    83     
    75     
    84     iTimer.CreateLocal();
    76     iTimer.CreateLocal();
    85     iWatch = ENone;
    77     iWatch = ENone;
    86     }
    78     }
    87 
    79 
    90 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
    91 //
    83 //
    92 void CTMActivityManager::SetTimeout(TInt aTimeout)
    84 void CTMActivityManager::SetTimeout(TInt aTimeout)
    93     {
    85     {
    94     TN_DEBUG1( "CTMActivityManager::SetTimeout()");
    86     TN_DEBUG1( "CTMActivityManager::SetTimeout()");
    95     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_SETTIMEOUT, "CTMActivityManager::SetTimeout" );
       
    96     
    87     
    97     iTimeout = aTimeout;
    88     iTimeout = aTimeout;
    98     Reset();
    89     Reset();
    99     }
    90     }
   100 
    91 
   103 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
   104 //
    95 //
   105 void CTMActivityManager::Reset()
    96 void CTMActivityManager::Reset()
   106     {
    97     {
   107     TN_DEBUG1( "CTMActivityManager::Reset()");
    98     TN_DEBUG1( "CTMActivityManager::Reset()");
   108     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_RESET, "CTMActivityManager::Reset" );
       
   109 
    99 
   110 #ifdef MONITOR_LIGHTS
   100 #ifdef MONITOR_LIGHTS
   111     delete iLight;
   101     delete iLight;
   112     iLight = NULL;
   102     iLight = NULL;
   113 #endif
   103 #endif
   120 // CTMActivityManager::DoCancel()
   110 // CTMActivityManager::DoCancel()
   121 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   122 void CTMActivityManager::DoCancel()
   112 void CTMActivityManager::DoCancel()
   123     {
   113     {
   124     TN_DEBUG1( "CTMActivityManager::DoCancel()");
   114     TN_DEBUG1( "CTMActivityManager::DoCancel()");
   125     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_DOCANCEL, "CTMActivityManager::DoCancel" );
       
   126     
   115     
   127 #ifdef MONITOR_LIGHTS
   116 #ifdef MONITOR_LIGHTS
   128     delete iLight;
   117     delete iLight;
   129     iLight = NULL;
   118     iLight = NULL;
   130 #endif
   119 #endif
   138 // ---------------------------------------------------------------------------
   127 // ---------------------------------------------------------------------------
   139 //
   128 //
   140 void CTMActivityManager::Start()
   129 void CTMActivityManager::Start()
   141     {
   130     {
   142     TN_DEBUG1( "CTMActivityManager::Start()");
   131     TN_DEBUG1( "CTMActivityManager::Start()");
   143     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_START, "CTMActivityManager::Start" );
       
   144     
   132     
   145 #ifdef MONITOR_LIGHTS
   133 #ifdef MONITOR_LIGHTS
   146     if(!iLight)
   134     if(!iLight)
   147         {
   135         {
   148         TRAP_IGNORE(iLight = CHWRMLight::NewL(this));
   136         TRAP_IGNORE(iLight = CHWRMLight::NewL(this));
   167 // ---------------------------------------------------------------------------
   155 // ---------------------------------------------------------------------------
   168 //
   156 //
   169 void CTMActivityManager::RunL()
   157 void CTMActivityManager::RunL()
   170     {
   158     {
   171     TN_DEBUG4( "CTMActivityManager::RunL(0x%08x) %d, observer = 0x%08x", this, iStatus.Int(), iObserver);
   159     TN_DEBUG4( "CTMActivityManager::RunL(0x%08x) %d, observer = 0x%08x", this, iStatus.Int(), iObserver);
   172     OstTrace1( TRACE_NORMAL, CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL;this=%o", this );
       
   173     OstTrace1( TRACE_NORMAL, DUP5_CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL;iStatus.Int()=%d", iStatus.Int() );
       
   174     
   160     
   175     if(iFirstRound)
   161     if(iFirstRound)
   176         {
   162         {
   177         TN_DEBUG1( "CTMActivityManager::RunL() iFirstRound");
   163         TN_DEBUG1( "CTMActivityManager::RunL() iFirstRound");
   178         OstTrace0( TRACE_NORMAL, DUP1_CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL - iFirstRound" );
       
   179         iFirstRound = EFalse;
   164         iFirstRound = EFalse;
   180         if (!IsActive())
   165         if (!IsActive())
   181              {
   166              {
   182              iWatch = EWaitingForInactivity;
   167              iWatch = EWaitingForInactivity;
   183              iTimer.Inactivity(iStatus, iTimeout);
   168              iTimer.Inactivity(iStatus, iTimeout);
   193             {
   178             {
   194             TInt inactivity = User::InactivityTime().Int();
   179             TInt inactivity = User::InactivityTime().Int();
   195             if (inactivity >= iTimeout)
   180             if (inactivity >= iTimeout)
   196                 {
   181                 {
   197                 TN_DEBUG1( "CTMActivityManager::RunL() inactive");
   182                 TN_DEBUG1( "CTMActivityManager::RunL() inactive");
   198                 OstTrace0( TRACE_NORMAL, DUP2_CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL - inactive" );
       
   199                 NotifyObserver();
   183                 NotifyObserver();
   200 
   184 
   201                 if (!IsActive()) //observer might have called a Reset()
   185                 if (!IsActive()) //observer might have called a Reset()
   202                     {
   186                     {
   203                     iTimer.Inactivity(iStatus,0);
   187                     iTimer.Inactivity(iStatus,0);
   210                 }
   194                 }
   211             }
   195             }
   212         else if (iWatch == EWaitingForActivity)
   196         else if (iWatch == EWaitingForActivity)
   213             {
   197             {
   214             TN_DEBUG1( "CTMActivityManager::RunL() active");
   198             TN_DEBUG1( "CTMActivityManager::RunL() active");
   215             OstTrace0( TRACE_NORMAL, DUP3_CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL - active" );
       
   216             NotifyObserver();
   199             NotifyObserver();
   217              
   200              
   218             if (!IsActive()) //observer might have called a Reset()
   201             if (!IsActive()) //observer might have called a Reset()
   219                 {
   202                 {
   220                 iTimer.Inactivity(iStatus,iTimeout);
   203                 iTimer.Inactivity(iStatus,iTimeout);
   230     else
   213     else
   231         {
   214         {
   232         iWatch = ENone;
   215         iWatch = ENone;
   233         }
   216         }
   234         TN_DEBUG1( "CTMActivityManager::RunL() end");
   217         TN_DEBUG1( "CTMActivityManager::RunL() end");
   235         OstTrace0( TRACE_NORMAL, DUP4_CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL - end" );
       
   236     }
   218     }
   237 
   219 
   238 // ---------------------------------------------------------------------------
   220 // ---------------------------------------------------------------------------
   239 // CTMActivityManager::RunError()
   221 // CTMActivityManager::RunError()
   240 // ---------------------------------------------------------------------------
   222 // ---------------------------------------------------------------------------
   241 //
   223 //
   242 TInt CTMActivityManager::RunError(TInt aError)
   224 TInt CTMActivityManager::RunError(TInt aError)
   243     {
   225     {
   244     TN_DEBUG2( "CTMActivityManager::RunError() %d", aError);
   226     TN_DEBUG2( "CTMActivityManager::RunError() %d", aError);
   245     OstTrace1( TRACE_NORMAL, CTMACTIVITYMANAGER_RUNERROR, "CTMActivityManager::RunError;aError=%d", aError );
       
   246     
   227     
   247     if (aError != KErrNone)
   228     if (aError != KErrNone)
   248         {
   229         {
   249         Reset();
   230         Reset();
   250         }
   231         }
   259 //
   240 //
   260 TBool CTMActivityManager::IsInactive()
   241 TBool CTMActivityManager::IsInactive()
   261     {
   242     {
   262 #ifdef MONITOR_LIGHTS
   243 #ifdef MONITOR_LIGHTS
   263 #ifdef _DEBUG
   244 #ifdef _DEBUG
   264 TInt inactivityTime = User::InactivityTime().Int();
       
   265 TN_DEBUG3( "CTMActivityManager::IsInactive()= %d, iLights = %d", User::InactivityTime().Int(), iLights);
   245 TN_DEBUG3( "CTMActivityManager::IsInactive()= %d, iLights = %d", User::InactivityTime().Int(), iLights);
   266 OstTrace1( TRACE_NORMAL, DUP6_CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL;inactivityTime=%d", inactivityTime );
       
   267 #endif
   246 #endif
   268 #else
   247 #else
   269 TInt inactivityTime = User::InactivityTime().Int();
       
   270 TN_DEBUG2( "CTMActivityManager::IsInactive()= %d", User::InactivityTime().Int());
   248 TN_DEBUG2( "CTMActivityManager::IsInactive()= %d", User::InactivityTime().Int());
   271 OstTrace1( TRACE_NORMAL, DUP7_CTMACTIVITYMANAGER_RUNL, "CTMActivityManager::RunL;inactivityTime=%d", inactivityTime );
       
   272 #endif
   249 #endif
   273 
   250 
   274     //if lights are off or inactivity timer is less that target the device is not idle
   251     //if lights are off or inactivity timer is less that target the device is not idle
   275     if( User::InactivityTime() >= TTimeIntervalSeconds(iTimeout)
   252     if( User::InactivityTime() >= TTimeIntervalSeconds(iTimeout)
   276 #ifdef MONITOR_LIGHTS
   253 #ifdef MONITOR_LIGHTS
   277             || !iLights
   254             || !iLights
   278 #endif
   255 #endif
   279             )
   256             )
   280       {
   257       {
   281       TN_DEBUG1( "CTMActivityManager::IsInactive() ETrue");
   258       TN_DEBUG1( "CTMActivityManager::IsInactive() ETrue");
   282       OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_ISINACTIVE, "CTMActivityManager::IsInactive - ETrue" );
       
   283       return ETrue;
   259       return ETrue;
   284       }
   260       }
   285     TN_DEBUG1( "CTMActivityManager::IsInactive() EFalse");
   261     TN_DEBUG1( "CTMActivityManager::IsInactive() EFalse");
   286     OstTrace0( TRACE_NORMAL, DUP1_CTMACTIVITYMANAGER_ISINACTIVE, "CTMActivityManager::IsInactive - EFalse" );
       
   287     return EFalse;
   262     return EFalse;
   288     }
   263     }
   289 
   264 
   290 #ifdef MONITOR_LIGHTS
   265 #ifdef MONITOR_LIGHTS
   291 // -----------------------------------------------------------------------------
   266 // -----------------------------------------------------------------------------
   293 // -----------------------------------------------------------------------------
   268 // -----------------------------------------------------------------------------
   294 //
   269 //
   295 void CTMActivityManager::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus)
   270 void CTMActivityManager::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus)
   296     {
   271     {
   297     TN_DEBUG3( "CTMActivityManager::LightStatusChanged() aTarget = %d, aStatus == %d", aTarget, aStatus);
   272     TN_DEBUG3( "CTMActivityManager::LightStatusChanged() aTarget = %d, aStatus == %d", aTarget, aStatus);
   298     OstTraceExt2( TRACE_NORMAL, CTMACTIVITYMANAGER_LIGHTSTATUSCHANGED, "CTMActivityManager::LightStatusChanged;aTarget=%d;aStatus=%u", aTarget, aStatus );    
       
   299     
   273     
   300     if(aTarget & CHWRMLight::EPrimaryDisplay)
   274     if(aTarget & CHWRMLight::EPrimaryDisplay)
   301         {
   275         {
   302          if( aStatus == CHWRMLight::ELightOff )
   276          if( aStatus == CHWRMLight::ELightOff )
   303             {
   277             {
   304             TN_DEBUG1( "CTMActivityManager::LightStatusChanged() -- OFF");
   278             TN_DEBUG1( "CTMActivityManager::LightStatusChanged() -- OFF");
   305             OstTrace0( TRACE_NORMAL, DUP1_CTMACTIVITYMANAGER_LIGHTSTATUSCHANGED, "CTMActivityManager::LightStatusChanged - OFF" );
       
   306             iLights = EFalse;
   279             iLights = EFalse;
   307             }
   280             }
   308         else
   281         else
   309             {
   282             {
   310             TN_DEBUG1( "CTMActivityManager::LightStatusChanged() -- ON");
   283             TN_DEBUG1( "CTMActivityManager::LightStatusChanged() -- ON");
   311             OstTrace0( TRACE_NORMAL, DUP2_CTMACTIVITYMANAGER_LIGHTSTATUSCHANGED, "CTMActivityManager::LightStatusChanged - ON" );
       
   312             iLights = ETrue;
   284             iLights = ETrue;
   313             }
   285             }
   314      
   286      
   315         NotifyObserver();
   287         NotifyObserver();
   316         }
   288         }
   322 // -----------------------------------------------------------------------------
   294 // -----------------------------------------------------------------------------
   323 //
   295 //
   324 void CTMActivityManager::NotifyObserver()
   296 void CTMActivityManager::NotifyObserver()
   325     {
   297     {
   326     TN_DEBUG1( "void CTMAActivityManager::NotifyObserver()");
   298     TN_DEBUG1( "void CTMAActivityManager::NotifyObserver()");
   327     OstTrace0( TRACE_NORMAL, CTMACTIVITYMANAGER_NOTIFYOBSERVER, "CTMActivityManager::NotifyObserver" );
       
   328     
   299     
   329     TBool status = IsInactive();
   300     TBool status = IsInactive();
   330     
   301     
   331     if( iPreviousStatus != status )
   302     if( iPreviousStatus != status )
   332         {
   303         {