|
Blender
V2.59
|
00001 /* 00002 * $Id: callbacks.c 37799 2011-06-24 23:14:26Z gsrb3d $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Blender Foundation (2011) 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00025 #include "BLI_utildefines.h" 00026 #include "BLI_listbase.h" 00027 #include "BLI_callbacks.h" 00028 00029 #include "MEM_guardedalloc.h" 00030 00031 static ListBase callback_slots[BLI_CB_EVT_TOT]= {{0}}; 00032 00033 void BLI_exec_cb(struct Main *main, struct ID *self, eCbEvent evt) 00034 { 00035 ListBase *lb= &callback_slots[evt]; 00036 bCallbackFuncStore *funcstore; 00037 00038 for(funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= (bCallbackFuncStore *)funcstore->next) { 00039 funcstore->func(main, self, funcstore->arg); 00040 } 00041 } 00042 00043 void BLI_add_cb(bCallbackFuncStore *funcstore, eCbEvent evt) 00044 { 00045 ListBase *lb= &callback_slots[evt]; 00046 BLI_addtail(lb, funcstore); 00047 } 00048 00049 void BLI_cb_init(void) 00050 { 00051 /* do nothing */ 00052 } 00053 00054 /* call on application exit */ 00055 void BLI_cb_finalize(void) 00056 { 00057 eCbEvent evt; 00058 for(evt= 0; evt < BLI_CB_EVT_TOT; evt++) { 00059 ListBase *lb= &callback_slots[evt]; 00060 bCallbackFuncStore *funcstore; 00061 bCallbackFuncStore *funcstore_next; 00062 for(funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= funcstore_next) { 00063 funcstore_next= (bCallbackFuncStore *)funcstore->next; 00064 BLI_remlink(lb, funcstore); 00065 if(funcstore->alloc) { 00066 MEM_freeN(funcstore); 00067 } 00068 } 00069 } 00070 }