Event (computing)
Encyclopedia
In computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

 an event is an action that is usually initiated outside the scope of a program and that is handled by a piece of code inside the program. Typically events are handled synchronous with the program flow, that is, the program has one or more dedicated places where events are handled. Typical sources of events include the user (who presses a key on the keyboard
Keyboard (computing)
In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches...

, in other words, through a keystroke). Another source is a hardware device such as a timer. A computer program that changes its behavior in response to events is said to be event-driven
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

, often with the goal of being interactive
Interactivity
In the fields of information science, communication, and industrial design, there is debate over the meaning of interactivity. In the "contingency view" of interactivity, there are three levels:...

.

Description

Event driven systems are typically used when there is some asynchronous external activity that needs to be handled by a program. For example, a user who presses a button on their mouse. The outside activity causes the event (it fires), some outside hardware and or software will collect data about the event, and when the program signals that it is ready to accept an event, the event will be dispatched to the event handler software that will deal with it.

A program can choose to ignore events, and there may be libraries to dispatch an event to multiple handlers that may be programmed to listen for a particular event. The data associated with an event at a minimum specifies what type of event it is, but may include other information such as when it occurred, who or what caused it to occur, and extra data provided by the event source to the handler about how the event should be processed.

Events are typically used in user interfaces, where actions in the outside world (mouse clicks, window-resizing, keyboard presses, messages from other programs, etc.) are handled by the program as a series of events. Programs written for many windowing environments consist predominantly of event handlers.

Events can also be used at instruction set
Instruction set
An instruction set, or instruction set architecture , is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O...

 level, where they complement interrupts. Compared to interrupts, events are normally handled synchronously: the program explicitly waits for an event to be serviced (typically by calling an instruction that dispatches the next event), whereas an interrupt can demand service at any time.

Delegate event model

A very common and very "programmer-friendly" variant is the delegate event model, which is provided by the most popular graphic frameworks.

This model is based on three entities:
  • a control, which is the event source,
  • consumer
    Consumer
    Consumer is a broad label for any individuals or households that use goods generated within the economy. The concept of a consumer occurs in different contexts, so that the usage and significance of the term may vary.-Economics and marketing:...

    s, also called listeners
    Observer pattern
    The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods...

    , that receive the events from the source,
  • interfaces
    Interface (computer science)
    In the field of computer science, an interface is a tool and concept that refers to a point of interaction between components, and is applicable at the level of both hardware and software...

     (in the broader meaning of the term) that describe the protocol
    Protocol (object-oriented programming)
    In object-oriented programming, a protocol or interface is a common means for unrelated objects to communicate with each other. These are definitions of methods and values which the objects agree upon in order to cooperate....

     by which every event is to be communicated.


Furthermore, the model requires that
  • every listener must implement the interface for the event
    Event-driven programming
    In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

     it wants to listen to
  • every listener must register with the source to declare its desire to listen to some particular event
  • every time the source generates an event, it communicates it to the registered listeners, following the protocol of the interface.


C# uses events as special delegates that can only be fired by the class that declares it. This is makes a better abstraction possible. Here's an example:


class Model {
public event Notifier notifyViews;
public void Change { ... notifyViews("Model"); }
}

class FirstView {
public View1(Model m) {
m.notifyViews += new Notifier(this.Update1);
}

void Update1(string sender) {
Console.WriteLine(sender + " was changed during update"); }
}

class SecondView {
public View2(Model m) {
m.notifyViews += new Notifier(this.Update2);
}

void Update2(string sender) {
Console.WriteLine(sender + " was changed"); }
}

class Test {
static void Main {
Model m = new Model;

new FirstView(m);
new SecondView(m);
m.Change;}
}

Event handler

In computer programming, an event handler is an asynchronous callback
Callback (computer science)
In computer programming, a callback is a reference to executable code, or a piece of executable code, that is passed as an argument to other code. This allows a lower-level software layer to call a subroutine defined in a higher-level layer....

 subroutine that handles inputs received in a program. Each event is a piece of application-level information from the underlying framework
Application framework
In computer programming, an application framework consists of a software framework used by software developers to implement the standard structure of an application for a specific development environment ....

, typically the GUI toolkit. GUI events include key
Computer keyboard
In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches...

 presses, mouse movement, action selections, and timer
Timer
A timer is a specialized type of clock. A timer can be used to control the sequence of an event or process. Whereas a stopwatch counts upwards from zero for measuring elapsed time, a timer counts down from a specified time interval, like an hourglass.Timers can be mechanical, electromechanical,...

s expiring. On a lower level, events can represent availability of new data for reading a file or network stream. Event handlers are a central concept in event-driven programming
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

.

The events are created by the framework based on interpreting lower-level inputs, which may be lower-level events themselves. For example, mouse movements and clicks are interpreted as menu selections. The events initially originate from actions on the operating system level, such as interrupts generated by hardware devices, software interrupt instructions, or state changes in polling
Polling (computer science)
Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity. Polling is most often used in terms of input/output , and is also referred to as polled or software driven .Polling is sometimes used...

. On this level, interrupt handler
Interrupt handler
An interrupt handler, also known as an interrupt service routine , is a callback subroutine in microcontroller firmware, operating system or device driver whose execution is triggered by the reception of an interrupt...

s and signal handlers correspond to event handlers.

Created events are first processed by an event dispatcher within the framework. It typically manages the associations between events and event handlers, and may queue event handlers or events for later processing. Event dispatchers may call event handlers directly, or wait for events to be dequeued with information about the handler to be executed.

Event notification

Event notification is a term used in conjunction with communication
Telecommunication
Telecommunication is the transmission of information over significant distances to communicate. In earlier times, telecommunications involved the use of visual signals, such as beacons, smoke signals, semaphore telegraphs, signal flags, and optical heliographs, or audio messages via coded...

s software for linking applications that generate small messages (the "events") to applications that monitor the associated conditions and may take actions triggered by events.

Event notification is an important feature in modern database
Database
A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...

 systems (used to inform applications when conditions they are watching for have occurred), modern operating systems (used to inform applications when they should take some action, such as refreshing a window), and modern distributed systems, where the producer of an event might be on a different machine than the consumer, or consumers. Event notification platforms are normally designed so that the application producing events does not need to know which applications will consume them, or even how many applications will monitor the event stream.

It is sometimes used as a synonym for publish-subscribe, a term that relates to one class of products supporting event notification in networked settings. The virtual synchrony
Virtual synchrony
Virtual synchrony is an interprocess messaging passing technology. Virtual synchrony systems allow programs running in a network to organize themselves into process groups, and to send messages to groups...

 model is sometimes used to endow event notification systems, and publish-subscribe systems, with stronger fault-tolerance and consistency guarantees.

Mouse

With a pointing device
Pointing device
A pointing device is an input interface that allows a user to input spatial data to a computer...

 such as a mouse, clicking a button
Mouse button
A mouse button is a microswitch on a computer mouse which can be pressed in order to select or interact with an element of a graphical user interface.The three-button scrollmouse has become the most commonly available design...

 triggers a "mouse click" event. The programmer would then program the software to respond to this "mouse click" event. Typical mouse events include mouse move and mouse button up/down.

Keyboard

When a user presses a key on a keyboard, the program currently running would receive a keyboard "KeyDown" event along with relevant data such as which key the user pressed.

See also

  • Callback (computer science)
    Callback (computer science)
    In computer programming, a callback is a reference to executable code, or a piece of executable code, that is passed as an argument to other code. This allows a lower-level software layer to call a subroutine defined in a higher-level layer....

  • DOM Events
    DOM Events
    DOM events allow event-driven programming languages like JavaScript, JScript, ECMAScript, VBScript and Java to register various event handlers/listeners on the element nodes inside a DOM tree, e.g. HTML, XHTML, XUL and SVG documents....

  • Event-driven programming
    Event-driven programming
    In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

  • Exception handling
    Exception handling
    Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....

  • Interrupt handler
    Interrupt handler
    An interrupt handler, also known as an interrupt service routine , is a callback subroutine in microcontroller firmware, operating system or device driver whose execution is triggered by the reception of an interrupt...

  • Interrupts
  • Observer pattern
    Observer pattern
    The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods...

     (e.g. Event listener)
  • Signal handler
  • Virtual synchrony
    Virtual synchrony
    Virtual synchrony is an interprocess messaging passing technology. Virtual synchrony systems allow programs running in a network to organize themselves into process groups, and to send messages to groups...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK