EMANE  1.0.1
Event Service

The EventRegistrar is used by components to register to receive events. Events target a specific NEM Id or the NEM Id 0 to indicate all NEMs. In order for a component to receive an event it must register for the event and the inbound event NEM target must match the component's NEM Id or be addressed to all NEMs.

Registering for an Event

Events can only be registered during Component::initialize. The EventRegistrar is accessible via the initialize method's Registrar argument.

Components register to receive an event using EventRegistrar::registerEvent.

auto & eventRegistrar = registrar.eventRegistrar();
eventRegistrar.registerEvent(Events::PathlossEvent::IDENTIFIER);
eventRegistrar.registerEvent(Events::LocationEvent::IDENTIFIER);
eventRegistrar.registerEvent(Events::AntennaProfileEvent::IDENTIFIER);

Handling an Event

When a registered event is received for a targeted NEM it is pushed onto the NEM's functor queue as an EventServiceUser::processEvent method. The event data is serialized and an event object must be restored (de-serialized) in order to access the event data.

const Serialization & serialization)
{
"PHYI %03hu FrameworkPHY::%s event id: %hu",
id_,
__func__,
eventId);
switch(eventId)
{
{
Events::AntennaProfileEvent antennaProfile{serialization};
gainManager_.update(antennaProfile.getAntennaProfiles());
eventTablePublisher_.update(antennaProfile.getAntennaProfiles());
Events::AntennaProfileEventFormatter(antennaProfile),
"PHYI %03hu FrameworkPHY::%s antenna profile event: ",
id_,
__func__);
}
break;
{
Events::LocationEvent locationEvent{serialization};
locationManager_.update(locationEvent.getLocations());
eventTablePublisher_.update(locationEvent.getLocations());
Events::LocationEventFormatter(locationEvent),
"PHYI %03hu FrameworkPHY::%s location event: ",
id_,
__func__);
}
break;
{
Events::PathlossEvent pathlossEvent{serialization};
pPropagationModelAlgorithm_->update(pathlossEvent.getPathlosses());
eventTablePublisher_.update(pathlossEvent.getPathlosses());
Events::PathlossEventFormatter(pathlossEvent),
"PHYI %03hu FrameworkPHY::%s pathloss event: ",
id_,
__func__);
}
break;
}
}

Sending an Event

All components have the ability to send events using EventServiceProvider::sendEvent. The EventServiceProvider is accessed via the PlatformServiceProvider. All components are given a reference to the PlatformServiceProvider when they are constructed.

Events::AntennaProfiles profiles{{id_,
pAntennaProfileControlMessage->getAntennaProfileId(),
pAntennaProfileControlMessage->getAntennaAzimuthDegrees(),
pAntennaProfileControlMessage->getAntennaElevationDegrees()}};
gainManager_.update(profiles);
pPlatformService_->eventService().sendEvent(0,Events::AntennaProfileEvent{profiles});

A component will never receive an event it sends even if it targets its own NEM Id or sends the event to all NEMs.