Serenity Operating System
at portability 48 lines 1.3 kB view raw
1#include <LibGUI/Notification.h> 2#include <LibIPC/ServerConnection.h> 3#include <NotificationServer/NotificationClientEndpoint.h> 4#include <NotificationServer/NotificationServerEndpoint.h> 5 6namespace GUI { 7 8class NotificationServerConnection : public IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint> 9 , public NotificationClientEndpoint { 10 C_OBJECT(NotificationServerConnection) 11public: 12 virtual void handshake() override 13 { 14 auto response = send_sync<Messages::NotificationServer::Greet>(); 15 set_my_client_id(response->client_id()); 16 } 17 18private: 19 NotificationServerConnection() 20 : IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify") 21 { 22 23 } 24 virtual void handle(const Messages::NotificationClient::Dummy&) override {} 25}; 26 27Notification::Notification() 28{ 29} 30 31Notification::~Notification() 32{ 33} 34 35static NotificationServerConnection& notification_server_connection() 36{ 37 static NotificationServerConnection* connection; 38 if (!connection) 39 connection = &NotificationServerConnection::construct().leak_ref(); 40 return *connection; 41} 42 43void Notification::show() 44{ 45 notification_server_connection().post_message(Messages::NotificationServer::ShowNotification(m_text, m_title)); 46} 47 48}