10 #:*glib-interface-age*
22 (eval-when (:compile-toplevel :load-toplevel :execute)
23 (define-foreign-library glib
24 (:unix "libglib-2.0.so")
27 (use-foreign-library glib)
29 (load-foreign-library "libgthread-2.0.so")
36 ;; Fundamentals - Basic types
40 ;; TODO: not sure about these: for amd64 they are ok
41 (eval-when (:compile-toplevel :load-toplevel :execute)
42 (if (cffi-features:cffi-feature-p :x86-64)
43 (defctype gsize :uint64)
44 (error "Unknown type 'gsize'")))
46 (defctype gssize :long)
48 (defctype goffset :uint64)
52 ;; Fundamentals - Version information
55 (defcvar (*glib-major-version* "glib_major_version" :read-only t :library glib) :uint)
56 (defcvar (*glib-minor-version* "glib_minor_version" :read-only t :library glib) :uint)
57 (defcvar (*glib-micro-version* "glib_micro_version" :read-only t :library glib) :uint)
58 (defcvar (*glib-binary-age* "glib_binary_age" :read-only t :library glib) :uint)
59 (defcvar (*glib-interface-age* "glib_interface_age" :read-only t :library glib) :uint)
63 ;; Limits of Basic Types, Standard Macros, Type Conversion Macros, Byte Order Macros,
64 ;; Numerical Definitions, Miscellaneous Macros, Atomic operations
67 ;; Core Application Support - The Main Event Loop
69 (defcstruct g-main-loop)
70 (defcstruct g-main-context)
72 (defcstruct g-source-funcs
77 (closure-callback :pointer)
78 (closure-marshal :pointer))
79 (defcstruct g-source-callback-funcs
87 (fd :int) ;; TODO: #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
91 (defcstruct g-time-val
97 (defcfun (g-main-loop-new "g_main_loop_new" :library glib) (:pointer g-main-loop)
98 (context (:pointer g-main-context))
99 (is-running :boolean))
101 (defcfun (g-main-loop-ref "g_main_loop_ref" :library glib) (:pointer g-main-loop)
102 (loop (:pointer g-main-loop)))
104 (defcfun (g-main-loop-unref "g_main_loop_unref" :library glib) (:pointer g-main-loop)
105 (loop (:pointer g-main-loop)))
107 (defcfun (g-main-loop-run "g_main_loop_run" :library glib) :void
108 (loop (:pointer g-main-loop)))
110 (defcfun (g-main-loop-quit "g_main_loop_quit" :library glib) :void
111 (loop (:pointer g-main-loop)))
113 (defcfun (g-main-loop-is-running "g_main_loop_is_running" :library glib) :boolean
114 (loop (:pointer g-main-loop)))
116 (defcfun (g-main-loop-get-context "g_main_loop_get_context" :library glib) (:pointer g-main-context)
117 (loop (:pointer g-main-loop)))
119 (defconstant +g-priority-high+ -100)
120 (defconstant +g-priority-default+ 0)
121 (defconstant +g-priority-high-idle+ 100)
122 (defconstant +g-priority-default-idle+ 200)
123 (defconstant +g-priority-low+ 300)
125 (defcfun (g-main-context-new "g_main_context_new" :library glib) (:pointer g-main-context))
127 (defcfun (g-main-context-ref "g_main_context_ref" :library glib) (:pointer g-main-context)
128 (context (:pointer g-main-context)))
130 (defcfun (g-main-context-unref "g_main_context_unref" :library glib) (:pointer g-main-context)
131 (context (:pointer g-main-context)))
133 (defcfun (g-main-context-default "g_main_context_default" :library glib) (:pointer g-main-context))
135 (defcfun (g-main-context-iteration "g_main_context_iteration" :library glib) :boolean
136 (context (:pointer g-main-context))
137 (may-block :boolean))
139 (defcfun (g-main-context-pending "g_main_context_pending" :library glib) :boolean
140 (context (:pointer g-main-context)))
142 (defcfun (g-main-context-find-source-by-id "g_main_context_find_source_by_id" :library glib) (:pointer g-source)
143 (context (:pointer g-main-context))
146 (defcfun (g-main-context-find-source-by-user-data "g_main_context_find_source_by_user_data" :library glib) (:pointer g-source)
147 (context (:pointer g-main-context))
148 (user-data :pointer))
150 (defcfun (g-main-context-find-source-by-funcs-user-data "g_main_context_find_source_by_funcs_user_data" :library glib) (:pointer g-source)
151 (context (:pointer g-main-context))
152 (funcs (:pointer g-source-funcs))
153 (user-data :pointer))
155 (defcfun (g-main-context-wakeup "g_main_context_wakeup" :library glib) :void
156 (context (:pointer g-main-context)))
158 (defcfun (g-main-context-acquire "g_main_context_acquire" :library glib) :boolean
159 (context (:pointer g-main-context)))
161 (defcfun (g-main-context-release "g_main_context_release" :library glib) :void
162 (context (:pointer g-main-context)))
164 (defcfun (g-main-context-is-owner "g_main_context_is_owner" :library glib) :boolean
165 (context (:pointer g-main-context)))
167 (defcfun (g-main-context-wait "g_main_context_wait" :library glib) :boolean
168 (context (:pointer g-main-context))
169 (cond (:pointer g-cond))
170 (mutex (:pointer g-mutex)))
172 (defcfun (g_main_context_prepare "g_main_context_prepare" :library glib) :boolean
173 (context (:pointer g-main-context))
174 (priority-ret (:pointer :int)))
176 (defcfun (g_main_context_query "g_main_context_query" :library glib) :int
177 (context (:pointer g-main-context))
179 (timeout-ret (:pointer :int))
180 (fds-ret (:pointer g-poll-fd))
183 (defcfun (g-main-context-check "g_main_context_check" :library glib) :int
184 (context (:pointer g-main-context))
186 (fds (:pointer g-poll-fd))
189 (defcfun (g-main-context-dispatch "g_main_context_dispatch" :library glib) :void
190 (context (:pointer g-main-context)))
192 (defcfun (g-main-context-set-poll-func "g_main_context_set_poll_func" :library glib) :void
193 (context (:pointer g-main-context))
196 (defcfun (g-main-context-get-poll-func "g_main_context_get_poll_func" :library glib) :pointer
197 (context (:pointer g-main-context)))
199 (defcfun (g-main-context-add-poll "g_main_context_add_poll" :library glib) :void
200 (context (:pointer g-main-context))
201 (fd (:pointer g-poll-fd))
204 (defcfun (g-main-context-remove-poll "g_main_context_remove_poll" :library glib) :void
205 (context (:pointer g-main-context))
206 (fd (:pointer g-poll-fd)))
208 (defcfun (g-main-depth "g_main_depth" :library glib) :int)
210 (defcfun (g-main-current-source "g_main_current_source" :library glib) (:pointer g-source))
212 (defcfun (g-timeout-source-new "g_timeout_source_new" :library glib) (:pointer g-source)
213 (interval-milliseconds :int))
215 (defcfun (g-timeout-source-new-seconds "g_timeout_source_new_seconds" :library glib) (:pointer g-source)
216 (interval-seconds :int))
218 (defcfun (g-timeout-add "g_timeout_add" :library glib) :uint
219 (interval-milliseconds :uint)
223 (defcfun (g-timeout-add-full "g_timeout_add_full" :library glib) :uint
225 (interval-milliseconds :uint)
228 (destroy-notify :pointer))
230 (defcfun (g-timeout-add-seconds "g_timeout_add_seconds" :library glib) :uint
231 (interval-seconds :uint)
235 (defcfun (g-timeout-add-seconds-full "g_timeout_add_seconds_full" :library glib) :uint
237 (interval-seconds :uint)
240 (destroy-notify :pointer))
242 (defcfun (g-idle-source-new "g_idle_source_new" :library glib) (:pointer g-source))
244 (defcfun (g-idle-add "g_idle_add" :library glib) :uint
248 (defcfun (g-idle-add-full "g_idle_add_full" :library glib) :uint
254 (defcfun (g-idle-remove-by-data "g_idle_remove_by_data" :library glib) :boolean
257 ;(defctype g-pid :int) ;;TODO: might work on amd64 linux, but on others
259 ;; Omitted GPid, g_child_add_watch, g_child_add_watch_full
261 (defcfun (g-source-new "g_source_new" :library glib) (:pointer g-source)
262 (source-funcs (:pointer g-source-funcs))
265 (defcfun (g-source-ref "g_source_ref" :library glib) (:pointer g-source)
266 (source (:pointer g-source)))
268 (defcfun (g-source-unref "g_source_unref" :library glib) :void
269 (source (:pointer g-source)))
271 (defcfun (g-source-set-funcs "g_source_set_funcs" :library glib) :void
272 (source (:pointer g-source))
273 (funcs (:pointer g-source-funcs)))
275 (defcfun (g-source-attach "g_source_attach" :library glib) :uint
276 (source (:pointer g-source))
277 (context (:pointer g-main-context)))
279 (defcfun (g-source-destroy "g_source_destroy" :library glib) :void
280 (source (:pointer g-source)))
282 (defcfun (g-source-is-destroyed "g_source_is_destroyed" :library glib) :boolean
283 (source (:pointer g-source)))
285 (defcfun (g-source-set-priority "g_source_set_priority" :library glib) :void
286 (source (:pointer g-source))
289 (defcfun (g-source-get-priority "g_source_get_priority" :library glib) :int
290 (source (:pointer g-source)))
292 (defcfun (g-source-set-can-recurse "g_source_set_can_recurse" :library glib) :void
293 (source (:pointer g-source))
294 (can-recurse :boolean))
296 (defcfun (g-source-get-can-recurse "g_source_get_can_recurse" :library glib) :boolean
297 (source (:pointer g-source)))
299 (defcfun (g-source-get-id "g_source_get_id" :library glib) :uint
300 (source (:pointer g-source)))
302 (defcfun (g-source-get-context "g_source_get_context" :library glib) (:pointer g-main-context)
303 (source (:pointer g-source)))
305 (defcfun (g-source-set-callback "g_source_set_callback" :library glib) :void
306 (source (:pointer g-source))
311 (defcfun (g-source-add-poll "g_source_add_poll" :library glib) :void
312 (source (:pointer g-source))
313 (fd (:pointer g-poll-fd)))
315 (defcfun (g-source-remove-poll "g_source_remove_poll" :library glib) :void
316 (source (:pointer g-source))
317 (fd (:pointer g-poll-fd)))
319 (defcfun (g-source-get-current-time "g_source_get_current_time" :library glib) :void
320 (source (:pointer g-source))
321 (timeval-ret (:pointer g-time-val)))
323 (defcfun (g-source-remove "g_source_remove" :library glib) :boolean
326 (defcfun (g-source-remove-by-funcs-user-data "g_source_remove_by_funcs_user_data" :library glib) :boolean
327 (funcs (:pointer g-source-funcs))
330 (defcfun (g-source-remove-by-user-data "g_source_remove_by_user_data" :library glib) :boolean
334 ;; Core Application Support - Threads
337 (defcenum g-thread-error
338 :g-thread-error-again)
340 ;omitted: struct GThreadFunctions
342 (defcfun (g-thread-init "g_thread_init") :void
345 (g-thread-init (null-pointer))
347 (defcenum g-thread-priority
348 :g-thread-priority-low
349 :g-thread-priority-normal
350 :g-thread-priority-hight
351 :g-thread-priority-urgent)
353 ;omitted: g_thread_create, g_thread_create_full, g_thread_yield, g_thread_exit, g_thread_foreach
355 (defcfun (g-thread-self "g_thread_self" :library glib) (:pointer g-thread))
357 (defcfun (g-thread-join "g_thread_join" :library glib) :pointer
358 (thread (:pointer g-thread)))
360 (defcfun (g-thread-priority "g_thread_set_priority" :library glib) :void
361 (thread (:pointer g-thread))
362 (priority g-thread-priority))
364 (defcfun (g-mutex-new "g_mutex_new" :library glib) (:pointer g-mutex))
366 (defcfun (g-mutex-lock "g_mutex_lock" :library glib) :void
367 (mutex (:pointer g-mutex)))
369 (defcfun (g-mutex-try-lock "g_mutex_trylock" :library glib) :boolean
370 (mutex (:pointer g-mutex)))
372 (defcfun (g-mutex-free "g_mutex_free" :library glib) :void
373 (mutex (:pointer g-mutex)))
375 ;omitted: GStaticMutex, GStaticRWLock stuff
377 (defcfun (g-cond-new "g_cond_new" :library glib) (:pointer g-cond))
379 (defcfun (g-cond-signal "g_cond_signal" :library glib) :void
380 (cond (:pointer g-cond)))
382 (defcfun (g-cond-broadcast "g_cond_broadcast" :library glib) :void
383 (cond (:pointer g-cond)))
385 (defcfun (g-cond-wait "g_cond_wait" :library glib) :void
386 (cond (:pointer g-cond))
387 (mutex (:pointer g-mutex)))
389 (defcfun (g-cond-timed-wait "g_cond_timed_wait" :library glib) :boolean
390 (cond (:pointer g-cond))
391 (mutex (:pointer g-mutex))
392 (abs-time (:pointer g-time-val)))
394 (defcfun (g-cond-free "g_cond_free" :library glib) :void
395 (cond (:pointer g-cond)))
397 ;omitted: GPrivate, GOnce stuff
399 ;omitted: Thread pools, Asynchronous queues, Dynamic Loading of Modules,
400 ; Memory Allocation, IO Channels, Error Reporting, Message Output and Debugging Functions, Message Logging
402 (defcfun g-free :void
405 (defcfun (g-malloc "g_malloc0") :pointer
408 (defcfun g-strdup :pointer
409 (str (:string :free-to-foreign t)))
411 ;omitted all GLib Utilites
412 ;TODO: omitted Date and Time Functions