4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * Contributor(s): Blender Foundation (2011)
22 * ***** END GPL LICENSE BLOCK *****
25 #include "BLI_utildefines.h"
26 #include "BLI_listbase.h"
27 #include "BLI_callbacks.h"
29 #include "MEM_guardedalloc.h"
31 static ListBase callback_slots[BLI_CB_EVT_TOT]= {{0}};
33 void BLI_exec_cb(struct Main *main, struct ID *self, eCbEvent evt)
35 ListBase *lb= &callback_slots[evt];
36 bCallbackFuncStore *funcstore;
38 for(funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= (bCallbackFuncStore *)funcstore->next) {
39 funcstore->func(main, self, funcstore->arg);
43 void BLI_add_cb(bCallbackFuncStore *funcstore, eCbEvent evt)
45 ListBase *lb= &callback_slots[evt];
46 BLI_addtail(lb, funcstore);
49 void BLI_cb_init(void)
54 /* call on application exit */
55 void BLI_cb_finalize(void)
58 for(evt= 0; evt < BLI_CB_EVT_TOT; evt++) {
59 ListBase *lb= &callback_slots[evt];
60 bCallbackFuncStore *funcstore;
61 bCallbackFuncStore *funcstore_next;
62 for(funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= funcstore_next) {
63 funcstore_next= (bCallbackFuncStore *)funcstore->next;
64 BLI_remlink(lb, funcstore);
65 if(funcstore->alloc) {