Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / tilt-sensor-impl.h
1 #ifndef __DALI_INTERNAL_ADAPTOR_TILT_SENSOR_H__
2 #define __DALI_INTERNAL_ADAPTOR_TILT_SENSOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #ifdef CAPI_SYSTEM_SENSOR_SUPPORT
23 #include <sensor/sensor.h>
24
25 #define SENSOR_ENABLED
26 #endif
27
28 #include <deque>
29 #include <dali/public-api/object/base-object.h>
30
31 // INTERNAL INCLUDES
32 #include <public-api/adaptor-framework/timer.h>
33 #include <devel-api/adaptor-framework/tilt-sensor.h>
34
35 namespace Dali
36 {
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43
44 /**
45  * TiltSensor provides pitch & roll values when the device is tilted.
46  */
47 class TiltSensor : public Dali::BaseObject
48 {
49 public:
50
51   typedef Dali::TiltSensor::TiltedSignalType TiltedSignalType;
52
53   /**
54    * Create a TiltSensor.
55    * This should only be called once by the Adaptor class.
56    * @return A newly allocated tilt-sensor.
57    */
58   static Dali::TiltSensor New();
59
60   /**
61    * @copydoc Dali::TiltSensor::Get()
62    */
63   static Dali::TiltSensor Get();
64
65   /**
66    * @copydoc Dali::TiltSensor::Enable()
67    */
68   bool Enable();
69
70   /**
71    * @copydoc Dali::TiltSensor::Disable()
72    */
73   void Disable();
74
75   /**
76    * @copydoc Dali::TiltSensor::IsEnabled()
77    */
78   bool IsEnabled() const;
79
80   /**
81    * @copydoc Dali::TiltSensor::GetRoll()
82    */
83   float GetRoll() const;
84
85   /**
86    * @copydoc Dali::TiltSensor::GetPitch()
87    */
88   float GetPitch() const;
89
90   /**
91    * @copydoc Dali::TiltSensor::GetRotation()
92    */
93   Quaternion GetRotation() const;
94
95   /**
96    * @copydoc Dali::TiltSensor::TiltedSignal()
97    */
98   TiltedSignalType& TiltedSignal();
99
100   /**
101    * @copydoc Dali::TiltSensor::SetUpdateFrequency()
102    */
103   void SetUpdateFrequency( float frequencyHertz );
104
105   /**
106    * @copydoc Dali::TiltSensor::GetUpdateFrequency()
107    */
108   float GetUpdateFrequency() const;
109
110   /**
111    * @copydoc Dali::TiltSensor::SetRotationThreshold()
112    */
113   void SetRotationThreshold(Radian rotationThreshold);
114
115   /**
116    * @copydoc Dali::TiltSensor::GetRotationThreshold()
117    */
118   Radian GetRotationThreshold() const;
119
120   /**
121    * Connects a callback function with the object's signals.
122    * @param[in] object The object providing the signal.
123    * @param[in] tracker Used to disconnect the signal.
124    * @param[in] signalName The signal to connect to.
125    * @param[in] functor A newly allocated FunctorDelegate.
126    * @return True if the signal was connected.
127    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
128    */
129   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
130
131   /**
132    * Update sensor data
133    * @note This is called by static sensor callback function
134    * @param[in] event sensor event data
135    */
136 #ifdef SENSOR_ENABLED
137   void Update(sensor_event_s *event);
138 #endif
139
140 private:
141
142   enum State
143   {
144     DISCONNECTED,
145     CONNECTED,
146     STARTED,
147     STOPPED
148   };
149
150   /**
151    * Private constructor; see also TiltSensor::New()
152    */
153   TiltSensor();
154
155   /**
156    * Destructor
157    */
158   virtual ~TiltSensor();
159
160   /**
161    * Connect sensor device
162    */
163   bool Connect();
164   /**
165    * Disconnect sensor device
166    */
167   void Disconnect();
168
169   /**
170    * Start sensor operation
171    */
172   bool Start();
173   /**
174    * Stop sensor operation
175    */
176   void Stop();
177
178   // Undefined
179   TiltSensor(const TiltSensor&);
180
181   // Undefined
182   TiltSensor& operator=(TiltSensor&);
183
184 private:
185   State mState;
186   float mFrequencyHertz;
187
188 #ifdef SENSOR_ENABLED
189   sensor_type_e mSensorType;
190   sensor_h mSensor;
191   sensor_listener_h mSensorListener;
192 #else
193   int mSensorType;
194   int* mSensor;
195   int* mSensorListener;
196 #endif
197
198   float mRoll;
199   float mPitch;
200   Quaternion mRotation;
201
202   Radian mRotationThreshold;
203
204   TiltedSignalType mTiltedSignal;
205 };
206
207 } // namespace Adaptor
208
209 } // namespace Internal
210
211 // Helpers for public-api forwarding methods
212
213 inline Internal::Adaptor::TiltSensor& GetImplementation(Dali::TiltSensor& sensor)
214 {
215   DALI_ASSERT_ALWAYS( sensor && "TiltSensor handle is empty" );
216
217   BaseObject& handle = sensor.GetBaseObject();
218
219   return static_cast<Internal::Adaptor::TiltSensor&>(handle);
220 }
221
222 inline const Internal::Adaptor::TiltSensor& GetImplementation(const Dali::TiltSensor& sensor)
223 {
224   DALI_ASSERT_ALWAYS( sensor && "TiltSensor handle is empty" );
225
226   const BaseObject& handle = sensor.GetBaseObject();
227
228   return static_cast<const Internal::Adaptor::TiltSensor&>(handle);
229 }
230
231 } // namespace Dali
232
233 #endif // __DALI_INTERNAL_ADAPTOR_TILT_SENSOR_H__