Upstream version 7.35.144.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 "ui/gfx/display.h"
12
13 namespace xwalk {
14
15 class SensorProvider {
16  public:
17   class Observer {
18    public:
19     virtual ~Observer() {}
20
21     virtual void OnRotationChanged(gfx::Display::Rotation r) {}
22     virtual void OnOrientationChanged(float alpha, float beta, float gamma) {}
23     virtual void OnAccelerationChanged(float raw_x, float raw_y, float raw_z,
24                                        float x, float y, float z) {}
25     virtual void OnRotationRateChanged(float alpha, float beta, float gamma) {}
26   };
27
28   static SensorProvider* GetInstance();
29
30   virtual ~SensorProvider();
31
32   virtual void AddObserver(Observer* observer);
33   virtual void RemoveObserver(Observer* observer);
34
35   virtual gfx::Display::Rotation GetCurrentRotation() const {
36     return last_rotation_;
37   }
38
39   static bool initialized_;
40
41  protected:
42   SensorProvider();
43
44   virtual bool Initialize() = 0;
45   virtual void Finish() {}
46
47   virtual void OnRotationChanged(gfx::Display::Rotation rotation);
48   virtual void OnOrientationChanged(float alpha, float beta, float gamma);
49   virtual void OnAccelerationChanged(float raw_x, float raw_y, float raw_z,
50                                      float x, float y, float z);
51   virtual void OnRotationRateChanged(float alpha, float beta, float gamma);
52
53   std::set<Observer*> observers_;
54   gfx::Display::Rotation last_rotation_;
55
56  private:
57   static scoped_ptr<SensorProvider> instance_;
58
59   DISALLOW_COPY_AND_ASSIGN(SensorProvider);
60 };
61
62 }  // namespace xwalk
63
64 #endif  // XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_