1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

LibIPC+AudioServer: Allow unsolicited server-to-client IPC messages

Client-side connection objects must now provide both client and server
endpoint types. When a message is received from the server side, we try
to decode it using both endpoint types and then send it to the right
place for handling.

This now makes it possible for AudioServer to send unsolicited messages
to its clients. This opens up a ton of possibilities :^)
This commit is contained in:
Andreas Kling 2019-11-23 16:43:21 +01:00
parent 06ee24263c
commit 630d5b3ffd
13 changed files with 95 additions and 42 deletions

View file

@ -1,10 +1,9 @@
#include "ASClientConnection.h"
#include "ASMixer.h"
#include "AudioClientEndpoint.h"
#include <LibAudio/ABuffer.h>
#include <LibCore/CEventLoop.h>
#include <SharedBuffer.h>
#include <errno.h>
#include <stdio.h>
#include <sys/socket.h>
@ -30,10 +29,9 @@ void ASClientConnection::die()
s_connections.remove(client_id());
}
void ASClientConnection::did_finish_playing_buffer(Badge<ASMixer>, int buffer_id)
void ASClientConnection::did_finish_playing_buffer(Badge<ASBufferQueue>, int buffer_id)
{
(void)buffer_id;
//post_message(AudioClient::FinishedPlayingBuffer(buffer_id));
post_message(AudioClient::FinishedPlayingBuffer(buffer_id));
}
OwnPtr<AudioServer::GreetResponse> ASClientConnection::handle(const AudioServer::Greet& message)

View file

@ -13,7 +13,7 @@ class ASClientConnection final : public IPC::Server::ConnectionNG<AudioServerEnd
public:
explicit ASClientConnection(CLocalSocket&, int client_id, ASMixer& mixer);
~ASClientConnection() override;
void did_finish_playing_buffer(Badge<ASMixer>, int buffer_id);
void did_finish_playing_buffer(Badge<ASBufferQueue>, int buffer_id);
virtual void die() override;

View file

@ -1,5 +1,6 @@
#pragma once
#include "ASClientConnection.h"
#include <AK/ByteBuffer.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/Queue.h>
@ -36,6 +37,7 @@ public:
++m_played_samples;
if (m_position >= m_current->sample_count()) {
m_client->did_finish_playing_buffer({}, m_current->shared_buffer_id());
m_current = nullptr;
m_position = 0;
}
@ -61,8 +63,10 @@ public:
int get_remaining_samples() const { return m_remaining_samples; }
int get_played_samples() const { return m_played_samples; }
int get_playing_buffer() const {
if(m_current) return m_current->shared_buffer_id();
int get_playing_buffer() const
{
if (m_current)
return m_current->shared_buffer_id();
return -1;
}

View file

@ -1,4 +1,4 @@
endpoint AudioClient
endpoint AudioClient = 82
{
FinishedPlayingBuffer(i32 buffer_id) =|
}

View file

@ -1,4 +1,4 @@
endpoint AudioServer
endpoint AudioServer = 85
{
// Basic protocol
Greet(i32 client_pid) => (i32 server_pid, i32 client_id)

View file

@ -13,11 +13,14 @@ DEFINES += -DUSERLAND
all: $(APP)
*.cpp: AudioServerEndpoint.h
*.cpp: AudioServerEndpoint.h AudioClientEndpoint.h
AudioServerEndpoint.h: AudioServer.ipc
@echo "IPC $<"; $(IPCCOMPILER) $< > $@
AudioClientEndpoint.h: AudioClient.ipc
@echo "IPC $<"; $(IPCCOMPILER) $< > $@
$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lc -lcore -lipc -lthread -lpthread
@ -27,5 +30,5 @@ $(APP): $(OBJS)
-include $(OBJS:%.o=%.d)
clean:
@echo "CLEAN"; rm -f $(APP) $(OBJS) *.d AudioServerEndpoint.h
@echo "CLEAN"; rm -f $(APP) $(OBJS) *.d AudioServerEndpoint.h AudioClientEndpoint.h