1 /*************************************************************************** 2 $RCSfile$ 3 ------------------- 4 cvs : $Id: stringlist_p.h 786 2005-07-09 13:38:17Z aquamaniac $ 5 begin : Thu Apr 03 2003 6 copyright : (C) 2003 by Martin Preuss 7 email : martin@libchipcard.de 8 9 *************************************************************************** 10 * * 11 * This library is free software; you can redistribute it and/or * 12 * modify it under the terms of the GNU Lesser General Public * 13 * License as published by the Free Software Foundation; either * 14 * version 2.1 of the License, or (at your option) any later version. * 15 * * 16 * This library is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 19 * Lesser General Public License for more details. * 20 * * 21 * You should have received a copy of the GNU Lesser General Public * 22 * License along with this library; if not, write to the Free Software * 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 24 * MA 02111-1307 USA * 25 * * 26 ***************************************************************************/ 27 28 #ifndef GWENHYWFAR_SIGNAL_H 29 #define GWENHYWFAR_SIGNAL_H 30 31 #include <gwenhywfar/gwenhywfarapi.h> 32 #include <gwenhywfar/types.h> 33 #include <gwenhywfar/list2.h> 34 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /** 41 * @defgroup MOD_SIGNALSLOT Module for Signals and Slots 42 * @ingroup MOD_BASE 43 * @short Basic signal handling. 44 * 45 * This module introduces a simple signal-slot framework. 46 * Signals have a fixed list of arguments: 47 * <ul> 48 * <li>a void* pointer</li> 49 * <li>1st integer argument</li> 50 * <li>2nd integer argument</li> 51 * </ul> 52 * The actual type of the void pointer is defined by the signal and 53 * corresponding slot(s): Gwen checks the type at runtime and refuses to 54 * connect signals with slots which define this pointer to be of a different 55 * type. 56 * Any signal can be connected to any number of matching slots. 57 * 58 * The central object in this framework is @ref GWEN_SIGNALOBJECT. It holds 59 * a list of signals and slots for a given object. 60 * 61 * 62 */ 63 /*@{*/ 64 65 typedef struct GWEN_SIGNALOBJECT GWEN_SIGNALOBJECT; 66 67 typedef struct GWEN_SIGNAL GWEN_SIGNAL; 68 69 typedef struct GWEN_SLOT GWEN_SLOT; 70 71 72 /** 73 * This is the prototype for the slot function. If there is a problem in the 74 * function it should return 1, otherwise 0. 75 */ 76 typedef int GWENHYWFAR_CB(*GWEN_SLOT_FUNCTION)(GWEN_SLOT *slot, void *userData, void *pArg1, void *pArg2, int iArg3, 77 int iArg4); 78 79 80 /** @name SignalObject 81 * 82 */ 83 /*@{*/ 84 GWENHYWFAR_API 85 GWEN_SIGNALOBJECT *GWEN_SignalObject_new(void); 86 87 GWENHYWFAR_API 88 void GWEN_SignalObject_free(GWEN_SIGNALOBJECT *so); 89 90 GWENHYWFAR_API 91 GWEN_SIGNAL *GWEN_SignalObject_FindSignal(const GWEN_SIGNALOBJECT *so, 92 const char *name, 93 const char *typeOfArg1, 94 const char *typeOfArg2); 95 96 GWENHYWFAR_API 97 GWEN_SLOT *GWEN_SignalObject_FindSlot(const GWEN_SIGNALOBJECT *so, 98 const char *name, 99 const char *typeOfArg1, 100 const char *typeOfArg2); 101 102 /** 103 * This function removes all signals and slots for the given derived 104 * type. This function can be used from within the FREEDATA function 105 * of the GWEN_INHERIT framework. 106 */ 107 GWENHYWFAR_API 108 void GWEN_SignalObject_RemoveForDerivedType(GWEN_SIGNALOBJECT *so, 109 const char *derivedType); 110 111 112 /** 113 * @defgroup MOD_SIGNALSLOT_SIGNAL Signals 114 * @short Signals 115 * 116 */ 117 /*@{*/ 118 119 GWENHYWFAR_API 120 GWEN_SIGNAL *GWEN_Signal_new(GWEN_SIGNALOBJECT *so, 121 const char *derivedType, 122 const char *name, 123 const char *typeOfArg1, 124 const char *typeOfArg2); 125 126 GWENHYWFAR_API 127 void GWEN_Signal_free(GWEN_SIGNAL *sig); 128 129 130 GWENHYWFAR_API 131 GWEN_SIGNALOBJECT *GWEN_Signal_GetSignalObject(const GWEN_SIGNAL *sig); 132 133 134 GWENHYWFAR_API 135 int GWEN_Signal_Connect(GWEN_SIGNAL *sig, GWEN_SLOT *slot); 136 137 GWENHYWFAR_API 138 int GWEN_Signal_Disconnect(GWEN_SIGNAL *sig, GWEN_SLOT *slot); 139 140 /** 141 * This function calls the slot function of all connected slots. 142 * If any of the slot functions called returns with code 1 then 143 * this function will return 1, too. Otherwise 0 is returned. 144 * This means that this function will only return 0 if every called slot 145 * function returns 0. 146 */ 147 GWENHYWFAR_API 148 int GWEN_Signal_Emit(GWEN_SIGNAL *sig, 149 void *pArg1, void *pArg2, int iArg3, int iArg4); 150 /*@}*/ 151 152 153 /** 154 * @defgroup MOD_SIGNALSLOT_SLOT Slots 155 * @short Slots 156 * 157 */ 158 /*@{*/ 159 160 GWENHYWFAR_API 161 GWEN_SLOT *GWEN_Slot_new(GWEN_SIGNALOBJECT *so, 162 const char *derivedType, 163 const char *name, 164 const char *typeOfArg1, 165 const char *typeOfArg2, 166 GWEN_SLOT_FUNCTION fn, 167 void *userData); 168 169 GWENHYWFAR_API 170 void GWEN_Slot_free(GWEN_SLOT *slot); 171 172 GWENHYWFAR_API 173 GWEN_SIGNALOBJECT *GWEN_Slot_GetSignalObject(const GWEN_SLOT *slot); 174 175 176 /*@}*/ /* defgroup */ 177 178 179 /*@}*/ /* defgroup */ 180 181 182 183 #ifdef __cplusplus 184 } /* extern C */ 185 #endif 186 187 188 #endif 189 190