|
1 /* |
|
2 * Copyright (c) 2007-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: Remcon bearer observer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //INCLUDE |
|
20 #include <e32def.h> |
|
21 #include <e32cmn.h> |
|
22 #include <coreapplicationuisdomainpskeys.h> |
|
23 |
|
24 #include "hidremconbearerinternalpskeys.h" |
|
25 #include "hidremconbearerobserver.h" |
|
26 #include "debug.h" |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 // |
|
29 // --------------------------------------------------------------------------- |
|
30 // CHidRemconBearerObserver::NewL() |
|
31 // Constructs a new entry with given values. |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CHidRemconBearerObserver* CHidRemconBearerObserver::NewL( |
|
35 MCallBackReceiver& aCallback, TInt aKeyType ) |
|
36 { |
|
37 CHidRemconBearerObserver* self = new ( ELeave ) CHidRemconBearerObserver( |
|
38 aCallback ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL( aKeyType ); |
|
41 CleanupStack::Pop(); |
|
42 return self; |
|
43 } |
|
44 // --------------------------------------------------------------------------- |
|
45 // CHidRemconBearerObserver::CHidRemconBearerObserver() |
|
46 // C++ constructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CHidRemconBearerObserver::CHidRemconBearerObserver( |
|
50 MCallBackReceiver& aCallback ) : |
|
51 CActive( EPriorityStandard ), iCallback( aCallback ) |
|
52 { |
|
53 //Pass |
|
54 TRACE_FUNC |
|
55 } |
|
56 // --------------------------------------------------------------------------- |
|
57 // CHidRemconBearerObserver::CHidRemconBearerObserver() |
|
58 // Destructor |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CHidRemconBearerObserver::~CHidRemconBearerObserver() |
|
62 { |
|
63 TRACE_FUNC |
|
64 Stop(); |
|
65 if ( iProperty.Handle() != KNullHandle ) |
|
66 { |
|
67 iProperty.Close(); |
|
68 } |
|
69 } |
|
70 // --------------------------------------------------------------------------- |
|
71 // CHidRemconBearerObserver::ConstructL() |
|
72 // Symbian OS default constructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CHidRemconBearerObserver::ConstructL( TInt aKeyType ) |
|
76 { |
|
77 TRACE_FUNC |
|
78 iKeyType = aKeyType; |
|
79 // Add this active object to the scheduler. |
|
80 CActiveScheduler::Add( this ); |
|
81 switch ( iKeyType ) |
|
82 { |
|
83 case EMediaKeys: |
|
84 User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier, |
|
85 KHidControlKeyEvent ) ); |
|
86 break; |
|
87 case EAccessoryVolumeKeys: |
|
88 User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier, |
|
89 KHidAccessoryVolumeEvent ) ); |
|
90 break; |
|
91 case EMuteKey: |
|
92 User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier, |
|
93 KHidMuteKeyEvent ) ); |
|
94 break; |
|
95 case EHookKeys: |
|
96 User::LeaveIfError( iProperty.Attach( KPSUidHidEventNotifier, |
|
97 KHidHookKeyEvent ) ); |
|
98 break; |
|
99 default: |
|
100 User::Leave( KErrArgument ); |
|
101 } |
|
102 Start(); |
|
103 } |
|
104 // --------------------------------------------------------------------------- |
|
105 // CHidRemconBearerObserver::Start() |
|
106 // Starts listening KUidCurrentCall event |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 TInt CHidRemconBearerObserver::Start() |
|
110 { |
|
111 TRACE_FUNC |
|
112 if ( IsActive() ) |
|
113 { |
|
114 return KErrInUse; |
|
115 } |
|
116 iStatus = KRequestPending; |
|
117 iProperty.Subscribe( iStatus ); |
|
118 SetActive(); |
|
119 return KErrNone; |
|
120 } |
|
121 // --------------------------------------------------------------------------- |
|
122 // CHidRemconBearerObserver::Stop() |
|
123 // Stops listening KUidCurrentCall event |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CHidRemconBearerObserver::Stop() |
|
127 { |
|
128 TRACE_FUNC |
|
129 Cancel(); |
|
130 } |
|
131 // --------------------------------------------------------------------------- |
|
132 // CHidRemconBearerObserver::RunL() |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CHidRemconBearerObserver::RunL() |
|
136 { |
|
137 TInt scanCode; |
|
138 TInt ret = 0; |
|
139 ret = iProperty.Get( scanCode ); |
|
140 if ( ret == KErrNone ) |
|
141 { |
|
142 // If this Active Object is for receiving the USB MTP status, the |
|
143 // scanCode varibale contains the status whether transfer is |
|
144 // happening now(active) or not(not active). |
|
145 iCallback.ReceivedKeyEvent( scanCode, iKeyType ); |
|
146 } |
|
147 } |
|
148 // --------------------------------------------------------------------------- |
|
149 // CHidRemconBearerObserver::DoCancel() |
|
150 // Cancels event listening |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CHidRemconBearerObserver::DoCancel() |
|
154 { |
|
155 iProperty.Cancel(); |
|
156 } |