Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef XDISPATCH_SOURCE_H_
00024 #define XDISPATCH_SOURCE_H_
00025
00031 #ifndef __XDISPATCH_INDIRECT__
00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00033 #endif
00034
00035 #include "any.h"
00036
00037 __XDISPATCH_BEGIN_NAMESPACE
00038
00039 class source;
00040
00041
00050 class XDISPATCH_EXPORT sourcetype {
00051
00052 public:
00053 virtual ~sourcetype();
00054
00055 protected:
00056 sourcetype();
00057
00064 void ready(const any& = any());
00073 virtual dispatch_source_t native();
00082 virtual void on_cancel();
00092 virtual void on_resume();
00102 virtual void on_suspend();
00116 virtual bool propagate_targetqueue() const { return false; }
00117
00118 private:
00119 sourcetype(const sourcetype&){}
00120 void set_cb(source*);
00121 friend class source;
00122 source* cb;
00123 };
00124
00125
00126 class native_source_wrapper;
00127
00137 class XDISPATCH_EXPORT native_source : public sourcetype {
00138
00139 public:
00140 native_source(dispatch_source_t);
00141 ~native_source();
00142
00143 protected:
00144 virtual dispatch_source_t native();
00145 void on_resume ();
00146 void on_suspend ();
00147 void on_cancel ();
00148 bool propagate_targetqueue () const;
00149
00155 virtual void on_source_ready();
00156
00157 private:
00158 pointer<native_source_wrapper>::shared _source;
00159 };
00160
00161
00176 class XDISPATCH_EXPORT source : public object {
00177
00178 public:
00182 source(sourcetype*);
00183 ~source();
00184
00185 void resume();
00186 void suspend();
00187
00194 void handler(xdispatch::operation*);
00195 #if XDISPATCH_HAS_BLOCKS
00196
00202 virtual inline void handler(dispatch_block_t b) {
00203 handler( new block_operation(b) );
00204 }
00205 #endif
00206 #if XDISPATCH_HAS_FUNCTION
00207
00213 virtual inline void handler(const lambda_function& b) {
00214 handler( new function_operation(b) );
00215 }
00216 #endif
00217
00220 void target_queue(const xdispatch::queue&);
00224 xdispatch::queue target_queue() const;
00237 template <typename T> static T data(){
00238 return _data()->cast<T>();
00239 }
00240
00246 virtual dispatch_object_t native() const;
00252 dispatch_source_t native_source() const;
00275 void cancel();
00284 void cancel_handler(xdispatch::operation*);
00285 #if XDISPATCH_HAS_BLOCKS
00286
00294 virtual inline void cancel_handler(dispatch_block_t b) {
00295 cancel_handler( new block_operation(b) );
00296 }
00297 #endif
00298 #if XDISPATCH_HAS_FUNCTION
00299
00307 virtual inline void cancel_handler(const lambda_function& b) {
00308 cancel_handler( new function_operation(b) );
00309 }
00310 #endif
00311
00312 private:
00313 source(const source&);
00314 source& operator=(const source&);
00315 class pdata;
00316 pointer<pdata>::shared d;
00317
00318 void notify(const any&);
00319 sourcetype* source_type();
00320 static const any* _data();
00321 friend class sourcetype;
00322 friend class timer;
00323 };
00324
00325 __XDISPATCH_END_NAMESPACE
00326
00329 #endif