Choreonoid  1.8
LazyCaller.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BASE_LAZY_CALLER_H
6 #define CNOID_BASE_LAZY_CALLER_H
7 
8 #include <functional>
9 #include "exportdecl.h"
10 
11 namespace cnoid {
12 
13 class LazyCallerImpl;
14 
15 
20 class CNOID_EXPORT LazyCaller
21 {
22  friend class LazyCallerImpl;
23 
24  bool isPending_;
25  bool isNextPending;
26  LazyCallerImpl* impl;
27 
28 public:
29  enum Priority {
30  HighPriority = 0,
34 
35  // deprecated
36  PRIORITY_HIGH = HighPriority,
37  PRIORITY_NORMAL = NormalPriority,
38  PRIORITY_LOW = LowPriority
39  };
40 
41  LazyCaller();
42  LazyCaller(const std::function<void(void)>& function, int priority = HighPriority);
43  LazyCaller(const LazyCaller& org);
44  virtual ~LazyCaller();
45 
46  void setFunction(const std::function<void(void)>& function);
47  void setPriority(int priority);
48 
55  void setConservative(bool on);
56 
57  bool isPending() const { return isPending_; }
58 
59  void flush();
60 
61  typedef void result_type;
62 
66  void operator()() {
67  if(!isPending_){
68  isPending_ = true;
69  postCallEvent();
70  }
71  }
72 
73  void cancel();
74 
75 private:
76  void postCallEvent();
77 };
78 
79 
80 class QueuedCallerImpl;
81 
82 class CNOID_EXPORT QueuedCaller
83 {
84  QueuedCallerImpl* impl;
85 
86  QueuedCaller(const QueuedCaller& org);
87 
88  public:
92  QueuedCaller();
93  virtual ~QueuedCaller();
94 
95  void callLater(const std::function<void()>& function, int priority = LazyCaller::NormalPriority);
96 
97  void cancel();
98 };
99 
100 
105 
106 CNOID_EXPORT void callLater(const std::function<void()>& function, int priority = LazyCaller::NormalPriority);
107 CNOID_EXPORT void callFromMainThread(const std::function<void()>& function, int priority = LazyCaller::NormalPriority);
108 CNOID_EXPORT bool callSynchronously(const std::function<void()>& function, int priority = LazyCaller::NormalPriority);
109 
110 CNOID_EXPORT bool isRunningInMainThread();
111 
112 }
113 
114 #endif
cnoid::LazyCaller::result_type
void result_type
Definition: LazyCaller.h:61
cnoid::LazyCaller::PRIORITY_HIGH
@ PRIORITY_HIGH
Definition: LazyCaller.h:36
cnoid::LazyCaller::NormalPriority
@ NormalPriority
Definition: LazyCaller.h:31
cnoid::callLater
CNOID_EXPORT void callLater(const std::function< void()> &function, int priority=LazyCaller::NormalPriority)
cnoid::LazyCaller::PRIORITY_NORMAL
@ PRIORITY_NORMAL
Definition: LazyCaller.h:37
cnoid::IDLE_PRIORITY_HIGH
@ IDLE_PRIORITY_HIGH
Definition: LazyCaller.h:102
cnoid::callFromMainThread
CNOID_EXPORT void callFromMainThread(const std::function< void()> &function, int priority=LazyCaller::NormalPriority)
cnoid::LazyCaller::PRIORITY_LOW
@ PRIORITY_LOW
Definition: LazyCaller.h:38
cnoid::IDLE_PRIORITY_LOW
@ IDLE_PRIORITY_LOW
Definition: LazyCaller.h:104
cnoid::LazyCaller
Definition: LazyCaller.h:20
cnoid::LazyCaller::LowPriority
@ LowPriority
Definition: LazyCaller.h:32
cnoid::LazyCaller::MinimumPriority
@ MinimumPriority
Definition: LazyCaller.h:33
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::LazyCaller::Priority
Priority
Definition: LazyCaller.h:29
cnoid::isRunningInMainThread
CNOID_EXPORT bool isRunningInMainThread()
Definition: LazyCaller.cpp:115
cnoid::QueuedCaller
Definition: LazyCaller.h:82
cnoid::LazyCaller::operator()
void operator()()
Definition: LazyCaller.h:66
cnoid::IDLE_PRIORITY_NORMAL
@ IDLE_PRIORITY_NORMAL
Definition: LazyCaller.h:103
cnoid::LazyCaller::isPending
bool isPending() const
Definition: LazyCaller.h:57
cnoid::callSynchronously
CNOID_EXPORT bool callSynchronously(const std::function< void()> &function, int priority=LazyCaller::NormalPriority)