libqi-api
2.0.6.8
|
00001 #pragma once 00002 /* 00003 ** Copyright (C) 2012 Aldebaran Robotics 00004 ** See COPYING for the license 00005 */ 00006 00007 #ifndef _QI_EVENTLOOP_HPP_ 00008 #define _QI_EVENTLOOP_HPP_ 00009 00010 #ifdef _MSC_VER 00011 # pragma warning( disable: 4503 ) // decorated name length 00012 #endif 00013 00014 #include <boost/shared_ptr.hpp> 00015 #include <boost/function.hpp> 00016 00017 #include <qi/types.hpp> 00018 #include <qi/api.hpp> 00019 00020 #ifdef _MSC_VER 00021 # pragma warning( push ) 00022 # pragma warning( disable: 4251 ) 00023 #endif 00024 00025 namespace boost { 00026 namespace asio { 00027 class io_service; 00028 }} 00029 00030 namespace qi 00031 { 00032 template<typename T> class Future; 00033 00034 class EventLoopPrivate; 00035 class QI_API EventLoop 00036 { 00037 public: 00041 EventLoop(); 00042 ~EventLoop(); 00044 bool isInEventLoopThread(); 00046 void start(int nthreads = 0); 00048 void startThreadPool(int minWorkers=-1, int maxWorkers=-1, int minIdleWorkers=-1, int maxIdleWorkers=-1); 00050 void join(); 00052 void stop(); 00054 void run(); 00056 void setEmergencyCallback(boost::function<void()> cb); 00057 00059 void setMaxThreads(unsigned int max); 00060 00061 // Internal function 00062 void *nativeHandle(); 00063 00065 00069 template<typename R> 00070 Future<R> async(boost::function<R()> callback, uint64_t usDelay=0); 00071 Future<void> async(boost::function<void ()> callback, uint64_t usDelay=0); 00072 00074 00076 void post(const boost::function<void ()>& callback, uint64_t usDelay=0); 00077 00085 Future<void> monitorEventLoop(EventLoop* helper, uint64_t maxUsDelay); 00086 00087 EventLoopPrivate *_p; 00088 }; 00089 00091 QI_API EventLoop* getEventLoop(); 00092 00094 QI_API void startEventLoop(int nthread); 00095 00097 QI_API boost::asio::io_service& getIoService(); 00098 00101 QI_API QI_API_DEPRECATED EventLoop* getDefaultNetworkEventLoop(); 00103 QI_API QI_API_DEPRECATED EventLoop* getDefaultObjectEventLoop(); 00105 QI_API QI_API_DEPRECATED EventLoop* getDefaultThreadPoolEventLoop(); 00106 } 00107 00108 #ifdef _MSC_VER 00109 # pragma warning( pop ) 00110 #endif 00111 00112 #include <qi/details/eventloop.hxx> 00113 #endif // _QI_EVENTLOOP_HPP_