bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
1 |
/*
|
2 |
Copyright (c) 2013-2015 Gustav Hartvigsson
|
|
3 |
||
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5 |
of this software and associated documentation files (the "Software"), to deal
|
|
6 |
in the Software without restriction, including without limitation the rights
|
|
7 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8 |
copies of the Software, and to permit persons to whom the Software is
|
|
9 |
furnished to do so, subject to the following conditions:
|
|
10 |
||
11 |
The above copyright notice and this permission notice shall be included in
|
|
12 |
all copies or substantial portions of the Software.
|
|
13 |
||
14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20 |
THE SOFTWARE.
|
|
21 |
*/
|
|
22 |
||
23 |
#include "Callback.h" |
|
24 |
||
109.1.1
by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList? |
25 |
SCallbackEntry * |
26 |
s_callback_entry_new_real (const schar * name, |
|
27 |
Callback callback, |
|
28 |
SCallbackType type) { |
|
121.1.3
by Gustav Hartvigsson
* Made the GC switchable at rutime (once) when compiled with S_USE_GC set. |
29 |
SCallbackEntry * self = s_malloc (sizeof (SCallbackEntry)); |
109.1.1
by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList? |
30 |
self->name = s_string_new (name); |
31 |
self->callback = callback; |
|
32 |
self->type = type; |
|
33 |
return self; |
|
34 |
}
|
|
35 |
||
36 |
void
|
|
37 |
s_callback_entry_free (SCallbackEntry * self) { |
|
121.1.3
by Gustav Hartvigsson
* Made the GC switchable at rutime (once) when compiled with S_USE_GC set. |
38 |
s_free (self->name); |
39 |
s_free (self); |
|
109.1.1
by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList? |
40 |
}
|
41 |
||
42 |
void
|
|
43 |
s_object_install_callbacks (SObject * obj, |
|
44 |
size_t n_callbacks, |
|
45 |
SCallbackEntry ** callback_entries) { |
|
46 |
assert (obj); |
|
47 |
assert (callback_entries); |
|
48 |
s_dbg_print ("Adding Callbacks, n_callbacks: %zd", n_callbacks); |
|
49 |
for (size_t i = 0; i < n_callbacks ; i++) { |
|
50 |
s_dbg_print ("Loop: Adding Callbacks"); |
|
51 |
SCallbackEntry * entry = callback_entries[i]; |
|
52 |
s_object_install_callback (obj, entry); |
|
53 |
} |
|
54 |
}
|
|
55 |
||
56 |
void
|
|
57 |
s_object_install_callback (SObject * obj, |
|
58 |
SCallbackEntry * callback_entry) { |
|
59 |
// |
|
60 |
assert (obj); |
|
61 |
assert (callback_entry); |
|
62 |
s_dbg_print ("Adding callback"); |
|
109.1.8
by Gustav Hartvigsson
* Fixed SMap so the callbacks will work... What a single line of code can do.. |
63 |
s_map_add (obj->callbacks, s_string_new (callback_entry->name), callback_entry); |
109.1.1
by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList? |
64 |
}
|
65 |
||
66 |
spointer
|
|
67 |
s_object_notify (SObject * self, |
|
68 |
schar * name, |
|
69 |
spointer * user_data) { |
|
70 |
// |
|
71 |
SCallbackEntry * entry = s_map_get (self->callbacks, name); |
|
72 |
assert (s_string_is_equal (entry->name, name)); |
|
73 |
||
74 |
Callback callback = entry->callback; |
|
75 |
return callback (self, user_data); |
|
76 |
}
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
77 |