/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace Clipboard { static HashMap> s_connections; void ClientConnection::for_each_client(Function callback) { for (auto& it : s_connections) { callback(*it.value); } } ClientConnection::ClientConnection(NonnullRefPtr socket, int client_id) : IPC::ClientConnection(*this, move(socket), client_id) { s_connections.set(client_id, *this); } ClientConnection::~ClientConnection() { } void ClientConnection::die() { s_connections.remove(client_id()); } void ClientConnection::handle(const Messages::ClipboardServer::Greet&) { } void ClientConnection::handle(const Messages::ClipboardServer::SetClipboardData& message) { Storage::the().set_data(message.data(), message.mime_type(), message.metadata().entries()); } Messages::ClipboardServer::GetClipboardDataResponse ClientConnection::handle(const Messages::ClipboardServer::GetClipboardData&) { 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())); } }