1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00
serenity/Userland/Services/NotificationServer/ClientConnection.cpp
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

77 lines
2.7 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ClientConnection.h"
#include "NotificationWindow.h"
#include <AK/HashMap.h>
#include <NotificationServer/NotificationClientEndpoint.h>
namespace NotificationServer {
static HashMap<int, RefPtr<ClientConnection>> s_connections;
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> client_socket, int client_id)
: IPC::ClientConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, move(client_socket), client_id)
{
s_connections.set(client_id, *this);
}
ClientConnection::~ClientConnection()
{
}
void ClientConnection::die()
{
s_connections.remove(client_id());
}
OwnPtr<Messages::NotificationServer::GreetResponse> ClientConnection::handle(const Messages::NotificationServer::Greet&)
{
return make<Messages::NotificationServer::GreetResponse>();
}
OwnPtr<Messages::NotificationServer::ShowNotificationResponse> ClientConnection::handle(const Messages::NotificationServer::ShowNotification& message)
{
auto window = NotificationWindow::construct(client_id(), message.text(), message.title(), message.icon());
window->show();
return make<Messages::NotificationServer::ShowNotificationResponse>();
}
OwnPtr<Messages::NotificationServer::CloseNotificationResponse> ClientConnection::handle([[maybe_unused]] const Messages::NotificationServer::CloseNotification& message)
{
auto window = NotificationWindow::get_window_by_id(client_id());
if (window) {
window->close();
}
return make<Messages::NotificationServer::CloseNotificationResponse>();
}
OwnPtr<Messages::NotificationServer::UpdateNotificationIconResponse> ClientConnection::handle(const Messages::NotificationServer::UpdateNotificationIcon& message)
{
auto window = NotificationWindow::get_window_by_id(client_id());
if (window) {
window->set_image(message.icon());
}
return make<Messages::NotificationServer::UpdateNotificationIconResponse>(window);
}
OwnPtr<Messages::NotificationServer::UpdateNotificationTextResponse> ClientConnection::handle(const Messages::NotificationServer::UpdateNotificationText& message)
{
auto window = NotificationWindow::get_window_by_id(client_id());
if (window) {
window->set_text(message.text());
window->set_title(message.title());
}
return make<Messages::NotificationServer::UpdateNotificationTextResponse>(window);
}
OwnPtr<Messages::NotificationServer::IsShowingResponse> ClientConnection::handle(const Messages::NotificationServer::IsShowing&)
{
auto window = NotificationWindow::get_window_by_id(client_id());
return make<Messages::NotificationServer::IsShowingResponse>(window);
}
}