mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:18:11 +00:00
AudioServer: Port to the new generated IPC mechanism
Fork the IPC Connection classes into Server:: and Client::ConnectionNG. The new IPC messages are serialized very snugly instead of using the same generic data structure for all messages. Remove ASAPI.h since we now generate all of it from AudioServer.ipc :^)
This commit is contained in:
parent
3519b6c201
commit
8e684f0959
14 changed files with 327 additions and 329 deletions
|
@ -2,7 +2,6 @@
|
|||
#include "ASMixer.h"
|
||||
|
||||
#include <LibAudio/ABuffer.h>
|
||||
#include <LibAudio/ASAPI.h>
|
||||
#include <LibCore/CEventLoop.h>
|
||||
#include <SharedBuffer.h>
|
||||
|
||||
|
@ -14,7 +13,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
ASClientConnection::ASClientConnection(CLocalSocket& client_socket, int client_id, ASMixer& mixer)
|
||||
: Connection(client_socket, client_id)
|
||||
: ConnectionNG(*this, client_socket, client_id)
|
||||
, m_mixer(mixer)
|
||||
{
|
||||
}
|
||||
|
@ -23,58 +22,44 @@ ASClientConnection::~ASClientConnection()
|
|||
{
|
||||
}
|
||||
|
||||
void ASClientConnection::send_greeting()
|
||||
{
|
||||
post_message(ASAPI_Server::Greeting(getpid(), client_id()));
|
||||
}
|
||||
|
||||
bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, const ByteBuffer&&)
|
||||
{
|
||||
switch (message.type) {
|
||||
case ASAPI_ClientMessage::Type::Greeting:
|
||||
set_client_pid(message.greeting.client_pid);
|
||||
break;
|
||||
case ASAPI_ClientMessage::Type::EnqueueBuffer: {
|
||||
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.play_buffer.buffer_id);
|
||||
if (!shared_buffer) {
|
||||
did_misbehave();
|
||||
return false;
|
||||
}
|
||||
|
||||
ASAPI_ServerMessage reply;
|
||||
reply.type = ASAPI_ServerMessage::Type::EnqueueBufferResponse;
|
||||
reply.playing_buffer.buffer_id = message.play_buffer.buffer_id;
|
||||
|
||||
if (!m_queue)
|
||||
m_queue = m_mixer.create_queue(*this);
|
||||
|
||||
if (m_queue->is_full()) {
|
||||
post_message(ASAPI_Server::EnqueueBufferResponse(false, message.play_buffer.buffer_id));
|
||||
break;
|
||||
}
|
||||
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: {
|
||||
post_message(ASAPI_Server::DidGetMainMixVolume(m_mixer.main_volume()));
|
||||
break;
|
||||
}
|
||||
case ASAPI_ClientMessage::Type::SetMainMixVolume: {
|
||||
m_mixer.set_main_volume(message.value);
|
||||
post_message(ASAPI_Server::DidSetMainMixVolume());
|
||||
break;
|
||||
}
|
||||
case ASAPI_ClientMessage::Type::Invalid:
|
||||
default:
|
||||
dbgprintf("ASClientConnection: Unexpected message ID %d\n", int(message.type));
|
||||
did_misbehave();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ASClientConnection::did_finish_playing_buffer(Badge<ASMixer>, int buffer_id)
|
||||
{
|
||||
post_message(ASAPI_Server::FinishedPlayingBuffer(buffer_id));
|
||||
(void)buffer_id;
|
||||
//post_message(AudioClient::FinishedPlayingBuffer(buffer_id));
|
||||
}
|
||||
|
||||
OwnPtr<AudioServer::GreetResponse> ASClientConnection::handle(const AudioServer::Greet& message)
|
||||
{
|
||||
set_client_pid(message.client_pid());
|
||||
return make<AudioServer::GreetResponse>(getpid(), client_id());
|
||||
}
|
||||
|
||||
OwnPtr<AudioServer::GetMainMixVolumeResponse> ASClientConnection::handle(const AudioServer::GetMainMixVolume&)
|
||||
{
|
||||
return make<AudioServer::GetMainMixVolumeResponse>(m_mixer.main_volume());
|
||||
}
|
||||
|
||||
OwnPtr<AudioServer::SetMainMixVolumeResponse> ASClientConnection::handle(const AudioServer::SetMainMixVolume& message)
|
||||
{
|
||||
m_mixer.set_main_volume(message.volume());
|
||||
return make<AudioServer::SetMainMixVolumeResponse>();
|
||||
}
|
||||
|
||||
OwnPtr<AudioServer::EnqueueBufferResponse> ASClientConnection::handle(const AudioServer::EnqueueBuffer& message)
|
||||
{
|
||||
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.buffer_id());
|
||||
if (!shared_buffer) {
|
||||
// FIXME: The shared buffer should have been retrieved for us already.
|
||||
// We don't want to do IPC error checking at this layer.
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (!m_queue)
|
||||
m_queue = m_mixer.create_queue(*this);
|
||||
|
||||
if (m_queue->is_full())
|
||||
return make<AudioServer::EnqueueBufferResponse>(false);
|
||||
|
||||
m_queue->enqueue(ABuffer::create_with_shared_buffer(*shared_buffer));
|
||||
return make<AudioServer::EnqueueBufferResponse>(true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue