Components issue events in order to inform other components that something has happened. Other components can register themselves as event sinks and be notified when a specific event has occurred. Some typical events that can occur in WinGate include
- When a web browser connects to a WinGate proxy service
- When the Kaspersky AV scanner detects a virus
- When a WinGate SMTP service receives an email
- When client software connects via NAT
- When WinGate starts up or shuts down
The general object structure for event sources is as follows:
Setting up an event source
Adding event source support to your component requires:
- Registering a class (template) for your event source with EventRegisterSourceClass. This class describes the events and parameters to those events that instantiations of the event source will contain. You can then instantiate an event source based on this template without having to respecify all of the events and parameters again. For example: The WWW Proxy Service in WinGate registers a source class that describes the events a WWW proxy service can create. Because you can have multiple proxy services, each with the exact same events and event parameter types, all that is needed is to register the event source class once, and then instantiate a new event source from this class when the user creates a new WWW Proxy Service.
- Add events to the class with EventRegisterEvent
- Add datum (parameters) to the events of the class with EventRegisterEventDatum
- Optionally place the event into a realm with EventAssociateRealm
- Instantiate the source with EventRegisterEventSource
Signalling an event
Before signalling an event you need to set up an event source and its associated events with calls to EventRegisterSourceClass, EventRegisterEventSource and EventRegisterEvent amongst others. Once your source and events are set up, you can signal an event by calling EventProcessEvent passing in an EventContextHandle that describes the event you wish to send.
The fields in the EventContextHandle that you need to set are as follows:
- The name of the event. Set this with EventContextSetEventName
- The event source. Set this with EventContextSetEventSource
- Data. Depending on the event you need to push all expected data with EventContextPushData
After setting up the event context, you can call EventProcessEvent
Event processing is a serialised operation. When an event occurs, the event handlers for that event are processed one after the other with each handler able to cancel event handling when they process the event.