Skip to content

Commit

Permalink
WindowServer: Port to the new IPC system
Browse files Browse the repository at this point in the history
This patch introduces code generation for the WindowServer IPC with
its clients. The client/server endpoints are defined by the two .ipc
files in Servers/WindowServer/: WindowServer.ipc and WindowClient.ipc

It now becomes significantly easier to add features and capabilities
to WindowServer since you don't have to know nearly as much about all
the intricate paths that IPC messages take between LibGUI and WSWindow.

The new system also uses significantly less IPC bandwidth since we're
now doing packed serialization instead of passing fixed-sized structs
of ~600 bytes for each message.

Some repaint coalescing optimizations are lost in this conversion and
we'll need to look at how to implement those in the new world.

The old CoreIPC::Client::Connection and CoreIPC::Server::Connection
classes are removed by this patch and replaced by use of ConnectionNG,
which will be renamed eventually.

Goodbye, old WindowServer IPC. You served us well :^)
  • Loading branch information
awesomekling committed Dec 2, 2019
1 parent 30db781 commit 272d65e
Show file tree
Hide file tree
Showing 42 changed files with 807 additions and 2,817 deletions.
6 changes: 1 addition & 5 deletions Applications/DisplayProperties/DisplayProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,8 @@ void DisplayPropertiesWidget::send_settings_to_window_server(int tab_index)
builder.append(m_selected_wallpaper);
GDesktop::the().set_wallpaper(builder.to_string());
} else if (tab_index == TabIndices::Settings) {
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::SetResolution;
dbg() << "Attempting to set resolution " << m_selected_resolution;
request.wm_conf.resolution = { m_selected_resolution.width(), m_selected_resolution.height() };
auto response = GWindowServerConnection::the().sync_request(request, WSAPI_ServerMessage::Type::DidSetResolution);
ASSERT(response.value == 1);
GWindowServerConnection::the().send_sync<WindowServer::SetResolution>(m_selected_resolution);
} else {
dbg() << "Invalid tab index " << tab_index;
}
Expand Down
8 changes: 1 addition & 7 deletions Applications/Taskbar/TaskbarButton.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "TaskbarButton.h"
#include <LibGUI/GAction.h>
#include <LibGUI/GWindowServerConnection.h>
#include <WindowServer/WSAPITypes.h>

TaskbarButton::TaskbarButton(const WindowIdentifier& identifier, GWidget* parent)
: GButton(parent)
Expand All @@ -15,10 +14,5 @@ TaskbarButton::~TaskbarButton()

void TaskbarButton::context_menu_event(GContextMenuEvent&)
{
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::WM_PopupWindowMenu;
request.wm.client_id = m_identifier.client_id();
request.wm.window_id = m_identifier.window_id();
request.wm.position = screen_relative_rect().location();
GWindowServerConnection::the().post_message_to_server(request);
GWindowServerConnection::the().post_message(WindowServer::WM_PopupWindowMenu(m_identifier.client_id(), m_identifier.window_id(), screen_relative_rect().location()));
}
1 change: 0 additions & 1 deletion Applications/Taskbar/TaskbarWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <LibGUI/GDesktop.h>
#include <LibGUI/GFrame.h>
#include <LibGUI/GWindow.h>
#include <WindowServer/WSAPITypes.h>
#include <stdio.h>

//#define EVENT_DEBUG
Expand Down
13 changes: 3 additions & 10 deletions Applications/Taskbar/WindowList.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "WindowList.h"
#include <LibGUI/GWindowServerConnection.h>
#include <WindowServer/WSAPITypes.h>

WindowList& WindowList::the()
{
Expand All @@ -25,18 +24,12 @@ Window& WindowList::ensure_window(const WindowIdentifier& identifier)
return *it->value;
auto window = make<Window>(identifier);
window->set_button(aid_create_button(identifier));
window->button()->on_click = [window = window.ptr(), identifier](GButton&) {
WSAPI_ClientMessage message;
window->button()->on_click = [window = window.ptr(), identifier](auto&) {
if (window->is_minimized() || !window->is_active()) {
message.type = WSAPI_ClientMessage::Type::WM_SetActiveWindow;
GWindowServerConnection::the().post_message(WindowServer::WM_SetActiveWindow(identifier.client_id(), identifier.window_id()));
} else {
message.type = WSAPI_ClientMessage::Type::WM_SetWindowMinimized;
message.wm.minimized = true;
GWindowServerConnection::the().post_message(WindowServer::WM_SetWindowMinimized(identifier.client_id(), identifier.window_id(), true));
}
message.wm.client_id = identifier.client_id();
message.wm.window_id = identifier.window_id();
bool success = GWindowServerConnection::the().post_message_to_server(message);
ASSERT(success);
};
auto& window_ref = *window;
m_windows.set(identifier, move(window));
Expand Down
2 changes: 1 addition & 1 deletion Demos/Fire/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEFINES += -DUSERLAND
all: $(APP)

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
2 changes: 1 addition & 1 deletion Demos/HelloWorld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEFINES += -DUSERLAND
all: $(APP)

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
2 changes: 1 addition & 1 deletion Demos/HelloWorld2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ UI_HelloWorld2.h: HelloWorld2.frm
../../DevTools/FormCompiler/FormCompiler $< > $@

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
2 changes: 1 addition & 1 deletion Demos/WidgetGallery/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEFINES += -DUSERLAND
all: $(APP)

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
105 changes: 95 additions & 10 deletions DevTools/IPCCompiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <ctype.h>
#include <stdio.h>

//#define GENERATE_DEBUG_CODE

struct Parameter {
String type;
String name;
Expand Down Expand Up @@ -71,7 +73,7 @@ int main(int argc, char** argv)

auto consume_specific = [&](char ch) {
if (peek() != ch) {
dbg() << "consume_specific: wanted '" << ch << "', but got '" << peek() << "'";
dbg() << "consume_specific: wanted '" << ch << "', but got '" << peek() << "' at index " << index;
}
ASSERT(peek() == ch);
++index;
Expand Down Expand Up @@ -197,6 +199,8 @@ int main(int argc, char** argv)
dbg() << "#pragma once";
dbg() << "#include <AK/BufferStream.h>";
dbg() << "#include <AK/OwnPtr.h>";
dbg() << "#include <LibDraw/Color.h>";
dbg() << "#include <LibDraw/Rect.h>";
dbg() << "#include <LibIPC/IEndpoint.h>";
dbg() << "#include <LibIPC/IMessage.h>";
dbg();
Expand Down Expand Up @@ -279,17 +283,66 @@ int main(int argc, char** argv)

if (parameter.type == "String") {
dbg() << " int " << parameter.name << "_length = 0;";
dbg() << " char* " << parameter.name << "_buffer = nullptr;";
dbg() << " stream >> " << parameter.name << "_length;";
dbg() << " auto " << parameter.name << "_impl = StringImpl::create_uninitialized(" << parameter.name << "_length, " << parameter.name << "_buffer);";
dbg() << " for (int i = 0; i < " << parameter.name << "_length; ++i) {";
dbg() << " stream >> " << parameter.name << "_buffer[i];";
dbg() << " if (" << parameter.name << "_length == 0) {";
dbg() << " " << parameter.name << " = String::empty();";
dbg() << " } else if (" << parameter.name << "_length == -1) {";
dbg() << " " << parameter.name << " = String();";
dbg() << " } else {";
dbg() << " char* " << parameter.name << "_buffer = nullptr;";
dbg() << " auto " << parameter.name << "_impl = StringImpl::create_uninitialized(" << parameter.name << "_length, " << parameter.name << "_buffer);";
dbg() << " for (int i = 0; i < " << parameter.name << "_length; ++i) {";
dbg() << " stream >> " << parameter.name << "_buffer[i];";
dbg() << " }";
dbg() << " " << parameter.name << " = *" << parameter.name << "_impl;";
dbg() << " }";
} else if (parameter.type == "Color") {
dbg() << " u32 " << parameter.name << "_rgba = 0;";
dbg() << " stream >> " << parameter.name << "_rgba;";
dbg() << " " << parameter.name << " = Color::from_rgba(" << parameter.name << "_rgba);";
} else if (parameter.type == "Size") {
dbg() << " int " << parameter.name << "_width = 0;";
dbg() << " stream >> " << parameter.name << "_width;";
dbg() << " int " << parameter.name << "_height = 0;";
dbg() << " stream >> " << parameter.name << "_height;";
dbg() << " " << parameter.name << " = { " << parameter.name << "_width, " << parameter.name << "_height };";
} else if (parameter.type == "Point") {
dbg() << " int " << parameter.name << "_x = 0;";
dbg() << " stream >> " << parameter.name << "_x;";
dbg() << " int " << parameter.name << "_y = 0;";
dbg() << " stream >> " << parameter.name << "_y;";
dbg() << " " << parameter.name << " = { " << parameter.name << "_x, " << parameter.name << "_y };";
} else if (parameter.type == "Rect") {
dbg() << " int " << parameter.name << "_x = 0;";
dbg() << " stream >> " << parameter.name << "_x;";
dbg() << " int " << parameter.name << "_y = 0;";
dbg() << " stream >> " << parameter.name << "_y;";
dbg() << " int " << parameter.name << "_width = 0;";
dbg() << " stream >> " << parameter.name << "_width;";
dbg() << " int " << parameter.name << "_height = 0;";
dbg() << " stream >> " << parameter.name << "_height;";
dbg() << " " << parameter.name << " = { " << parameter.name << "_x, " << parameter.name << "_y, " << parameter.name << "_width, " << parameter.name << "_height };";
} else if (parameter.type == "Vector<Rect>") {
dbg() << " int " << parameter.name << "_size = 0;";
dbg() << " stream >> " << parameter.name << "_size;";
dbg() << " for (int i = 0; i < " << parameter.name << "_size; ++i) {";
dbg() << " int " << parameter.name << "_x = 0;";
dbg() << " stream >> " << parameter.name << "_x;";
dbg() << " int " << parameter.name << "_y = 0;";
dbg() << " stream >> " << parameter.name << "_y;";
dbg() << " int " << parameter.name << "_width = 0;";
dbg() << " stream >> " << parameter.name << "_width;";
dbg() << " int " << parameter.name << "_height = 0;";
dbg() << " stream >> " << parameter.name << "_height;";
dbg() << " " << parameter.name << ".empend(" << parameter.name << "_x, " << parameter.name << "_y, " << parameter.name << "_width, " << parameter.name << "_height);";
dbg() << " }";
dbg() << " " << parameter.name << " = *" << parameter.name << "_impl;";
} else {
dbg() << " stream >> " << parameter.name << ";";
}
dbg() << " if (stream.handle_read_failure()) {";
#ifdef GENERATE_DEBUG_CODE
dbg() << " dbg() << \"Failed to decode " << name << "." << parameter.name << "\";";
#endif
dbg() << " return nullptr;";
dbg() << " }";
}
Expand All @@ -307,14 +360,39 @@ int main(int argc, char** argv)
dbg() << " virtual ByteBuffer encode() const override";
dbg() << " {";
// FIXME: Support longer messages:
dbg() << " auto buffer = ByteBuffer::create_uninitialized(1024);";
dbg() << " auto buffer = ByteBuffer::create_uninitialized(4096);";
dbg() << " BufferStream stream(buffer);";
dbg() << " stream << endpoint_magic();";
dbg() << " stream << (int)MessageID::" << name << ";";
for (auto& parameter : parameters) {
if (parameter.type == "String") {
dbg() << " stream << m_" << parameter.name << ".length();";
dbg() << " stream << m_" << parameter.name << ";";
dbg() << " if (m_" << parameter.name << ".is_null()) {";
dbg() << " stream << (i32)-1;";
dbg() << " } else {";
dbg() << " stream << m_" << parameter.name << ".length();";
dbg() << " stream << m_" << parameter.name << ";";
dbg() << " }";
} else if (parameter.type == "Color") {
dbg() << " stream << m_" << parameter.name << ".value();";
} else if (parameter.type == "Size") {
dbg() << " stream << m_" << parameter.name << ".width();";
dbg() << " stream << m_" << parameter.name << ".height();";
} else if (parameter.type == "Point") {
dbg() << " stream << m_" << parameter.name << ".x();";
dbg() << " stream << m_" << parameter.name << ".y();";
} else if (parameter.type == "Rect") {
dbg() << " stream << m_" << parameter.name << ".x();";
dbg() << " stream << m_" << parameter.name << ".y();";
dbg() << " stream << m_" << parameter.name << ".width();";
dbg() << " stream << m_" << parameter.name << ".height();";
} else if (parameter.type == "Vector<Rect>") {
dbg() << " stream << m_" << parameter.name << ".size();";
dbg() << " for (auto& rect : m_" << parameter.name << ") {";
dbg() << " stream << rect.x();";
dbg() << " stream << rect.y();";
dbg() << " stream << rect.width();";
dbg() << " stream << rect.height();";
dbg() << " }";
} else {
dbg() << " stream << m_" << parameter.name << ";";
}
Expand Down Expand Up @@ -356,8 +434,12 @@ int main(int argc, char** argv)
dbg() << " BufferStream stream(const_cast<ByteBuffer&>(buffer));";
dbg() << " i32 message_endpoint_magic = 0;";
dbg() << " stream >> message_endpoint_magic;";
dbg() << " if (message_endpoint_magic != " << endpoint.magic << ")";
dbg() << " if (message_endpoint_magic != " << endpoint.magic << ") {";
#ifdef GENERATE_DEBUG_CODE
dbg() << " dbg() << \"endpoint magic \" << message_endpoint_magic << \" != " << endpoint.magic << "\";";
#endif
dbg() << " return nullptr;";
dbg() << " }";
dbg() << " i32 message_id = 0;";
dbg() << " stream >> message_id;";
dbg() << " switch (message_id) {";
Expand All @@ -371,6 +453,9 @@ int main(int argc, char** argv)
do_decode_message(message.response_name());
}
dbg() << " default:";
#ifdef GENERATE_DEBUG_CODE
dbg() << " dbg() << \"Failed to decode " << endpoint.name << ".(\" << message_id << \")\";";
#endif
dbg() << " return nullptr;";

dbg() << " }";
Expand Down
2 changes: 1 addition & 1 deletion DevTools/Inspector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DEFINES += -DUSERLAND
all: $(APP)

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
2 changes: 1 addition & 1 deletion DevTools/VisualBuilder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DEFINES += -DUSERLAND
all: $(APP)

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
2 changes: 1 addition & 1 deletion Games/Minesweeper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DEFINES += -DUSERLAND
all: $(APP)

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
2 changes: 1 addition & 1 deletion Games/Snake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DEFINES += -DUSERLAND
all: $(APP)

$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lipc -lcore -lc

.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
11 changes: 8 additions & 3 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,9 @@ ssize_t Process::sys$read(int fd, u8* buffer, ssize_t size)
int Process::sys$close(int fd)
{
auto* description = file_description(fd);
#ifdef DEBUG_IO
dbgprintf("%s(%u) sys$close(%d) %p\n", name().characters(), pid(), fd, description);
#endif
if (!description)
return -EBADF;
int rc = description->close();
Expand Down Expand Up @@ -1367,10 +1370,10 @@ int Process::sys$open(const Syscall::SC_open_params* params)
return -EINVAL;
if (!validate_read(path, path_length))
return -EFAULT;
int fd = alloc_fd();
#ifdef DEBUG_IO
dbgprintf("%s(%u) sys$open(\"%s\")\n", name().characters(), pid(), path);
dbgprintf("%s(%u) sys$open(\"%s\") -> %d\n", name().characters(), pid(), path, fd);
#endif
int fd = alloc_fd();
if (fd < 0)
return fd;
auto result = VFS::the().open(path, options, mode & ~umask(), current_directory());
Expand Down Expand Up @@ -2141,8 +2144,10 @@ int Process::sys$select(const Syscall::SC_select_params* params)
return 0;
for (int fd = 0; fd < params->nfds; ++fd) {
if (FD_ISSET(fd, fds)) {
if (!file_description(fd))
if (!file_description(fd)) {
dbg() << *current << " sys$select: Bad fd number " << fd;
return -EBADF;
}
vector.append(fd);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Kernel/makeall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ build_targets="$build_targets ../Libraries/LibPthread"
build_targets="$build_targets ../Servers/AudioServer"
build_targets="$build_targets ../Servers/LookupServer"
build_targets="$build_targets ../Servers/ProtocolServer"
build_targets="$build_targets ../Libraries/LibAudio"
build_targets="$build_targets ../Servers/WindowServer"

build_targets="$build_targets ../AK"

build_targets="$build_targets ../Libraries/LibAudio"
build_targets="$build_targets ../Libraries/LibDraw"
build_targets="$build_targets ../Libraries/LibGUI"
build_targets="$build_targets ../Libraries/LibHTML"
Expand Down Expand Up @@ -81,7 +82,6 @@ build_targets="$build_targets ../Games/Snake"
build_targets="$build_targets ../Servers/SystemServer"
build_targets="$build_targets ../Servers/TTYServer"
build_targets="$build_targets ../Servers/TelnetServer"
build_targets="$build_targets ../Servers/WindowServer"

build_targets="$build_targets ../Shell"

Expand Down
Loading

0 comments on commit 272d65e

Please sign in to comment.