diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-07-17 19:46:06 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-17 20:16:44 +0200 |
commit | 9c8dd836fc079666f3dfa92ae23c31d7c46bd769 (patch) | |
tree | 3346e43c9a69aa71f592b5da26df6212927dfd95 | |
parent | 2177594c960976d82c5eb6fac3f90f3345d37854 (diff) | |
download | serenity-9c8dd836fc079666f3dfa92ae23c31d7c46bd769.zip |
Rename new IPC headers & classes
Sticking these in a namespace allows us to use a more generic
("Connection") term without clashing, which is way easier to understand
than to try to come up with unique names for both.
-rw-r--r-- | Libraries/LibAudio/AClientConnection.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibAudio/AClientConnection.h | 4 | ||||
-rw-r--r-- | Libraries/LibCore/CoreIPCClient.h (renamed from Libraries/LibCore/CIPCClientSideConnection.h) | 44 | ||||
-rw-r--r-- | Libraries/LibCore/CoreIPCServer.h (renamed from Libraries/LibCore/CIPCServerSideClient.h) | 50 | ||||
-rw-r--r-- | Libraries/LibGUI/GEventLoop.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/GEventLoop.h | 8 | ||||
-rw-r--r-- | Servers/AudioServer/ASClientConnection.cpp | 2 | ||||
-rw-r--r-- | Servers/AudioServer/ASClientConnection.h | 4 | ||||
-rw-r--r-- | Servers/AudioServer/ASEventLoop.cpp | 3 | ||||
-rw-r--r-- | Servers/WindowServer/WSClientConnection.cpp | 4 | ||||
-rw-r--r-- | Servers/WindowServer/WSClientConnection.h | 4 | ||||
-rw-r--r-- | Servers/WindowServer/WSEventLoop.cpp | 3 |
12 files changed, 71 insertions, 59 deletions
diff --git a/Libraries/LibAudio/AClientConnection.cpp b/Libraries/LibAudio/AClientConnection.cpp index 7f5da5f937..1b52acc63d 100644 --- a/Libraries/LibAudio/AClientConnection.cpp +++ b/Libraries/LibAudio/AClientConnection.cpp @@ -3,7 +3,7 @@ #include "AClientConnection.h" AClientConnection::AClientConnection() - : CIPCClientSideConnection("/tmp/asportal") + : Connection("/tmp/asportal") { } diff --git a/Libraries/LibAudio/AClientConnection.h b/Libraries/LibAudio/AClientConnection.h index 6a8701635c..312b8a22b5 100644 --- a/Libraries/LibAudio/AClientConnection.h +++ b/Libraries/LibAudio/AClientConnection.h @@ -2,12 +2,12 @@ #include <LibCore/CLocalSocket.h> #include <LibCore/CNotifier.h> -#include <LibCore/CIPCClientSideConnection.h> +#include <LibCore/CoreIPCClient.h> #include <LibAudio/ASAPI.h> class ABuffer; -class AClientConnection : public CIPCClientSideConnection<ASAPI_ServerMessage, ASAPI_ClientMessage> { +class AClientConnection : public IPC::Client::Connection<ASAPI_ServerMessage, ASAPI_ClientMessage> { public: AClientConnection(); diff --git a/Libraries/LibCore/CIPCClientSideConnection.h b/Libraries/LibCore/CoreIPCClient.h index 9877ba6f6b..6d54d61e10 100644 --- a/Libraries/LibCore/CIPCClientSideConnection.h +++ b/Libraries/LibCore/CoreIPCClient.h @@ -15,23 +15,27 @@ //#define CIPC_DEBUG -class CIPCClientEvent : public CEvent { +namespace IPC +{ +namespace Client { + +class Event : public CEvent { public: enum Type { Invalid = 2000, - DoPostprocess, + PostProcess, }; - CIPCClientEvent() {} - explicit CIPCClientEvent(Type type) + Event() {} + explicit Event(Type type) : CEvent(type) { } }; -class CIPCClientPostprocessEvent : public CIPCClientEvent { +class PostProcessEvent : public Event { public: - explicit CIPCClientPostprocessEvent(int client_id) - : CIPCClientEvent(DoPostprocess) + explicit PostProcessEvent(int client_id) + : Event(PostProcess) , m_client_id(client_id) { } @@ -43,16 +47,16 @@ private: }; template <typename ServerMessage, typename ClientMessage> -class CIPCClientSideConnection : public CObject { +class Connection : public CObject { public: - CIPCClientSideConnection(const StringView& address) + Connection(const StringView& address) : m_notifier(CNotifier(m_connection.fd(), CNotifier::Read)) { // We want to rate-limit our clients m_connection.set_blocking(true); m_notifier.on_ready_to_read = [this] { drain_messages_from_server(); - CEventLoop::current().post_event(*this, make<CIPCClientPostprocessEvent>(m_connection.fd())); + CEventLoop::current().post_event(*this, make<PostProcessEvent>(m_connection.fd())); }; int retries = 1000; @@ -61,7 +65,7 @@ public: break; } - dbgprintf("CIPCClientSideConnection: connect failed: %d, %s\n", errno, strerror(errno)); + dbgprintf("Client::Connection: connect failed: %d, %s\n", errno, strerror(errno)); sleep(1); --retries; } @@ -73,7 +77,7 @@ public: virtual void event(CEvent& event) override { - if (event.type() == CIPCClientEvent::DoPostprocess) { + if (event.type() == Event::PostProcess) { postprocess_bundles(m_unprocessed_bundles); } else { CObject::event(event); @@ -94,7 +98,7 @@ public: if (m_unprocessed_bundles[i].message.type == type) { event = move(m_unprocessed_bundles[i].message); m_unprocessed_bundles.remove(i); - CEventLoop::current().post_event(*this, make<CIPCClientPostprocessEvent>(m_connection.fd())); + CEventLoop::current().post_event(*this, make<PostProcessEvent>(m_connection.fd())); return true; } } @@ -115,7 +119,7 @@ public: if (m_unprocessed_bundles[i].message.type == type) { event = move(m_unprocessed_bundles[i].message); m_unprocessed_bundles.remove(i); - CEventLoop::current().post_event(*this, make<CIPCClientPostprocessEvent>(m_connection.fd())); + CEventLoop::current().post_event(*this, make<PostProcessEvent>(m_connection.fd())); return true; } } @@ -164,14 +168,14 @@ public: } protected: - struct IncomingASMessageBundle { + struct IncomingMessageBundle { ServerMessage message; ByteBuffer extra_data; }; - virtual void postprocess_bundles(Vector<IncomingASMessageBundle>& new_bundles) + virtual void postprocess_bundles(Vector<IncomingMessageBundle>& new_bundles) { - dbg() << "CIPCClientSideConnection " << " warning: discarding " << new_bundles.size() << " unprocessed bundles; this may not be what you want"; + dbg() << "Client::Connection: " << " warning: discarding " << new_bundles.size() << " unprocessed bundles; this may not be what you want"; new_bundles.clear(); } @@ -214,7 +218,11 @@ private: CLocalSocket m_connection; CNotifier m_notifier; - Vector<IncomingASMessageBundle> m_unprocessed_bundles; + Vector<IncomingMessageBundle> m_unprocessed_bundles; int m_server_pid; int m_my_client_id; }; + +} // Client +} // IPC + diff --git a/Libraries/LibCore/CIPCServerSideClient.h b/Libraries/LibCore/CoreIPCServer.h index 7bb17a9e98..c49ebcc25b 100644 --- a/Libraries/LibCore/CIPCServerSideClient.h +++ b/Libraries/LibCore/CoreIPCServer.h @@ -15,23 +15,27 @@ //#define CIPC_DEBUG -class CIPCServerEvent : public CEvent { +namespace IPC +{ +namespace Server { + +class Event : public CEvent { public: enum Type { Invalid = 2000, - ClientDisconnected, + Disconnected, }; - CIPCServerEvent() {} - explicit CIPCServerEvent(Type type) + Event() {} + explicit Event(Type type) : CEvent(type) { } }; -class ASClientDisconnectedNotification : public CIPCServerEvent { +class DisconnectedEvent : public Event { public: - explicit ASClientDisconnectedNotification(int client_id) - : CIPCServerEvent(ClientDisconnected) + explicit DisconnectedEvent(int client_id) + : Event(Disconnected) , m_client_id(client_id) { } @@ -43,7 +47,7 @@ private: }; template <typename T, class... Args> -T* CIPCServerSideClientCreator(Args&& ... args) +T* new_connection_for_client(Args&& ... args) { auto conn = new T(AK::forward<Args>(args)...) /* arghs */; conn->send_greeting(); @@ -51,24 +55,24 @@ T* CIPCServerSideClientCreator(Args&& ... args) }; template <typename ServerMessage, typename ClientMessage> -class CIPCServerSideClient : public CObject +class Connection : public CObject { public: - CIPCServerSideClient(int fd, int client_id) + Connection(int fd, int client_id) : m_socket(fd) , m_notifier(CNotifier(fd, CNotifier::Read)) , m_client_id(client_id) { m_notifier.on_ready_to_read = [this] { drain_client(); }; #if defined(CIPC_DEBUG) - dbg() << "S: Created new CIPCServerSideClient " << fd << client_id << " and said hello"; + dbg() << "S: Created new Connection " << fd << client_id << " and said hello"; #endif } - ~CIPCServerSideClient() + ~Connection() { #if defined(CIPC_DEBUG) - dbg() << "S: Destroyed CIPCServerSideClient " << m_socket.fd() << client_id(); + dbg() << "S: Destroyed Connection " << m_socket.fd() << client_id(); #endif } @@ -96,17 +100,17 @@ public: if (nwritten < 0) { switch (errno) { case EPIPE: - dbgprintf("WSClientConnection::post_message: Disconnected from peer.\n"); + dbgprintf("Connection::post_message: Disconnected from peer.\n"); delete_later(); return; break; case EAGAIN: - dbgprintf("WSClientConnection::post_message: Client buffer overflowed.\n"); + dbgprintf("Connection::post_message: Client buffer overflowed.\n"); did_misbehave(); return; break; default: - perror("WSClientConnection::post_message writev"); + perror("Connection::post_message writev"); ASSERT_NOT_REACHED(); } } @@ -124,7 +128,7 @@ public: if (nread == 0 || (nread == -1 && errno == EAGAIN)) { if (!messages_received) { // TODO: is delete_later() sufficient? - CEventLoop::current().post_event(*this, make<ASClientDisconnectedNotification>(client_id())); + CEventLoop::current().post_event(*this, make<DisconnectedEvent>(client_id())); } break; } @@ -159,12 +163,12 @@ public: void did_misbehave() { - dbgprintf("CIPCServerSideClient{%p} (id=%d, pid=%d) misbehaved, disconnecting.\n", this, client_id(), m_pid); + dbgprintf("Connection{%p} (id=%d, pid=%d) misbehaved, disconnecting.\n", this, client_id(), m_pid); delete_later(); m_notifier.set_enabled(false); } - const char* class_name() const override { return "CIPCServerSideClient"; } + const char* class_name() const override { return "Connection"; } int client_id() const { return m_client_id; } pid_t client_pid() const { return m_pid; } @@ -176,9 +180,9 @@ public: protected: void event(CEvent& event) { - if (event.type() == CIPCServerEvent::ClientDisconnected) { - int client_id = static_cast<const ASClientDisconnectedNotification&>(event).client_id(); - dbgprintf("CIPCServerSideClient: Client disconnected: %d\n", client_id); + if (event.type() == Event::Disconnected) { + int client_id = static_cast<const DisconnectedEvent&>(event).client_id(); + dbgprintf("Connection: Client disconnected: %d\n", client_id); delete this; return; } @@ -215,4 +219,6 @@ private: int m_pid; }; +} // Server +} // IPC diff --git a/Libraries/LibGUI/GEventLoop.cpp b/Libraries/LibGUI/GEventLoop.cpp index 9815464123..cba2460397 100644 --- a/Libraries/LibGUI/GEventLoop.cpp +++ b/Libraries/LibGUI/GEventLoop.cpp @@ -188,7 +188,7 @@ void GWindowServerConnection::handle_wm_event(const WSAPI_ServerMessage& event, ASSERT_NOT_REACHED(); } -void GWindowServerConnection::postprocess_bundles(Vector<CIPCClientSideConnection::IncomingASMessageBundle>& bundles) +void GWindowServerConnection::postprocess_bundles(Vector<IncomingMessageBundle>& bundles) { int coalesced_paints = 0; int coalesced_resizes = 0; diff --git a/Libraries/LibGUI/GEventLoop.h b/Libraries/LibGUI/GEventLoop.h index 303a77e835..9a539f05c4 100644 --- a/Libraries/LibGUI/GEventLoop.h +++ b/Libraries/LibGUI/GEventLoop.h @@ -1,7 +1,7 @@ #pragma once #include <LibCore/CEventLoop.h> -#include <LibCore/CIPCClientSideConnection.h> +#include <LibCore/CoreIPCClient.h> #include <LibGUI/GEvent.h> #include <WindowServer/WSAPITypes.h> @@ -10,16 +10,16 @@ class CObject; class CNotifier; class GWindow; -class GWindowServerConnection : public CIPCClientSideConnection<WSAPI_ServerMessage, WSAPI_ClientMessage> { +class GWindowServerConnection : public IPC::Client::Connection<WSAPI_ServerMessage, WSAPI_ClientMessage> { public: GWindowServerConnection() - : CIPCClientSideConnection("/tmp/wsportal") + : Connection("/tmp/wsportal") {} void handshake() override; private: - void postprocess_bundles(Vector<IncomingASMessageBundle>& m_unprocessed_bundles) override; + void postprocess_bundles(Vector<IncomingMessageBundle>& m_unprocessed_bundles) override; void handle_paint_event(const WSAPI_ServerMessage&, GWindow&, const ByteBuffer& extra_data); void handle_resize_event(const WSAPI_ServerMessage&, GWindow&); void handle_mouse_event(const WSAPI_ServerMessage&, GWindow&); diff --git a/Servers/AudioServer/ASClientConnection.cpp b/Servers/AudioServer/ASClientConnection.cpp index d34de74eaa..acb467ddbc 100644 --- a/Servers/AudioServer/ASClientConnection.cpp +++ b/Servers/AudioServer/ASClientConnection.cpp @@ -14,7 +14,7 @@ #include <stdio.h> ASClientConnection::ASClientConnection(int fd, int client_id, ASMixer& mixer) - : CIPCServerSideClient(fd, client_id) + : Connection(fd, client_id) , m_mixer(mixer) { } diff --git a/Servers/AudioServer/ASClientConnection.h b/Servers/AudioServer/ASClientConnection.h index 5065994481..ecc48477d1 100644 --- a/Servers/AudioServer/ASClientConnection.h +++ b/Servers/AudioServer/ASClientConnection.h @@ -1,11 +1,11 @@ #pragma once -#include <LibCore/CIPCServerSideClient.h> +#include <LibCore/CoreIPCServer.h> #include <LibAudio/ASAPI.h> class ASMixer; -class ASClientConnection final : public CIPCServerSideClient<ASAPI_ServerMessage, ASAPI_ClientMessage> +class ASClientConnection final : public IPC::Server::Connection<ASAPI_ServerMessage, ASAPI_ClientMessage> { public: explicit ASClientConnection(int fd, int client_id, ASMixer& mixer); diff --git a/Servers/AudioServer/ASEventLoop.cpp b/Servers/AudioServer/ASEventLoop.cpp index 203ba6538c..dfb4ce3a2a 100644 --- a/Servers/AudioServer/ASEventLoop.cpp +++ b/Servers/AudioServer/ASEventLoop.cpp @@ -31,8 +31,7 @@ void ASEventLoop::drain_server() } else { dbgprintf("AudioServer: accept()ed client %d\n", client_fd); static int s_next_client_id = 0; - CIPCServerSideClientCreator<ASClientConnection>(client_fd, s_next_client_id++, m_mixer); - //new ASClientConnection(client_fd, s_next_client_id++, m_mixer); + IPC::Server::new_connection_for_client<ASClientConnection>(client_fd, s_next_client_id++, m_mixer); } } diff --git a/Servers/WindowServer/WSClientConnection.cpp b/Servers/WindowServer/WSClientConnection.cpp index 2caabd7191..e5343b7fca 100644 --- a/Servers/WindowServer/WSClientConnection.cpp +++ b/Servers/WindowServer/WSClientConnection.cpp @@ -40,7 +40,7 @@ WSClientConnection* WSClientConnection::from_client_id(int client_id) } WSClientConnection::WSClientConnection(int fd, int client_id) - : CIPCServerSideClient(fd, client_id) + : Connection(fd, client_id) { if (!s_connections) s_connections = new HashMap<int, WSClientConnection*>; @@ -88,7 +88,7 @@ void WSClientConnection::event(CEvent& event) return; } - CIPCServerSideClient::event(event); + Connection::event(event); } static Vector<Rect, 32> get_rects(const WSAPI_ClientMessage& message, const ByteBuffer& extra_data) diff --git a/Servers/WindowServer/WSClientConnection.h b/Servers/WindowServer/WSClientConnection.h index b13d2fab6c..4c621fe422 100644 --- a/Servers/WindowServer/WSClientConnection.h +++ b/Servers/WindowServer/WSClientConnection.h @@ -5,7 +5,7 @@ #include <AK/OwnPtr.h> #include <AK/WeakPtr.h> #include <LibCore/CObject.h> -#include <LibCore/CIPCServerSideClient.h> +#include <LibCore/CoreIPCServer.h> #include <SharedGraphics/GraphicsBitmap.h> #include <WindowServer/WSEvent.h> @@ -13,7 +13,7 @@ class WSWindow; class WSMenu; class WSMenuBar; -class WSClientConnection final : public CIPCServerSideClient<WSAPI_ServerMessage, WSAPI_ClientMessage> { +class WSClientConnection final : public IPC::Server::Connection<WSAPI_ServerMessage, WSAPI_ClientMessage> { public: explicit WSClientConnection(int fd, int client_id); ~WSClientConnection() override; diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp index f2590b0ba5..c8b6e2d5cd 100644 --- a/Servers/WindowServer/WSEventLoop.cpp +++ b/Servers/WindowServer/WSEventLoop.cpp @@ -62,8 +62,7 @@ void WSEventLoop::drain_server() } else { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - - CIPCServerSideClientCreator<WSClientConnection>(client_fd, client_id); + IPC::Server::new_connection_for_client<WSClientConnection>(client_fd, client_id); } } |