summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-29 22:28:47 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-29 22:39:20 +0200
commite6db1b81b80ef9d68e1ba4846a324b3544bcf49a (patch)
treefc835d251c3ba55d25ea0e55b71af82d5ae0994f /Servers
parenta175e76948679a241745302d4b10637eecd8f275 (diff)
downloadserenity-e6db1b81b80ef9d68e1ba4846a324b3544bcf49a.zip
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. :^)
Diffstat (limited to 'Servers')
-rw-r--r--Servers/AudioServer/ASClientConnection.cpp28
1 files changed, 8 insertions, 20 deletions
diff --git a/Servers/AudioServer/ASClientConnection.cpp b/Servers/AudioServer/ASClientConnection.cpp
index 94d30e00d2..bebf2c3927 100644
--- a/Servers/AudioServer/ASClientConnection.cpp
+++ b/Servers/AudioServer/ASClientConnection.cpp
@@ -25,11 +25,7 @@ ASClientConnection::~ASClientConnection()
void ASClientConnection::send_greeting()
{
- ASAPI_ServerMessage message;
- message.type = ASAPI_ServerMessage::Type::Greeting;
- message.greeting.server_pid = getpid();
- message.greeting.your_client_id = client_id();
- post_message(message);
+ post_message(ASAPI_Server::Greeting(getpid(), client_id()));
}
bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, const ByteBuffer&&)
@@ -53,25 +49,20 @@ bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, cons
m_queue = m_mixer.create_queue(*this);
if (m_queue->is_full()) {
- reply.success = false;
- } else {
- m_queue->enqueue(ABuffer::create_with_shared_buffer(*shared_buffer));
+ post_message(ASAPI_Server::EnqueueBufferResponse(false, message.play_buffer.buffer_id));
+ break;
}
- post_message(reply);
+ m_queue->enqueue(ABuffer::create_with_shared_buffer(*shared_buffer));
+ post_message(ASAPI_Server::EnqueueBufferResponse(true, message.play_buffer.buffer_id));
break;
}
case ASAPI_ClientMessage::Type::GetMainMixVolume: {
- ASAPI_ServerMessage reply;
- reply.type = ASAPI_ServerMessage::Type::DidGetMainMixVolume;
- reply.value = m_mixer.main_volume();
- post_message(reply);
+ post_message(ASAPI_Server::DidGetMainMixVolume(m_mixer.main_volume()));
break;
}
case ASAPI_ClientMessage::Type::SetMainMixVolume: {
- ASAPI_ServerMessage reply;
- reply.type = ASAPI_ServerMessage::Type::DidSetMainMixVolume;
m_mixer.set_main_volume(message.value);
- post_message(reply);
+ post_message(ASAPI_Server::DidSetMainMixVolume());
break;
}
case ASAPI_ClientMessage::Type::Invalid:
@@ -85,8 +76,5 @@ bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, cons
void ASClientConnection::did_finish_playing_buffer(Badge<ASMixer>, int buffer_id)
{
- ASAPI_ServerMessage reply;
- reply.type = ASAPI_ServerMessage::Type::FinishedPlayingBuffer;
- reply.playing_buffer.buffer_id = buffer_id;
- post_message(reply);
+ post_message(ASAPI_Server::FinishedPlayingBuffer(buffer_id));
}