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);
eventRegistrar.registerEvent(Events::FadingSelectionEvent::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.
{
"PHYI %03hu FrameworkPHY::%s event id: %hu",
__func__,
eventId);
switch(eventId)
{
{
gainManager_.
update(antennaProfile.getAntennaProfiles());
eventTablePublisher_.
update(antennaProfile.getAntennaProfiles());
Events::AntennaProfileEventFormatter(antennaProfile),
"PHYI %03hu FrameworkPHY::%s antenna profile event: ",
__func__);
}
break;
{
fadingManager_.
update(fadingSelection.getFadingSelections());
eventTablePublisher_.
update(fadingSelection.getFadingSelections());
Events::FadingSelectionEventFormatter(fadingSelection),
"PHYI %03hu FrameworkPHY::%s fading selection event: ",
__func__);
}
break;
{
locationManager_.
update(locationEvent.getLocations());
eventTablePublisher_.
update(locationEvent.getLocations());
Events::LocationEventFormatter(locationEvent),
"PHYI %03hu FrameworkPHY::%s location event: ",
__func__);
}
break;
{
pPropagationModelAlgorithm_->update(pathlossEvent.getPathlosses());
eventTablePublisher_.
update(pathlossEvent.getPathlosses());
Events::PathlossEventFormatter(pathlossEvent),
"PHYI %03hu FrameworkPHY::%s pathloss event: ",
__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.
pAntennaProfileControlMessage->getAntennaProfileId(),
pAntennaProfileControlMessage->getAntennaAzimuthDegrees(),
pAntennaProfileControlMessage->getAntennaElevationDegrees()}};
gainManager_.update(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.