securitydialogs/AutolockSrv/autolockuseractivityservice/s60/src/autolockuseractivityservice_p.cpp
changeset 17 8957df7b0072
equal deleted inserted replaced
15:318c4eab2439 17:8957df7b0072
       
     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: autolockuseractivityservice_p.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 #include "autolockuseractivityservice.h"
       
    19 #include "autolockuseractivityservice_p.h"
       
    20 #include <e32debug.h>
       
    21 
       
    22 #include <activitymanager.h>
       
    23 
       
    24 const int lDefaultInactivityPeriod(5);
       
    25 
       
    26 // ======== LOCAL FUNCTIONS ========
       
    27 
       
    28 /*!
       
    29     Called as callback to activity event.
       
    30     \param pointer to activity callback object.
       
    31     \retval error code.    
       
    32 */
       
    33 TInt activityCallback(TAny *ptr)
       
    34 {
       
    35 	RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
    36 
       
    37     static_cast<AutolockUserActivityServicePrivate *>(ptr)->emitActive();
       
    38     // activity manager doesn't care about the return value,
       
    39     // we return a value indicating 'true' to be elegant (see CIdle)
       
    40     return 1;
       
    41 }
       
    42 
       
    43 /*!
       
    44     Called as callback to inactivity event.
       
    45     \param pointer to inactivity callback object.
       
    46     \retval error code.    
       
    47 */
       
    48 TInt inactivityCallback(TAny *ptr)
       
    49 {
       
    50 	RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
    51 
       
    52     static_cast<AutolockUserActivityServicePrivate *>(ptr)->emitNotActive();
       
    53     // activity manager doesn't care about the return value,
       
    54     // we return a value indicating 'true' to be elegant (see CIdle)
       
    55     return 1;
       
    56 }
       
    57 
       
    58 // ======== MEMBER FUNCTIONS ========
       
    59 
       
    60 /*!
       
    61     Constructor.
       
    62     \param servicePublic public implementation.
       
    63 */
       
    64 AutolockUserActivityServicePrivate::AutolockUserActivityServicePrivate(AutolockUserActivityService *servicePublic) :
       
    65     m_q(servicePublic), mActivityManager(0), mInactivityPeriod(lDefaultInactivityPeriod)
       
    66 {
       
    67     mActivityManager = CUserActivityManager::NewL(CActive::EPriorityStandard);
       
    68 }
       
    69 
       
    70 /*!
       
    71     Destructor.
       
    72 */
       
    73 AutolockUserActivityServicePrivate::~AutolockUserActivityServicePrivate()
       
    74 {
       
    75     delete mActivityManager;
       
    76 }
       
    77 
       
    78 /*!
       
    79     Sets the inactivity period after which to emit signal of inactivity.
       
    80     \param seconds after which inactivity is detected.
       
    81 */
       
    82 void AutolockUserActivityServicePrivate::setInactivityPeriod(int seconds)
       
    83 {
       
    84 	RDebug::Printf( "%s %s (%u) seconds=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, seconds );
       
    85 
       
    86     mInactivityPeriod = seconds;
       
    87     // activity manager panics if timeout set before start
       
    88     if (isWatching())
       
    89     {
       
    90         mActivityManager->SetInactivityTimeout(TTimeIntervalSeconds(mInactivityPeriod));   
       
    91     }
       
    92 }
       
    93 
       
    94 /*!
       
    95     Retrives the current inactivity period setting.
       
    96     \retval inactivity period set.
       
    97 */
       
    98 int AutolockUserActivityServicePrivate::inactivityPeriod() const
       
    99 {
       
   100     return mInactivityPeriod;
       
   101 }
       
   102 
       
   103 /*!
       
   104     Starts or stops activity manager user activity watching.
       
   105     \param shouldWatch determines if we shoul start watching or stop watching.
       
   106 */
       
   107 void AutolockUserActivityServicePrivate::watch(bool shouldWatch)
       
   108 {
       
   109 	RDebug::Printf( "%s %s (%u) shouldWatch=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, shouldWatch );
       
   110     if (shouldWatch && !isWatching()) {
       
   111         mActivityManager->Start(
       
   112                 TTimeIntervalSeconds(mInactivityPeriod),
       
   113                 TCallBack(inactivityCallback, this),
       
   114                 TCallBack(activityCallback, this));
       
   115     } else if (!shouldWatch && isWatching()) {
       
   116         mActivityManager->Cancel();
       
   117     }
       
   118 }
       
   119 
       
   120 /*!
       
   121     Checks if activity service is currently watching for user activity.
       
   122     \retval true if user acitivity service is active.
       
   123 */
       
   124 bool AutolockUserActivityServicePrivate::isWatching() const
       
   125 {
       
   126     return mActivityManager && mActivityManager->IsActive();
       
   127 }
       
   128 
       
   129 /*!
       
   130     Emits signal that user is active.
       
   131 */
       
   132 void AutolockUserActivityServicePrivate::emitActive() const
       
   133 {
       
   134     emit m_q->active();
       
   135 }
       
   136 
       
   137 /*!
       
   138     Emits signal that user is not active.
       
   139 */
       
   140 void AutolockUserActivityServicePrivate::emitNotActive() const
       
   141 {
       
   142     emit m_q->notActive();
       
   143 }