[Tizen][dev] Fix TV build
[platform/framework/web/chromium-efl.git] / tizen_src / impl / browser / device_sensors / data_fetcher_impl_tizen.h
1 /*
2    Copyright (C) 2014 Samsung Electronics
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef DATA_FETCHER_IMPL_TIZEN_H_
21 #define DATA_FETCHER_IMPL_TIZEN_H_
22
23 #ifndef TIZEN_LEGACY_V_2_2_1
24 #include <sensor/sensor.h>
25 #else
26 #include <sensors.h>
27 #endif
28
29 #include "base/memory/scoped_ptr.h"
30 #include "base/synchronization/lock.h"
31 #include "content/browser/device_sensors/inertial_sensor_consts.h"
32 #include "content/common/device_sensors/device_motion_hardware_buffer.h"
33 #include "content/common/device_sensors/device_orientation_hardware_buffer.h"
34
35 template<typename T> struct DefaultSingletonTraits;
36
37 namespace content {
38
39 class DataFetcherImplTizen {
40  public:
41   static DataFetcherImplTizen* GetInstance();
42
43   // Shared memory related methods.
44   bool StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer);
45   void StopFetchingDeviceMotionData();
46
47   bool StartFetchingDeviceOrientationData(
48       DeviceOrientationHardwareBuffer* buffer);
49   void StopFetchingDeviceOrientationData();
50
51   virtual bool Start(ConsumerType);
52   virtual void Stop(ConsumerType);
53
54  protected:
55   DataFetcherImplTizen();
56   virtual ~DataFetcherImplTizen();
57   static void onOrientationChanged(unsigned long long timestamp,
58                                    sensor_data_accuracy_e, float azimuth,
59                                    float pitch, float roll, void* userData);
60   static void onAccelerationChanged(unsigned long long timestamp,
61                                     sensor_data_accuracy_e, float x, float y,
62                                     float z, void* userData);
63
64  private:
65   friend struct DefaultSingletonTraits<DataFetcherImplTizen>;
66
67   void SetOrientationBufferReadyStatus(bool ready);
68
69   DeviceMotionHardwareBuffer* device_motion_buffer_;
70   DeviceOrientationHardwareBuffer* device_orientation_buffer_;
71   blink::WebDeviceMotionData last_motion_data_;
72   bool has_last_motion_data_;
73   unsigned long long last_motion_timestamp_;
74   bool is_orientation_buffer_ready_;
75
76   base::Lock motion_buffer_lock_;
77   base::Lock orientation_buffer_lock_;
78
79   sensor_h handle_;
80
81   DISALLOW_COPY_AND_ASSIGN(DataFetcherImplTizen);
82 };
83
84 } // namespace content
85
86 #endif  // DATA_FETCHER_IMPL_TIZEN_H_