|
1 /* |
|
2 * Copyright (c) 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: Haptics status observer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <hwrmhapticsactuatorobserver.h> |
|
20 |
|
21 #include "hwrmhapticstrace.h" |
|
22 #include "hwrmhapticssession.h" |
|
23 #include "hwrmhapticsstatusobserver.h" |
|
24 |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Two-phased constructor. |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CHWRMHapticsStatusObserver* CHWRMHapticsStatusObserver::NewL( |
|
31 MHWRMHapticsObserver* aHapticsCallback, |
|
32 MHWRMHapticsActuatorObserver* aActuatorCallback, |
|
33 RHWRMHapticsSession* aClient ) |
|
34 { |
|
35 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::NewL(0x%x, 0x%x)" ), aHapticsCallback, aActuatorCallback ) ); |
|
36 |
|
37 CHWRMHapticsStatusObserver* self = |
|
38 new ( ELeave ) CHWRMHapticsStatusObserver( aHapticsCallback, |
|
39 aActuatorCallback, |
|
40 aClient ); |
|
41 |
|
42 CleanupStack::PushL( self ); |
|
43 |
|
44 self->ConstructL(); |
|
45 |
|
46 CleanupStack::Pop( self ); |
|
47 |
|
48 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::NewL - return 0x%x" ), self ) ); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Destructor. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CHWRMHapticsStatusObserver::~CHWRMHapticsStatusObserver() |
|
58 { |
|
59 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::~CHWRMHapticsStatusObserver()" ) ) ); |
|
60 |
|
61 Cancel(); |
|
62 |
|
63 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::~CHWRMHapticsStatusObserver - return" ) ) ); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Returns current haptics status. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 MHWRMHapticsObserver::THWRMHapticsStatus |
|
71 CHWRMHapticsStatusObserver::CurrentStatus() const |
|
72 { |
|
73 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::CurrentStatus()" ) ) ); |
|
74 |
|
75 return iHapticsStatus; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Handle notification from pubsub session. |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CHWRMHapticsStatusObserver::RunL() |
|
83 { |
|
84 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::RunL()" ) ) ); |
|
85 |
|
86 // if status was received successfully, inform status to callbacks |
|
87 if ( iStatus == KErrNone ) |
|
88 { |
|
89 // notify callbacks, if available |
|
90 if ( iStatusType == EHWRMHapticsActuatorStatus && iActuatorCallback ) |
|
91 { |
|
92 // actuator event value |
|
93 TActuatorStatus status = |
|
94 static_cast<TActuatorStatus>( iLastStatus ); |
|
95 |
|
96 // notify actuator event |
|
97 iActuatorCallback->ActuatorEventL( status, iActuator ); |
|
98 } |
|
99 else if ( iStatusType == EHWRMHapticsSessionStatus && iHapticsCallback ) |
|
100 { |
|
101 // store haptics status value so that it can be fetched |
|
102 iHapticsStatus = static_cast<THapticsStatus>( iLastStatus ); |
|
103 |
|
104 // notify haptics status change |
|
105 iHapticsCallback->HapticsStatusChangedL( iHapticsStatus ); |
|
106 } |
|
107 |
|
108 // Reorder notification |
|
109 OrderNotification(); |
|
110 } |
|
111 |
|
112 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::RunL - return" ) ) ); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Handle error of RunL. |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 TInt CHWRMHapticsStatusObserver::RunError( TInt /*aError*/ ) |
|
120 { |
|
121 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::RunError()" ) ) ); |
|
122 |
|
123 // Error occurred while setting new status value using callback |
|
124 // --> ignore error |
|
125 |
|
126 return KErrNone; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // Handle cancel order on this active object. |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CHWRMHapticsStatusObserver::DoCancel() |
|
134 { |
|
135 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::DoCancel()" ) ) ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // C++ constructor. |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 CHWRMHapticsStatusObserver::CHWRMHapticsStatusObserver( |
|
143 MHWRMHapticsObserver* aHapticsCallback, |
|
144 MHWRMHapticsActuatorObserver* aActuatorCallback, |
|
145 RHWRMHapticsSession* aClient ) |
|
146 : CActive( EPriorityStandard ), |
|
147 iHapticsCallback( aHapticsCallback ), |
|
148 iActuatorCallback( aActuatorCallback ), |
|
149 iClient ( aClient ), |
|
150 iHapticsStatus( MHWRMHapticsObserver::EHWRMHapticsStatusAvailable ), |
|
151 iStatusPckg( iLastStatus ), |
|
152 iStatusTypePckg( iStatusType ), |
|
153 iActuatorPckg( iActuator ) |
|
154 { |
|
155 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::CHWRMHapticsStatusObserver(0x%x, 0x%x)" ), aHapticsCallback, aActuatorCallback ) ); |
|
156 |
|
157 CActiveScheduler::Add( this ); |
|
158 |
|
159 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::CHWRMHapticsStatusObserver - return" ) ) ); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // Symbian 2nd phase constructor. |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CHWRMHapticsStatusObserver::ConstructL() |
|
167 { |
|
168 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::ConstructL()" ) ) ); |
|
169 |
|
170 // activate the observation |
|
171 OrderNotification(); |
|
172 |
|
173 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::ConstructL - return" ) ) ); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // Order new notification. |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CHWRMHapticsStatusObserver::OrderNotification() |
|
181 { |
|
182 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::OrderNotification()" ) ) ); |
|
183 |
|
184 if ( !IsActive() && iClient && iClient->Handle() ) |
|
185 { |
|
186 // update status type |
|
187 iStatusType = NotificationStatusType(); |
|
188 |
|
189 // request haptics status notification |
|
190 iClient->ExecuteAsyncOperation( EHWRMHapticsStatusNotification, |
|
191 TIpcArgs( iStatusType, |
|
192 &iStatusTypePckg, |
|
193 &iStatusPckg, |
|
194 &iActuatorPckg ), |
|
195 iStatus ); |
|
196 |
|
197 // activate object |
|
198 SetActive(); |
|
199 } |
|
200 |
|
201 COMPONENT_TRACE( ( _L( "CHWRMHapticsStatusObserver::OrderNotification - return" ) ) ); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // Based on available callback instances, returns the type |
|
206 // of status notification, which should be used in notification requests. |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 THWRMHapticsStatusTypes |
|
210 CHWRMHapticsStatusObserver::NotificationStatusType() const |
|
211 { |
|
212 THWRMHapticsStatusTypes statusType = EHWRMHapticsSessionStatus; |
|
213 |
|
214 // there is always at least one callback |
|
215 if ( iHapticsCallback && iActuatorCallback ) |
|
216 { |
|
217 statusType = EHWRMHapticsBothStatus; |
|
218 } |
|
219 else if ( iActuatorCallback ) |
|
220 { |
|
221 statusType = EHWRMHapticsActuatorStatus; |
|
222 } |
|
223 else // iHapticsCallback |
|
224 { |
|
225 statusType = EHWRMHapticsSessionStatus; |
|
226 } |
|
227 |
|
228 return statusType; |
|
229 } |
|
230 |
|
231 // End of File |