summaryrefslogtreecommitdiffstats
path: root/plugins/sensors/symbian/sensorbackendsym.h
blob: 5cfb9d31734cbfede7f9c7925002a69991c749bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef SENSORBACKENDSYM_H
#define SENSORBACKENDSYM_H

// QT Mobility Sensor API headers
#include <qsensorbackend.h>

// Standard Symbian Headers
#include <e32std.h>
#include <e32cmn.h>

// Sensor client headers
// Common Sensor Headers
#include <sensrvchannel.h>
#include <sensrvchannelinfo.h>
#include <sensrvtypes.h>
#include <sensrvchannelfinder.h>
#include <sensrvdatalistener.h>
#include <sensrvpropertylistener.h>

// Internal Headers
#include "sensorbackenddatasym.h"

QTM_USE_NAMESPACE

class CSensorBackendSym : public CBase, public QSensorBackend, public MSensrvDataListener, public MSensrvPropertyListener
    {
    public:
        // From QSensorBackend

        /**
         *  start is used to start listening to the sensor
         */
        virtual void start();

        /*
         * stop is used to stop listening to the sensor
         */
        virtual void stop();

        /*
         * Backend Destructor
         */
        ~CSensorBackendSym();

        // From MSensrvDataListener

        /*
         * DataReceived is called by the Sensor Server when ever data is available in the
         * sensor buffer
         */
        // implemnented by sub-classes
        //void  DataReceived(CSensrvChannel &aChannel, TInt aCount, TInt aDataLost);

        /**
         * DataError is called to indicate an error, fatal errors are unrecoverable
         */
        void  DataError(CSensrvChannel &aChannel, TSensrvErrorSeverity aError);

        /*
         * GetDataListenerInterfaceL is used to get a pointer to the sensor server backend
         * It is not required for QT Mobility Sensors API
         */
        void  GetDataListenerInterfaceL(TUid aInterfaceUid, TAny *&aInterface);

        // From MSensrvProeprtyListener

        /**
         * Notification about the changed value of a property.
         */
        void  PropertyChanged (CSensrvChannel &aChannel, const TSensrvProperty &aChangedProperty);

        /**
         *  Property listening failed.
         */
        void  PropertyError (CSensrvChannel &aChannel, TSensrvErrorSeverity aError);

        /**
         * Set a listener for the indication, if the setting of the property succeeded.
         */
        void  SetPropertySuccessIndicationChanged (TSetPropertySuccessIndicator aIndication);

        /*
         * Returns a pointer to a specified interface extension - to allow future extension of this class without breaking binary compatibility.
         */
        void  GetPropertyListenerInterfaceL (TUid aInterfaceUid, TAny *&aInterface);

        /*
         * To enable/disable data/property listening
         */
        void SetListening(TBool aDataListening, TBool aPropertyListening);

    protected:

        /*
         * Default C++ constructor
         */
        CSensorBackendSym(QSensor *sensor);

        /**
         * Deriving class implements this if it requires property change notification
         */
        virtual void HandlePropertyChange(CSensrvChannel &aChannel, const TSensrvProperty &aChangedProperty);

        /*
         * InitializeL is used to create and init the sensor server objects
         */
        void InitializeL();

        /*
         * SetProperty is used to set property to the channel
         */
        TInt SetProperty(TSensrvPropertyId aPropertyId, TSensrvPropertyType aPropertyType, TSensrvArrayIndex aArrayIndex, TReal aValue);

        /*
         * SetMeasurementRange is used to check measurement range type and set the measurement range
         */
        TInt SetMeasurementRange();

        /*
         * SetDataRate is used to calculate appropriate data rate for given interval and set that interval to the channel
         */
        TInt SetDataRate();

        /*
         * SetProperties is used to set properties on the channel before start data listening
         */
        void SetProperties();

        /*
         * GetPropertiesL used to get the properties from sensor server and sets as metadata for Qt.
         */
        void GetPropertiesL();

        /*
         * GetDescription used to get description of sensor from symbian and set
         * as description in Qt
         */
        void GetDescription();

        /*
         * GetDataRate used to get available datarates from symbian and set
         * as availableDataRates in Qt
         */
        void GetDataRate();

        /*
         * GetMeasurementrangeAndAccuracy used to get measurement ranges and accuracy from
         * symbian and set as outputRanges in Qt
         */
        virtual void GetMeasurementrangeAndAccuracy();

        /*
         * Close is used to release all the sensor server objects
         * May change when error handling is supported by mobility apis
         */
        TInt Close();

        /*
         * FindSensorL is used to find if a specific sensor is available on the
         * device, if FindSensorL leaves then the sensor is not supported
         */
        void FindSensorL();

        /*
         * OpenSensorChannelL is used to open the channel for sensor as indicated by
         * iPrivateData.iChannelInfo
         */
        void OpenSensorChannelL();

        /*
         * CloseSensorChannel is used to close the sensor channel and release the
         * resources
         */
        void CloseSensorChannelL();

        /*
         * Used to start listening to the sensor
         */
        void StartListeningL();

        /*
         * Used to stop listening to the sensor
         */
        void StopListeningL();

        /*
         * ProcessReading is used to process one sensor reading
         * It is implemented the the sensor concrete class and handles sensor specific
         * reading data and provides conversion and utility code
         */
        virtual void ProcessReading() = 0;

        /*
         * ProcessData is called by the sub-clases to handle the conditional fetching logic
         * It either processes all arriving readings or just the last one. It calls
         * ProcessReading to do the actual processing
         */
        template <typename T>
        void ProcessData(CSensrvChannel &aChannel, TInt aCount, T &iData)
            {
            int loopMax = aCount;
            if (!m_processAllReadings)
                {
                for (int i = 0; i < aCount; i++)
                    {
                    TPckg<T> pkg( iData );
                    TInt ret = aChannel.GetData( pkg );
                    if (ret != KErrNone)
                        return;
                    }
                loopMax = 1;
                }

            for (int i = 0; i < loopMax; i++)
                {
                if (m_processAllReadings)
                    {
                    TPckg<T> pkg( iData );
                    TInt ret = aChannel.GetData( pkg );
                    if (ret != KErrNone)
                        return;
                    }
                ProcessReading();
                }
            }

    private:
        TSensrvPropertyType propertyType(TSensrvPropertyId, TInt&);

    protected:
        TSensorBackendDataSym iBackendData;
        int m_maximumReadingCount;
        bool m_processAllReadings;
        int m_desiredReadingCount;
        int m_bufferingPeriod;
    };

#endif //SENSORBACKENDSYM_H