1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:18:12 +00:00
serenity/Userland/Services/Clipboard/ClientConnection.cpp
Gunnar Beutner 065040872f Userland: Change IPC funcs to use plain arguments instead of a struct
Instead of having a single overloaded handle method each method gets
its own unique method name now.
2021-05-03 21:14:06 +02:00

58 lines
1.4 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Badge.h>
#include <Clipboard/ClientConnection.h>
#include <Clipboard/ClipboardClientEndpoint.h>
#include <Clipboard/Storage.h>
namespace Clipboard {
static HashMap<int, RefPtr<ClientConnection>> s_connections;
void ClientConnection::for_each_client(Function<void(ClientConnection&)> callback)
{
for (auto& it : s_connections) {
callback(*it.value);
}
}
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
: IPC::ClientConnection<ClipboardClientEndpoint, ClipboardServerEndpoint>(*this, move(socket), client_id)
{
s_connections.set(client_id, *this);
}
ClientConnection::~ClientConnection()
{
}
void ClientConnection::die()
{
s_connections.remove(client_id());
}
void ClientConnection::greet()
{
}
void ClientConnection::set_clipboard_data(Core::AnonymousBuffer const& data, String const& mime_type, IPC::Dictionary const& metadata)
{
Storage::the().set_data(data, mime_type, metadata.entries());
}
Messages::ClipboardServer::GetClipboardDataResponse ClientConnection::get_clipboard_data()
{
auto& storage = Storage::the();
return { storage.buffer(), storage.mime_type(), storage.metadata() };
}
void ClientConnection::notify_about_clipboard_change()
{
post_message(Messages::ClipboardClient::ClipboardDataChanged(Storage::the().mime_type()));
}
}