|
1 /* |
|
2 * Copyright (c) 2005-2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //INCLUDE |
|
20 #include <e32def.h> |
|
21 #include <e32cmn.h> |
|
22 |
|
23 #include <mediakeysinternalpskeys.h> |
|
24 #include <UsbWatcherInternalPSKeys.h> |
|
25 #include "MMKeyBearerObserverPS.h" |
|
26 #include "trace.h" |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 // |
|
30 // ---------------------------------------------------------- |
|
31 // CMMKeyBearerObserver::NewL() |
|
32 // Constructs a new entry with given values. |
|
33 // ---------------------------------------------------------- |
|
34 // |
|
35 CMMKeyBearerObserver* CMMKeyBearerObserver::NewL(MCallBackReceiver& aCallback, |
|
36 TInt aKeyType) |
|
37 { |
|
38 FUNC_LOG; |
|
39 |
|
40 CMMKeyBearerObserver* self = new (ELeave) CMMKeyBearerObserver(aCallback); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(aKeyType); |
|
43 CleanupStack::Pop(); |
|
44 return self; |
|
45 } |
|
46 // ---------------------------------------------------------- |
|
47 // CMMKeyBearerObserver::CMMKeyBearerObserver() |
|
48 // C++ constructor |
|
49 // ---------------------------------------------------------- |
|
50 // |
|
51 CMMKeyBearerObserver::CMMKeyBearerObserver(MCallBackReceiver& aCallback) |
|
52 : CActive(EPriorityStandard) ,iCallback(aCallback) |
|
53 { |
|
54 FUNC_LOG; |
|
55 |
|
56 //Pass |
|
57 } |
|
58 // ---------------------------------------------------------- |
|
59 // CMMKeyBearerObserver::CMMKeyBearerObserver() |
|
60 // Destructor |
|
61 // ---------------------------------------------------------- |
|
62 // |
|
63 CMMKeyBearerObserver::~CMMKeyBearerObserver() |
|
64 { |
|
65 FUNC_LOG; |
|
66 |
|
67 Cancel(); |
|
68 } |
|
69 // ---------------------------------------------------------- |
|
70 // CMMKeyBearerObserver::ConstructL() |
|
71 // Symbian OS default constructor |
|
72 // ---------------------------------------------------------- |
|
73 // |
|
74 void CMMKeyBearerObserver::ConstructL(TInt aKeyType) |
|
75 { |
|
76 FUNC_LOG; |
|
77 |
|
78 iKeyType = aKeyType; |
|
79 |
|
80 // Add this active object to the scheduler. |
|
81 CActiveScheduler::Add(this); |
|
82 Start(); |
|
83 } |
|
84 // ---------------------------------------------------------- |
|
85 // CMMKeyBearerObserver::Start() |
|
86 // Starts listening KUidCurrentCall event |
|
87 // ---------------------------------------------------------- |
|
88 // |
|
89 TInt CMMKeyBearerObserver::Start() |
|
90 { |
|
91 FUNC_LOG; |
|
92 |
|
93 if (IsActive()) |
|
94 { |
|
95 ERROR( KErrInUse, "Start observing" ); |
|
96 return KErrInUse; |
|
97 } |
|
98 |
|
99 iProperty.Close(); |
|
100 iStatus = KRequestPending; |
|
101 if (iKeyType == ESideVolumeKeys) |
|
102 { |
|
103 iProperty.Attach(KPSUidMediaKeysEventNotifier, |
|
104 KMediaKeysVolumeKeyEvent); |
|
105 } |
|
106 else if (iKeyType == EMediaKeys) |
|
107 { |
|
108 iProperty.Attach(KPSUidMediaKeysEventNotifier, |
|
109 KMediaKeysControlKeyEvent); |
|
110 } |
|
111 else if (iKeyType == EAccessoryVolumeKeys) |
|
112 { |
|
113 iProperty.Attach(KPSUidMediaKeysEventNotifier, |
|
114 KMediaKeysAccessoryVolumeEvent); |
|
115 } |
|
116 else if (iKeyType == EFileTransferStatus) |
|
117 { |
|
118 iProperty.Attach(KPSUidUsbWatcher, |
|
119 KUsbWatcherSelectedPersonality); |
|
120 } |
|
121 iProperty.Subscribe(iStatus); |
|
122 |
|
123 SetActive(); |
|
124 |
|
125 INFO_1( "Start observing: iKeyType = %d", iKeyType ); |
|
126 |
|
127 return KErrNone; |
|
128 } |
|
129 // ---------------------------------------------------------- |
|
130 // CMMKeyBearerObserver::Stop() |
|
131 // Stops listening KUidCurrentCall event |
|
132 // ---------------------------------------------------------- |
|
133 // |
|
134 void CMMKeyBearerObserver::Stop() |
|
135 { |
|
136 FUNC_LOG; |
|
137 |
|
138 Cancel(); |
|
139 } |
|
140 // ---------------------------------------------------------- |
|
141 // CMMKeyBearerObserver::RunL() |
|
142 // |
|
143 // ---------------------------------------------------------- |
|
144 // |
|
145 void CMMKeyBearerObserver::RunL() |
|
146 { |
|
147 FUNC_LOG; |
|
148 |
|
149 TInt scanCode; |
|
150 iProperty.Get( scanCode); |
|
151 |
|
152 ERROR_1( iStatus.Int(), "Observed key failed: keyType = %d", iKeyType ); |
|
153 INFO_2( "Observed key: keyType = %d, scanCode = %d", iKeyType, scanCode ); |
|
154 |
|
155 // If this Active Object is for receiving the USB MTP status, the |
|
156 // scanCode varibale contains the status whether transfer is |
|
157 // happening now(active) or not(not active). |
|
158 |
|
159 iCallback.ReceivedKeyEvent(scanCode, iKeyType); |
|
160 } |
|
161 // ---------------------------------------------------------- |
|
162 // CMMKeyBearerObserver::DoCancel() |
|
163 // Cancels event listening |
|
164 // ---------------------------------------------------------- |
|
165 // |
|
166 void CMMKeyBearerObserver::DoCancel() |
|
167 { |
|
168 FUNC_LOG; |
|
169 |
|
170 iProperty.Cancel(); |
|
171 iProperty.Close(); |
|
172 } |
|
173 |
|
174 // ---------------------------------------------------------- |
|
175 // CMMKeyBearerObserver::GetValue() |
|
176 // |
|
177 // ---------------------------------------------------------- |
|
178 // |
|
179 TInt CMMKeyBearerObserver::GetValue() |
|
180 { |
|
181 FUNC_LOG; |
|
182 |
|
183 TInt ret = 0; |
|
184 TInt err = iProperty.Get( ret ); |
|
185 if ( err != KErrNone ) |
|
186 { |
|
187 ERROR_1( err, "Observer value read failed: keyType = %d", iKeyType ); |
|
188 } |
|
189 return ret; |
|
190 } |
|
191 |
|
192 // End of file |