Skip to content

Commit

Permalink
Add untested ParametersClientAAPXS async functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed Nov 6, 2023
1 parent 510ea61 commit 83f8b51
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
56 changes: 56 additions & 0 deletions androidaudioplugin/src/main/cpp/core/aapxs/parameters-aapxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<aap_parameter_info_t>(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<aap_parameter_enum_t>(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);
}
24 changes: 22 additions & 2 deletions include/aap/core/aapxs/parameters-aapxs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,36 @@ 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();
aap_parameter_info_t getParameter(int32_t index);
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 {
Expand All @@ -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; }
};
}

Expand Down

0 comments on commit 83f8b51

Please sign in to comment.