Implementing the Call to the Notification Endpoint
Let’s first look at an excerpt from WeatherSummaryImp.cpp showing the implementation for the one-way operation method weatherUpdate(). This implementation does not really do anything with the weather update, but uses the message’s arrival as the event that triggers a call to the notification operation method weatherNotification() in the specially-generated class WeatherSummaryNotificationProxy. In a more complete implementation, the data would probably be persisted in some way, but here the only point is to demonstrate how to implement a notification.
void WeatherSummaryImp::weatherUpdate(rwsf::CallInfo& callInfo,
const wsx::WeatherSummary& weatherData_in) //1
std::list<std::string>::iterator iter = subscriptions_.begin(); //2
for (; iter != subscriptions_.end(); ++iter) {
WeatherSummaryNotificationProxy notifProxy =
WeatherSummaryNotificationProxy::make(*iter); //3
notifProxy.weatherNotification(weatherData_in); //4
//1 Represents the end point implementation for the weatherUpdate() one-way message from the client. Since the request is one-way, no necessary response is expected. But in this case, this message serves as the trigger for a notification message back to the client.
//2 Creates an iterator for cycling through the locations registered with the server to receive notifications when a weather update is received. In our simple example, the only location registered is the same client that sent the weather update.
//3 For each registered client, obtains a notification proxy.
//4 Sends a notification to the client based on the input data from weatherUpdate().