mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
Introduce CIPCServerSideClient
As a new base class of IPC connections server-side. Port ASClientConnection to CIPCServerSideClient.
This commit is contained in:
parent
10ffaf019f
commit
edcbba9e98
4 changed files with 224 additions and 179 deletions
|
@ -1,84 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibCore/CObject.h>
|
||||
#include <LibCore/CEvent.h>
|
||||
#include <LibCore/CIODevice.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
|
||||
struct ASAPI_ServerMessage;
|
||||
struct ASAPI_ClientMessage;
|
||||
|
||||
class ASEvent : public CEvent {
|
||||
public:
|
||||
enum Type {
|
||||
Invalid = 2000,
|
||||
WM_ClientDisconnected,
|
||||
};
|
||||
ASEvent() {}
|
||||
explicit ASEvent(Type type)
|
||||
: CEvent(type)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ASClientDisconnectedNotification : public ASEvent {
|
||||
public:
|
||||
explicit ASClientDisconnectedNotification(int client_id)
|
||||
: ASEvent(WM_ClientDisconnected)
|
||||
, m_client_id(client_id)
|
||||
{
|
||||
}
|
||||
|
||||
int client_id() const { return m_client_id; }
|
||||
|
||||
private:
|
||||
int m_client_id { 0 };
|
||||
};
|
||||
#include <LibCore/CIPCServerSideClient.h>
|
||||
#include <LibAudio/ASAPI.h>
|
||||
|
||||
class ASMixer;
|
||||
|
||||
class ASClientConnection : public CObject
|
||||
class ASClientConnection final : public CIPCServerSideClient<ASAPI_ServerMessage, ASAPI_ClientMessage>
|
||||
{
|
||||
public:
|
||||
ASClientConnection(int fd, int client_id, ASMixer& mixer);
|
||||
~ASClientConnection();
|
||||
|
||||
void post_message(const ASAPI_ServerMessage&, const ByteBuffer& = {});
|
||||
bool handle_message(const ASAPI_ClientMessage&, const ByteBuffer& = {});
|
||||
|
||||
void drain_client();
|
||||
|
||||
void did_misbehave();
|
||||
|
||||
explicit ASClientConnection(int fd, int client_id, ASMixer& mixer);
|
||||
~ASClientConnection() override;
|
||||
void send_greeting() override;
|
||||
bool handle_message(const ASAPI_ClientMessage&, const ByteBuffer& = {}) override;
|
||||
const char* class_name() const override { return "ASClientConnection"; }
|
||||
|
||||
protected:
|
||||
void event(CEvent& event) override;
|
||||
private:
|
||||
// TODO: A way to create some kind of CIODevice with an open FD would be nice.
|
||||
class ASOpenedSocket : public CIODevice
|
||||
{
|
||||
public:
|
||||
const char* class_name() const override { return "ASOpenedSocket"; }
|
||||
ASOpenedSocket(int fd)
|
||||
{
|
||||
set_fd(fd);
|
||||
set_mode(CIODevice::OpenMode::ReadWrite);
|
||||
}
|
||||
|
||||
bool open(CIODevice::OpenMode) override
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
return true;
|
||||
};
|
||||
|
||||
int fd() const { return CIODevice::fd(); }
|
||||
};
|
||||
|
||||
ASOpenedSocket m_socket;
|
||||
CNotifier m_notifier;
|
||||
int m_client_id;
|
||||
int m_pid;
|
||||
ASMixer& m_mixer;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue