htiui/HtiServicePlugins/HtiKeyEventServicePlugin/src/HtiKeyEventServicePlugin.cpp
changeset 0 39ab869ed429
equal deleted inserted replaced
-1:000000000000 0:39ab869ed429
       
     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:  KeyEventPlugin entry implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "HtiKeyEventServicePlugin.h"
       
    21 #include "KeyEventHandler.h"
       
    22 #include "PointerEventHandler.h"
       
    23 
       
    24 #include <HtiDispatcherInterface.h>
       
    25 #include <HtiLogging.h>
       
    26 #include <hwrmlightdomaincrkeys.h>
       
    27 
       
    28 // CONSTANTS
       
    29 _LIT8( KErrorMissingCommand, "Command was not given - message was empty" );
       
    30 const TInt KDefaultMinLightTimeout = 5;
       
    31 const TInt KWakeupWaitTime = 200000; // 0.2 sec
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // CHtiKeyEventServicePlugin::NewL()
       
    35 // Create instance of concrete ECOM interface implementation
       
    36 // ----------------------------------------------------------------------------
       
    37 CHtiKeyEventServicePlugin* CHtiKeyEventServicePlugin::NewL()
       
    38     {
       
    39     CHtiKeyEventServicePlugin* self = new (ELeave) CHtiKeyEventServicePlugin;
       
    40     CleanupStack::PushL (self);
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop();
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // CHtiKeyEventServicePlugin::CHtiKeyEventServicePlugin()
       
    48 // ----------------------------------------------------------------------------
       
    49 CHtiKeyEventServicePlugin::CHtiKeyEventServicePlugin()
       
    50         : iLightTimeout( KDefaultMinLightTimeout ),
       
    51           iCenRepSession( NULL ),
       
    52           iLightTimeoutSettingHandler( NULL )
       
    53     {
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CHtiKeyEventServicePlugin::~CHtiKeyEventServicePlugin()
       
    58 // ----------------------------------------------------------------------------
       
    59 CHtiKeyEventServicePlugin::~CHtiKeyEventServicePlugin()
       
    60     {
       
    61     HTI_LOG_TEXT( "CHtiKeyEventServicePlugin destroy" );
       
    62     delete iKeyHandler;
       
    63     delete iPointerHandler;
       
    64 
       
    65     if ( iLightTimeoutSettingHandler )
       
    66         {
       
    67         iLightTimeoutSettingHandler->StopListening();
       
    68         }
       
    69     delete iLightTimeoutSettingHandler;
       
    70     delete iCenRepSession;
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // CHtiKeyEventServicePlugin::ConstructL()
       
    75 // ----------------------------------------------------------------------------
       
    76 void CHtiKeyEventServicePlugin::ConstructL()
       
    77     {
       
    78     HTI_LOG_FUNC_IN( "CHtiKeyEventServicePlugin::ConstructL" );
       
    79     iCenRepSession = CRepository::NewL( KCRUidLightSettings );
       
    80     iLightTimeoutSettingHandler = CCenRepNotifyHandler::NewL( *this,
       
    81             *iCenRepSession, CCenRepNotifyHandler::EIntKey,
       
    82             KDisplayLightsTimeout );
       
    83     iLightTimeoutSettingHandler->StartListeningL();
       
    84     HTI_LOG_FUNC_OUT( "CHtiKeyEventServicePlugin::ConstructL" );
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CHtiKeyEventServicePlugin::ProcessMessageL()
       
    89 // ----------------------------------------------------------------------------
       
    90 void CHtiKeyEventServicePlugin::ProcessMessageL( const TDesC8& aMessage,
       
    91     THtiMessagePriority aPriority)
       
    92     {
       
    93     HTI_LOG_FUNC_IN( "CHtiKeyEventServicePlugin::ProcessMessageL" );
       
    94 
       
    95     if ( aMessage.Length() == 0 )
       
    96         {
       
    97         User::LeaveIfNull( iDispatcher );
       
    98         User::LeaveIfError( iDispatcher->DispatchOutgoingErrorMessage(
       
    99             CKeyEventHandler::EMissingCommand,
       
   100             KErrorMissingCommand, KKeyEventServiceUid ) );
       
   101         return;
       
   102         }
       
   103 
       
   104     HTI_LOG_FORMAT( "Light timeout = %d", iLightTimeout );
       
   105     TTimeIntervalSeconds inactivityTime = User::InactivityTime();
       
   106     HTI_LOG_FORMAT( "Inactivity time = %d", inactivityTime.Int() );
       
   107     if ( inactivityTime.Int() >= iLightTimeout )
       
   108         {
       
   109         HTI_LOG_TEXT( "Waking up" );
       
   110         User::ResetInactivityTime();
       
   111         User::After( KWakeupWaitTime );
       
   112         }
       
   113 
       
   114     if ( aMessage[0] <= CKeyEventHandler::EPressKeySequence )
       
   115         {
       
   116         if ( iKeyHandler == NULL )
       
   117             {
       
   118             iKeyHandler = CKeyEventHandler::NewL();
       
   119             iKeyHandler->SetDispatcher( iDispatcher );
       
   120             }
       
   121         iKeyHandler->ProcessMessageL( aMessage, aPriority );
       
   122         }
       
   123 
       
   124     else 
       
   125         {
       
   126         if ( iPointerHandler == NULL )
       
   127             {
       
   128             iPointerHandler = CPointerEventHandler::NewL();
       
   129             iPointerHandler->SetDispatcher( iDispatcher );
       
   130             }
       
   131         iPointerHandler->ProcessMessageL( aMessage, aPriority );
       
   132         }   
       
   133 
       
   134 
       
   135     HTI_LOG_FUNC_OUT( "CHtiKeyEventServicePlugin::ProcessMessageL: Done" );
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // From MCenRepNotifyHandlerCallback.
       
   140 // CHtiKeyEventServicePlugin::HandleNotifyInt
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CHtiKeyEventServicePlugin::HandleNotifyInt( TUint32 aId, TInt aNewValue )
       
   144     {
       
   145     HTI_LOG_FUNC_IN( "CHtiKeyEventServicePlugin::HandleNotifyInt" );
       
   146     if ( aId == KDisplayLightsTimeout )
       
   147         {
       
   148         HTI_LOG_FORMAT( "New light timeout value %d", aNewValue );
       
   149         iLightTimeout = aNewValue;
       
   150         }
       
   151     HTI_LOG_FUNC_OUT( "CHtiKeyEventServicePlugin::HandleNotifyInt" );
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // From MCenRepNotifyHandlerCallback.
       
   156 // CHtiKeyEventServicePlugin::HandleNotifyError
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CHtiKeyEventServicePlugin::HandleNotifyError( TUint32 /*aId*/,
       
   160         TInt /*error*/, CCenRepNotifyHandler* /*aHandler*/ )
       
   161     {
       
   162     HTI_LOG_TEXT( "CHtiKeyEventServicePlugin::HandleNotifyError()" );
       
   163     iLightTimeout = KDefaultMinLightTimeout;
       
   164     TRAP_IGNORE( iLightTimeoutSettingHandler->StartListeningL() );
       
   165     }
       
   166 
       
   167 // End of file