1 /*
2 * This file is part of d-dazzle.
3 *
4 * d-dazzle is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 3
7 * of the License, or (at your option) any later version, with
8 * some exceptions, please read the COPYING file.
9 *
10 * d-dazzle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with d-dazzle; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18 */19 moduledazzle.TaskCache;
20 21 privateimportdazzle.c.functions;
22 publicimportdazzle.c.types;
23 privateimportgio.AsyncResultIF;
24 privateimportgio.Cancellable;
25 privateimportglib.ConstructionException;
26 privateimportglib.ErrorG;
27 privateimportglib.GException;
28 privateimportglib.PtrArray;
29 privateimportglib.Str;
30 privateimportgobject.ObjectG;
31 32 33 /** */34 publicclassTaskCache : ObjectG35 {
36 /** the main Gtk struct */37 protectedDzlTaskCache* dzlTaskCache;
38 39 /** Get the main Gtk struct */40 publicDzlTaskCache* getTaskCacheStruct(booltransferOwnership = false)
41 {
42 if (transferOwnership)
43 ownedRef = false;
44 returndzlTaskCache;
45 }
46 47 /** the main Gtk struct as a void* */48 protectedoverridevoid* getStruct()
49 {
50 returncast(void*)dzlTaskCache;
51 }
52 53 /**
54 * Sets our main struct and passes it to the parent class.
55 */56 publicthis (DzlTaskCache* dzlTaskCache, boolownedRef = false)
57 {
58 this.dzlTaskCache = dzlTaskCache;
59 super(cast(GObject*)dzlTaskCache, ownedRef);
60 }
61 62 63 /** */64 publicstaticGTypegetType()
65 {
66 returndzl_task_cache_get_type();
67 }
68 69 /** */70 publicthis(GHashFunckeyHashFunc, GEqualFunckeyEqualFunc, GBoxedCopyFunckeyCopyFunc, GBoxedFreeFunckeyDestroyFunc, GBoxedCopyFuncvalueCopyFunc, GBoxedFreeFuncvalueFreeFunc, longtimeToLiveMsec, DzlTaskCacheCallbackpopulateCallback, void* populateCallbackData, GDestroyNotifypopulateCallbackDataDestroy)
71 {
72 autop = dzl_task_cache_new(keyHashFunc, keyEqualFunc, keyCopyFunc, keyDestroyFunc, valueCopyFunc, valueFreeFunc, timeToLiveMsec, populateCallback, populateCallbackData, populateCallbackDataDestroy);
73 74 if(pisnull)
75 {
76 thrownewConstructionException("null returned by new");
77 }
78 79 this(cast(DzlTaskCache*) p, true);
80 }
81 82 /** */83 publicboolevict(void* key)
84 {
85 returndzl_task_cache_evict(dzlTaskCache, key) != 0;
86 }
87 88 /** */89 publicvoidevictAll()
90 {
91 dzl_task_cache_evict_all(dzlTaskCache);
92 }
93 94 /** */95 publicvoidgetAsync(void* key, boolforceUpdate, Cancellablecancellable, GAsyncReadyCallbackcallback, void* userData)
96 {
97 dzl_task_cache_get_async(dzlTaskCache, key, forceUpdate, (cancellableisnull) ? null : cancellable.getCancellableStruct(), callback, userData);
98 }
99 100 /**
101 * Finish a call to dzl_task_cache_get_async().
102 *
103 * Returns: The result from the cache.
104 *
105 * Throws: GException on failure.
106 */107 publicvoid* getFinish(AsyncResultIFresult)
108 {
109 GError* err = null;
110 111 autop = dzl_task_cache_get_finish(dzlTaskCache, (resultisnull) ? null : result.getAsyncResultStruct(), &err);
112 113 if (err !isnull)
114 {
115 thrownewGException( newErrorG(err) );
116 }
117 118 returnp;
119 }
120 121 /**
122 * Gets all the values in the cache.
123 *
124 * The caller owns the resulting GPtrArray, which itself owns a reference to the children.
125 *
126 * Returns: The values.
127 */128 publicPtrArraygetValues()
129 {
130 autop = dzl_task_cache_get_values(dzlTaskCache);
131 132 if(pisnull)
133 {
134 returnnull;
135 }
136 137 returnnewPtrArray(cast(GPtrArray*) p);
138 }
139 140 /**
141 * Peeks to see @key is contained in the cache and returns the
142 * matching #GObject if it does.
143 *
144 * The reference count of the resulting #GObject is not incremented.
145 * For that reason, it is important to remember that this function
146 * may only be called from the main thread.
147 *
148 * Params:
149 * key = The key for the cache
150 *
151 * Returns: A #GObject or
152 * %NULL if the key was not found in the cache.
153 */154 publicObjectGpeek(void* key)
155 {
156 autop = dzl_task_cache_peek(dzlTaskCache, key);
157 158 if(pisnull)
159 {
160 returnnull;
161 }
162 163 returnObjectG.getDObject!(ObjectG)(cast(GObject*) p);
164 }
165 166 /** */167 publicvoidsetName(stringname)
168 {
169 dzl_task_cache_set_name(dzlTaskCache, Str.toStringz(name));
170 }
171 }