htiui/HtiServicePlugins/HtiKeyEventServicePlugin/src/HtiKeyEventServicePlugin.cpp
changeset 0 d6fe6244b863
child 3 2703485a934c
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     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     if ( iLightTimeoutSettingHandler )
       
    65         {
       
    66         iLightTimeoutSettingHandler->StopListening();
       
    67         }
       
    68     delete iLightTimeoutSettingHandler;
       
    69     delete iCenRepSession;
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // CHtiKeyEventServicePlugin::ConstructL()
       
    74 // ----------------------------------------------------------------------------
       
    75 void CHtiKeyEventServicePlugin::ConstructL()
       
    76     {
       
    77     HTI_LOG_FUNC_IN( "CHtiKeyEventServicePlugin::ConstructL" );
       
    78     iCenRepSession = CRepository::NewL( KCRUidLightSettings );
       
    79     iLightTimeoutSettingHandler = CCenRepNotifyHandler::NewL( *this,
       
    80             *iCenRepSession, CCenRepNotifyHandler::EIntKey,
       
    81             KDisplayLightsTimeout );
       
    82     iLightTimeoutSettingHandler->StartListeningL();
       
    83     HTI_LOG_FUNC_OUT( "CHtiKeyEventServicePlugin::ConstructL" );
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // CHtiKeyEventServicePlugin::ProcessMessageL()
       
    88 // ----------------------------------------------------------------------------
       
    89 void CHtiKeyEventServicePlugin::ProcessMessageL( const TDesC8& aMessage,
       
    90     THtiMessagePriority aPriority)
       
    91     {
       
    92     HTI_LOG_FUNC_IN( "CHtiKeyEventServicePlugin::ProcessMessageL" );
       
    93 
       
    94     if ( aMessage.Length() == 0 )
       
    95         {
       
    96         User::LeaveIfNull( iDispatcher );
       
    97         User::LeaveIfError( iDispatcher->DispatchOutgoingErrorMessage(
       
    98             CKeyEventHandler::EMissingCommand,
       
    99             KErrorMissingCommand, KKeyEventServiceUid ) );
       
   100         return;
       
   101         }
       
   102 
       
   103     HTI_LOG_FORMAT( "Light timeout = %d", iLightTimeout );
       
   104     TTimeIntervalSeconds inactivityTime = User::InactivityTime();
       
   105     HTI_LOG_FORMAT( "Inactivity time = %d", inactivityTime.Int() );
       
   106     if ( inactivityTime.Int() >= iLightTimeout )
       
   107         {
       
   108         HTI_LOG_TEXT( "Waking up" );
       
   109         User::ResetInactivityTime();
       
   110         User::After( KWakeupWaitTime );
       
   111         }
       
   112 
       
   113     if ( aMessage[0] <= CKeyEventHandler::EPressKeySequence )
       
   114         {
       
   115         if ( iKeyHandler == NULL )
       
   116             {
       
   117             iKeyHandler = CKeyEventHandler::NewL();
       
   118             iKeyHandler->SetDispatcher( iDispatcher );
       
   119             }
       
   120         iKeyHandler->ProcessMessageL( aMessage, aPriority );
       
   121         }
       
   122 
       
   123     else
       
   124         {
       
   125         if ( iPointerHandler == NULL )
       
   126             {
       
   127             iPointerHandler = CPointerEventHandler::NewL();
       
   128             iPointerHandler->SetDispatcher( iDispatcher );
       
   129             }
       
   130         iPointerHandler->ProcessMessageL( aMessage, aPriority );
       
   131         }
       
   132 
       
   133     HTI_LOG_FUNC_OUT( "CHtiKeyEventServicePlugin::ProcessMessageL: Done" );
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // From MCenRepNotifyHandlerCallback.
       
   138 // CHtiKeyEventServicePlugin::HandleNotifyInt
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CHtiKeyEventServicePlugin::HandleNotifyInt( TUint32 aId, TInt aNewValue )
       
   142     {
       
   143     HTI_LOG_FUNC_IN( "CHtiKeyEventServicePlugin::HandleNotifyInt" );
       
   144     if ( aId == KDisplayLightsTimeout )
       
   145         {
       
   146         HTI_LOG_FORMAT( "New light timeout value %d", aNewValue );
       
   147         iLightTimeout = aNewValue;
       
   148         }
       
   149     HTI_LOG_FUNC_OUT( "CHtiKeyEventServicePlugin::HandleNotifyInt" );
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // From MCenRepNotifyHandlerCallback.
       
   154 // CHtiKeyEventServicePlugin::HandleNotifyError
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CHtiKeyEventServicePlugin::HandleNotifyError( TUint32 /*aId*/,
       
   158         TInt /*error*/, CCenRepNotifyHandler* /*aHandler*/ )
       
   159     {
       
   160     HTI_LOG_TEXT( "CHtiKeyEventServicePlugin::HandleNotifyError()" );
       
   161     iLightTimeout = KDefaultMinLightTimeout;
       
   162     TRAP_IGNORE( iLightTimeoutSettingHandler->StartListeningL() );
       
   163     }
       
   164 
       
   165 // End of file