localconnectivityservice/headset/hidremconbearer/src/hidremconbearerobserver.cpp
author hgs
Fri, 25 Jun 2010 16:54:01 +0800
changeset 29 3ae5cb0b4c02
permissions -rw-r--r--
201025_07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     1
/*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     3
* All rights reserved.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     8
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     9
* Initial Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    11
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    12
* Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    13
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    14
* Description:  Remcon bearer observer implementation
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    15
 *
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    16
*/
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    17
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    18
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    19
//INCLUDE
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    20
#include <e32def.h>
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    21
#include <e32cmn.h>
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    22
#include <coreapplicationuisdomainpskeys.h>
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    23
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    24
#include "hidremconbearerinternalpskeys.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    25
#include "hidremconbearerobserver.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    26
#include "debug.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    27
// ======== MEMBER FUNCTIONS ========
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    28
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    29
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    30
// CHidRemconBearerObserver::NewL()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    31
// Constructs a new entry with given values.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    32
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    33
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    34
CHidRemconBearerObserver* CHidRemconBearerObserver::NewL(
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    35
        MCallBackReceiver& aCallback, TInt aKeyType )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    36
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    37
    CHidRemconBearerObserver* self = new ( ELeave ) CHidRemconBearerObserver(
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    38
            aCallback );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    39
    CleanupStack::PushL( self );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    40
    self->ConstructL( aKeyType );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    41
    CleanupStack::Pop();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    42
    return self;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    43
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    44
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    45
// CHidRemconBearerObserver::CHidRemconBearerObserver()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    46
// C++ constructor
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    47
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    48
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    49
CHidRemconBearerObserver::CHidRemconBearerObserver(
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    50
        MCallBackReceiver& aCallback ) :
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    51
    CActive( EPriorityStandard ), iCallback( aCallback )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    52
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    53
    //Pass        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    54
    TRACE_FUNC
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    55
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    56
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    57
// CHidRemconBearerObserver::CHidRemconBearerObserver()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    58
// Destructor
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    59
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    60
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    61
CHidRemconBearerObserver::~CHidRemconBearerObserver()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    62
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    63
    TRACE_FUNC
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    64
    Stop();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    65
    if ( iProperty.Handle() != KNullHandle )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    66
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    67
        iProperty.Close();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    68
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    69
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    70
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    71
// CHidRemconBearerObserver::ConstructL()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    72
// Symbian OS default constructor
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    73
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    74
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    75
void CHidRemconBearerObserver::ConstructL( TInt aKeyType )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    76
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    77
    TRACE_FUNC
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    78
    iKeyType = aKeyType;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    79
    // Add this active object to the scheduler.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    80
    CActiveScheduler::Add( this );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    81
    switch ( iKeyType )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    82
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    83
        case EMediaKeys:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    84
            User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier,
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    85
                    KHidControlKeyEvent ) );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    86
            break;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    87
        case EAccessoryVolumeKeys:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    88
            User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier,
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    89
                    KHidAccessoryVolumeEvent ) );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    90
            break;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    91
        case EMuteKey:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    92
            User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier,
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    93
                    KHidMuteKeyEvent ) );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    94
            break;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    95
        case EHookKeys:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    96
            User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier,
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    97
                    KHidHookKeyEvent ) );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    98
            break;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    99
        default:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   100
            User::Leave( KErrArgument );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   101
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   102
    Start();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   103
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   104
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   105
// CHidRemconBearerObserver::Start()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   106
// Starts listening KUidCurrentCall event  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   107
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   108
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   109
TInt CHidRemconBearerObserver::Start()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   110
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   111
    TRACE_FUNC
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   112
    if ( IsActive() )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   113
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   114
        return KErrInUse;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   115
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   116
    iStatus = KRequestPending;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   117
    iProperty.Subscribe( iStatus );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   118
    SetActive();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   119
    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   120
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   121
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   122
// CHidRemconBearerObserver::Stop()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   123
// Stops listening KUidCurrentCall event 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   124
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   125
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   126
void CHidRemconBearerObserver::Stop()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   127
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   128
    TRACE_FUNC
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   129
    Cancel();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   130
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   131
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   132
// CHidRemconBearerObserver::RunL()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   133
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   134
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   135
void CHidRemconBearerObserver::RunL()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   136
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   137
    TInt scanCode;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   138
    TInt ret = 0;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   139
    ret = iProperty.Get( scanCode );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   140
    if ( ret == KErrNone )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   141
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   142
        // If this Active Object is for receiving the USB MTP status, the
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   143
        // scanCode varibale contains the status whether transfer is 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   144
        // happening now(active) or not(not active).    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   145
        iCallback.ReceivedKeyEvent( scanCode, iKeyType );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   146
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   147
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   148
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   149
// CHidRemconBearerObserver::DoCancel()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   150
// Cancels event listening
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   151
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   152
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   153
void CHidRemconBearerObserver::DoCancel()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   154
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   155
    iProperty.Cancel();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   156
    }