summaryrefslogtreecommitdiffstats
path: root/Audio-Common
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-08-16 10:49:51 +0200
committerFulup Ar Foll <fulup@iot.bzh>2017-08-16 10:49:51 +0200
commit4ca8fd4015479fa758a789d137a693c30fec8cae (patch)
tree45cac25de622ded5802f69f71ce958d3633ab22a /Audio-Common
parent716d28f99637d6f2b8eb2758c2da41da67b8027c (diff)
Moved FileConfigScan to AudioCommon and Documentation
Diffstat (limited to 'Audio-Common')
-rw-r--r--Audio-Common/CMakeLists.txt2
-rw-r--r--Audio-Common/audio-common.h3
-rw-r--r--Audio-Common/filescan-utils.c121
-rw-r--r--Audio-Common/filescan-utils.h41
4 files changed, 166 insertions, 1 deletions
diff --git a/Audio-Common/CMakeLists.txt b/Audio-Common/CMakeLists.txt
index 7544fe6..bd3f344 100644
--- a/Audio-Common/CMakeLists.txt
+++ b/Audio-Common/CMakeLists.txt
@@ -20,7 +20,7 @@
PROJECT_TARGET_ADD(audio-common)
# Define targets
- ADD_LIBRARY(${TARGET_NAME} STATIC audio-common.c wrap-json.c)
+ ADD_LIBRARY(${TARGET_NAME} STATIC audio-common.c wrap-json.c filescan-utils)
# Library properties
SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
diff --git a/Audio-Common/audio-common.h b/Audio-Common/audio-common.h
index e7057d3..0a68eb3 100644
--- a/Audio-Common/audio-common.h
+++ b/Audio-Common/audio-common.h
@@ -25,6 +25,8 @@
#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include <json-c/json.h>
+#include "filescan-utils.h"
+#include "wrap-json.h"
// Waiting for official macro from José
#define AFB_GET_VERBOSITY afb_get_verbosity_v2()
@@ -34,6 +36,7 @@
#endif
#define STATIC static
+
// Soft control have dynamically allocated numid
#define CTL_AUTO -1
diff --git a/Audio-Common/filescan-utils.c b/Audio-Common/filescan-utils.c
new file mode 100644
index 0000000..9fa121b
--- /dev/null
+++ b/Audio-Common/filescan-utils.c
@@ -0,0 +1,121 @@
+/*
+ * 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 <time.h>
+#include <sys/prctl.h>
+#include <dirent.h>
+
+#include "audio-common.h"
+
+
+
+// List Avaliable Configuration Files
+PUBLIC json_object* ScanForConfig (char* searchPath, CtlScanDirModeT mode, char *pre, char *ext) {
+ json_object *responseJ;
+ char *dirPath;
+ char* dirList= strdup(searchPath);
+ size_t extLen=0;
+
+ void ScanDir (char *searchPath) {
+ DIR *dirHandle;
+ struct dirent *dirEnt;
+ dirHandle = opendir (searchPath);
+ if (!dirHandle) {
+ AFB_DEBUG ("CONFIG-SCANNING dir=%s not readable", searchPath);
+ return;
+ }
+
+ //AFB_NOTICE ("CONFIG-SCANNING:ctl_listconfig scanning: %s", searchPath);
+ while ((dirEnt = readdir(dirHandle)) != NULL) {
+
+ // recursively search embedded directories ignoring any directory starting by '.' or '_'
+ if (dirEnt->d_type == DT_DIR && mode == CTL_SCAN_RECURSIVE) {
+ char newpath[CONTROL_MAXPATH_LEN];
+ if (dirEnt->d_name[0]=='.' || dirEnt->d_name[0]=='_') continue;
+
+ strncpy(newpath, searchPath, sizeof(newpath));
+ strncat(newpath, "/", sizeof(newpath));
+ strncat(newpath, dirEnt->d_name, sizeof(newpath));
+ ScanDir(newpath);
+ continue;
+ }
+
+ // Unknown type is accepted to support dump filesystems
+ if (dirEnt->d_type == DT_REG || dirEnt->d_type == DT_UNKNOWN) {
+
+ // check prefix and extention
+ size_t extIdx=strlen(dirEnt->d_name)-extLen;
+ if (extIdx <= 0) continue;
+ if (pre && !strcasestr (dirEnt->d_name, pre)) continue;
+ if (ext && strcasecmp (ext, &dirEnt->d_name[extIdx])) continue;
+
+ struct json_object *pathJ = json_object_new_object();
+ json_object_object_add(pathJ, "fullpath", json_object_new_string(searchPath));
+ json_object_object_add(pathJ, "filename", json_object_new_string(dirEnt->d_name));
+ json_object_array_add(responseJ, pathJ);
+ }
+ }
+ closedir(dirHandle);
+ }
+
+ if (ext) extLen=strlen(ext);
+ responseJ = json_object_new_array();
+
+ // loop recursively on dir
+ for (dirPath= strtok(dirList, ":"); dirPath && *dirPath; dirPath=strtok(NULL,":")) {
+ ScanDir (dirPath);
+ }
+
+ free (dirList);
+ return (responseJ);
+}
+
+PUBLIC const char *GetMidleName(const char*name) {
+ char *fullname = strdup(name);
+
+ for (int idx = 0; fullname[idx] != '\0'; idx++) {
+ int start;
+ if (fullname[idx] == '-') {
+ start = idx + 1;
+ for (int jdx = start; fullname[jdx] != '\0'; jdx++) {
+ if (fullname[jdx] == '-') {
+ fullname[jdx] = '\0';
+ return &fullname[start];
+ break;
+ }
+ }
+ break;
+ }
+ }
+ return "";
+}
+
+PUBLIC const char *GetBinderName() {
+ char psName[17];
+ static char *binderName=NULL;
+
+ if (binderName) return binderName;
+
+ // retrieve binder name from process name afb-name-trailer
+ prctl(PR_GET_NAME, psName,NULL,NULL,NULL);
+ binderName=GetMidleName(psName);
+
+ return binderName;
+} \ No newline at end of file
diff --git a/Audio-Common/filescan-utils.h b/Audio-Common/filescan-utils.h
new file mode 100644
index 0000000..eba504e
--- /dev/null
+++ b/Audio-Common/filescan-utils.h
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ *
+ * reference:
+ * amixer contents; amixer controls;
+ * http://www.tldp.org/HOWTO/Alsa-sound-6.html
+ */
+
+#ifndef FILESCAN_UTILS_H
+#define FILESCAN_UTILS_H
+
+#ifndef PUBLIC
+ #define PUBLIC
+#endif
+#define STATIC static
+
+// ctl-misc.c
+typedef enum {
+ CTL_SCAN_FLAT=0,
+ CTL_SCAN_RECURSIVE=1,
+} CtlScanDirModeT;
+
+PUBLIC const char *GetMidleName(const char*name);
+PUBLIC const char *GetBinderName();
+PUBLIC json_object* ScanForConfig (char* searchPath, CtlScanDirModeT mode, char *pre, char *ext);
+
+#endif /* FILESCAN_UTILS_H */
+