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// Specifies the type of the @value_destroy_func and @key_destroy_func
14// functions passed to g_cache_new(). The functions are passed a
15// pointer to the #GCache key or #GCache value and should free any
16// memory and other resources associated with it.
17type CacheDestroyFunc func(uintptr)
18
19// Specifies the type of the @key_dup_func function passed to
20// g_cache_new(). The function is passed a key
21// (__not__ a value as the prototype implies) and
22// should return a duplicate of the key.
23type CacheDupFunc func(uintptr) uintptr
24
25// Specifies the type of the @value_new_func function passed to
26// g_cache_new(). It is passed a #GCache key and should create the
27// value corresponding to the key.
28type CacheNewFunc func(uintptr) uintptr
29
30// A `GCache` allows sharing of complex data structures, in order to
31// save system resources.
32//
33// `GCache` uses keys and values. A `GCache` key describes the properties
34// of a particular resource. A `GCache` value is the actual resource.
35//
36// `GCache` has been marked as deprecated, since this API is rarely
37// used and not very actively maintained.
38type Cache struct {
39 _ structs.HostLayout
40}
41
42func (x *Cache) GoPointer() uintptr {
43 return uintptr(unsafe.Pointer(x))
44}
45
46var xCacheDestroy func(uintptr)
47
48// Frees the memory allocated for the #GCache.
49//
50// Note that it does not destroy the keys and values which were
51// contained in the #GCache.
52func (x *Cache) Destroy() {
53
54 xCacheDestroy(x.GoPointer())
55
56}
57
58var xCacheInsert func(uintptr, uintptr) uintptr
59
60// Gets the value corresponding to the given key, creating it if
61// necessary. It first checks if the value already exists in the
62// #GCache, by using the @key_equal_func function passed to
63// g_cache_new(). If it does already exist it is returned, and its
64// reference count is increased by one. If the value does not currently
65// exist, if is created by calling the @value_new_func. The key is
66// duplicated by calling @key_dup_func and the duplicated key and value
67// are inserted into the #GCache.
68func (x *Cache) Insert(KeyVar uintptr) uintptr {
69
70 cret := xCacheInsert(x.GoPointer(), KeyVar)
71 return cret
72}
73
74var xCacheKeyForeach func(uintptr, uintptr, uintptr)
75
76// Calls the given function for each of the keys in the #GCache.
77//
78// NOTE @func is passed three parameters, the value and key of a cache
79// entry and the @user_data. The order of value and key is different
80// from the order in which g_hash_table_foreach() passes key-value
81// pairs to its callback function !
82func (x *Cache) KeyForeach(FuncVar *HFunc, UserDataVar uintptr) {
83
84 var FuncVarRef uintptr
85 if FuncVar != nil {
86 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
87 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
88 FuncVarRef = cbRefPtr
89 } else {
90 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
91 cbFn := *FuncVar
92 cbFn(arg0, arg1, arg2)
93 }
94 FuncVarRef = purego.NewCallback(fcb)
95 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
96 }
97 }
98
99 xCacheKeyForeach(x.GoPointer(), FuncVarRef, UserDataVar)
100
101}
102
103var xCacheRemove func(uintptr, uintptr)
104
105// Decreases the reference count of the given value. If it drops to 0
106// then the value and its corresponding key are destroyed, using the
107// @value_destroy_func and @key_destroy_func passed to g_cache_new().
108func (x *Cache) Remove(ValueVar uintptr) {
109
110 xCacheRemove(x.GoPointer(), ValueVar)
111
112}
113
114var xCacheValueForeach func(uintptr, uintptr, uintptr)
115
116// Calls the given function for each of the values in the #GCache.
117func (x *Cache) ValueForeach(FuncVar *HFunc, UserDataVar uintptr) {
118
119 var FuncVarRef uintptr
120 if FuncVar != nil {
121 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
122 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
123 FuncVarRef = cbRefPtr
124 } else {
125 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
126 cbFn := *FuncVar
127 cbFn(arg0, arg1, arg2)
128 }
129 FuncVarRef = purego.NewCallback(fcb)
130 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
131 }
132 }
133
134 xCacheValueForeach(x.GoPointer(), FuncVarRef, UserDataVar)
135
136}
137
138func init() {
139 core.SetPackageName("GLIB", "glib-2.0")
140 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
141 var libs []uintptr
142 for _, libPath := range core.GetPaths("GLIB") {
143 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
144 if err != nil {
145 panic(err)
146 }
147 libs = append(libs, lib)
148 }
149
150 core.PuregoSafeRegister(&xCacheDestroy, libs, "g_cache_destroy")
151 core.PuregoSafeRegister(&xCacheInsert, libs, "g_cache_insert")
152 core.PuregoSafeRegister(&xCacheKeyForeach, libs, "g_cache_key_foreach")
153 core.PuregoSafeRegister(&xCacheRemove, libs, "g_cache_remove")
154 core.PuregoSafeRegister(&xCacheValueForeach, libs, "g_cache_value_foreach")
155
156}