Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "deviceorientation.h"
43
44#include <e32base.h>
45#include <sensrvchannelfinder.h>
46#include <sensrvdatalistener.h>
47#include <sensrvchannel.h>
48#include <sensrvorientationsensor.h>
49
50class SymbianOrientation : public DeviceOrientation, public MSensrvDataListener
51{
52 Q_OBJECT
53public:
54 SymbianOrientation()
55 : DeviceOrientation(), m_current(UnknownOrientation), m_sensorChannel(0), m_channelOpen(false)
56 {
57 TRAP_IGNORE(initL());
58 if (!m_sensorChannel)
59 qWarning("No valid sensors found.");
60 }
61
62 ~SymbianOrientation()
63 {
64 if (m_sensorChannel) {
65 m_sensorChannel->StopDataListening();
66 m_sensorChannel->CloseChannel();
67 delete m_sensorChannel;
68 }
69 }
70
71 void initL()
72 {
73 CSensrvChannelFinder *channelFinder = CSensrvChannelFinder::NewLC();
74 RSensrvChannelInfoList channelInfoList;
75 CleanupClosePushL(channelInfoList);
76
77 TSensrvChannelInfo searchConditions;
78 searchConditions.iChannelType = KSensrvChannelTypeIdOrientationData;
79 channelFinder->FindChannelsL(channelInfoList, searchConditions);
80
81 for (int i = 0; i < channelInfoList.Count(); ++i) {
82 TRAPD(error, m_sensorChannel = CSensrvChannel::NewL(channelInfoList[i]));
83 if (!error)
84 TRAP(error, m_sensorChannel->OpenChannelL());
85 if (!error) {
86 TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
87 m_channelOpen = true;
88 break;
89 }
90 if (error) {
91 delete m_sensorChannel;
92 m_sensorChannel = 0;
93 }
94 }
95
96 channelInfoList.Close();
97 CleanupStack::Pop(&channelInfoList);
98 CleanupStack::PopAndDestroy(channelFinder);
99 }
100
101 Orientation orientation() const
102 {
103 return m_current;
104 }
105
106 void setOrientation(Orientation) { }
107
108private:
109 DeviceOrientation::Orientation m_current;
110 CSensrvChannel *m_sensorChannel;
111 bool m_channelOpen;
112 void pauseListening() {
113 if (m_sensorChannel && m_channelOpen) {
114 m_sensorChannel->StopDataListening();
115 m_sensorChannel->CloseChannel();
116 m_channelOpen = false;
117 }
118 }
119
120 void resumeListening() {
121 if (m_sensorChannel && !m_channelOpen) {
122 TRAPD(error, m_sensorChannel->OpenChannelL());
123 if (!error) {
124 TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
125 if (!error) {
126 m_channelOpen = true;
127 }
128 }
129 if (error) {
130 delete m_sensorChannel;
131 m_sensorChannel = 0;
132 }
133 }
134 }
135
136 void DataReceived(CSensrvChannel &channel, TInt count, TInt dataLost)
137 {
138 Q_UNUSED(dataLost)
139 if (channel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdOrientationData) {
140 TSensrvOrientationData data;
141 for (int i = 0; i < count; ++i) {
142 TPckgBuf<TSensrvOrientationData> dataBuf;
143 channel.GetData(dataBuf);
144 data = dataBuf();
145 Orientation orientation = UnknownOrientation;
146 switch (data.iDeviceOrientation) {
147 case TSensrvOrientationData::EOrientationDisplayUp:
148 orientation = Portrait;
149 break;
150 case TSensrvOrientationData::EOrientationDisplayRightUp:
151 orientation = Landscape;
152 break;
153 case TSensrvOrientationData::EOrientationDisplayLeftUp:
154 orientation = LandscapeInverted;
155 break;
156 case TSensrvOrientationData::EOrientationDisplayDown:
157 orientation = PortraitInverted;
158 break;
159 case TSensrvOrientationData::EOrientationUndefined:
160 case TSensrvOrientationData::EOrientationDisplayUpwards:
161 case TSensrvOrientationData::EOrientationDisplayDownwards:
162 default:
163 break;
164 }
165
166 if (m_current != orientation && orientation != UnknownOrientation) {
167 m_current = orientation;
168 emit orientationChanged();
169 }
170 }
171 }
172 }
173
174 void DataError(CSensrvChannel& /* channel */, TSensrvErrorSeverity /* error */)
175 {
176 }
177
178 void GetDataListenerInterfaceL(TUid /* interfaceUid */, TAny*& /* interface */)
179 {
180 }
181};
182
183
184DeviceOrientation* DeviceOrientation::instance()
185{
186 static SymbianOrientation *o = 0;
187 if (!o)
188 o = new SymbianOrientation;
189 return o;
190}
191
192#include "deviceorientation_symbian.moc"
193

Warning: That file was not part of the compilation database. It may have many parsing errors.