1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#ifndef __H_CALLBACK__
#define __H_CALLBACK__
#include "baseobject.h"
#include "defs.h"
#include "Func.h"
BEGIN_DECLS
/**
* @file
* @defgroup SCallback SCallback
* @addtogroup SCallback
* @{
* Callbacks are used to signals one part of the a program to an other.
* It is manly used in SObject s and its children.
*
* Please note that this is the best way to implement an "interface".
*
* @sa GlobalNotify
*/
/**
* The types for callbacks.
*/
typedef enum {
S_CALLBACK_NULL,
S_CALLBACK_CALLBACK,
S_CALLBACK_NOTIFY,
S_CALLBACK_NOTIFY_CHANGE
} SCallbackType;
/**
* A list containing the names of the callback types.
*/
static char * SCallbackTypeNames[] __attribute__((unused)) = {
"NULL",
"CALLBACK",
"NOTIFY",
"NOTIFY_CHANGE",
0x0,
0x0,
};
/**
* An SCallbackEntry is used for convenience when installing callbacks into
* SObjects.
*
* an example of how this could be used is:
@code{.c}
const SCallbackEntry foo_callback_entries[] = {
{"val_x_change", S_CALLBACK_NOTIFY_CHANGE, CALLBACK(foo_val_x_change_func)},
{"used", S_CALLBACK_CALLBACK, CALLBACK(foo_used)}
};
s_object_install_callbacks (S_OBJECT(Foo), &foo_callback_entries);
* @endcode
*
* The callback must have the following signature:
* @code{.c}
spointer
foo_some_func (SObject obj, spointer user_data) {
// Do something
return ret_val; // Must return something, Be it NULL or something important
}
@endcode
*/
typedef struct SCallbackEntry {
char * name; /**< The name that is used to invoke the callback. */
SCallbackType type; /**< The type of the callback, is it a standard callback
* or a notify? */
Callback callback; /**< The callback that will be invoked.*/
} SCallbackEntry;
/**
* @}
* @addtogroup SObject
* @{
*/
/**
* Installs an array of callbackentries into an SObject.
*
* @param obj The object to install the callback entries into.
* @param callbackentries an array containing the callback entries.
*/
void
s_object_install_callbacks (SObject * obj, SCallbackEntry ** callcackentries);
/**
* Installs a singel callback into an SObject.
*
* @param obj The object to install the callback into.
* @param callbackentry The callback entry to install.
*/
void
s_object_install_callback (SObject * obj, SCallbackEntry * callbackentry);
/**
* @breif Do a callback.
*
* When this function is called a on an SObject it calls the appropriate
* callback that has been assigned the name.
*
* @param self The object to do the callback on.
* @param name The name of the callback, can contain any valid non-null
* character.
*/
spointer
s_object_notify (SObject * self, schar * name, spointer * user_data);
/**
* Alias to s_object_notify()
*/
#define s_object_call(o, n, d) s_object_notify (o, n, d)
/**@}*/
END_DECLS
#endif
|