Choreonoid  1.5
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 <boost/function.hpp>
9 #include "exportdecl.h"
10 
11 namespace cnoid {
12 
13 class LazyCallerImpl;
14 
15 
21 {
22  friend class LazyCallerImpl;
23 
24  bool isPending_;
25  bool isNextPending;
26  LazyCallerImpl* impl;
27 
28 public:
29  enum { PRIORITY_HIGH = 0, PRIORITY_NORMAL, PRIORITY_LOW };
30 
31  LazyCaller();
32  LazyCaller(const boost::function<void(void)>& function, int priority = PRIORITY_HIGH);
33  LazyCaller(const LazyCaller& org);
34  virtual ~LazyCaller();
35 
36  void setFunction(const boost::function<void(void)>& function);
37  void setPriority(int priority);
38 
44  void setConservative(bool on);
45 
46  bool isPending() const { return isPending_; }
47 
48  void flush();
49 
50  typedef void result_type;
51 
55  void operator()() {
56  if(!isPending_){
57  isPending_ = true;
58  postCallEvent();
59  }
60  }
61 
62  void cancel();
63 
64 private:
65  void postCallEvent();
66 };
67 
68 
69 class QueuedCallerImpl;
70 
72 {
73  QueuedCallerImpl* impl;
74 
75  QueuedCaller(const QueuedCaller& org);
76 
77  public:
81  QueuedCaller();
82  virtual ~QueuedCaller();
83 
84  void callLater(const boost::function<void()>& function, int priority = LazyCaller::PRIORITY_NORMAL);
85 
86  void cancel();
87 };
88 
89 
94 
95 CNOID_EXPORT void callLater(const boost::function<void()>& function, int priority = LazyCaller::PRIORITY_NORMAL);
96 CNOID_EXPORT void callFromMainThread(const boost::function<void()>& function, int priority = LazyCaller::PRIORITY_NORMAL);
97 CNOID_EXPORT bool callSynchronously(const boost::function<void()>& function, int priority = LazyCaller::PRIORITY_NORMAL);
98 
100 
101 }
102 
103 #endif
CNOID_EXPORT bool callSynchronously(const boost::function< void()> &function, int priority=LazyCaller::PRIORITY_NORMAL)
CNOID_EXPORT void callLater(const boost::function< void()> &function, int priority=LazyCaller::PRIORITY_NORMAL)
Definition: LazyCaller.h:29
bool isPending() const
Definition: LazyCaller.h:46
Definition: LazyCaller.h:29
Definition: LazyCaller.h:20
CNOID_EXPORT void callFromMainThread(const boost::function< void()> &function, int priority=LazyCaller::PRIORITY_NORMAL)
Definition: LazyCaller.h:91
Definition: LazyCaller.h:93
Defines the minimum processing for performing pasing file for STL.
Definition: AbstractSceneLoader.h:9
Definition: LazyCaller.h:71
Definition: LazyCaller.h:92
CNOID_EXPORT bool isRunningInMainThread()
Definition: LazyCaller.cpp:106
#define CNOID_EXPORT
Definition: Util/exportdecl.h:37
void result_type
Definition: LazyCaller.h:50
Definition: LazyCaller.h:29
void operator()()
Definition: LazyCaller.h:55