cc6602dc514f692356784c70bc98a45c1d507538
[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 #include <sensor.h>
24
25 #include "base/memory/scoped_ptr.h"
26 #include "base/synchronization/lock.h"
27 #include "content/browser/device_sensors/inertial_sensor_consts.h"
28 #include "content/common/device_sensors/device_motion_hardware_buffer.h"
29 #include "content/common/device_sensors/device_orientation_hardware_buffer.h"
30
31 template<typename T> struct DefaultSingletonTraits;
32
33 namespace content {
34
35 class DataFetcherImplTizen {
36  public:
37   static DataFetcherImplTizen* GetInstance();
38
39   // Shared memory related methods.
40   bool StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer);
41   void StopFetchingDeviceMotionData();
42
43   bool StartFetchingDeviceOrientationData(
44       DeviceOrientationHardwareBuffer* buffer);
45   void StopFetchingDeviceOrientationData();
46
47   virtual bool Start(ConsumerType);
48   virtual void Stop(ConsumerType);
49
50  protected:
51   DataFetcherImplTizen();
52   virtual ~DataFetcherImplTizen();
53   static void onOrientationChanged(unsigned long long timestamp,
54                                    sensor_data_accuracy_e, float azimuth,
55                                    float pitch, float roll, void* userData);
56   static void onAccelerationChanged(unsigned long long timestamp,
57                                     sensor_data_accuracy_e, float x, float y,
58                                     float z, void* userData);
59
60  private:
61   friend struct DefaultSingletonTraits<DataFetcherImplTizen>;
62
63   void SetOrientationBufferReadyStatus(bool ready);
64
65   DeviceMotionHardwareBuffer* device_motion_buffer_;
66   DeviceOrientationHardwareBuffer* device_orientation_buffer_;
67   blink::WebDeviceMotionData last_motion_data_;
68   bool has_last_motion_data_;
69   unsigned long long last_motion_timestamp_;
70   bool is_orientation_buffer_ready_;
71
72   base::Lock motion_buffer_lock_;
73   base::Lock orientation_buffer_lock_;
74
75   sensor_h handle_;
76
77   DISALLOW_COPY_AND_ASSIGN(DataFetcherImplTizen);
78 };
79
80 } // namespace content
81
82 #endif  // DATA_FETCHER_IMPL_TIZEN_H_