1 /// Bindings for libdispatch (those symbols that are needed).
2 module mecca.platform.os.darwin.dispatch;
3 
4 version (Darwin):
5 package(mecca.platform.os):
6 
7 import core.stdc.config : c_ulong;
8 
9 extern (C):
10 
11 @nogc:
12 nothrow:
13 
14 alias dispatch_function_t = void function(void*);
15 alias dispatch_queue_attr_t = dispatch_queue_attr_s*;
16 alias dispatch_queue_t = dispatch_queue_s*;
17 alias dispatch_source_t = dispatch_source_s*;
18 alias dispatch_source_type_t = const(dispatch_source_type_s)*;
19 alias dispatch_time_t = ulong;
20 
21 enum ulong DISPATCH_TIME_NOW = 0;
22 enum ulong NSEC_PER_SEC	= 1000000000;
23 
24 enum DISPATCH_SOURCE_TYPE_TIMER = &_dispatch_source_type_timer;
25 
26 extern __gshared const dispatch_source_type_s _dispatch_source_type_timer;
27 
28 struct dispatch_queue_attr_s;
29 struct dispatch_queue_s;
30 struct dispatch_source_s;
31 struct dispatch_source_type_s {} // this is actually an opaque type but D doesn't allow defining variables of opaque types
32 
33 union dispatch_object_t
34 {
35     dispatch_queue_s* _dq;
36     dispatch_source_s* _ds;
37 }
38 
39 dispatch_queue_t dispatch_queue_create(
40     const char* label,
41     dispatch_queue_attr_t attr
42 );
43 
44 dispatch_source_t dispatch_source_create (
45     dispatch_source_type_t type,
46     uint handle,
47     c_ulong mask,
48     dispatch_queue_t queue
49 );
50 
51 void dispatch_source_set_event_handler_f(
52     dispatch_source_t source,
53     dispatch_function_t handler
54 );
55 
56 void dispatch_source_set_cancel_handler_f(
57     dispatch_source_t source,
58     dispatch_function_t handler
59 );
60 
61 dispatch_time_t dispatch_time(dispatch_time_t when, long delta);
62 
63 void dispatch_source_set_timer(
64     dispatch_source_t source,
65     dispatch_time_t start,
66     ulong interval,
67     ulong leeway
68 );
69 
70 void dispatch_activate(dispatch_source_t object);
71 void dispatch_source_cancel(dispatch_source_t source);
72 
73 void dispatch_release(dispatch_object_t);
74 
75 extern (D) void dispatch_release(dispatch_queue_t queue)
76 {
77     dispatch_object_t object = { _dq: queue };
78     dispatch_release(object);
79 }
80 
81 extern (D) void dispatch_release(dispatch_source_t source)
82 {
83     dispatch_object_t object = { _ds: source };
84     dispatch_release(object);
85 }
86 
87 void dispatch_set_context(dispatch_source_t object, void* context);