diff --git a/androidaudioplugin/src/main/cpp/core/aapxs/parameters-aapxs.cpp b/androidaudioplugin/src/main/cpp/core/aapxs/parameters-aapxs.cpp index cdab6517..833a608f 100644 --- a/androidaudioplugin/src/main/cpp/core/aapxs/parameters-aapxs.cpp +++ b/androidaudioplugin/src/main/cpp/core/aapxs/parameters-aapxs.cpp @@ -117,6 +117,62 @@ aap::xs::ParametersClientAAPXS::getEnumeration(int32_t index, int32_t enumIndex) OPCODE_PARAMETERS_GET_PARAMETER_COUNT); } +void aap::xs::ParametersClientAAPXS::completeWithParameterCallback (void* callbackData, void* pluginOrHost, int32_t requestId) { + auto cb = (CallbackData*) callbackData; + auto thiz = (ParametersClientAAPXS *) cb->context; + auto result = thiz->getTypedResult(thiz->serialization); + ((aapxs_async_get_parameter_callback) cb->callback) (thiz, pluginOrHost, requestId, cb->index, result); + cb->context = nullptr; +} + +void aap::xs::ParametersClientAAPXS::completeWithEnumCallback (void* callbackData, void* pluginOrHost, int32_t requestId) { + auto cb = (CallbackData*) callbackData; + auto thiz = (ParametersClientAAPXS *) cb->context; + auto result = getTypedResult(thiz->serialization); + ((aapxs_async_get_enumeration_callback) cb->callback) (thiz, pluginOrHost, requestId, cb->index, cb->enum_index, result); + cb->context = nullptr; +} + + +int32_t +aap::xs::ParametersClientAAPXS::getParameterAsync(int32_t index, + aapxs_async_get_parameter_callback* callback) { + *((int32_t*) serialization->data) = index; + + uint32_t requestId = aapxs_instance->get_new_request_id(aapxs_instance); + CallbackData *callbackData = nullptr; + for (size_t i = 0; i < UINT8_MAX; i++) + if (pending_calls[i].context == nullptr) + callbackData = pending_calls + i; + assert(callbackData); + *callbackData = {this, callback, index, 0}; + AAPXSRequestContext request{completeWithParameterCallback, callbackData, serialization, + 0, AAP_PARAMETERS_EXTENSION_URI, requestId, OPCODE_PARAMETERS_GET_PARAMETER}; + + aapxs_instance->send_aapxs_request(aapxs_instance, &request); + + return requestId; +} + +int32_t aap::xs::ParametersClientAAPXS::getEnumerationAsync(int32_t index, int32_t enumIndex, + aapxs_async_get_enumeration_callback* callback) { + *((int32_t*) serialization->data) = index; + + uint32_t requestId = aapxs_instance->get_new_request_id(aapxs_instance); + CallbackData *callbackData = nullptr; + for (size_t i = 0; i < UINT8_MAX; i++) + if (pending_calls[i].context == nullptr) + callbackData = pending_calls + i; + assert(callbackData); + *callbackData = {this, callback, index, enumIndex}; + AAPXSRequestContext request{completeWithEnumCallback, callbackData, serialization, + 0, AAP_PARAMETERS_EXTENSION_URI, requestId, OPCODE_PARAMETERS_GET_ENUMERATION}; + + aapxs_instance->send_aapxs_request(aapxs_instance, &request); + + return requestId; +} + void aap::xs::ParametersServiceAAPXS::notifyParametersChanged() { callVoidFunctionSynchronously(OPCODE_NOTIFY_PARAMETERS_CHANGED); } diff --git a/include/aap/core/aapxs/parameters-aapxs.h b/include/aap/core/aapxs/parameters-aapxs.h index ce449165..29bd9a5b 100644 --- a/include/aap/core/aapxs/parameters-aapxs.h +++ b/include/aap/core/aapxs/parameters-aapxs.h @@ -59,9 +59,24 @@ namespace aap::xs { }; class ParametersClientAAPXS : public TypedAAPXS { + typedef void (*aapxs_async_get_parameter_callback) (aap::xs::ParametersClientAAPXS*, void * pluginOrHost, int32_t requestId, int32_t index, aap_parameter_info_t result); + typedef void (*aapxs_async_get_enumeration_callback) (aap::xs::ParametersClientAAPXS*, void * pluginOrHost, int32_t requestId, int32_t index, int32_t enumIndex, aap_parameter_enum_t result); + + struct CallbackData { + void* context{nullptr}; + void* callback{nullptr}; + int32_t index{0}; + int32_t enum_index{0}; + }; + + CallbackData pending_calls[UINT8_MAX]; + static void completeWithParameterCallback(void *callbackData, void *pluginOrHost, int32_t requestId); + static void completeWithEnumCallback(void *callbackData, void *pluginOrHost, int32_t requestId); + public: ParametersClientAAPXS(AAPXSInitiatorInstance* initiatorInstance, AAPXSSerializationContext* serialization) : TypedAAPXS(AAP_PARAMETERS_EXTENSION_URI, initiatorInstance, serialization) { + memset(pending_calls, 0, sizeof(CallbackData) * UINT8_MAX); } int32_t getParameterCount(); @@ -69,6 +84,11 @@ namespace aap::xs { double getProperty(int32_t index, int32_t propertyId); int32_t getEnumerationCount(int32_t index); aap_parameter_enum_t getEnumeration(int32_t index, int32_t enumIndex); + + // returns request ID + int32_t getParameterAsync(int32_t index, aapxs_async_get_parameter_callback* callback); + // returns request ID + int32_t getEnumerationAsync(int32_t index, int32_t enumIndex, aapxs_async_get_enumeration_callback* callback); }; class ParametersServiceAAPXS : public TypedAAPXS { @@ -82,9 +102,9 @@ namespace aap::xs { static void staticNotifyParametersChanged(aap_parameters_host_extension_t* ext, AndroidAudioPluginHost* host) { ((ParametersServiceAAPXS*) ext->aapxs_context)->notifyParametersChanged(); } - aap_parameters_host_extension_t as_host_extension{this, staticNotifyParametersChanged}; + aap_parameters_host_extension_t host_extension{this, staticNotifyParametersChanged}; - aap_parameters_host_extension_t* asHostExtension() { return &as_host_extension; } + aap_parameters_host_extension_t* asHostExtension() { return &host_extension; } }; }