Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
14 user(s) are online (10 user(s) are browsing encyclopedia)

Members: 0
Guests: 14

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

Event-driven programming

Event-driven programming is a computer programming paradigm. Unlike traditional programs, which follow their own control flow pattern, only sometimes changing course at branch points, the control flow of event-driven programs is largely driven by external events.

=Overview=

Instead of waiting for a complete command which may order it to process information, the system is preprogrammed with an event loop, to look repeatedly for information to process (whether this might be the appearance of a file in a folder, a keyboard or mouse operation, or a timer event) and then perform a trigger to process it. Programming an event driven system is thus a matter of rewriting the default trigger functions of the system, to match the required behavior.

The method by which information on events is acquired by the underlying system is immaterial. Inputs can be polling in the event loop, or interrupt handlers can be registered to react to hardware events; many systems use a mixture of both techniques. The preprogrammed algorithm ensures that triggers provided are executed when they are needed, thus providing a software abstraction that emulates an interrupt driven environment.

Event-driven programs typically consist of a number of small programs called event handlers, which are to be called in response to external events, and a dispatcher, which calls the event handlers, often using an event queue to hold unprocessed events.

In many cases event handlers can trigger events themselves, possibly leading to an event cascade.

Event-driven programming stresses flexibility and asynchrony as virtues, and tries to be as modeless as possible. Graphical user interface programs are typically programmed in an event-driven style.

Computer operating systems are another classic example of event-driven programs on at least two levels. At the lowest level, interrupt handlers act as direct event handlers for hardware events, with the Central processing unit hardware performing the role of the dispatcher. Operating systems also typically act as dispatchers for software processes, passing data and software interrupts to user processes that in many cases are programmed as event handlers themselves.

A command driven system can be viewed as a special case of the event driven model in which the system, inactive, awaits one very complex event--the entry of a command by the user.

=Example=

This example uses pseudo code to illustrate how data is read from a socket using an event driven approach:

function read_next_data(fd) data = read_async( fd ) if len(data) == 0 => Nothing to read, register to be called back when something is ready event_polling_register( fd, read_next_data ) => Go back to doing something else else => Data was available and len(data) was received add_data_to_buffer( buffer, data ) fi

=References=

*Grant Palmer: Java Event Handling , Prentice Hall, ISBN 0-13-041802-1 *David Luckham: The Power of Events - An Introduction to Complex Event Processing in Distributed Enterprise Systems , Addison-Wesley, ISBN 0-201-72789-7 *George S. Fishman: Discrete-Event Simulation - Modeling, Programming, and Analysis , Springer, ISBN 0-387-95160-1 *Miro Samek: Practical Statecharts in C/C++: Quantum Programming for Embedded Systems , CMP Books, ISBN 1-57820-110-1

=See also=

*Signal programming (a similar concept) *Flow-driven programming (contrast) *Programming paradigms *Reactor Pattern *SEDA *Quantum Leaps *Event driven programming language *Event Stream Processing (ESP) (a similar concept) *Message Oriented Middleware

=Event-driven frameworks and libraries=

*Liboop, event loop management library *Libsigc_plus_plus, Callback (computer_science) Framework for C++ *REBECA, Event-Based Electronic Commerce Architecture *Twisted, Python *PRADO, a component-based and event-driven Web programming framework for PHP 5

=External links=

*[http://c2.com/cgi/wikiEventDrivenProgramming Description] from Portland Pattern Repository *Tutorial [http://www.freenetpages.co.uk/hp/alan.gauld/tutevent.htm Event Driven Programming] by Alan Gauld *Article [http://www.devhood.com/tutorials/tutorial_details.aspxtutorial_id=504 Transitioning from Structured to Event-Driven Programming] by Ben Watson *Article [http://today.java.net/lpt/a/32 Rethinking Swing Threading] by Jonathan Simon *Article [http://www.csse.uwa.edu.au/cnet/eventdriven.html The event driven programming style] by Chris McDonald *Article [http://codeproject.com/cpp/static-callbacks.asp Event Driven Programming using Template Specialization] by Christopher Diggins *Article [http://visualbuilder.com/article/viewarticle.aspid=1473 Delegates and Event Handling in C#] by Faisal Jawaid *Article [http://www.swe.uni-linz.ac.at/people/schiffer/se-94-17/se-94-17.htm Concepts and Architecture of Vista - a Multiparadigm Programming Environment] by Stefan Schiffer and Joachim Hans Fröhlich *Chapter [http://ocaml-programming.de/packages/documentation/equeue/users-guide/c494.html Event-driven programming vs. multi-threaded programming] from the Equeue user s guide by Gerd Stolpmann *Chapter [http://docs.eiffel.com/eiffelstudio/general/guided_tour/language/invitation-09.html Event-Driven Programming and Agents] *[http://zone.ni.com/devzone/devzone.nsf/webcategories/FCE7EA7ECA51169C862567A9005878EA LabWindows/CVI Resources] *[http://javalobby.org/forums/thread.jspathreadID=13874&messageID=91806918&tstart=0 Comment] by Tim Boudreau *[http://citeseer.ist.psu.edu/cisq=event+driven+programming Citations from CiteSeer]