From be02238a0e92c74a13daaf516b5f379f29217eb8 Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Mon, 23 Oct 2017 18:26:46 +0900 Subject: Modify event notification from broadcast to subscribe model The event notification was implemented using a broadcast model, change it to a subscription model. Bug-AGL: SPEC-987 Change-Id: I344a3a73320eb81c3f670736b032f07400bb8f64 Signed-off-by: Kazumasa Mitsunari --- generate-binding-glue.py | 53 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'generate-binding-glue.py') diff --git a/generate-binding-glue.py b/generate-binding-glue.py index dbebbcd..376350a 100644 --- a/generate-binding-glue.py +++ b/generate-binding-glue.py @@ -30,22 +30,41 @@ def p(*args): def emit_func_impl(api, f): args = f.get('args', []) - if len(args) > 0: - p(' json_object *jreq = afb_req_json(req);', '') - for arg in args: - arg['jtype'] = arg.get('jtype', arg['type']) # add jtype default - p(' json_object *j_%(name)s = nullptr;' % arg, - ' if (! json_object_object_get_ex(jreq, "%(name)s", &j_%(name)s)) {' % arg, - ' afb_req_fail(req, "failed", "Need %(type)s argument %(name)s");' % arg, - ' return;', - ' }', - ' %(type)s a_%(name)s = json_object_get_%(jtype)s(j_%(name)s);' % arg, '') - p(' auto ret = %(api)s' % api + '%(name)s(' % f + ', '.join(map(lambda x: 'a_' + x['name'], args)) + ');') - p(' if (ret.is_err()) {', - ' afb_req_fail(req, "failed", ret.unwrap_err());', - ' return;', - ' }', '') - p(' afb_req_success(req, ret.unwrap(), "success");') + func_name = f.get('name', []) + if "wm_subscribe" == func_name: + p(' json_object *jreq = afb_req_json(req);') + p(' json_object *j = nullptr;') + p(' if (! json_object_object_get_ex(jreq, "event", &j)) {') + p(' afb_req_fail(req, "failed", "Need char const* argument event");') + p(' return;') + p(' }') + p(' int event_type = json_object_get_int(j);') + p(' const char *event_name = g_afb_instance->app.kListEventName[event_type];') + p(' struct afb_event event = g_afb_instance->app.map_afb_event[event_name];') + p(' int ret = afb_req_subscribe(req, event);') + p(' if (ret) {', + ' afb_req_fail(req, "failed", "Error: afb_req_subscribe()");', + ' return;', + ' }') + p(' afb_req_success(req, NULL, "success");') + + else: + if len(args) > 0: + p(' json_object *jreq = afb_req_json(req);', '') + for arg in args: + arg['jtype'] = arg.get('jtype', arg['type']) # add jtype default + p(' json_object *j_%(name)s = nullptr;' % arg, + ' if (! json_object_object_get_ex(jreq, "%(name)s", &j_%(name)s)) {' % arg, + ' afb_req_fail(req, "failed", "Need %(type)s argument %(name)s");' % arg, + ' return;', + ' }', + ' %(type)s a_%(name)s = json_object_get_%(jtype)s(j_%(name)s);' % arg, '') + p(' auto ret = %(api)s' % api + '%(name)s(' % f + ', '.join(map(lambda x: 'a_' + x['name'], args)) + ');') + p(' if (ret.is_err()) {', + ' afb_req_fail(req, "failed", ret.unwrap_err());', + ' return;', + ' }', '') + p(' afb_req_success(req, ret.unwrap(), "success");') def emit_func(api, f): p('void %(impl_name)s(afb_req req) noexcept {' % f) @@ -132,6 +151,8 @@ API = { { 'name': 'drawing_name', 'type': 'char const*', 'jtype': 'string' }, ], }, + { 'name': 'wm_subscribe', }, + { 'name': 'list_drawing_names', }, { 'name': 'ping' }, -- cgit 1.2.3-korg