Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / xwalk / tizen / mobile / sensor / sensor_provider.h
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.
4
5 #ifndef XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_
6 #define XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_
7
8 #include <set>
9
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"
14
15 namespace xwalk {
16
17 class SensorProvider {
18  public:
19   static SensorProvider* GetInstance();
20   virtual ~SensorProvider();
21
22   bool connected() const;
23
24   class Observer {
25    public:
26     virtual ~Observer() {}
27
28     virtual void OnScreenOrientationChanged(
29         blink::WebScreenOrientationType orientation) {}
30
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) {}
35
36     virtual void OnSensorConnected() {}
37   };
38
39   virtual void AddObserver(Observer* observer);
40   virtual void RemoveObserver(Observer* observer);
41
42   virtual blink::WebScreenOrientationType GetScreenOrientation() const {
43     return last_orientation_;
44   }
45
46   static bool initialized_;
47
48  protected:
49   SensorProvider();
50
51   virtual bool Initialize() = 0;
52   virtual void Finish() {}
53
54   virtual void OnScreenOrientationChanged(
55       blink::WebScreenOrientationType orientation);
56
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);
61
62   virtual void OnSensorConnected();
63
64   std::set<Observer*> observers_;
65   blink::WebScreenOrientationType last_orientation_;
66
67   mutable base::Lock lock_;
68   mutable bool connected_;
69
70  private:
71   static scoped_ptr<SensorProvider> instance_;
72
73   DISALLOW_COPY_AND_ASSIGN(SensorProvider);
74 };
75
76 }  // namespace xwalk
77
78 #endif  // XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_