diff options
35 files changed, 143 insertions, 38 deletions
diff --git a/AK/Forward.h b/AK/Forward.h index e1b66768f1..f109221344 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -71,6 +71,9 @@ template<typename T> class NonnullOwnPtr; template<typename T> +class Optional; + +template<typename T> class RefPtr; template<typename T> @@ -98,6 +101,7 @@ using AK::JsonObject; using AK::JsonValue; using AK::NonnullOwnPtr; using AK::NonnullRefPtr; +using AK::Optional; using AK::OwnPtr; using AK::RefPtr; using AK::SinglyLinkedList; diff --git a/AK/IntrusiveList.h b/AK/IntrusiveList.h index 23232bdbbc..09f35737d7 100644 --- a/AK/IntrusiveList.h +++ b/AK/IntrusiveList.h @@ -26,6 +26,8 @@ #pragma once +#include <AK/Assertions.h> + namespace AK { class IntrusiveListNode; diff --git a/AK/Optional.h b/AK/Optional.h index 1a1708beea..4c27ea545d 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -30,6 +30,8 @@ #include <AK/Platform.h> #include <AK/StdLibExtras.h> +namespace AK { + template<typename T> class CONSUMABLE(unknown) alignas(T) Optional { public: @@ -161,3 +163,7 @@ private: char m_storage[sizeof(T)]; bool m_has_value { false }; }; + +} + +using AK::Optional; diff --git a/Applications/Help/main.cpp b/Applications/Help/main.cpp index c39936f599..45baa6c1d1 100644 --- a/Applications/Help/main.cpp +++ b/Applications/Help/main.cpp @@ -26,6 +26,7 @@ #include "History.h" #include "ManualModel.h" +#include <AK/ByteBuffer.h> #include <LibCore/File.h> #include <LibGUI/AboutDialog.h> #include <LibGUI/Action.h> diff --git a/Applications/SystemMonitor/ProcessStacksWidget.cpp b/Applications/SystemMonitor/ProcessStacksWidget.cpp index 7e613d0cea..cfa3fe5aa9 100644 --- a/Applications/SystemMonitor/ProcessStacksWidget.cpp +++ b/Applications/SystemMonitor/ProcessStacksWidget.cpp @@ -25,6 +25,7 @@ */ #include "ProcessStacksWidget.h" +#include <AK/ByteBuffer.h> #include <LibCore/File.h> #include <LibCore/Timer.h> #include <LibGUI/BoxLayout.h> diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp index 9110955112..8cdbe83f15 100644 --- a/DevTools/HackStudio/Editor.cpp +++ b/DevTools/HackStudio/Editor.cpp @@ -26,6 +26,7 @@ #include "Editor.h" #include "EditorWrapper.h" +#include <AK/ByteBuffer.h> #include <AK/FileSystemPath.h> #include <LibCore/DirIterator.h> #include <LibCore/File.h> diff --git a/DevTools/IPCCompiler/main.cpp b/DevTools/IPCCompiler/main.cpp index 12b35d0e6c..e50db44377 100644 --- a/DevTools/IPCCompiler/main.cpp +++ b/DevTools/IPCCompiler/main.cpp @@ -25,6 +25,7 @@ */ #include <AK/BufferStream.h> +#include <AK/Function.h> #include <AK/HashMap.h> #include <AK/StringBuilder.h> #include <LibCore/File.h> diff --git a/Libraries/LibAudio/WavLoader.cpp b/Libraries/LibAudio/WavLoader.cpp index 667b1db88e..a4dd4e6708 100644 --- a/Libraries/LibAudio/WavLoader.cpp +++ b/Libraries/LibAudio/WavLoader.cpp @@ -25,6 +25,7 @@ */ #include <AK/BufferStream.h> +#include <AK/OwnPtr.h> #include <LibAudio/WavLoader.h> #include <LibCore/File.h> #include <LibCore/IODeviceStreamReader.h> diff --git a/Libraries/LibCore/Event.h b/Libraries/LibCore/Event.h index d3c7cc1f22..8c9bd06e33 100644 --- a/Libraries/LibCore/Event.h +++ b/Libraries/LibCore/Event.h @@ -30,11 +30,10 @@ #include <AK/String.h> #include <AK/Types.h> #include <AK/WeakPtr.h> +#include <LibCore/Forward.h> namespace Core { -class Object; - class Event { public: enum Type { diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp index 70190411b9..0ab29af071 100644 --- a/Libraries/LibCore/EventLoop.cpp +++ b/Libraries/LibCore/EventLoop.cpp @@ -24,12 +24,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/Badge.h> #include <AK/IDAllocator.h> #include <AK/JsonObject.h> #include <AK/JsonValue.h> #include <AK/Time.h> #include <LibCore/Event.h> #include <LibCore/EventLoop.h> +#include <LibCore/LocalServer.h> #include <LibCore/LocalSocket.h> #include <LibCore/Notifier.h> #include <LibCore/Object.h> @@ -328,7 +330,7 @@ void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event) #ifdef CEVENTLOOP_DEBUG dbg() << "Core::EventLoop::post_event: {" << m_queued_events.size() << "} << receiver=" << receiver << ", event=" << event; #endif - m_queued_events.append({ receiver.make_weak_ptr(), move(event) }); + m_queued_events.empend(receiver, move(event)); } void EventLoop::wait_for_event(WaitMode mode) @@ -509,4 +511,20 @@ void EventLoop::wake() } } +EventLoop::QueuedEvent::QueuedEvent(Object& receiver, NonnullOwnPtr<Event> event) + : receiver(receiver.make_weak_ptr()) + , event(move(event)) +{ +} + +EventLoop::QueuedEvent::QueuedEvent(QueuedEvent&& other) + : receiver(other.receiver) + , event(move(other.event)) +{ +} + +EventLoop::QueuedEvent::~QueuedEvent() +{ +} + } diff --git a/Libraries/LibCore/EventLoop.h b/Libraries/LibCore/EventLoop.h index 388b21310b..4d7807b2e9 100644 --- a/Libraries/LibCore/EventLoop.h +++ b/Libraries/LibCore/EventLoop.h @@ -26,23 +26,18 @@ #pragma once -#include <AK/Badge.h> +#include <AK/Forward.h> #include <AK/HashMap.h> #include <AK/OwnPtr.h> #include <AK/Vector.h> #include <AK/WeakPtr.h> -#include <LibCore/Event.h> -#include <LibCore/LocalServer.h> +#include <LibCore/Forward.h> +#include <LibCore/Object.h> #include <LibThread/Lock.h> -#include <sys/select.h> #include <sys/time.h> -#include <time.h> namespace Core { -class Object; -class Notifier; - class EventLoop { public: EventLoop(); @@ -87,6 +82,12 @@ private: void get_next_timer_expiration(timeval&); struct QueuedEvent { + AK_MAKE_NONCOPYABLE(QueuedEvent); + public: + QueuedEvent(Object& receiver, NonnullOwnPtr<Event>); + QueuedEvent(QueuedEvent&&); + ~QueuedEvent(); + WeakPtr<Object> receiver; NonnullOwnPtr<Event> event; }; diff --git a/Libraries/LibCore/Forward.h b/Libraries/LibCore/Forward.h new file mode 100644 index 0000000000..a639b18b4f --- /dev/null +++ b/Libraries/LibCore/Forward.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace Core { + +class ArgsParser; +class ChildEvent; +class ConfigFile; +class CustomEvent; +class DateTime; +class DirIterator; +class ElapsedTime; +class Event; +class EventLoop; +class File; +class HttpJob; +class HttpRequest; +class HttpResponse; +class IODevice; +class LocalServer; +class LocalSocket; +class MimeData; +class NetworkJob; +class NetworkResponse; +class Notifier; +class Object; +class ProcessStatisticsReader; +class Socket; +class SocketAddress; +class TCPServer; +class TCPSocket; +class TimerEvent; +class UdpServer; +class UdpSocket; + +enum class TimerShouldFireWhenNotVisible; + +} diff --git a/Libraries/LibCore/IODevice.cpp b/Libraries/LibCore/IODevice.cpp index 21a9140fcf..aef00b2c6d 100644 --- a/Libraries/LibCore/IODevice.cpp +++ b/Libraries/LibCore/IODevice.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/ByteBuffer.h> #include <AK/PrintfImplementation.h> #include <LibCore/IODevice.h> #include <LibCore/SyscallUtils.h> @@ -296,4 +297,10 @@ void IODevice::set_fd(int fd) m_fd = fd; did_update_fd(fd); } + +bool IODevice::write(const StringView& v) +{ + return write((const u8*)v.characters_without_null_termination(), v.length()); +} + } diff --git a/Libraries/LibCore/IODevice.h b/Libraries/LibCore/IODevice.h index 68b4d9782a..d9f2971769 100644 --- a/Libraries/LibCore/IODevice.h +++ b/Libraries/LibCore/IODevice.h @@ -26,8 +26,7 @@ #pragma once -#include <AK/ByteBuffer.h> -#include <AK/StringView.h> +#include <AK/Forward.h> #include <LibCore/Object.h> namespace Core { @@ -64,7 +63,7 @@ public: ByteBuffer read_all(); bool write(const u8*, int size); - bool write(const StringView& v) { return write((const u8*)v.characters_without_null_termination(), v.length()); } + bool write(const StringView&); // FIXME: I would like this to be const but currently it needs to call populate_read_buffer(). bool can_read_line(); diff --git a/Libraries/LibCore/LocalSocket.h b/Libraries/LibCore/LocalSocket.h index e5ea900b08..7d504cdae4 100644 --- a/Libraries/LibCore/LocalSocket.h +++ b/Libraries/LibCore/LocalSocket.h @@ -26,7 +26,6 @@ #pragma once -#include <AK/Badge.h> #include <LibCore/Socket.h> namespace Core { diff --git a/Libraries/LibCore/Notifier.cpp b/Libraries/LibCore/Notifier.cpp index 8dbe8f464b..7d39ae0e89 100644 --- a/Libraries/LibCore/Notifier.cpp +++ b/Libraries/LibCore/Notifier.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/Badge.h> #include <LibCore/Event.h> #include <LibCore/EventLoop.h> #include <LibCore/Notifier.h> diff --git a/Libraries/LibCore/Object.h b/Libraries/LibCore/Object.h index bc86be1350..60bf0a7628 100644 --- a/Libraries/LibCore/Object.h +++ b/Libraries/LibCore/Object.h @@ -26,19 +26,13 @@ #pragma once -#include <AK/Badge.h> -#include <AK/Function.h> +#include <AK/Forward.h> #include <AK/IntrusiveList.h> #include <AK/Noncopyable.h> #include <AK/NonnullRefPtrVector.h> -#include <AK/StdLibExtras.h> #include <AK/String.h> -#include <AK/Vector.h> #include <AK/Weakable.h> - -namespace AK { -class JsonObject; -} +#include <LibCore/Forward.h> namespace Core { @@ -47,12 +41,6 @@ enum class TimerShouldFireWhenNotVisible { Yes }; -class ChildEvent; -class CustomEvent; -class Event; -class EventLoop; -class TimerEvent; - #define C_OBJECT(klass) \ public: \ virtual const char* class_name() const override { return #klass; } \ diff --git a/Libraries/LibCore/Socket.cpp b/Libraries/LibCore/Socket.cpp index c2a5dc50e2..4810f1cd53 100644 --- a/Libraries/LibCore/Socket.cpp +++ b/Libraries/LibCore/Socket.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/ByteBuffer.h> #include <LibCore/Notifier.h> #include <LibCore/Socket.h> #include <arpa/inet.h> diff --git a/Libraries/LibCore/Socket.h b/Libraries/LibCore/Socket.h index 1b372e5be9..6523674b8c 100644 --- a/Libraries/LibCore/Socket.h +++ b/Libraries/LibCore/Socket.h @@ -26,6 +26,7 @@ #pragma once +#include <AK/Function.h> #include <LibCore/IODevice.h> #include <LibCore/SocketAddress.h> diff --git a/Libraries/LibCore/UdpServer.h b/Libraries/LibCore/UdpServer.h index 3e7e085bbf..a9a022459f 100644 --- a/Libraries/LibCore/UdpServer.h +++ b/Libraries/LibCore/UdpServer.h @@ -26,14 +26,13 @@ #pragma once -#include <AK/IPv4Address.h> -#include <LibCore/Notifier.h> +#include <AK/Forward.h> +#include <AK/Function.h> +#include <LibCore/Forward.h> #include <LibCore/Object.h> namespace Core { -class UdpSocket; - class UdpServer : public Object { C_OBJECT(UdpServer) public: diff --git a/Libraries/LibCore/UdpSocket.h b/Libraries/LibCore/UdpSocket.h index ad18a2312b..e5a4223e0e 100644 --- a/Libraries/LibCore/UdpSocket.h +++ b/Libraries/LibCore/UdpSocket.h @@ -26,7 +26,6 @@ #pragma once -#include <AK/Badge.h> #include <LibCore/Socket.h> namespace Core { diff --git a/Libraries/LibGUI/DragOperation.cpp b/Libraries/LibGUI/DragOperation.cpp index 6b10cb6841..81a1a8729d 100644 --- a/Libraries/LibGUI/DragOperation.cpp +++ b/Libraries/LibGUI/DragOperation.cpp @@ -24,9 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <LibGfx/Bitmap.h> +#include <AK/Badge.h> #include <LibGUI/DragOperation.h> #include <LibGUI/WindowServerConnection.h> +#include <LibGfx/Bitmap.h> namespace GUI { diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h index 7bd5003cce..625a02d960 100644 --- a/Libraries/LibGUI/Window.h +++ b/Libraries/LibGUI/Window.h @@ -26,14 +26,14 @@ #pragma once -#include <AK/Badge.h> +#include <AK/Function.h> #include <AK/HashMap.h> #include <AK/String.h> #include <AK/WeakPtr.h> #include <LibCore/Object.h> +#include <LibGUI/WindowType.h> #include <LibGfx/Bitmap.h> #include <LibGfx/Rect.h> -#include <LibGUI/WindowType.h> namespace GUI { diff --git a/Libraries/LibHTML/DOM/HTMLLinkElement.cpp b/Libraries/LibHTML/DOM/HTMLLinkElement.cpp index c96f123254..bf9e79ff68 100644 --- a/Libraries/LibHTML/DOM/HTMLLinkElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLLinkElement.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/ByteBuffer.h> #include <AK/URL.h> #include <LibCore/File.h> #include <LibHTML/DOM/Document.h> diff --git a/Libraries/LibIPC/ClientConnection.h b/Libraries/LibIPC/ClientConnection.h index 71836c8ed4..8e129d7416 100644 --- a/Libraries/LibIPC/ClientConnection.h +++ b/Libraries/LibIPC/ClientConnection.h @@ -26,6 +26,7 @@ #pragma once +#include <AK/ByteBuffer.h> #include <LibCore/Event.h> #include <LibCore/EventLoop.h> #include <LibCore/IODevice.h> diff --git a/Libraries/LibIPC/ServerConnection.h b/Libraries/LibIPC/ServerConnection.h index 05dcc0a875..8b74400dd9 100644 --- a/Libraries/LibIPC/ServerConnection.h +++ b/Libraries/LibIPC/ServerConnection.h @@ -26,6 +26,7 @@ #pragma once +#include <AK/ByteBuffer.h> #include <AK/NonnullOwnPtrVector.h> #include <LibCore/Event.h> #include <LibCore/EventLoop.h> diff --git a/Libraries/LibThread/BackgroundAction.h b/Libraries/LibThread/BackgroundAction.h index 62d41bdd36..0637fa71e4 100644 --- a/Libraries/LibThread/BackgroundAction.h +++ b/Libraries/LibThread/BackgroundAction.h @@ -30,6 +30,7 @@ #include <AK/NonnullRefPtr.h> #include <AK/Optional.h> #include <AK/Queue.h> +#include <LibCore/Event.h> #include <LibCore/EventLoop.h> #include <LibCore/Object.h> #include <LibThread/Lock.h> diff --git a/Servers/AudioServer/ASMixer.h b/Servers/AudioServer/ASMixer.h index d45b81529f..6e4d500f99 100644 --- a/Servers/AudioServer/ASMixer.h +++ b/Servers/AudioServer/ASMixer.h @@ -27,6 +27,7 @@ #pragma once #include "ASClientConnection.h" +#include <AK/Badge.h> #include <AK/ByteBuffer.h> #include <AK/NonnullRefPtrVector.h> #include <AK/Queue.h> diff --git a/Servers/LookupServer/main.cpp b/Servers/LookupServer/main.cpp index 37eddbcd45..d8f40e114b 100644 --- a/Servers/LookupServer/main.cpp +++ b/Servers/LookupServer/main.cpp @@ -26,6 +26,7 @@ #include "LookupServer.h" #include <LibCore/EventLoop.h> +#include <LibCore/LocalServer.h> #include <stdio.h> int main(int argc, char** argv) diff --git a/Servers/SystemServer/main.cpp b/Servers/SystemServer/main.cpp index e03686fc51..00f02d3e95 100644 --- a/Servers/SystemServer/main.cpp +++ b/Servers/SystemServer/main.cpp @@ -26,7 +26,9 @@ #include "Service.h" #include <AK/Assertions.h> +#include <AK/ByteBuffer.h> #include <LibCore/ConfigFile.h> +#include <LibCore/Event.h> #include <LibCore/EventLoop.h> #include <LibCore/File.h> #include <errno.h> diff --git a/Userland/dmesg.cpp b/Userland/dmesg.cpp index 013bb74c17..f116e3a3c5 100644 --- a/Userland/dmesg.cpp +++ b/Userland/dmesg.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/ByteBuffer.h> #include <LibCore/File.h> #include <assert.h> #include <fcntl.h> diff --git a/Userland/html.cpp b/Userland/html.cpp index 5e0594763a..67ae7a89f1 100644 --- a/Userland/html.cpp +++ b/Userland/html.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/ByteBuffer.h> #include <LibCore/File.h> #include <LibGUI/AboutDialog.h> #include <LibGUI/Action.h> diff --git a/Userland/man.cpp b/Userland/man.cpp index 528b41bb72..1c31ddce5b 100644 --- a/Userland/man.cpp +++ b/Userland/man.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/ByteBuffer.h> #include <AK/String.h> #include <LibCore/File.h> #include <LibMarkdown/MDDocument.h> diff --git a/Userland/md.cpp b/Userland/md.cpp index 49f938590e..50297ba47a 100644 --- a/Userland/md.cpp +++ b/Userland/md.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/ByteBuffer.h> #include <AK/String.h> #include <LibCore/File.h> #include <LibMarkdown/MDDocument.h> @@ -45,7 +46,8 @@ int main(int argc, char* argv[]) else file_name = argv[i]; - auto file = Core::File::construct();; + auto file = Core::File::construct(); + ; bool success; if (file_name == nullptr) { success = file->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescription::No); diff --git a/Userland/tail.cpp b/Userland/tail.cpp index 2d0acde35b..72d92ab991 100644 --- a/Userland/tail.cpp +++ b/Userland/tail.cpp @@ -25,6 +25,7 @@ */ #include <AK/Assertions.h> +#include <AK/ByteBuffer.h> #include <LibCore/ArgsParser.h> #include <LibCore/File.h> #include <errno.h> |