|
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 the License "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: Gesture helper implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "gesturehelpereventsender.h" |
|
19 #include "gesture.h" |
|
20 |
|
21 using namespace RT_GestureHelper; |
|
22 |
|
23 const TInt KEventsQueueGranularity = 4; |
|
24 |
|
25 CGestureEventSender* CGestureEventSender::NewL( MGestureObserver& aObserver ) |
|
26 { |
|
27 CGestureEventSender* self = new (ELeave) CGestureEventSender(aObserver); |
|
28 |
|
29 return self; |
|
30 } |
|
31 |
|
32 CGestureEventSender::CGestureEventSender( MGestureObserver& aObserver ) : |
|
33 CActive(EPriorityUserInput - 1), |
|
34 iObserver(aObserver), iEvents(KEventsQueueGranularity) |
|
35 { |
|
36 CActiveScheduler::Add(this); |
|
37 } |
|
38 |
|
39 CGestureEventSender::~CGestureEventSender() |
|
40 { |
|
41 if (IsActive()) |
|
42 { |
|
43 Cancel(); |
|
44 } |
|
45 |
|
46 iEvents.Close(); |
|
47 } |
|
48 |
|
49 TInt CGestureEventSender::AddEvent(const TGestureEvent& aGestureEvent) |
|
50 { |
|
51 iEvents.Append(aGestureEvent); |
|
52 if (iState != EBusy) |
|
53 { |
|
54 iState = EEventsReady; |
|
55 } |
|
56 |
|
57 if (!IsActive()) |
|
58 { |
|
59 Complete(); |
|
60 } |
|
61 return iEvents.Count(); |
|
62 } |
|
63 |
|
64 void CGestureEventSender::Complete() |
|
65 { |
|
66 TRequestStatus* status = &iStatus; |
|
67 User::RequestComplete(status, KErrNone); |
|
68 SetActive(); |
|
69 } |
|
70 |
|
71 void CGestureEventSender::RunL() |
|
72 { |
|
73 switch (iState) |
|
74 { |
|
75 case EEventsReady: |
|
76 { |
|
77 if (iEvents.Count() > 0) |
|
78 { |
|
79 TInt count = iEvents.Count(); |
|
80 for (int i = 0; i < count; i++) |
|
81 { |
|
82 TGestureEvent& gst = iEvents[i]; |
|
83 EmitEventL(gst); |
|
84 } |
|
85 } |
|
86 iEvents.Reset(); |
|
87 iState = ENoEvents; |
|
88 Complete(); |
|
89 break; |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 void CGestureEventSender::EmitEventL( const TGestureEvent& aGesture ) |
|
95 { |
|
96 iState = EBusy; |
|
97 iObserver.HandleGestureL(aGesture); |
|
98 iState = EEventsReady; |
|
99 } |
|
100 |
|
101 TInt CGestureEventSender::RunError(TInt aError) |
|
102 { |
|
103 iEvents.Reset(); |
|
104 return aError; |
|
105 } |
|
106 |
|
107 void CGestureEventSender::DoCancel() |
|
108 { |
|
109 iEvents.Reset(); |
|
110 iState = ENoEvents; |
|
111 } |