aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);