0001    //
0002    //  DispatchSource.swift
0003    //  DispatchKit <https://github.com/anpol/DispatchKit>
0004    //
0005    //  Copyright (c) 2014 Andrei Polushin. All rights reserved.
0006    //
0007    
0008    import Foundation
0009    
0010    public struct DispatchSource: DispatchObject, DispatchResumable, DispatchCancelable {
0011    
0012        @available(*, unavailable, renamed="rawValue")
0013        public var source: dispatch_source_t {
0014            return rawValue
0015        }
0016    
0017        @available(*, unavailable, renamed="DispatchSource(rawValue:)")
0018        public init(raw source: dispatch_source_t!) {
0019            self.rawValue = source
0020        }
0021    
0022        public let rawValue
DispatchSource.swift:25
        self.rawValue = rawValue
DispatchSource.swift:33
        self.rawValue = rawValue
DispatchSource.swift:38
        dispatch_suspend(rawValue)
DispatchSource.swift:42
        dispatch_resume(rawValue)
DispatchSource.swift:47
        dispatch_source_set_registration_handler(rawValue, handler)
DispatchSource.swift:51
        dispatch_source_set_event_handler(rawValue, handler)
DispatchSource.swift:55
        dispatch_source_set_cancel_handler(rawValue, handler)
DispatchSource.swift:60
        dispatch_source_cancel(rawValue)
DispatchSource.swift:64
        return 0 != dispatch_source_testcancel(rawValue)
DispatchSource.swift:69
        return Int(bitPattern: dispatch_source_get_handle(rawValue))
DispatchSource.swift:73
        return dispatch_source_get_mask(rawValue)
DispatchSource.swift:77
        return Int(bitPattern: dispatch_source_get_data(rawValue))
DispatchSource.swift:81
        dispatch_source_merge_data(rawValue, UInt(value))
DispatchSource.swift:85
        dispatch_source_set_timer(rawValue, start.rawValue, interval.rawValue, leeway.rawValue)
: dispatch_source_t 0023 0024 public init(rawValue: dispatch_source_t) { 0025 self.rawValue = rawValue 0026 } 0027 0028 public init!(_ type: DispatchSourceType, handle: UInt = 0, mask: UInt = 0, queue: DispatchQueue) { 0029 guard let rawValue = dispatch_source_create(type.toOpaque(), handle, mask, queue.rawValue) else { 0030 return nil 0031 } 0032 0033 self.rawValue = rawValue 0034 } 0035 0036 0037 public func suspend() { 0038 dispatch_suspend(rawValue) 0039 } 0040 0041 public func resume() { 0042 dispatch_resume(rawValue) 0043 } 0044 0045 0046 public func setRegistrationHandler(handler: dispatch_block_t!) { 0047 dispatch_source_set_registration_handler(rawValue, handler) 0048 } 0049 0050 public func setEventHandler(handler: dispatch_block_t!) { 0051 dispatch_source_set_event_handler(rawValue, handler) 0052 } 0053 0054 public func setCancelHandler(handler: dispatch_block_t!) { 0055 dispatch_source_set_cancel_handler(rawValue, handler) 0056 } 0057 0058 0059 public func cancel() { 0060 dispatch_source_cancel(rawValue) 0061 } 0062 0063 public func testCancel() -> Bool { 0064 return 0 != dispatch_source_testcancel(rawValue) 0065 } 0066 0067 0068 public var handle: Int { 0069 return Int(bitPattern: dispatch_source_get_handle(rawValue)) 0070 } 0071 0072 public var mask: UInt { 0073 return dispatch_source_get_mask(rawValue) 0074 } 0075 0076 public var data: Int { 0077 return Int(bitPattern: dispatch_source_get_data(rawValue)) 0078 } 0079 0080 public func mergeData(value: Int) { 0081 dispatch_source_merge_data(rawValue, UInt(value)) 0082 } 0083 0084 public func setTimer(start: DispatchTime, interval: DispatchTimeDelta, leeway: DispatchTimeDelta) { 0085 dispatch_source_set_timer(rawValue, start.rawValue, interval.rawValue, leeway.rawValue) 0086 } 0087 0088 } 0089