Is there anyone except for me that likes to use events in their code? In several of my projects, I've implemented eventsystems with a register_event() method and a fire_event() method in a very simple fashion. The thought has occured to me, to write something more general and put it within Pike.
But before I spend any time on it, I'd like some input on the matter. For instance, is it useful enough to write put in Pike? Would you like it to work in some special way? How do you normally implement events in Pike?
Hi,
But before I spend any time on it, I'd like some input on the matter. For instance, is it useful enough to write put in Pike? Would you like it to work in some special way? How do you normally implement events in Pike?
What's the difference with signal() ?
/ David
signal() is only an interface to the underlaying signals of your OS. It's limited to certain signals and you cannot pass parameters to your callbacks.
My implementations usually look something like: void register_event(string event_name, function cb) void fire_event(string event_name, mixed ... args)
You are allowed to register multiple callbacks for each event and each callback is called every time that event is fired.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-24 10:50: Subject: Re: Events in pike?
Hi,
But before I spend any time on it, I'd like some input on the matter. For instance, is it useful enough to write put in Pike? Would you like it to work in some special way? How do you normally implement events in Pike?
What's the difference with signal() ?
/ David
/ Brevbäraren
There is generic event (signal, in gtk parlance) code in the GTK (the pike-part) module.
/ Per Hedbor ()
Previous text:
2004-05-24 10:32: Subject: Events in pike?
Is there anyone except for me that likes to use events in their code? In several of my projects, I've implemented eventsystems with a register_event() method and a fire_event() method in a very simple fashion. The thought has occured to me, to write something more general and put it within Pike.
But before I spend any time on it, I'd like some input on the matter. For instance, is it useful enough to write put in Pike? Would you like it to work in some special way? How do you normally implement events in Pike?
/ Marcus Agehall (Scanian)
On Mon, May 24, 2004 at 10:55:01AM +0200, Per Hedbor () @ Pike (-) developers forum wrote:
There is generic event (signal, in gtk parlance) code in the GTK (the pike-part) module.
Isn't this a bit too much - to use GTK for such simple purpose? It is like using a cannon to shoot a fly :)
BTW, I am thinking about generic (and _simple_) event handling facilities for Pike... Most of this may be implemented (or, to be precise, simulated) on top of callouts, though.
A model like one used in GNU Pth or libevent would be wonderful :)
Regards, /Al
I don't see why using GTKSupport.Util.signal_handling would be any sort of overkill; it's just normal pike code. You don't have to use the GTK C module to put it to use.
/ Johan Sundström (Achtung Liebe!)
Previous text:
2004-05-24 11:29: Subject: Re: Events in pike?
On Mon, May 24, 2004 at 10:55:01AM +0200, Per Hedbor () @ Pike (-) developers forum wrote:
There is generic event (signal, in gtk parlance) code in the GTK (the pike-part) module.
Isn't this a bit too much - to use GTK for such simple purpose? It is like using a cannon to shoot a fly :)
BTW, I am thinking about generic (and _simple_) event handling facilities for Pike... Most of this may be implemented (or, to be precise, simulated) on top of callouts, though.
A model like one used in GNU Pth or libevent would be wonderful :)
Regards, /Al
/ Brevbäraren
The only objection to using GTK.Util.signal_handling, is that it is somewhat "hidden" within the GTK module. It would be nice if it was moved upwards in the namespace and separated from GTK. That way, people won't feel like they "have to use GTK" to use events.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-24 11:41: Subject: Re: Events in pike?
I don't see why using GTKSupport.Util.signal_handling would be any sort of overkill; it's just normal pike code. You don't have to use the GTK C module to put it to use.
/ Johan Sundström (Achtung Liebe!)
Like putting something like it in Function.pmod, or similar, instead? (It seems to expect all callbacks to take at least one mandatory argument, which might not be what you want in a more generic context.)
/ Johan Sundström (Achtung Liebe!)
Previous text:
2004-05-24 12:05: Subject: Re: Events in pike?
The only objection to using GTK.Util.signal_handling, is that it is somewhat "hidden" within the GTK module. It would be nice if it was moved upwards in the namespace and separated from GTK. That way, people won't feel like they "have to use GTK" to use events.
/ Marcus Agehall (Scanian)
Why not rewrite it so that it doesn't expect 1 arg?
Yeah, Function.pmod could do, or perhaps under Process? I'm not sure.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-24 12:08: Subject: Re: Events in pike?
Like putting something like it in Function.pmod, or similar, instead? (It seems to expect all callbacks to take at least one mandatory argument, which might not be what you want in a more generic context.)
/ Johan Sundström (Achtung Liebe!)
If done in-place I think the API would change, maybe breaking GTK. If you would do another version in a different module a tiny wrapper left in GTKSupport would alleviate that possible problem.
/ Johan Sundström (Achtung Liebe!)
Previous text:
2004-05-24 12:20: Subject: Re: Events in pike?
Why not rewrite it so that it doesn't expect 1 arg?
Yeah, Function.pmod could do, or perhaps under Process? I'm not sure.
/ Marcus Agehall (Scanian)
Yeah, leaving a wrapper may be a good idea. The first action, though, would be to implement the event-system and place it somewhere in the namespace. The question is where it fits best...
/ Marcus Agehall (Scanian)
Previous text:
2004-05-24 12:53: Subject: Re: Events in pike?
If done in-place I think the API would change, maybe breaking GTK. If you would do another version in a different module a tiny wrapper left in GTKSupport would alleviate that possible problem.
/ Johan Sundström (Achtung Liebe!)
sTeam has an extensive event system. it works similar to your descriptione with registering callbacks for event types. it has two phases which allow you to choose wether the callback is run before or after the event happens.
greetings, martin.
On Mon, May 24, 2004 at 05:10:29PM +0200, Martin Bähr wrote:
it has two phases which allow you to choose wether the callback is run before or after the event happens.
Huh? How is this possible? How do you know _which_ event happens to call callback _before_ it happens?
Of course there are some events (like scheduled on specific time) which are predictable, but there are also a lot of events (like user inputs, async I/O etc) which simply cannot be predicted...
Regards, /Al
On Mon, May 24, 2004 at 05:26:57PM +0200, Alexander Demenshin wrote:
it has two phases which allow you to choose wether the callback is run before or after the event happens.
Huh? How is this possible? How do you know _which_ event happens to call callback _before_ it happens?
simple. the event knows. every event first announces its intention to run, checks the results of any callbacks and if they are ok, it runs.
permission checks are a good example. they need to be done before the protected object is accessed (which is the actual event in question)
greetings, martin.
Hmm, that sounds interesting, but I think I would leave that up to the application. Ie, if the application wants to, it can fire two events instead of one. The fire_event() method could return an array with the results from the callbacks. This way, the application can test the result from all callbacks, to see if they failed or not.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-24 17:33: Subject: Re: Events in pike?
On Mon, May 24, 2004 at 05:26:57PM +0200, Alexander Demenshin wrote:
it has two phases which allow you to choose wether the callback is run before or after the event happens.
Huh? How is this possible? How do you know _which_ event happens to call callback _before_ it happens?
simple. the event knows. every event first announces its intention to run, checks the results of any callbacks and if they are ok, it runs.
permission checks are a good example. they need to be done before the protected object is accessed (which is the actual event in question)
greetings, martin.
/ Brevbäraren
Sounds similar to the simple event system I added in Sitebuilder some years ago. There were three callbacks: before, after and cancel. Whenever a handled event was going to happen, the "before" callbacks were called. Then the event took place. Then the "after" callbacks were called if the event finished successfully; otherwise the "cancel" callbacks were called.
/ Leif Stensson, Lysator
Previous text:
2004-05-24 17:33: Subject: Re: Events in pike?
On Mon, May 24, 2004 at 05:26:57PM +0200, Alexander Demenshin wrote:
it has two phases which allow you to choose wether the callback is run before or after the event happens.
Huh? How is this possible? How do you know _which_ event happens to call callback _before_ it happens?
simple. the event knows. every event first announces its intention to run, checks the results of any callbacks and if they are ok, it runs.
permission checks are a good example. they need to be done before the protected object is accessed (which is the actual event in question)
greetings, martin.
/ Brevbäraren
pike-devel@lists.lysator.liu.se