|
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: Base class for Publish & Subscripe -type Sensors |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CPSSENSORBASE_H |
|
19 #define CPSSENSORBASE_H |
|
20 |
|
21 #include <e32property.h> // Publish & Subscribe |
|
22 #include "csensorbase.h" |
|
23 |
|
24 // Forward declarations |
|
25 class CPSSensorBaseAsyncQuery; |
|
26 |
|
27 class CPSSensorBase : public CSensorBase |
|
28 { |
|
29 // Asynchronous query helper class |
|
30 class CPSSensorBaseAsyncQuery : public CActive |
|
31 { |
|
32 public: |
|
33 static CPSSensorBaseAsyncQuery* NewL(CPSSensorBase& aSensorBase, |
|
34 TUid aPropertyCategory, TInt aPropertyKey); |
|
35 virtual ~CPSSensorBaseAsyncQuery(); |
|
36 |
|
37 protected: |
|
38 void ConstructL(TUid aPropertyCategory, TInt aPropertyKey); |
|
39 CPSSensorBaseAsyncQuery(CPSSensorBase& aSensorBase); |
|
40 |
|
41 public: // From CActive |
|
42 void RunL(); |
|
43 void DoCancel(); |
|
44 |
|
45 public: // New methods |
|
46 void NotifyOnChange(); |
|
47 |
|
48 private: // Members |
|
49 CPSSensorBase& iSensorBase; |
|
50 |
|
51 /** |
|
52 * Property handle used to query property changes |
|
53 */ |
|
54 RProperty iProperty; |
|
55 }; |
|
56 |
|
57 // Poll timer helper class |
|
58 class CPSSensorDataListenTimer : public CTimer |
|
59 { |
|
60 public: |
|
61 static CPSSensorDataListenTimer* NewL(CPSSensorBase& iSensorBase); |
|
62 virtual ~CPSSensorDataListenTimer(); |
|
63 |
|
64 protected: |
|
65 CPSSensorDataListenTimer(CPSSensorBase& iSensorBase); |
|
66 |
|
67 public: // from CTimer |
|
68 void RunL(); |
|
69 void DoCancel(); |
|
70 |
|
71 public: // Members |
|
72 CPSSensorBase& iSensorBase; |
|
73 }; |
|
74 |
|
75 public: |
|
76 // Destructor |
|
77 virtual ~CPSSensorBase(); |
|
78 |
|
79 protected: |
|
80 // Second phase constructor |
|
81 void ConstructL(TUid aPropertyCategory, TInt aPropertyKey); |
|
82 |
|
83 // Constructor |
|
84 CPSSensorBase(TTimeIntervalMicroSeconds32 aPollInterval); |
|
85 |
|
86 public: // From Sensor |
|
87 |
|
88 virtual int OpenChannel(SensorListener* aListener); |
|
89 |
|
90 |
|
91 public: // From CSensorBase |
|
92 virtual TReal InterpretValue(TReal aValue) = 0; |
|
93 TBool EvaluateConditions(TInt aValue, TInt aChannelId); |
|
94 |
|
95 void AddConditionL(void** aHandle, int aChannelId, double aLowerLimit, |
|
96 double aUpperLimit, int aLowerOp, int aUpperOp); |
|
97 |
|
98 void StartDataListeningL(); |
|
99 void StartConditionListeningL(); |
|
100 void CancelDataListeningL(); |
|
101 void CloseChannelL(); |
|
102 void StopConditionListeningL(); |
|
103 |
|
104 private: // New methods |
|
105 |
|
106 /** |
|
107 * Leaving version of OpenChannel |
|
108 */ |
|
109 void OpenChannelL(SensorListener* aListener); |
|
110 /** |
|
111 * Reset data object and those member variables that are |
|
112 * involved in data accumulation round. |
|
113 */ |
|
114 void ResetAccumulationData(); |
|
115 |
|
116 /** |
|
117 * Callback method called by RunL of the poll timer. |
|
118 */ |
|
119 void AccumulateDataL(); |
|
120 |
|
121 /** |
|
122 * Used by AccumulateDataL to send data to Java side and do |
|
123 * necessary cleanup. |
|
124 */ |
|
125 void SendData(); |
|
126 |
|
127 /** |
|
128 * Called by RunL of iAsyncQuery when query is complete |
|
129 */ |
|
130 void PropertyValueChanged(); |
|
131 |
|
132 private: // Members |
|
133 |
|
134 /** |
|
135 * Property values |
|
136 */ |
|
137 TUid iPropertyCategory; |
|
138 TInt iPropertyKey; |
|
139 /** |
|
140 * Async query handler used to get property value change |
|
141 * notifications |
|
142 */ |
|
143 CPSSensorBaseAsyncQuery* iAsyncQuery; |
|
144 |
|
145 /** |
|
146 * Used to get property values periodically. |
|
147 */ |
|
148 CTimer* iPollTimer; |
|
149 |
|
150 /** |
|
151 * Property handle used to get property value |
|
152 */ |
|
153 RProperty iProperty; |
|
154 |
|
155 /** |
|
156 * Beat interval used in periodic polling |
|
157 */ |
|
158 TTimeIntervalMicroSeconds32 iPollInterval; |
|
159 |
|
160 /** |
|
161 * Values used in asynchronous polling |
|
162 */ |
|
163 TTime iStartTime; |
|
164 TInt iBufferPosition; |
|
165 }; |
|
166 |
|
167 #endif // CPSSENSORBASE_H |