aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-03-08 00:24:41 +0100
committerFulup Ar Foll <fulup@iot.bzh>2017-03-08 00:24:41 +0100
commit0964e7da8576b8761e8d3d16b50cc842406c7e67 (patch)
treeb8e3ba7cb0b46cee9a12e4d77f74f34b897d8b1e
parent49533399810630031541b25407cd88498a72f6c3 (diff)
Added High Level Logic Template
-rw-r--r--Alsa/core-binding/AlsaLibMapping.c4
-rw-r--r--Alsa/core-binding/README.md8
-rw-r--r--BusinessLogic/AudioLogicBinding.c78
-rw-r--r--BusinessLogic/AudioLogicMapping.c88
-rw-r--r--BusinessLogic/AudioLogicMapping.h50
-rw-r--r--BusinessLogic/CMakeLists.txt36
-rw-r--r--BusinessLogic/README.md18
-rw-r--r--CMakeLists.txt1
-rw-r--r--nbproject/project.xml2
9 files changed, 277 insertions, 8 deletions
diff --git a/Alsa/core-binding/AlsaLibMapping.c b/Alsa/core-binding/AlsaLibMapping.c
index 8d85f11..797f9ba 100644
--- a/Alsa/core-binding/AlsaLibMapping.c
+++ b/Alsa/core-binding/AlsaLibMapping.c
@@ -697,7 +697,7 @@ PUBLIC void alsaSubCtl (struct afb_req request) {
// create binder event attached to devid name
evtHandle->afbevt = afb_daemon_make_event (binderIface->daemon, devid);
- if (!evtHandle->afbevt.closure) {
+ if (!afb_event_is_valid (evtHandle->afbevt)) {
afb_req_fail_f (request, "register-event", "Cannot register new binder event name=%s", devid);
snd_ctl_close(ctlHandle);
goto ExitOnError;
@@ -710,7 +710,7 @@ 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 need WS", devid, err);
+ afb_req_fail_f (request, "register-eventname", "Cannot subscribe binder event name=%s [invalid channel]", devid, err);
goto ExitOnError;
}
diff --git a/Alsa/core-binding/README.md b/Alsa/core-binding/README.md
index 7f8c87a..4cce341 100644
--- a/Alsa/core-binding/README.md
+++ b/Alsa/core-binding/README.md
@@ -2,9 +2,9 @@
AlsaCore Low level binding maps AlsaLib APIs
------------------------------------------------------------------------
-Testing: (from Build dir with Binder install in $HOME/opt=
- * start binder: ~/opt/bin/afb-daemon --ldpaths=./Alsa/src/low-level-binding
- * connect browser on http://localhost:1234/api/alsacore/????
+Testing: (from project directory bindings)
+ * start binder: ~/opt/bin/afb-daemon --ldpaths=./Alsa/src/low-level-binding:./BusinessLogic/audiologic-afb.so --roothttp=htdocs
+ * connect browser on http://localhost:1234
# List Avaliable Sound cards
http://localhost:1234/api/alsacore/getinfo
@@ -18,5 +18,3 @@ 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 (warning fail if not WS)
- http://localhost:1234/api/alsacore/subctl?devid=hw:0 \ No newline at end of file
diff --git a/BusinessLogic/AudioLogicBinding.c b/BusinessLogic/AudioLogicBinding.c
new file mode 100644
index 0000000..4d7dc35
--- /dev/null
+++ b/BusinessLogic/AudioLogicBinding.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <math.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+#define _GNU_SOURCE // needed for vasprintf
+#include "AudioLogicMapping.h"
+
+PUBLIC const struct afb_binding_interface *binderIface;
+
+static void localping(struct afb_req request) {
+ json_object *query = afb_req_json(request);
+ afb_req_success(request, query, NULL);
+}
+
+/*
+ * array of the verbs exported to afb-daemon
+ */
+static const struct afb_verb_desc_v1 binding_verbs[] = {
+ /* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL SHORT DESCRIPTION */
+ { .name= "ping" , .session= AFB_SESSION_NONE, .callback= localping, .info= "Ping Binding" },
+ { .name= "setvolume", .session= AFB_SESSION_NONE, .callback= audioLogicSetVol, .info= "Set Volume" },
+ { .name= "getvolume", .session= AFB_SESSION_NONE, .callback= audioLogicGetVol, .info= "Get Volume" },
+ { .name= "subscribe", .session= AFB_SESSION_NONE, .callback= audioLogicSubscribe, .info= "Get Volume" },
+ { .name= NULL } /* marker for end of the array */
+};
+
+/*
+ * description of the binding for afb-daemon
+ */
+static const struct afb_binding binding_description = {
+ /* description conforms to VERSION 1 */
+ .type= AFB_BINDING_VERSION_1,
+ .v1= {
+ .prefix= "audio",
+ .info= "High Level Interface to Audio bindings",
+ .verbs = binding_verbs
+ }
+};
+
+extern int afbBindingV1ServiceInit(struct afb_service service) {
+ // this is call when after all bindings are loaded
+
+ return (audioLogicInit(service));
+};
+
+/*
+ * activation function for registering the binding called by afb-daemon
+ */
+const struct afb_binding *afbBindingV1Register(const struct afb_binding_interface *itf) {
+ binderIface= itf;
+
+ return &binding_description; /* returns the description of the binding */
+}
+
diff --git a/BusinessLogic/AudioLogicMapping.c b/BusinessLogic/AudioLogicMapping.c
new file mode 100644
index 0000000..8e0b773
--- /dev/null
+++ b/BusinessLogic/AudioLogicMapping.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <math.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+#include "AudioLogicMapping.h"
+static struct afb_service srvitf;
+
+#define _GNU_SOURCE // needed for vasprintf
+
+// this function is call after all binder are loaded and initialised
+PUBLIC int audioLogicInit (struct afb_service service) {
+ srvitf = service;
+ return 0;
+}
+
+STATIC void alsaSubcribeCB (void *handle, int iserror, struct json_object *result) {
+ struct afb_req request = afb_req_unstore(handle);
+ struct json_object *x, *resp = NULL;
+ const char *info = NULL;
+
+ if (result) {
+ fprintf (stdout, "result=[%s]\n", json_object_to_json_string (result));
+ if (json_object_object_get_ex(result, "request", &x) && json_object_object_get_ex(x, "info", &x))
+ info = json_object_get_string(x);
+ if (!json_object_object_get_ex(result, "response", &resp)) resp = NULL;
+ }
+
+ // push message respond
+ if (iserror) afb_req_fail_f(request, "Fail", info);
+ else afb_req_success(request, resp, info);
+
+ // free calling request
+ afb_req_unref(request);
+}
+
+
+PUBLIC void audioLogicSubscribe(struct afb_req request) {
+
+ // save request in session as it might be used after return by callback
+ struct afb_req *handle = afb_req_store(request);
+
+ // push request to low level binding
+ if (!handle) afb_req_fail(request, "error", "out of memory");
+ else afb_service_call(srvitf, "alsacore", "subctl", json_object_get(afb_req_json(request)), alsaSubcribeCB, handle);
+
+ // success/failure message will be position from callback
+}
+
+PUBLIC void audioLogicGetVol(struct afb_req request) {
+
+
+ afb_req_success (request, NULL, NULL);
+ return;
+
+}
+
+PUBLIC void audioLogicSetVol(struct afb_req request) {
+
+
+ afb_req_success (request, NULL, NULL);
+ return;
+
+}
+
diff --git a/BusinessLogic/AudioLogicMapping.h b/BusinessLogic/AudioLogicMapping.h
new file mode 100644
index 0000000..e1033f7
--- /dev/null
+++ b/BusinessLogic/AudioLogicMapping.h
@@ -0,0 +1,50 @@
+/*
+ * AlsaLibMapping -- provide low level interface with AUDIO lib (extracted from alsa-json-gateway code)
+ * Copyright (C) 2015,2016,2017, Fulup Ar Foll fulup@iot.bzh
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+// few coding convention
+typedef int BOOL;
+#ifndef PUBLIC
+ #define PUBLIC
+#endif
+#ifndef FALSE
+ #define FALSE 0
+#endif
+#ifndef TRUE
+ #define TRUE 1
+#endif
+#define STATIC static
+
+#ifndef AUDIOLIBMAPPING_H
+#define AUDIOLIBMAPPING_H
+
+#include <json-c/json.h>
+#include <afb/afb-binding.h>
+#include <afb/afb-service-itf.h>
+
+
+// import from AlsaAfbBinding
+extern const struct afb_binding_interface *binderIface;
+
+// import from AlsaAfbMapping
+PUBLIC void audioLogicSetVol (struct afb_req request);
+PUBLIC void audioLogicGetVol(struct afb_req request);
+PUBLIC void audioLogicSubscribe(struct afb_req request);
+PUBLIC int audioLogicInit (struct afb_service service);
+
+#endif /* AUDIOLIBMAPPING_H */
+
diff --git a/BusinessLogic/CMakeLists.txt b/BusinessLogic/CMakeLists.txt
new file mode 100644
index 0000000..7ae760b
--- /dev/null
+++ b/BusinessLogic/CMakeLists.txt
@@ -0,0 +1,36 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 IoT.bzh
+#
+# author: Fulup Ar Foll <fulup@iot.bzh>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###########################################################################
+
+
+INCLUDE_DIRECTORIES(${include_dirs})
+
+##################################################
+# AudioLogicBinding
+##################################################
+ADD_LIBRARY(audiologic-afb MODULE AudioLogicBinding.c AudioLogicMapping.c)
+
+SET_TARGET_PROPERTIES(audiologic-afb PROPERTIES
+ PREFIX ""
+ LINK_FLAGS "-Wl,--version-script=${CMAKE_SOURCE_DIR}/export.map"
+)
+
+TARGET_LINK_LIBRARIES(audiologic-afb ${link_libraries})
+INSTALL(TARGETS audiologic-afb
+ LIBRARY DESTINATION ${binding_install_dir})
+
+
diff --git a/BusinessLogic/README.md b/BusinessLogic/README.md
new file mode 100644
index 0000000..a07f752
--- /dev/null
+++ b/BusinessLogic/README.md
@@ -0,0 +1,18 @@
+------------------------------------------------------------------------
+ AudioLogic High Level APIs
+------------------------------------------------------------------------
+
+Testing: (from project directory bindings)
+ * start binder: ~/opt/bin/afb-daemon --ldpaths=./Alsa/src/low-level-binding:./BusinessLogic/audiologic-afb.so --roothttp=htdocs
+ * connect browser on http://localhost:1234
+
+ # Subscribe event for a given board
+ http://localhost:1234/api/audio/subscribe&devid=hw:0
+
+ # Increase Volume
+ http://localhost:1234/api/audio/setvol?devid=hw:0&pcm=master&vol=50%
+
+ # Get Volume
+ http://localhost:1234/api/audio/getvol?devid=hw:0&pcm=master
+
+ \ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d3167ad..a5fe3d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,3 +111,4 @@ SET(link_libraries
# Bindings to compile
# --------------------
add_subdirectory(Alsa)
+add_subdirectory(BusinessLogic)
diff --git a/nbproject/project.xml b/nbproject/project.xml
index 7ec3b29..be8b144 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</cpp-extensions>
+ <cpp-extensions>cpp,cxx</cpp-extensions>
<header-extensions>h</header-extensions>
<sourceEncoding>UTF-8</sourceEncoding>
<make-dep-projects/>