aboutsummaryrefslogtreecommitdiffstats
path: root/generate-binding-glue.py
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-10-23 18:26:46 +0900
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2017-11-01 11:02:10 +0000
commitbe02238a0e92c74a13daaf516b5f379f29217eb8 (patch)
tree15e1b814a50a9f4833a318a1ba55b8d029f81b8b /generate-binding-glue.py
parentac5b834e535b95d2b893dbe527b2a7a9b6e2103d (diff)
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 <knimitz@witz-inc.co.jp>
Diffstat (limited to 'generate-binding-glue.py')
-rw-r--r--generate-binding-glue.py53
1 files changed, 37 insertions, 16 deletions
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' },