Render to Frame Buffer Object.
[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::Start()
67    */
68   bool Start();
69
70   /**
71    * @copydoc Dali::TiltSensor::Stop()
72    */
73   void Stop();
74
75   /**
76    * @copydoc Dali::TiltSensor::IsStarted()
77    */
78   bool IsStarted() 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   // Undefined
170   TiltSensor(const TiltSensor&);
171
172   // Undefined
173   TiltSensor& operator=(TiltSensor&);
174
175 private:
176   State mState;
177   float mFrequencyHertz;
178
179 #ifdef SENSOR_ENABLED
180   sensor_type_e mSensorType;
181   sensor_h mSensor;
182   sensor_listener_h mSensorListener;
183 #else
184   int mSensorType;
185   int* mSensor;
186   int* mSensorListener;
187 #endif
188
189   float mRoll;
190   float mPitch;
191   Quaternion mRotation;
192
193   Radian mRotationThreshold;
194
195   TiltedSignalType mTiltedSignal;
196 };
197
198 } // namespace Adaptor
199
200 } // namespace Internal
201
202 // Helpers for public-api forwarding methods
203
204 inline Internal::Adaptor::TiltSensor& GetImplementation(Dali::TiltSensor& sensor)
205 {
206   DALI_ASSERT_ALWAYS( sensor && "TiltSensor handle is empty" );
207
208   BaseObject& handle = sensor.GetBaseObject();
209
210   return static_cast<Internal::Adaptor::TiltSensor&>(handle);
211 }
212
213 inline const Internal::Adaptor::TiltSensor& GetImplementation(const Dali::TiltSensor& sensor)
214 {
215   DALI_ASSERT_ALWAYS( sensor && "TiltSensor handle is empty" );
216
217   const BaseObject& handle = sensor.GetBaseObject();
218
219   return static_cast<const Internal::Adaptor::TiltSensor&>(handle);
220 }
221
222 } // namespace Dali
223
224 #endif // __DALI_INTERNAL_ADAPTOR_TILT_SENSOR_H__