mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
AudioServer: Begin work on a new IPC API style.
The goal here is to generate most of this code from IPC protocol descriptions, but for now I've spelled them all out to get started. Each message gets a wrapper class in the ASAPI_Client or ASAPI_Server namespace. They are convertible to and from the old message structs. The real hotness happens when you want to make a synchronous request to the other side: auto response = send_sync<ASAPI_Client::GetMainMixVolume>(); Each request class knows his corresponding response class, so in the above example, "response" will be an ASAPI_Server::DidGetMainMixVolume object, and we can get the volume like so: int volume = response.volume(); For posting messages that don't expect a response, you can still use post_message() since the message classes are convertible: post_message(ASAPI_Server::DidGetMainMixVolume(volume)); It's not perfect yet, but I already really like it. :^)
This commit is contained in:
parent
a175e76948
commit
e6db1b81b8
4 changed files with 227 additions and 40 deletions
|
@ -9,23 +9,17 @@ AClientConnection::AClientConnection()
|
|||
|
||||
void AClientConnection::handshake()
|
||||
{
|
||||
ASAPI_ClientMessage request;
|
||||
request.type = ASAPI_ClientMessage::Type::Greeting;
|
||||
request.greeting.client_pid = getpid();
|
||||
auto response = sync_request(request, ASAPI_ServerMessage::Type::Greeting);
|
||||
set_server_pid(response.greeting.server_pid);
|
||||
set_my_client_id(response.greeting.your_client_id);
|
||||
auto response = send_sync<ASAPI_Client::Greeting>(getpid());
|
||||
set_server_pid(response.server_pid());
|
||||
set_my_client_id(response.your_client_id());
|
||||
}
|
||||
|
||||
void AClientConnection::enqueue(const ABuffer& buffer)
|
||||
{
|
||||
for (;;) {
|
||||
const_cast<ABuffer&>(buffer).shared_buffer().share_with(server_pid());
|
||||
ASAPI_ClientMessage request;
|
||||
request.type = ASAPI_ClientMessage::Type::EnqueueBuffer;
|
||||
request.play_buffer.buffer_id = buffer.shared_buffer_id();
|
||||
auto response = sync_request(request, ASAPI_ServerMessage::Type::EnqueueBufferResponse);
|
||||
if (response.success)
|
||||
auto response = send_sync<ASAPI_Client::EnqueueBuffer>(buffer.shared_buffer_id());
|
||||
if (response.success())
|
||||
break;
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -33,16 +27,10 @@ void AClientConnection::enqueue(const ABuffer& buffer)
|
|||
|
||||
int AClientConnection::get_main_mix_volume()
|
||||
{
|
||||
ASAPI_ClientMessage request;
|
||||
request.type = ASAPI_ClientMessage::Type::GetMainMixVolume;
|
||||
auto response = sync_request(request, ASAPI_ServerMessage::Type::DidGetMainMixVolume);
|
||||
return response.value;
|
||||
return send_sync<ASAPI_Client::GetMainMixVolume>().volume();
|
||||
}
|
||||
|
||||
void AClientConnection::set_main_mix_volume(int volume)
|
||||
{
|
||||
ASAPI_ClientMessage request;
|
||||
request.type = ASAPI_ClientMessage::Type::SetMainMixVolume;
|
||||
request.value = volume;
|
||||
sync_request(request, ASAPI_ServerMessage::Type::DidSetMainMixVolume);
|
||||
send_sync<ASAPI_Client::SetMainMixVolume>(volume);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue