From 84eac57632f4374d3114ae0586061fd6c0a43bc3 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 8 Feb 2018 22:24:58 -0800 Subject: binding: weather: trigger weather event on subscribe Send current weather data to any new subscribers Bug-AGL: SPEC-1273 Change-Id: I96c92ba7e469a5cdc13c48694f1b0f2a42752b74 Signed-off-by: Matt Ranostay --- binding/afm-weather-binding.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'binding/afm-weather-binding.c') diff --git a/binding/afm-weather-binding.c b/binding/afm-weather-binding.c index e2094c0..1103722 100644 --- a/binding/afm-weather-binding.c +++ b/binding/afm-weather-binding.c @@ -223,8 +223,16 @@ static void subscribe(struct afb_req request) const char *value = afb_req_value(request, "value"); if (value && !strcasecmp(value, "weather")) { + json_object *jresp = NULL; + afb_req_subscribe(request, weather_event); afb_req_success(request, NULL, NULL); + + jresp = json_tokener_parse(data.buffer); + if (jresp) { + json_object_object_add(jresp, "url", json_object_new_string(data.url)); + afb_event_push(weather_event, jresp); + } return; } -- cgit 1.2.3-korg