- add sources.
[platform/framework/web/crosswalk.git] / src / ozone / wayland / dispatcher.h
1 // Copyright 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 OZONE_WAYLAND_DISPATCHER_H_
6 #define OZONE_WAYLAND_DISPATCHER_H_
7
8 #include "base/threading/thread.h"
9
10 namespace ozonewayland {
11 class OzoneDisplay;
12 class WaylandDispatcherDelegate;
13 class WindowChangeObserver;
14
15 // WaylandDispatcher class is used by OzoneDisplay for reading pending events
16 // coming from Wayland compositor and flush requests back. WaylandDispatcher is
17 // performed entirely in a separate IO thread and it can use polling as needed
18 // for the operations.
19
20 // WaylandDispatcher uses WaylandDispatcherDelegate to dispatch messages
21 // appropriately.
22
23 class WaylandDispatcher : public base::Thread {
24  public:
25   enum Task {
26     Flush = 0x01,  // Handles Flush in worker thread.
27     Poll = 0x02  // To poll on a display fd. Task has no effect in case
28                  // a valid display fd is not passed to WaylandDispatcher.
29   };
30
31   static WaylandDispatcher* GetInstance() { return instance_; }
32   void MotionNotify(float x, float y);
33   void ButtonNotify(unsigned handle, int state, int flags, float x, float y);
34   void AxisNotify(float x, float y, float xoffset, float yoffset);
35   void PointerEnter(unsigned handle, float x, float y);
36   void PointerLeave(unsigned handle, float x, float y);
37   void KeyNotify(unsigned type, unsigned code, unsigned modifiers);
38   void OutputSizeChanged(unsigned width, unsigned height);
39
40   // Posts task to worker thread.
41   void PostTask(Task type = Flush);
42
43   void SetWindowChangeObserver(WindowChangeObserver* observer);
44   void SetDelegate(WaylandDispatcherDelegate* delegate);
45   void SetActive(bool active);
46
47  private:
48   explicit WaylandDispatcher(int fd = 0);
49   virtual ~WaylandDispatcher();
50   static void HandleFlush();
51   static void DisplayRun(WaylandDispatcher* data);
52   bool active_ :1;
53   int epoll_fd_;
54   int display_fd_;
55   WaylandDispatcherDelegate* delegate_;
56   static WaylandDispatcher* instance_;
57   friend class OzoneDisplay;
58   DISALLOW_COPY_AND_ASSIGN(WaylandDispatcher);
59 };
60
61 }  // namespace ozonewayland
62
63 #endif  // OZONE_WAYLAND_DISPATCHER_H_