/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once

#include "baseobject.h"
#include "defs.h"
#include "Func.h"

S_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.
 */
S_UNUSED
static char *
SCallbackTypeNames[] = {
  "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 {
  schar * name; /**< The name that is used to invoke the callback. */
  Callback callback; /**< The callback that will be invoked.*/
  SCallbackType type; /**< The type of the callback, is it a standard callback
                       * or a notify? */
} SCallbackEntry;

#define s_callback_entry_new(n, c, t)\
 s_callback_entry_new_real (n, CALLBACK (c), t)

S_EXPORTED
SCallbackEntry *
s_callback_entry_new_real (const schar * name,
                           Callback callback,
                           SCallbackType type);


S_EXPORTED
void
s_callback_entry_free (SCallbackEntry * entry);

/**
 * @}
 * @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.
 */
S_EXPORTED
void
s_object_install_callbacks (SObject * obj,
                            size_t n_callbacks,
                            SCallbackEntry ** callback_entries);

/**
 * Installs a singel callback into an SObject.
 *
 * @param obj The object to install the callback into.
 * @param callbackentry The callback entry to install.
 */
S_EXPORTED
void
s_object_install_callback (SObject * obj, SCallbackEntry * callback_entry);

/**
 * @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.
 */
S_EXPORTED
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)

/**@}*/

S_END_DECLS