diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-03 19:41:02 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-03 19:49:19 +0200 |
commit | 8e684f095982597d548514ccd7f723f6f285b1f5 (patch) | |
tree | fb8d83acebd948580467af03bbb0f6b9d51c3462 /Servers | |
parent | 3519b6c201e53b703ced179b18d8570e93845d2d (diff) | |
download | serenity-8e684f095982597d548514ccd7f723f6f285b1f5.zip |
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 :^)
Diffstat (limited to 'Servers')
-rw-r--r-- | Servers/AudioServer/ASClientConnection.cpp | 77 | ||||
-rw-r--r-- | Servers/AudioServer/ASClientConnection.h | 13 | ||||
-rw-r--r-- | Servers/AudioServer/ASEventLoop.cpp | 2 | ||||
-rw-r--r-- | Servers/AudioServer/Makefile | 7 |
4 files changed, 46 insertions, 53 deletions
diff --git a/Servers/AudioServer/ASClientConnection.cpp b/Servers/AudioServer/ASClientConnection.cpp index bebf2c3927..968838a67e 100644 --- a/Servers/AudioServer/ASClientConnection.cpp +++ b/Servers/AudioServer/ASClientConnection.cpp @@ -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() +void ASClientConnection::did_finish_playing_buffer(Badge<ASMixer>, int buffer_id) { - post_message(ASAPI_Server::Greeting(getpid(), client_id())); + (void)buffer_id; + //post_message(AudioClient::FinishedPlayingBuffer(buffer_id)); } -bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, const ByteBuffer&&) +OwnPtr<AudioServer::GreetResponse> ASClientConnection::handle(const AudioServer::Greet& message) { - 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; - } + set_client_pid(message.client_pid()); + return make<AudioServer::GreetResponse>(getpid(), client_id()); +} - ASAPI_ServerMessage reply; - reply.type = ASAPI_ServerMessage::Type::EnqueueBufferResponse; - reply.playing_buffer.buffer_id = message.play_buffer.buffer_id; +OwnPtr<AudioServer::GetMainMixVolumeResponse> ASClientConnection::handle(const AudioServer::GetMainMixVolume&) +{ + return make<AudioServer::GetMainMixVolumeResponse>(m_mixer.main_volume()); +} - if (!m_queue) - m_queue = m_mixer.create_queue(*this); +OwnPtr<AudioServer::SetMainMixVolumeResponse> ASClientConnection::handle(const AudioServer::SetMainMixVolume& message) +{ + m_mixer.set_main_volume(message.volume()); + return make<AudioServer::SetMainMixVolumeResponse>(); +} - 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(); +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(); } - return true; -} + if (!m_queue) + m_queue = m_mixer.create_queue(*this); -void ASClientConnection::did_finish_playing_buffer(Badge<ASMixer>, int buffer_id) -{ - post_message(ASAPI_Server::FinishedPlayingBuffer(buffer_id)); + 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); } diff --git a/Servers/AudioServer/ASClientConnection.h b/Servers/AudioServer/ASClientConnection.h index 5747bdc841..583fa2f312 100644 --- a/Servers/AudioServer/ASClientConnection.h +++ b/Servers/AudioServer/ASClientConnection.h @@ -1,23 +1,26 @@ #pragma once -#include <LibAudio/ASAPI.h> +#include <AudioServer/AudioServerEndpoint.h> #include <LibCore/CoreIPCServer.h> class ABuffer; class ASBufferQueue; class ASMixer; -class ASClientConnection final : public IPC::Server::Connection<ASAPI_ServerMessage, ASAPI_ClientMessage> { +class ASClientConnection final : public IPC::Server::ConnectionNG<AudioServerEndpoint> + , public AudioServerEndpoint { C_OBJECT(ASClientConnection) public: explicit ASClientConnection(CLocalSocket&, int client_id, ASMixer& mixer); ~ASClientConnection() override; - void send_greeting() override; - bool handle_message(const ASAPI_ClientMessage&, const ByteBuffer&& = {}) override; - void did_finish_playing_buffer(Badge<ASMixer>, int buffer_id); private: + virtual OwnPtr<AudioServer::GreetResponse> handle(const AudioServer::Greet&) override; + virtual OwnPtr<AudioServer::GetMainMixVolumeResponse> handle(const AudioServer::GetMainMixVolume&) override; + virtual OwnPtr<AudioServer::SetMainMixVolumeResponse> handle(const AudioServer::SetMainMixVolume&) override; + virtual OwnPtr<AudioServer::EnqueueBufferResponse> handle(const AudioServer::EnqueueBuffer&) override; + ASMixer& m_mixer; RefPtr<ASBufferQueue> m_queue; }; diff --git a/Servers/AudioServer/ASEventLoop.cpp b/Servers/AudioServer/ASEventLoop.cpp index 46b0fb12f0..876e8e9379 100644 --- a/Servers/AudioServer/ASEventLoop.cpp +++ b/Servers/AudioServer/ASEventLoop.cpp @@ -16,6 +16,6 @@ ASEventLoop::ASEventLoop() } static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::Server::new_connection_for_client<ASClientConnection>(*client_socket, client_id, m_mixer); + IPC::Server::new_connection_ng_for_client<ASClientConnection>(*client_socket, client_id, m_mixer); }; } diff --git a/Servers/AudioServer/Makefile b/Servers/AudioServer/Makefile index 07cbcb5fbd..59a66fa302 100644 --- a/Servers/AudioServer/Makefile +++ b/Servers/AudioServer/Makefile @@ -13,6 +13,11 @@ DEFINES += -DUSERLAND all: $(APP) +main.cpp: AudioServerEndpoint.h + +AudioServerEndpoint.h: AudioServer.ipc + @echo "IPC $<"; $(IPCCOMPILER) $< > $@ + $(APP): $(OBJS) $(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lc -lcore -lipc @@ -22,5 +27,5 @@ $(APP): $(OBJS) -include $(OBJS:%.o=%.d) clean: - @echo "CLEAN"; rm -f $(APP) $(OBJS) *.d + @echo "CLEAN"; rm -f $(APP) $(OBJS) *.d AudioServerEndpoint.h |