1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11)
12
13// `GTimer` records a start time, and counts microseconds elapsed since
14// that time.
15//
16// This is done somewhat differently on different platforms, and can be
17// tricky to get exactly right, so `GTimer` provides a portable/convenient interface.
18type Timer struct {
19 _ structs.HostLayout
20}
21
22func (x *Timer) GoPointer() uintptr {
23 return uintptr(unsafe.Pointer(x))
24}
25
26var xTimerContinue func(uintptr)
27
28// Resumes a timer that has previously been stopped with
29// g_timer_stop(). g_timer_stop() must be called before using this
30// function.
31func (x *Timer) Continue() {
32
33 xTimerContinue(x.GoPointer())
34
35}
36
37var xTimerDestroy func(uintptr)
38
39// Destroys a timer, freeing associated resources.
40func (x *Timer) Destroy() {
41
42 xTimerDestroy(x.GoPointer())
43
44}
45
46var xTimerElapsed func(uintptr, uint) float64
47
48// If @timer has been started but not stopped, obtains the time since
49// the timer was started. If @timer has been stopped, obtains the
50// elapsed time between the time it was started and the time it was
51// stopped. The return value is the number of seconds elapsed,
52// including any fractional part. The @microseconds out parameter is
53// essentially useless.
54func (x *Timer) Elapsed(MicrosecondsVar uint) float64 {
55
56 cret := xTimerElapsed(x.GoPointer(), MicrosecondsVar)
57 return cret
58}
59
60var xTimerIsActive func(uintptr) bool
61
62// Exposes whether the timer is currently active.
63func (x *Timer) IsActive() bool {
64
65 cret := xTimerIsActive(x.GoPointer())
66 return cret
67}
68
69var xTimerReset func(uintptr)
70
71// This function is useless; it's fine to call g_timer_start() on an
72// already-started timer to reset the start time, so g_timer_reset()
73// serves no purpose.
74func (x *Timer) Reset() {
75
76 xTimerReset(x.GoPointer())
77
78}
79
80var xTimerStart func(uintptr)
81
82// Marks a start time, so that future calls to g_timer_elapsed() will
83// report the time since g_timer_start() was called. g_timer_new()
84// automatically marks the start time, so no need to call
85// g_timer_start() immediately after creating the timer.
86func (x *Timer) Start() {
87
88 xTimerStart(x.GoPointer())
89
90}
91
92var xTimerStop func(uintptr)
93
94// Marks an end time, so calls to g_timer_elapsed() will return the
95// difference between this end time and the start time.
96func (x *Timer) Stop() {
97
98 xTimerStop(x.GoPointer())
99
100}
101
102const (
103 // Number of microseconds in one second (1 million).
104 // This macro is provided for code readability.
105 USEC_PER_SEC int = 1000000
106)
107
108var xTimeValFromIso8601 func(string, *TimeVal) bool
109
110// Converts a string containing an ISO 8601 encoded date and time
111// to a #GTimeVal and puts it into @time_.
112//
113// @iso_date must include year, month, day, hours, minutes, and
114// seconds. It can optionally include fractions of a second and a time
115// zone indicator. (In the absence of any time zone indication, the
116// timestamp is assumed to be in local time.)
117//
118// Any leading or trailing space in @iso_date is ignored.
119//
120// This function was deprecated, along with #GTimeVal itself, in GLib 2.62.
121// Equivalent functionality is available using code like:
122// |[
123// GDateTime *dt = g_date_time_new_from_iso8601 (iso8601_string, NULL);
124// gint64 time_val = g_date_time_to_unix (dt);
125// g_date_time_unref (dt);
126// ]|
127func TimeValFromIso8601(IsoDateVar string, TimeVar *TimeVal) bool {
128
129 cret := xTimeValFromIso8601(IsoDateVar, TimeVar)
130
131 return cret
132}
133
134var xUsleep func(uint)
135
136// Pauses the current thread for the given number of microseconds.
137//
138// There are 1 million microseconds per second (represented by the
139// %G_USEC_PER_SEC macro). g_usleep() may have limited precision,
140// depending on hardware and operating system; don't rely on the exact
141// length of the sleep.
142func Usleep(MicrosecondsVar uint) {
143
144 xUsleep(MicrosecondsVar)
145
146}
147
148func init() {
149 core.SetPackageName("GLIB", "glib-2.0")
150 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
151 var libs []uintptr
152 for _, libPath := range core.GetPaths("GLIB") {
153 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
154 if err != nil {
155 panic(err)
156 }
157 libs = append(libs, lib)
158 }
159
160 core.PuregoSafeRegister(&xTimeValFromIso8601, libs, "g_time_val_from_iso8601")
161 core.PuregoSafeRegister(&xUsleep, libs, "g_usleep")
162
163 core.PuregoSafeRegister(&xTimerContinue, libs, "g_timer_continue")
164 core.PuregoSafeRegister(&xTimerDestroy, libs, "g_timer_destroy")
165 core.PuregoSafeRegister(&xTimerElapsed, libs, "g_timer_elapsed")
166 core.PuregoSafeRegister(&xTimerIsActive, libs, "g_timer_is_active")
167 core.PuregoSafeRegister(&xTimerReset, libs, "g_timer_reset")
168 core.PuregoSafeRegister(&xTimerStart, libs, "g_timer_start")
169 core.PuregoSafeRegister(&xTimerStop, libs, "g_timer_stop")
170
171}