diff options
author | Milan Srdinko <msrdinko@alps.cz> | 2017-02-13 16:34:44 +0100 |
---|---|---|
committer | Milan Srdinko <msrdinko@alps.cz> | 2017-03-17 12:15:13 +0100 |
commit | 3d17ff13b8a7fe9a2c60f815b1805ec619285b18 (patch) | |
tree | 86ff8687001fc784a8fa43c47d08c29b9d157e06 | |
parent | 13d17203d42320370d0253cfb68059fb4ee7f08a (diff) |
WiFi: add event unsubscribe/delete on Wi-Fi disable
Change-Id: I2b3c74fc24b57c6152f105ff7bd8b090d9dad155
Signed-off-by: Milan Srdinko <msrdinko@alps.cz>
-rw-r--r-- | app/wifi/Wifi.qml | 27 | ||||
-rw-r--r-- | binding-wifi/wifi-api.c | 37 |
2 files changed, 58 insertions, 6 deletions
diff --git a/app/wifi/Wifi.qml b/app/wifi/Wifi.qml index 3bf4774..f3871a6 100644 --- a/app/wifi/Wifi.qml +++ b/app/wifi/Wifi.qml @@ -185,7 +185,8 @@ SettingPage { } else if (websocket.status == WebSocket.Closed) { status_str = "Socket closed" - //TODO: unsubscribe for events + console.log("Socket closed, bye.") + } console.log(status_str) @@ -207,6 +208,30 @@ SettingPage { var parameterJson = 'None' sendSocketMesage(verb_str, parameterJson) + + verb_str = "eventunsub" + parameterJson = { + tag: 'password' + } + sendSocketMesage(verb_str, parameterJson) + + verb_str = "eventdel" + parameterJson = { + tag: 'password' + } + sendSocketMesage(verb_str, parameterJson) + + verb_str = "eventunsub" + parameterJson = { + tag: 'networkList' + } + sendSocketMesage(verb_str, parameterJson) + + verb_str = "eventdel" + parameterJson = { + tag: 'networkList' + } + websocket.active = false } diff --git a/binding-wifi/wifi-api.c b/binding-wifi/wifi-api.c index 933a121..02ff106 100644 --- a/binding-wifi/wifi-api.c +++ b/binding-wifi/wifi-api.c @@ -585,6 +585,18 @@ static void eventadd (struct afb_req request) afb_req_success(request, NULL, NULL); } +static void eventdel (struct afb_req request) +{ + const char *tag = afb_req_value(request, "tag"); + + if (tag == NULL) + afb_req_fail(request, "failed", "bad arguments"); + else if (0 != event_del(tag)) + afb_req_fail(request, "failed", "deletion error"); + else + afb_req_success(request, NULL, NULL); +} + static int event_subscribe(struct afb_req request, const char *tag) { struct event *e; @@ -592,6 +604,13 @@ static int event_subscribe(struct afb_req request, const char *tag) return e ? afb_req_subscribe(request, e->event) : -1; } +static int event_unsubscribe(struct afb_req request, const char *tag) +{ + struct event *e; + e = event_get(tag); + return e ? afb_req_unsubscribe(request, e->event) : -1; +} + static void eventsub (struct afb_req request) { const char *tag = afb_req_value(request, "tag"); @@ -604,6 +623,17 @@ static void eventsub (struct afb_req request) afb_req_success(request, NULL, NULL); } +static void eventunsub (struct afb_req request) +{ + const char *tag = afb_req_value(request, "tag"); + + if (tag == NULL) + afb_req_fail(request, "failed", "bad arguments"); + else if (0 != event_unsubscribe(request, tag)) + afb_req_fail(request, "failed", "unsubscription error"); + else + afb_req_success(request, NULL, NULL); +} /* @@ -623,11 +653,8 @@ static const struct afb_verb_desc_v1 binding_verbs[] = { { .name = "eventadd", .session = AFB_SESSION_NONE, .callback = eventadd, .info ="adds the event of 'name' for the 'tag'"}, { .name = "eventsub", .session = AFB_SESSION_NONE, .callback = eventsub, .info ="unsubscribes to the event of 'tag'"}, { .name = "eventpush", .session = AFB_SESSION_NONE, .callback = eventpush, .info ="pushes the event of 'tag' with the 'data'"}, - - - - - +{ .name = "eventunsub", .session = AFB_SESSION_NONE, .callback = eventunsub, .info ="unsubscribes to the event of 'tag'"}, +{ .name = "eventdel", .session = AFB_SESSION_NONE, .callback = eventdel, .info ="deletes the event of 'tag'"}, { .name = NULL } /* marker for end of the array */ }; |