From 49533399810630031541b25407cd88498a72f6c3 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Tue, 7 Mar 2017 22:35:52 +0100 Subject: Lock on WS afb-daemon Segmentation fault --- Alsa/CMakeLists.txt | 5 ++ Alsa/core-binding/AlsaLibMapping.c | 3 +- Alsa/core-binding/README.md | 2 +- CMakeLists.txt | 3 +- README.md | 2 +- htdocs/README.md | 7 +++ htdocs/alsa-core.html | 43 ++++++++++++++ htdocs/index.html | 7 +++ htdocs/websock.js | 117 +++++++++++++++++++++++++++++++++++++ nbproject/configurations.xml | 4 +- nbproject/project.xml | 2 +- 11 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 htdocs/README.md create mode 100644 htdocs/alsa-core.html create mode 100644 htdocs/index.html create mode 100644 htdocs/websock.js diff --git a/Alsa/CMakeLists.txt b/Alsa/CMakeLists.txt index 22061eb..e8173f9 100644 --- a/Alsa/CMakeLists.txt +++ b/Alsa/CMakeLists.txt @@ -22,5 +22,10 @@ PKG_CHECK_MODULES(alsa REQUIRED alsa) # Max Sound Card Number eligible to ctlevent subscription defstr(MAX_SND_CARD 16) +SET(link_libraries + ${alsa_LIBRARIES} + ${link_libraries} + ) + ADD_SUBDIRECTORY(core-binding) diff --git a/Alsa/core-binding/AlsaLibMapping.c b/Alsa/core-binding/AlsaLibMapping.c index e4f27c9..8d85f11 100644 --- a/Alsa/core-binding/AlsaLibMapping.c +++ b/Alsa/core-binding/AlsaLibMapping.c @@ -710,10 +710,11 @@ PUBLIC void alsaSubCtl (struct afb_req request) { // subscribe to binder event err = afb_req_subscribe(request, evtHandle->afbevt); if (err != 0) { - afb_req_fail_f (request, "register-eventname", "Cannot subscribe binder event name=%s err=%d", devid, err); + afb_req_fail_f (request, "register-eventname", "Cannot subscribe binder event name=%s need WS", devid, err); goto ExitOnError; } + // increase usage count and return success sndHandles[idx].ucount ++; afb_req_success(request, NULL, NULL); return; diff --git a/Alsa/core-binding/README.md b/Alsa/core-binding/README.md index 12c8d5e..7f8c87a 100644 --- a/Alsa/core-binding/README.md +++ b/Alsa/core-binding/README.md @@ -18,5 +18,5 @@ Testing: (from Build dir with Binder install in $HOME/opt= # Get detail on a given control (optional quiet=0=verbose,1,2) http://localhost:1234/api/alsacore/getctl?devid=hw:0&numid=1&quiet=0 - # Subscribe to event from a given sound card + # Subscribe to event from a given sound card (warning fail if not WS) http://localhost:1234/api/alsacore/subctl?devid=hw:0 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bc5965..d3167ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ PKG_CHECK_MODULES(json-c REQUIRED json-c) PKG_CHECK_MODULES(afb-daemon REQUIRED afb-daemon) IF(CMAKE_BUILD_TYPE MATCHES Debug) - # CHECK_LIBRARY_EXISTS(efence malloc "" HAVE_LIBEFENCE) + CHECK_LIBRARY_EXISTS(efence malloc "" HAVE_LIBEFENCE) IF(HAVE_LIBEFENCE) MESSAGE(STATUS "Linking with ElectricFence for debugging purposes...") SET(libefence_LIBRARIES "-lefence") @@ -106,7 +106,6 @@ SET(include_dirs SET(link_libraries ${libefence_LIBRARIES} ${json-c_LIBRARIES} - ${alsa_LIBRARIES} ) # Bindings to compile diff --git a/README.md b/README.md index 7bc2868..bbc7b9c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ make install ls # Start the binder -afb-daemon --token=x --ldpaths=$INSTALL_DIR/lib --port=5555 --rootdir=$INSTALL_DIR --verbose +afb-daemon --token=x --ldpaths=$INSTALL_DIR/lib --port=1234 --roothttp=$INSTALL_DIR/htdocs/audio-bindings --verbose ``` diff --git a/htdocs/README.md b/htdocs/README.md new file mode 100644 index 0000000..6468356 --- /dev/null +++ b/htdocs/README.md @@ -0,0 +1,7 @@ +------------------------------------------------------------------------ + Simple HTML test +------------------------------------------------------------------------ + + # Load bindings directly from development tree for debug + afb-daemon --token=x --ldpaths=build/Alsa/core-binding --port=1234 --roothttp=htdocs --verbose + diff --git a/htdocs/alsa-core.html b/htdocs/alsa-core.html new file mode 100644 index 0000000..e408a01 --- /dev/null +++ b/htdocs/alsa-core.html @@ -0,0 +1,43 @@ + + + Hello world test + + + + + +

Hello world test

+
    +
  1. getinfo: List Sound Cards +
  2. Card info about hw:0 +
  3. List controls for hw:0 (quiet) +
  4. List controls for hw:0 (verbose) +
  5. return control numid=1 for hw:0 +
  6. + diff --git a/htdocs/index.html b/htdocs/index.html new file mode 100644 index 0000000..dfb3c71 --- /dev/null +++ b/htdocs/index.html @@ -0,0 +1,7 @@ + + + AGL-AudioBindins tests + +

    audio-bindings test

    +
      +
    1. AlsaCore Low Level Binding diff --git a/htdocs/websock.js b/htdocs/websock.js new file mode 100644 index 0000000..c429553 --- /dev/null +++ b/htdocs/websock.js @@ -0,0 +1,117 @@ + +AfbCtxItf = (function(){ + + var UUID = undefined; + var TOKEN = undefined; + + function AfbCtxItf(token, uuid) { + this.token = token; + this.uuid = uuid; + } + + AfbCtxItf.prototype = { + get token() {return TOKEN;}, + set token(tok) {if(tok) TOKEN=tok;}, + get uuid() {return UUID;}, + set uuid(id) {if(id) UUID=id;} + }; + + return AfbCtxItf; +})(); + + +AfbWsItf = (function(){ + + var CALL = 2; + var RETOK = 3; + var RETERR = 4; + + function AfbWsItf(base, onopen, onabort, ctx) { + ctx = ctx || new AfbCtxItf(); + var wl = window.location; + var u = "ws://"+wl.host+"/"+base; + if (ctx.token) { + u = u + '?x-afb-token=' + ctx.token; + if (ctx.uuid) + u = u + '&x-afb-uuid=' + ctx.uuid; + } + this.ws = new (WebSocket || MozWebSocket)(u, [ "x-afb-ws-json1" ]); + this.pendings = {}; + this.counter = 0; + this.ctx = ctx; + this.ws.onopen = onopen.bind(this); + this.ws.onerror = onerror.bind(this); + this.ws.onclose = onclose.bind(this); + this.ws.onmessage = onmessage.bind(this); + this.onopen = onopen; + this.onabort = onabort; + } + + function onerror(event) { + var f = this.onabort; + if (f) { + delete this.onopen; + delete this.onabort; + f && f(this); + } + this.onerror && this.onerror(this); + } + + function onopen(event) { + var f = this.onopen; + delete this.onopen; + delete this.onabort; + f && f(this); + } + + function onclose(event) { + for (var id in this.pendings) { + var ferr = this.pendings[id].onerror; + ferr && ferr(null, this); + } + this.pendings = {}; + this.onclose && this.onclose(); + } + + function onmessage(event) { + var obj = JSON.parse(event.data); + var code = obj[0]; + var id = obj[1]; + var ans = obj[2]; + this.ctx.token = obj[3]; + var pend; + if (id && id in this.pendings) { + pend = this.pendings[id]; + delete this.pendings[id]; + } + switch (code) { + case RETOK: + pend && pend.onsuccess && pend.onsuccess(ans, this); + break; + case RETERR: + default: + pend && pend.onerror && pend.onerror(ans, this); + break; + } + } + + function close() { + this.ws.close(); + } + + function call(api, verb, request, onsuccess, onerror) { + var id = String(++this.counter); + this.pendings[id] = { onsuccess: onsuccess, onerror: onerror }; + var arr = [CALL, id, api+"/"+verb, request ]; + if (this.ctx.token) arr.push(this.ctx.token); + this.ws.send(JSON.stringify(arr)); + } + + AfbWsItf.prototype = { + close: close, + call: call + }; + + return AfbWsItf; +})(); + diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index e9d0ed5..370176d 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -46,13 +46,13 @@ - Build + build ${MAKE} -f Makefile ${MAKE} -f Makefile clean - Build + build cmake -Wno-dev -DCXX=g++-5 -DCC=gcc-5 .. true diff --git a/nbproject/project.xml b/nbproject/project.xml index be8b144..7ec3b29 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -5,7 +5,7 @@ AGL-AudioBindings c - cpp,cxx + cpp h UTF-8 -- cgit 1.2.3-korg