c121f1e5a6b9dbb2170911ac892c6a5dd715af8c
[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  protected:
40   SensorProvider();
41
42   virtual bool Initialize() = 0;
43   virtual void Finish() {}
44
45   virtual void OnRotationChanged(gfx::Display::Rotation rotation);
46   virtual void OnOrientationChanged(float alpha, float beta, float gamma);
47   virtual void OnAccelerationChanged(float raw_x, float raw_y, float raw_z,
48                                      float x, float y, float z);
49   virtual void OnRotationRateChanged(float alpha, float beta, float gamma);
50
51   std::set<Observer*> observers_;
52   gfx::Display::Rotation last_rotation_;
53
54  private:
55   static scoped_ptr<SensorProvider> instance_;
56
57   DISALLOW_COPY_AND_ASSIGN(SensorProvider);
58 };
59
60 }  // namespace xwalk
61
62 #endif  // XWALK_TIZEN_MOBILE_SENSOR_SENSOR_PROVIDER_H_