Framework - CDPEventManager
CDPEventManager Introduction
The CDPEventManager library, an internal part of the CDP Core Framework, provides a system for collecting and distributing events. It can be configured to collect and forward events to subscribing CDP applications.
Most CDP Applications are already pre-configured with 2 CDPEventManager components: CDPEventNode and CDPEventSubscriber. The CDPEventNode will log events from it's local application, and send them to subscribers. An application's CDPEventSubscriber is by default subscribing for events from it's local CDPEventNode, but can be configured to subscribe for events from other CDP Applications as well, see Receiving Events In Native GUI Applications. In GUI applications, you may use the Event List, which is a configurable widget for showing events from CDP applications. In Design mode you will find the Event List widget under 'Other'. CDPEventNode and CDPEventSubscriber are not visible in CDP Studio unless Hide Internal Items is unchecked in the filtering in upper right corner. CDPEventNode and CDPEventSubscriber are found in the application's 'CDP' component.
Key features for CDPEventManager:
- CDPEventNode can log events from any custom objects that reports events (e.g. alarms), and distributes events to subscribers.
- Any custom objects can report events by implementing the IEventLogger interface.
- CDPEventSubscriber can subscribe events from CDPEventNodes in applications within the system.
- All reported events are guarantied to be received by the subscriber. (As long as circular event buffer is not overloaded. If overrun occurs it is detected by the protocol and alarm is triggered.).
- In case the event-messages do not reach their destination, the event-message protocol takes care of resending.
Generating Events
CDPAlarm event triggered
CDPAlarm is an alarm object in CDP. See the CDP Code Documentation for documentation on how to use the CDPAlarm object. The CDPAlarm triggers events in the following situations:
CDPAlarm event | Event type | EventCode | EventCode value | Description |
---|---|---|---|---|
Set | SimpleEvent | EVENT_ALARMSET | 0x00000001 | The alarm is set/triggered |
Acknowledge | SimpleEvent | EVENT_ALARMACK | 0x00000004 | A set alarm is acknowledged by someone (but still remains set) |
Clear | SimpleEvent | EVENT_ALARMCLEAR | 0x00000002 | A set alarm is cleared |
Other Events
Event type | EventCode | EventCode value | Description |
---|---|---|---|
SimpleEvent | EVENT_REPRISE | x (x = last event reported on the alarm) | 0x00000040 | x | A set or unacknowledged alarm will reinsert the last event reported at customisable intervals |
ExtendedEvent | EVENT_PROPERTY_CHANGE | 0x00000008 | Some property was changed |
SimpleEvent | EVENT_SOURCE_OBJECT_UNAVAILABLE | 0x00000100 | The provider of the event has become unavailable (disconnected or similar) |
SimpleEvent and ExtendedEvent | EVENT_NODE_BOOT | 0x40000000 | The provider reports that the CDPEventNode just have booted |
SimpleEvent | EVENT_EXTENDED_INFO_AVAILABLE | 0x80000000 | Indicates that this event also have sent extended event, and that the extended event info is available as extended event |
For each alarm that is in Set or Unacknowledged state, the last event performed on the alarm will be reinserted if no new events have been performed on it within a set (configurable) amount of time. This guaranties Set and/or Unacknowledged alarms to reach all subscribers, even if 'last-message' of a event transfer is lost in the network. This event is reported as a simple event in the CDPEventManager system. The value of timestamp and state is not changed, but a new event id will be created and the old id will be retained in the originalEventId property. The interval is set by the parameter "ReReportAlarmInterval" (currently 15s).
How To Generate Own Events
Report events through the IEventLogger interface. Typically from a CDPObject to a CDPEventNode. Users can implement event reporting from any custom made object using CDPObject as its base. Code example of generating a simple event:
#include <CDPSystem/EventLogger/IEventLogger.h> .... if (IEventLogger::GetInstance( Handle() ) != NULL) { char szTimeStamp[22]; //The time stamp for the alarm and the reported event. szTimeStamp[0] = 0; unsigned int newEventId = IEventLogger::GetInstance( Handle() )->ReportSimpleEvent(Handle(), status, eventCode, szTimeStamp);
Code example of generating an extended event (ReportExtendedEvent() will also call ReportSimpleEvent() with EVENT_EXTENDED_INFO_AVAILABLE bit set):
#include <CDPSystem/EventLogger/IEventLogger.h> .... if (IEventLogger::GetInstance( Handle() ) != NULL) { unsigned int newEventId = IEventLogger::GetInstance( Handle() )->ReportExtendedEvent(Handle(),0,EVENT_PROPERTY_CHANGE,"Clock",timeprint.length()+1,timeprint.c_str());
Receiving Events
The most easy way to receive events is to use the Event List widget in GUI applications.
Another way is to use the IEventManager interface. The purpose of IEventManager interface is to enable interfacing the CDPEventManager without creating a dependency to the CDPEventManager library. The functions in this interface will typically be implemented by IEventSubscriber, or another class implementing the IEventSubscriber interface.
Another way is use the IEventSubscriber interface. You could make your own CDPComponent called e.g. MyComponent, which inherits IEventSubscriber, and override wanted functions like this:
#include <CDPEventLogger/IEventSubscriber.h> class MyComponent : public IEventSubscriber, public CDPComponent virtual bool EventCallback(Event& event); virtual bool ExtendedEventCallback(ExtendedEvent& extEvent);
Event Info
The Event object stores information about the event that occurs. The events are classified in two main types of events: SimpleEvents and ExtendedEvents. The SimpleEvent is the actual event. This is where the time stamp is set, and this is where the status of the signaling object is stored. If there is more information available for an event (EVENT_EXTENDED_INFO_AVAILABLE is set in the SimpleEvent), this information is distributed as an ExtendedEvent. In the extended event, there are 932 bytes available for a textual name + data. For both event types, the event code gives a description of the event that happened. Both simple events and extended events contain information about which object generated the event (handle), and also have an event id. The event id is unique for the provider for some period of time, typically at least for some minutes. The event id is used to request extended information regarding the event, and to ensure that all events are transferred to the subscribers (the event id is automatically generated by CDP in the IEventLogger interface.)
Simple Events
Member variables for a Simple Event:
Data type | Member variable name | Description |
---|---|---|
unsigned int | eventId | EventID - Unique identifier (for this event node) |
unsigned int | originalEventId | Set for reprise events |
unsigned int | handle | CDP Handle of object that generated the event |
int | status | New status of object after the event |
int | eventCode | Code describing the event |
char[22] | timestamp | Time stamp when event was reported (local time in reporting node) |
char | padding_00 | 'padding_nn' not used, needed to be compatible with 4bytes Struct Member Alignment used in old CDP |
char | padding_01 | 'padding_nn' not used, needed to be compatible with 4bytes Struct Member Alignment used in old CDP |
The eventCode bitmask in the event object denotes which type of event it is. If more information is available, the eventCode also indicates this by having the EVENT_EXTENDED_INFO_AVAILABLE flag set. If the information in the SimpleEvent is sufficient, just do the necessary processing upon the event. Typically this is when only the state has changed in the reporting object. Status, typically the object state, of the object that generated the event is inserted in 'status' when applicable. If the SimpleEvent indicates that there is extended data, for instance a property change, then extended event information will be requested by the IEventSubscriber interface.
Extended Events
Member variables for a Extended Event:
Data type | Member variable name | Description |
---|---|---|
int | size | Size of this event info object (16+length(eventNameAndData)) |
unsigned int | handle | CDP Handle of object that generated the event |
unsigned int | eventId | EventID - Unique identifier (for this event node) |
int | eventCode | Code describing the alarm event |
char[932] | eventNameAndData | This will be a up to 932 bytes of data. eventName (name identifying the event type) is found in start of eventNameAndData, and must always be null-terminated. Then comes eventData: Note that this is not necessarily ascii data |
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.