32 #ifndef VSMC_GCD_DISPATCH_SOURCE_HPP
33 #define VSMC_GCD_DISPATCH_SOURCE_HPP
70 template <DispatchSourceType Type>
75 void resume ()
const {::dispatch_resume(this->
object());}
77 void suspend ()
const {::dispatch_suspend(this->
object());}
79 void cancel ()
const {::dispatch_source_cancel(this->
object());}
82 {return ::dispatch_source_testcancel(this->
object());}
85 {return ::dispatch_source_get_data(this->
object());}
88 {return ::dispatch_source_get_handle(this->
object());}
91 {return ::dispatch_source_get_mask(this->
object());}
94 {::dispatch_source_set_cancel_handler_f(this->
object(), cancel_handler);}
97 {::dispatch_source_set_event_handler_f(this->
object(), event_handler);}
101 registration_handler)
const
103 ::dispatch_source_set_registration_handler_f(
104 this->
object(), registration_handler);
106 #endif // VSMC_HAS_GCD_LION
110 {::dispatch_source_set_cancel_handler(this->
object(), cancel_handler);}
113 {::dispatch_source_set_event_handler(this->
object(), event_handler);}
115 #if VSMC_HAS_GCD_LION
117 registration_handler)
const
119 ::dispatch_source_set_registration_handler(
120 this->
object(), registration_handler);
122 #endif // VSMC_HAS_GCD_LION
127 template <DispatchSourceType>
struct source_type {};
134 source_type_t(source_type<Type>()),
135 handle, mask, queue), false) {}
139 static ::dispatch_source_type_t source_type_t (
140 source_type<DispatchDataAdd>)
141 {
return DISPATCH_SOURCE_TYPE_DATA_ADD;}
143 static ::dispatch_source_type_t source_type_t (
144 source_type<DispatchDataOr>)
145 {
return DISPATCH_SOURCE_TYPE_DATA_OR;}
147 static ::dispatch_source_type_t source_type_t (
148 source_type<DispatchMachRecv>)
149 {
return DISPATCH_SOURCE_TYPE_MACH_RECV;}
151 static ::dispatch_source_type_t source_type_t (
152 source_type<DispatchMachSend>)
153 {
return DISPATCH_SOURCE_TYPE_MACH_SEND;}
155 static ::dispatch_source_type_t source_type_t (
156 source_type<DispatchProc>)
157 {
return DISPATCH_SOURCE_TYPE_PROC;}
159 static ::dispatch_source_type_t source_type_t (
160 source_type<DispatchRead>)
161 {
return DISPATCH_SOURCE_TYPE_READ;}
163 static ::dispatch_source_type_t source_type_t (
164 source_type<DispatchSignal>)
165 {
return DISPATCH_SOURCE_TYPE_SIGNAL;}
167 static ::dispatch_source_type_t source_type_t (
168 source_type<DispatchTimer>)
169 {
return DISPATCH_SOURCE_TYPE_TIMER;}
171 static ::dispatch_source_type_t source_type_t (
172 source_type<DispatchVnode>)
173 {
return DISPATCH_SOURCE_TYPE_VNODE;}
175 static ::dispatch_source_type_t source_type_t (
176 source_type<DispatchWrite>)
177 {
return DISPATCH_SOURCE_TYPE_WRITE;}
182 template <DispatchSourceType Type>
183 class DispatchSource :
public DispatchSourceBase<Type>
187 template <DispatchQueueType QType>
205 template <DispatchQueueType QType>
215 {::dispatch_source_merge_data(this->
object(), value);}
226 template <DispatchQueueType QType>
236 {::dispatch_source_merge_data(this->
object(), value);}
247 template <DispatchQueueType QType>
257 uint64_t interval, uint64_t leeway)
const
258 {::dispatch_source_set_timer(this->
object(), start, interval, leeway);}
263 #endif // VSMC_GCD_DISPATCH_SOURCE_HPP
DISPATCH_SOURCE_TYPE_SIGNAL.
Base class of Dispatch objects.
uintptr_t get_handle() const
DispatchSourceBase(uintptr_t handle, unsigned long mask,::dispatch_queue_t queue)
DispatchSource(uintptr_t handle, unsigned long mask, const DispatchQueue< QType > &queue)
void set_cancel_handler_f(::dispatch_function_t cancel_handler) const
DISPATCH_SOURCE_TYPE_PROC.
DispatchSource(uintptr_t handle, unsigned long mask, const DispatchQueue< QType > &queue)
void set_event_handler_f(::dispatch_function_t event_handler) const
void set_event_handler(::dispatch_block_t event_handler) const
void merge_data(unsigned long value) const
DISPATCH_SOURCE_TYPE_VNODE.
void set_cancel_handler(::dispatch_block_t cancel_handler) const
void set_registration_handler_f(::dispatch_function_t registration_handler) const
Base class of DispatchSource.
void set_timer(::dispatch_time_t start, uint64_t interval, uint64_t leeway) const
DispatchSource(uintptr_t handle, unsigned long mask, const DispatchQueue< QType > &queue)
DISPATCH_SOURCE_TYPE_MACH_RECV.
DISPATCH_SOURCE_TYPE_READ.
DispatchSource(uintptr_t handle, unsigned long mask,::dispatch_queue_t queue)
DISPATCH_SOURCE_TYPE_WRITE.
DISPATCH_SOURCE_TYPE_MACH_SEND.
void set_registration_handler(::dispatch_block_t registration_handler) const
DispatchSource(uintptr_t handle, unsigned long mask,::dispatch_queue_t queue)
DISPATCH_SOURCE_TYPE_DATA_OR.
unsigned long get_data() const
DispatchSourceType
Types of DispatchSource.
void merge_data(unsigned long value) const
DISPATCH_SOURCE_TYPE_DATA_ADD.
unsigned long get_mask() const
DISPATCH_SOURCE_TYPE_TIMER.
DispatchSource(uintptr_t handle, unsigned long mask,::dispatch_queue_t queue)
DispatchSource(uintptr_t handle, unsigned long mask, const DispatchQueue< QType > &queue)
DispatchSource(uintptr_t handle, unsigned long mask,::dispatch_queue_t queue)
::dispatch_source_t object() const
Return the underlying Dispatch object.