summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alsa/CMakeLists.txt5
-rw-r--r--Alsa/core-binding/AlsaLibMapping.c3
-rw-r--r--Alsa/core-binding/README.md2
-rw-r--r--CMakeLists.txt3
-rw-r--r--README.md2
-rw-r--r--htdocs/README.md7
-rw-r--r--htdocs/alsa-core.html43
-rw-r--r--htdocs/index.html7
-rw-r--r--htdocs/websock.js117
-rw-r--r--nbproject/configurations.xml4
-rw-r--r--nbproject/project.xml2
11 files changed, 187 insertions, 8 deletions
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 @@
+<html>
+<head>
+ <title>Hello world test</title>
+
+ <script type="text/javascript" src="websock.js"></script>
+ <script type="text/javascript">
+ var ws;
+
+ function onopen() {
+ document.getElementById("main").style.visibility = "visible";
+ document.getElementById("connected").innerHTML = "WebSocket Open";
+ }
+ function onabort() {
+ document.getElementById("main").style.visibility = "hidden";
+ document.getElementById("connected").innerHTML = "Connected Closed";
+ }
+ function init() {
+ ws = new AfbWsItf("api", onopen, onabort, new AfbCtxItf("hello"));
+ }
+ function replyok(obj) {
+ document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj);
+ }
+ function replyerr(obj) {
+ document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj);
+ }
+ function subscribe(devid) {
+ ws.call("alsacore", "subctl", {devid:devid}, replyok, replyerr);
+ }
+ </script>
+
+<body onload="init();">
+ <h1>Hello world test</h1>
+ <ol>
+ <li><a href="api/alsacore/getinfo">getinfo: List Sound Cards</a>
+ <li><a href="api/alsacore/getinfo?devid=hw:0">Card info about hw:0</a>
+ <li><a href="api/alsacore/getctl?devid=hw:0">List controls for hw:0 (quiet)</a>
+ <li><a href="api/alsacore/getctl?devid=hw:0&quiet=0">List controls for hw:0 (verbose)</a>
+ <li><a href="api/alsacore/getctl?devid=hw:0&numid=1&quiet=0">return control numid=1 for hw:0</a>
+ <li><button id="connected" onclick="subscribe('hw:0')">Click to Connected</button></li>
+ <div id="main" style="visibility:hidden">
+ <p>Event Output</p>
+ Server says... <div id="output"></div>
+ </div>
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 @@
+<html>
+ <head>
+ <title>AGL-AudioBindins tests</title>
+ <body>
+ <h1>audio-bindings test</h1>
+ <ol>
+ <li><a href="alsa-core.html">AlsaCore Low Level Binding</a>
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 @@
</codeAssistance>
<makefileType>
<makeTool>
- <buildCommandWorkingDir>Build</buildCommandWorkingDir>
+ <buildCommandWorkingDir>build</buildCommandWorkingDir>
<buildCommand>${MAKE} -f Makefile</buildCommand>
<cleanCommand>${MAKE} -f Makefile clean</cleanCommand>
<executablePath></executablePath>
</makeTool>
<preBuild>
- <preBuildCommandWorkingDir>Build</preBuildCommandWorkingDir>
+ <preBuildCommandWorkingDir>build</preBuildCommandWorkingDir>
<preBuildCommand>cmake -Wno-dev -DCXX=g++-5 -DCC=gcc-5 ..</preBuildCommand>
<preBuildFirst>true</preBuildFirst>
</preBuild>
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 @@
<data xmlns="http://www.netbeans.org/ns/make-project/1">
<name>AGL-AudioBindings</name>
<c-extensions>c</c-extensions>
- <cpp-extensions>cpp,cxx</cpp-extensions>
+ <cpp-extensions>cpp</cpp-extensions>
<header-extensions>h</header-extensions>
<sourceEncoding>UTF-8</sourceEncoding>
<make-dep-projects/>