summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-06 15:06:55 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-06 15:06:55 +0200
commit66623af9225cb98e2c2491ad8608eb814513ae10 (patch)
tree21318704ec09dc39c21633d31635b8d6978d5d83 /lib
parentb7dec82b85e887716ca26839705ec1f291d3fedf (diff)
Add func to generate 'hal-dependencies' info json
Add functions to generate 'hal-dependencies' information json. Provide two type of json generation ('compact' with only extended card number info, and 'full' with all ALSA card info). Provide function to get information about all 'hal-dependencies' and another function to get information about validated 'hal-dependencies'. BUG-AGL: SPEC-2329 Change-Id: If04cbbab7c79a066d2d03fa5ff16ea698de9b018 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'lib')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.c355
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.h41
2 files changed, 389 insertions, 7 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index b1401a9..845ea59 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -48,6 +48,28 @@ enum ProbedDeviceClasses HalUtlGetProbedDeviceClassFromString(char *probedDevice
return INVALID_PROBED_DEVICE;
}
+char *HalUtlGetProbedDeviceClassString(enum ProbedDeviceClasses deviceClass)
+{
+ switch(deviceClass) {
+ case STATIC_PROBED_DEVICE:
+ return "static";
+
+ case DYNAMIC_PROBED_DEVICE:
+ return "dynamic";
+
+ case MANDATORY_PROBED_DEVICE:
+ return "mandatory";
+
+ case INVALID_PROBED_DEVICE:
+ return "invalid";
+
+ default:
+ return "unknown";
+ }
+
+ return NULL;
+}
+
struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct InternalHalProbedDevice **probedDevicesList)
{
struct InternalHalProbedDevice *currentProbedDevice;
@@ -222,6 +244,339 @@ struct InternalHalDeviceData *HalUtlAllocateAndFillProbedDeviceDataUsingInfoGetR
return currentProbedDeviceData;
}
+json_object *HalUtlGetCompactJsonForSpecificDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice *requestedProbedDevice)
+{
+ int wrapRet;
+
+ char *cardNb;
+
+ json_object *requestedProbedDeviceJ;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle is not valid");
+ return NULL;
+ }
+
+ if(! requestedProbedDevice) {
+ AFB_API_ERROR(apiHandle, "Requested dependency is not valid");
+ return NULL;
+ }
+
+ if(! requestedProbedDevice->deviceData ||
+ requestedProbedDevice->deviceData->cardNb == HAL_UNKNOWN_DEVICE)
+ cardNb = NULL;
+ else
+ cardNb = requestedProbedDevice->deviceData->extendedCardNb;
+
+ wrapRet = wrap_json_pack(&requestedProbedDeviceJ,
+ "{s:s s:s}",
+ "uid", requestedProbedDevice->uid,
+ "cardNb", cardNb ? cardNb : "none");
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate (uid: '%s') dependency compact json object",
+ requestedProbedDevice->uid);
+ return NULL;
+ }
+
+ return requestedProbedDeviceJ;
+}
+
+json_object *HalUtlGetFullJsonForSpecificDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice *requestedProbedDevice)
+{
+ int wrapRet;
+
+ json_object *requestedProbedDeviceJ, *additionalInfoJ;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle is not valid");
+ return NULL;
+ }
+
+ if(! requestedProbedDevice) {
+ AFB_API_ERROR(apiHandle, "Requested dependency is not valid");
+ return NULL;
+ }
+
+ wrapRet = wrap_json_pack(&requestedProbedDeviceJ,
+ "{s:s s:s s:b}",
+ "uid", requestedProbedDevice->uid,
+ "class", HalUtlGetProbedDeviceClassString(requestedProbedDevice->deviceClass),
+ "available", requestedProbedDevice->deviceData ? 1 : 0);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate first part of requested (uid: '%s') dependency full json object",
+ requestedProbedDevice->uid);
+ return NULL;
+ }
+
+ if(! requestedProbedDevice->deviceData ||
+ requestedProbedDevice->deviceData->cardNb == HAL_UNKNOWN_DEVICE)
+ return requestedProbedDeviceJ;
+
+ wrapRet = wrap_json_pack(&additionalInfoJ,
+ "{s:i s:s s:s s:s s:s s:s s:s s:s}",
+ "cardNb", requestedProbedDevice->deviceData->cardNb,
+ "cardId", requestedProbedDevice->deviceData->cardId,
+ "cardShortName", requestedProbedDevice->deviceData->cardShortName,
+ "cardLongName", requestedProbedDevice->deviceData->cardLongName,
+ "cardDriver", requestedProbedDevice->deviceData->cardDriver,
+ "cardMixerName", requestedProbedDevice->deviceData->cardMixerName,
+ "cardComponents", requestedProbedDevice->deviceData->cardComponents,
+ "extendedCardNb", requestedProbedDevice->deviceData->extendedCardNb);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate second part of requested (uid: '%s') dependency full json object",
+ requestedProbedDevice->uid);
+ json_object_put(requestedProbedDeviceJ);
+ return NULL;
+ }
+
+ wrap_json_object_add(requestedProbedDeviceJ, additionalInfoJ);
+
+ if(requestedProbedDevice->deviceData->playbackDeviceNb == HAL_UNKNOWN_DEVICE)
+ return requestedProbedDeviceJ;
+
+ wrapRet = wrap_json_pack(&additionalInfoJ,
+ "{s:i s:s s:s}",
+ "playbackDeviceNb", requestedProbedDevice->deviceData->playbackDeviceNb,
+ "playbackDeviceId", requestedProbedDevice->deviceData->playbackDeviceId,
+ "playbackDeviceName", requestedProbedDevice->deviceData->playbackDeviceName);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate third part of requested (uid: '%s') dependency full json object",
+ requestedProbedDevice->uid);
+ json_object_put(requestedProbedDeviceJ);
+ return NULL;
+ }
+
+ wrap_json_object_add(requestedProbedDeviceJ, additionalInfoJ);
+
+ return requestedProbedDeviceJ;
+}
+
+json_object *HalUtlGetJsonForSpecificDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice *requestedProbedDevice,
+ enum DependencyInfoJsonFormat jsonFormat)
+{
+ json_object *requestedProbedDeviceJ;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle is not valid");
+ return NULL;
+ }
+
+ if(! requestedProbedDevice) {
+ AFB_API_ERROR(apiHandle, "Requested dependency is not valid");
+ return NULL;
+ }
+
+ switch(jsonFormat) {
+ case DEPENDENCY_COMPACT_JSON:
+ requestedProbedDeviceJ = HalUtlGetCompactJsonForSpecificDependencies(apiHandle,requestedProbedDevice);
+ if(! requestedProbedDeviceJ) {
+ AFB_API_ERROR(apiHandle,
+ "An error happened when generating compact json for selected dependency (uid: '%s')",
+ requestedProbedDevice->uid);
+ return NULL;
+ }
+ return requestedProbedDeviceJ;
+
+ case DEPENDENCY_FULL_JSON:
+ requestedProbedDeviceJ = HalUtlGetFullJsonForSpecificDependencies(apiHandle,requestedProbedDevice);
+ if(! requestedProbedDeviceJ) {
+ AFB_API_ERROR(apiHandle,
+ "An error happened when generating full json for selected dependency (uid: '%s')",
+ requestedProbedDevice->uid);
+ return NULL;
+ }
+ return requestedProbedDeviceJ;
+
+ default:
+ AFB_API_ERROR(apiHandle, "Unrecognized requested json format");
+ return NULL;
+ }
+}
+
+json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
+ struct InternalHalProbedDevice **probedDevicesList,
+ char *uid,
+ enum DependencyInfoJsonFormat jsonFormat)
+{
+ json_object *requestedProbedDeviceJ;
+
+ struct InternalHalProbedDevice *requestedProbedDevice;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle is not valid");
+ return NULL;
+ }
+
+ if(! probedDevicesList || ! *probedDevicesList) {
+ AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ return NULL;
+ }
+
+ if(! uid) {
+ AFB_API_ERROR(apiHandle, "Requested dependency uid is not valid");
+ return NULL;
+ }
+
+ requestedProbedDevice = HalUtlSearchProbedDeviceDataById(probedDevicesList, uid);
+ if(! requestedProbedDevice) {
+ AFB_API_ERROR(apiHandle,
+ "Requested dependency uid ('%s) was not found in probed device list",
+ uid);
+ return NULL;
+ }
+
+ requestedProbedDeviceJ = HalUtlGetJsonForSpecificDependencies(apiHandle, requestedProbedDevice, jsonFormat);
+ if(! requestedProbedDeviceJ) {
+ AFB_API_ERROR(apiHandle,
+ "An error happened when generating json for selected dependency (uid: '%s')",
+ requestedProbedDevice->uid);
+ return NULL;
+ }
+
+ return requestedProbedDeviceJ;
+}
+
+int HalUtlIsDependencySelected(struct InternalHalProbedDevice *probedDevice, enum DependencyStatus requestedStatus)
+{
+ if(! probedDevice) {
+ return 0;
+ }
+
+ switch(requestedStatus) {
+ case UNAVAILABLE_DEPENDENCY:
+ if(! probedDevice->deviceData)
+ return 1;
+ else
+ return 0;
+
+ case AVAILABLE_DEPENDENCY:
+ if(probedDevice->deviceData)
+ return 1;
+ else
+ return 0;
+
+ case ALL_DEPENDENCY:
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+json_object *HalUtlGetJsonArrayForSelectedDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice **probedDevicesList,
+ enum DependencyInfoJsonFormat jsonFormat,
+ enum DependencyStatus requestedStatus)
+{
+ json_object *requestedProbedDeviceJ, *requestedDependenciesInfoJ;
+
+ struct InternalHalProbedDevice *currentProbedDevice;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle is not valid");
+ return NULL;
+ }
+
+ if(! probedDevicesList || ! *probedDevicesList) {
+ AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ return NULL;
+ }
+
+ requestedDependenciesInfoJ = json_object_new_array();
+ if(! requestedDependenciesInfoJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate probed devices (dependencies) json array");
+ return NULL;
+ }
+
+ currentProbedDevice = *probedDevicesList;
+ while(currentProbedDevice) {
+ requestedProbedDeviceJ = NULL;
+
+ if(HalUtlIsDependencySelected(currentProbedDevice, requestedStatus)) {
+ requestedProbedDeviceJ = HalUtlGetJsonForSpecificDependencies(apiHandle,
+ currentProbedDevice,
+ jsonFormat);
+ if(! requestedProbedDeviceJ) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to get json for probed devices (dependencies) with uid : '%s'",
+ currentProbedDevice->uid);
+ json_object_put(requestedDependenciesInfoJ);
+ return NULL;
+ }
+ }
+
+ if(requestedProbedDeviceJ)
+ json_object_array_add(requestedDependenciesInfoJ, requestedProbedDeviceJ);
+
+ currentProbedDevice = currentProbedDevice->next;
+ }
+
+ return requestedDependenciesInfoJ;
+}
+
+json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice **probedDevicesList,
+ enum DependencyInfoJsonFormat jsonFormat)
+{
+ json_object *requestedDependenciesInfoJ;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle is not valid");
+ return NULL;
+ }
+
+ if(! probedDevicesList || ! *probedDevicesList) {
+ AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ return NULL;
+ }
+
+ requestedDependenciesInfoJ = HalUtlGetJsonArrayForSelectedDependencies(apiHandle,
+ probedDevicesList,
+ jsonFormat,
+ AVAILABLE_DEPENDENCY);
+ if(! requestedDependenciesInfoJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed get available devices (dependencies) info");
+ return NULL;
+ }
+
+ return requestedDependenciesInfoJ;
+}
+
+json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice **probedDevicesList,
+ enum DependencyInfoJsonFormat jsonFormat)
+{
+ json_object *requestedDependenciesInfoJ;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle is not valid");
+ return NULL;
+ }
+
+ if(! probedDevicesList || ! *probedDevicesList) {
+ AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ return NULL;
+ }
+
+ requestedDependenciesInfoJ = HalUtlGetJsonArrayForSelectedDependencies(apiHandle,
+ probedDevicesList,
+ jsonFormat,
+ ALL_DEPENDENCY);
+ if(! requestedDependenciesInfoJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed get available devices (dependencies) info");
+ return NULL;
+ }
+
+ return requestedDependenciesInfoJ;
+}
+
/*******************************************************************************
* Internal Hal - Streams data handling functions *
******************************************************************************/
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.h b/lib/4a-hal-utilities/4a-hal-utilities-data.h
index 6d5cd2d..c051373 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.h
@@ -34,17 +34,30 @@
// Enum for hal status
enum HalStatus {
- HAL_STATUS_UNAVAILABLE=0,
- HAL_STATUS_AVAILABLE=1,
- HAL_STATUS_READY=2
+ HAL_STATUS_UNAVAILABLE = 0,
+ HAL_STATUS_AVAILABLE = 1,
+ HAL_STATUS_READY = 2
};
// Enum for probed devices (dependencies) class
enum ProbedDeviceClasses {
- INVALID_PROBED_DEVICE=0,
- STATIC_PROBED_DEVICE=1,
- DYNAMIC_PROBED_DEVICE=2,
- MANDATORY_PROBED_DEVICE=3
+ INVALID_PROBED_DEVICE = 0,
+ STATIC_PROBED_DEVICE = 1,
+ DYNAMIC_PROBED_DEVICE = 2,
+ MANDATORY_PROBED_DEVICE = 3
+};
+
+// Enum for probed devices (dependencies) info format requested
+enum DependencyInfoJsonFormat {
+ DEPENDENCY_COMPACT_JSON = 0,
+ DEPENDENCY_FULL_JSON = 1
+};
+
+// Enum for probed devices (dependencies) info format requested
+enum DependencyStatus {
+ UNAVAILABLE_DEPENDENCY = 0,
+ AVAILABLE_DEPENDENCY = 1,
+ ALL_DEPENDENCY = 2
};
// Structure to store data for audio devices validated by dependencies
@@ -132,6 +145,7 @@ struct HalMgrData {
// Internal Hal - Probed devices structure handling functions
enum ProbedDeviceClasses HalUtlGetProbedDeviceClassFromString(char *probedDeviceString);
+char *HalUtlGetProbedDeviceClassString(enum ProbedDeviceClasses deviceClass);
struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct InternalHalProbedDevice **probedDevicesList);
int HalUtlRemoveSelectedProbedDeviceFromList(struct InternalHalProbedDevice **probedDevicesList,
struct InternalHalProbedDevice *probedDeviceToRemove);
@@ -140,6 +154,19 @@ int HalUtlGetNumberOfProbedDevicesInList(struct InternalHalProbedDevice **probed
struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct InternalHalProbedDevice **probedDevicesList,
char *uid);
struct InternalHalDeviceData *HalUtlAllocateAndFillProbedDeviceDataUsingInfoGetResponse(json_object *responseJ);
+json_object *HalUtlGetJsonForSpecificDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice *requestedProbedDevice,
+ enum DependencyInfoJsonFormat jsonFormat);
+json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
+ struct InternalHalProbedDevice **probedDevicesList,
+ char *uid,
+ enum DependencyInfoJsonFormat jsonFormat);
+json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice **probedDevicesList,
+ enum DependencyInfoJsonFormat jsonFormat);
+json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
+ struct InternalHalProbedDevice **probedDevicesList,
+ enum DependencyInfoJsonFormat jsonFormat);
// Internal Hal - Streams data handling functions
struct InternalHalMixerData *HalUtlAddMixerDataToMixerDataList(struct InternalHalMixerData **mixerDataList);