|
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: |
|
15 */ |
|
16 |
|
17 #ifndef HARVESTEREVENTOBSERVERAO_H |
|
18 #define HARVESTEREVENTOBSERVERAO_H |
|
19 |
|
20 #include <e32base.h> // For CActive, link against: euser.lib |
|
21 #include <e32std.h> // For RTimer, link against: euser.lib |
|
22 #include <e32msgqueue.h> |
|
23 |
|
24 #include "harvestercommon.h" |
|
25 |
|
26 class RHarvesterClient; |
|
27 class MHarvesterEventObserver; |
|
28 |
|
29 struct THarvesterEventObserver |
|
30 { |
|
31 MHarvesterEventObserver& iObserver; |
|
32 THarvesterEventObserverInfo iObserverInfo; |
|
33 |
|
34 THarvesterEventObserver(MHarvesterEventObserver& aObserver) : iObserver(aObserver) {} |
|
35 |
|
36 static TInt CompareObserverIds( |
|
37 const THarvesterEventObserver& aFirst, |
|
38 const THarvesterEventObserver& aSecond) |
|
39 { |
|
40 if( aFirst.iObserverInfo.iObserverId < aSecond.iObserverInfo.iObserverId ) |
|
41 { |
|
42 return -1; |
|
43 } |
|
44 else if( aFirst.iObserverInfo.iObserverId > aSecond.iObserverInfo.iObserverId ) |
|
45 { |
|
46 return 1; |
|
47 } |
|
48 else |
|
49 { |
|
50 return 0; |
|
51 } |
|
52 } |
|
53 }; |
|
54 |
|
55 NONSHARABLE_CLASS( CHarvesterEventObserverAO ) : public CActive |
|
56 { |
|
57 public: |
|
58 // Cancel and destroy |
|
59 ~CHarvesterEventObserverAO(); |
|
60 |
|
61 // Two-phased constructor. |
|
62 static CHarvesterEventObserverAO* NewL( RHarvesterClient& aHC ); |
|
63 |
|
64 // Two-phased constructor. |
|
65 static CHarvesterEventObserverAO* NewLC( RHarvesterClient& aHC ); |
|
66 |
|
67 public: |
|
68 // New functions |
|
69 // Function for making the initial request |
|
70 void AddHarvesterEventObserverL( |
|
71 MHarvesterEventObserver& aHarvesterEventObserver, |
|
72 TInt aHEObserverType, |
|
73 TInt aEventInterval ); |
|
74 |
|
75 void RemoveHarvesterEventObserverL( MHarvesterEventObserver& aHarvesterEventObserver ); |
|
76 |
|
77 private: |
|
78 // C++ constructor |
|
79 CHarvesterEventObserverAO( RHarvesterClient& aHC ); |
|
80 |
|
81 // Second-phase constructor |
|
82 void ConstructL(); |
|
83 |
|
84 /** |
|
85 * Get next free observer ID |
|
86 * @return Observer ID |
|
87 */ |
|
88 TUint NextObserverId(); |
|
89 |
|
90 /** |
|
91 * Get handle to event queue. Creates event queue if it doesn't exist. |
|
92 * @return Event queue handle |
|
93 */ |
|
94 RHandleBase& GetEventQueueHandleL(); |
|
95 |
|
96 private: |
|
97 // From CActive |
|
98 // Handle completion |
|
99 void RunL(); |
|
100 |
|
101 // How to cancel me |
|
102 void DoCancel(); |
|
103 |
|
104 // Override to handle leaves from RunL(). Default implementation causes |
|
105 // the active scheduler to panic. |
|
106 TInt RunError(TInt aError); |
|
107 |
|
108 private: |
|
109 RPointerArray<THarvesterEventObserver> iObservers; |
|
110 THarvesterEventQueue iHarvesterEventQueue; |
|
111 RHarvesterClient& iHarvesterClient; |
|
112 }; |
|
113 |
|
114 #endif // HARVESTEREVENTOBSERVERAO_H |