1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_
6 #define XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/synchronization/lock.h"
12 #include "ui/gfx/display.h"
13 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
17 class SensorProvider {
19 static SensorProvider* GetInstance();
20 virtual ~SensorProvider();
22 bool connected() const;
26 virtual ~Observer() {}
28 virtual void OnScreenOrientationChanged(
29 blink::WebScreenOrientationType orientation) {}
31 virtual void OnOrientationChanged(float alpha, float beta, float gamma) {}
32 virtual void OnAccelerationChanged(float raw_x, float raw_y, float raw_z,
33 float x, float y, float z) {}
34 virtual void OnRotationRateChanged(float alpha, float beta, float gamma) {}
36 virtual void OnSensorConnected() {}
39 virtual void AddObserver(Observer* observer);
40 virtual void RemoveObserver(Observer* observer);
42 virtual blink::WebScreenOrientationType GetScreenOrientation() const {
43 return last_orientation_;
46 static bool initialized_;
51 virtual bool Initialize() = 0;
52 virtual void Finish() {}
54 virtual void OnScreenOrientationChanged(
55 blink::WebScreenOrientationType orientation);
57 virtual void OnOrientationChanged(float alpha, float beta, float gamma);
58 virtual void OnAccelerationChanged(float raw_x, float raw_y, float raw_z,
59 float x, float y, float z);
60 virtual void OnRotationRateChanged(float alpha, float beta, float gamma);
62 virtual void OnSensorConnected();
64 std::set<Observer*> observers_;
65 blink::WebScreenOrientationType last_orientation_;
67 mutable base::Lock lock_;
68 mutable bool connected_;
71 static scoped_ptr<SensorProvider> instance_;
73 DISALLOW_COPY_AND_ASSIGN(SensorProvider);
78 #endif // XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_