Serenity Operating System
1/*
2 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include "ConnectionFromClient.h"
8#include "NotificationWindow.h"
9#include <AK/HashMap.h>
10#include <NotificationServer/NotificationClientEndpoint.h>
11
12namespace NotificationServer {
13
14static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
15
16ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket> client_socket, int client_id)
17 : IPC::ConnectionFromClient<NotificationClientEndpoint, NotificationServerEndpoint>(*this, move(client_socket), client_id)
18{
19 s_connections.set(client_id, *this);
20}
21
22void ConnectionFromClient::die()
23{
24 s_connections.remove(client_id());
25}
26
27void ConnectionFromClient::show_notification(DeprecatedString const& text, DeprecatedString const& title, Gfx::ShareableBitmap const& icon)
28{
29 auto window = NotificationWindow::construct(client_id(), text, title, icon);
30 window->show();
31}
32
33void ConnectionFromClient::close_notification()
34{
35 auto window = NotificationWindow::get_window_by_id(client_id());
36 if (window) {
37 window->close();
38 }
39}
40
41Messages::NotificationServer::UpdateNotificationIconResponse ConnectionFromClient::update_notification_icon(Gfx::ShareableBitmap const& icon)
42{
43 auto window = NotificationWindow::get_window_by_id(client_id());
44 if (window) {
45 window->set_image(icon);
46 }
47 return !!window;
48}
49
50Messages::NotificationServer::UpdateNotificationTextResponse ConnectionFromClient::update_notification_text(DeprecatedString const& text, DeprecatedString const& title)
51{
52 auto window = NotificationWindow::get_window_by_id(client_id());
53 if (window) {
54 window->set_text(text);
55 window->set_title(title);
56 }
57 return !!window;
58}
59
60Messages::NotificationServer::IsShowingResponse ConnectionFromClient::is_showing()
61{
62 auto window = NotificationWindow::get_window_by_id(client_id());
63 return !!window;
64}
65
66}