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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
(c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
(c) Copyright 2000-2004 Convergence (integrated media) GmbH
All rights reserved.
Written by Denis Oliver Kropp <dok@directfb.org>,
Andreas Hundt <andi@fischlustig.de>,
Sven Neumann <neo@directfb.org>,
Ville Syrjälä <syrjala@sci.fi> and
Claudio Ciccani <klan@users.sf.net>.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __FUSION__REACTOR_H__
#define __FUSION__REACTOR_H__
#include <direct/list.h>
#include <fusion/types.h>
#include <fusion/call.h>
#include <fusion/lock.h>
typedef enum {
RS_OK,
RS_REMOVE,
RS_DROP
} ReactionResult;
typedef ReactionResult (*ReactionFunc)( const void *msg_data,
void *ctx );
typedef struct {
DirectLink link;
ReactionFunc func;
void *ctx;
void *node_link;
} Reaction;
typedef struct {
DirectLink link;
int index;
void *ctx;
bool attached;
} GlobalReaction;
/*
* Create a new reactor configured for the specified message data size.
*/
FusionReactor *fusion_reactor_new ( int msg_size,
const char *name,
const FusionWorld *world );
/*
* Destroy the reactor.
*/
DirectResult fusion_reactor_destroy ( FusionReactor *reactor );
/*
* Free the reactor.
*/
DirectResult fusion_reactor_free ( FusionReactor *reactor );
/*
* Makes the reactor use the specified lock for managing global reactions.
*
* After creating the reactor a global default lock is set which is created
* by Fusion once during initialization.
*
* To avoid dead locks caused by alternating lock orders of the global reaction
* lock and another lock, the default lock is replaced by the other lock.
*/
DirectResult fusion_reactor_set_lock ( FusionReactor *reactor,
FusionSkirmish *skirmish );
DirectResult fusion_reactor_set_lock_only( FusionReactor *reactor,
FusionSkirmish *lock );
/*
* Attach a local reaction to the reactor (channel 0).
*/
DirectResult fusion_reactor_attach ( FusionReactor *reactor,
ReactionFunc func,
void *ctx,
Reaction *reaction );
/*
* Attach a local reaction to a specific reactor channel (0-1023).
*/
DirectResult fusion_reactor_attach_channel( FusionReactor *reactor,
int channel,
ReactionFunc func,
void *ctx,
Reaction *reaction );
/*
* Detach an attached local reaction from the reactor.
*/
DirectResult fusion_reactor_detach ( FusionReactor *reactor,
Reaction *reaction );
/*
* Attach a global reaction to the reactor.
*
* It's always called directly, no matter which Fusionee calls fusion_reactor_dispatch().
* Any data referenced by the reaction function has to be in shared memory, unless it uses a
* mechanism to lookup a local counter part or representative, based on shared information.
*
* A global reaction is not defined directly as a function pointer, because that's always a
* local address. Instead, it's specified by an index into a built in function table that
* must be passed to fusion_reactor_dispatch() each time it is called.
*/
DirectResult fusion_reactor_attach_global( FusionReactor *reactor,
int index,
void *ctx,
GlobalReaction *reaction );
/*
* Detach an attached global reaction from the reactor.
*/
DirectResult fusion_reactor_detach_global( FusionReactor *reactor,
GlobalReaction *reaction );
/*
* Dispatch a message to any attached reaction (channel 0).
*
* Setting 'self' to false excludes the caller's local reactions.
*/
DirectResult fusion_reactor_dispatch ( FusionReactor *reactor,
const void *msg_data,
bool self,
const ReactionFunc *globals );
/*
* Dispatch a message to any attached reaction with a given size. Instead of
* using the size defined by the reactor, the caller can specify the size of
* the data.
*
* Setting 'self' to false excludes the caller's local reactions.
*/
DirectResult fusion_reactor_sized_dispatch( FusionReactor *reactor,
const void *msg_data,
int msg_size,
bool self,
const ReactionFunc *globals );
/*
* Dispatch a message via a specific channel (0-1023).
*
* Setting 'self' to false excludes the caller's local reactions.
*/
DirectResult fusion_reactor_dispatch_channel( FusionReactor *reactor,
int channel,
const void *msg_data,
int msg_size,
bool self,
const ReactionFunc *globals );
/*
* Have the call executed when a dispatched message has been processed by all recipients.
*/
DirectResult fusion_reactor_set_dispatch_callback( FusionReactor *reactor,
FusionCall *call,
void *call_ptr );
/*
* Change the name of the reactor (debug).
*/
DirectResult fusion_reactor_set_name ( FusionReactor *reactor,
const char *name );
/*
* Specify whether local message handlers (reactions) should be called directly.
*/
DirectResult fusion_reactor_direct ( FusionReactor *reactor,
bool direct );
#endif
|