d2e05c9c68f7bcc34162c75ffaaff19435c2926e
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_ECORE_H_
7 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_ECORE_H_
8
9 #include "base/base_export.h"
10 #include "base/macros.h"
11 #include "base/message_loop/message_pump.h"
12 #include "base/synchronization/lock.h"
13 #include "base/time/time.h"
14
15 #include <Ecore.h>
16
17 namespace base {
18
19 class BASE_EXPORT MessagePumpEcore : public MessagePump {
20  public:
21   MessagePumpEcore();
22   ~MessagePumpEcore() override;
23
24   void Run(Delegate* delegate) override;
25   void Quit() override;
26   void ScheduleWork() override;
27   void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
28
29  private:
30   static void OnWakeup(void* data, void* buffer, unsigned int nbyte);
31   static Eina_Bool OnTimerFired(void* data);
32
33   // We may make recursive calls to Run, so we save state that needs to be
34   // separate between them in this structure type.
35   struct RunState;
36   RunState* state_;
37
38   // We use a wakeup pipe to make sure we'll get out of the ecore mainloop
39   // blocking phase when another thread has scheduled us to do some work.
40   Ecore_Pipe* wakeup_pipe_;
41
42   // The lock that protects access to wakeup pipe.
43   base::Lock wakeup_pipe_lock_;
44
45   // This is the time when we need to do delayed work.
46   TimeTicks delayed_work_time_;
47
48   // This is the timer that is needed to get out of ecore mainloop blocking
49   // phase after delay.
50   Ecore_Timer* delayed_work_timer_;
51
52   DISALLOW_COPY_AND_ASSIGN(MessagePumpEcore);
53 };
54
55 }  // namespace base
56
57 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_ECORE_H_