Commit Graph

63 Commits

Author SHA1 Message Date
Andreas Kling
ab8891c064 LibCore: Initialize pid/id variables in CoreIPC{Client,Server}
Also rename CoreIPCServer::m_pid to m_client_pid for clarification.

Found by PVS-Studio.
2019-08-01 11:42:30 +02:00
Andreas Kling
caeb4b7a7e CEventLoop: Add a missing initializer to EventLoopTimer. 2019-08-01 10:49:31 +02:00
Andreas Kling
385e9268f4 CIODevice: printf() thought it was calling ::write() but it was write()
There's some confusion between the write syscall and CIODevice::write()
here. The internal write() returns a boolean, and has already whined
in case the syscall failed, so we don't need to do that again.
2019-08-01 10:41:04 +02:00
Andreas Kling
0f3d191a70 LibCore: Rename CFileStreamReader => CIODeviceStreamReader. 2019-07-30 15:16:39 +02:00
Andreas Kling
e6db1b81b8 AudioServer: Begin work on a new IPC API style.
The goal here is to generate most of this code from IPC protocol
descriptions, but for now I've spelled them all out to get started.

Each message gets a wrapper class in the ASAPI_Client or ASAPI_Server
namespace. They are convertible to and from the old message structs.

The real hotness happens when you want to make a synchronous request
to the other side:

    auto response = send_sync<ASAPI_Client::GetMainMixVolume>();

Each request class knows his corresponding response class, so in the
above example, "response" will be an ASAPI_Server::DidGetMainMixVolume
object, and we can get the volume like so:

    int volume = response.volume();

For posting messages that don't expect a response, you can still use
post_message() since the message classes are convertible:

    post_message(ASAPI_Server::DidGetMainMixVolume(volume));

It's not perfect yet, but I already really like it. :^)
2019-07-29 22:39:20 +02:00
Andreas Kling
5ded77df39 Kernel+ProcessManager: Let processes have an icon and show it in the table.
Processes can now have an icon assigned, which is essentially a 16x16 RGBA32
bitmap exposed as a shared buffer ID.

You set the icon ID by calling set_process_icon(int) and the icon ID will be
exposed through /proc/all.

To make this work, I added a mechanism for making shared buffers globally
accessible. For safety reasons, each app seals the icon buffer before making
it global.

Right now the first call to GWindow::set_icon() is what determines the
process icon. We'll probably change this in the future. :^)
2019-07-29 07:26:01 +02:00
Andreas Kling
a292d8cd5a LibCore: Add CFileStreamReader, a simple streaming CFile reader.
This is extremely barebones right now, but can be used to easily read binary
data from a CFile piece by piece.
2019-07-27 16:38:44 +02:00
Andreas Kling
9ed7f4576b CIODevice: Try to preallocate the exact needed buffer size in read_all().
If we can get the exact file size from fstat(), it's a very good idea to use
it since it means we avoid eleventy thousand reallocations.
2019-07-27 14:24:19 +02:00
Andreas Kling
e7957db173 LibCore: Remove CSocket's bind() and listen().
We're going to be using dedicated server socket classes instead.
This was only implemented for CLocalSocket, and clients have been switched
over to using CLocalServer.
2019-07-27 10:58:21 +02:00
Andreas Kling
fe45f5a6d2 LibCore: Port CoreIPCServer to using CLocalServer.
Use CLocalServer to listen for connections in WindowServer and AudioServer.
This allows us to accept incoming CLocalSocket objects from the CLocalServer
and construct client connections based on those.

Removed COpenedSocket since it's replaced by CLocalSocket.
2019-07-27 10:53:50 +02:00
Andreas Kling
c289e49ee5 LibCore: Use clang-format on CoreIPC{Client,Server}. 2019-07-27 10:50:26 +02:00
Andreas Kling
82446ea701 CSocket: Add an on_ready_to_read callback.
This callback uses a CNotifier internally and will fire whenever there's
something to be read from the socket.
2019-07-27 10:48:43 +02:00
Andreas Kling
8f4fba95c0 CIODevice: Add a virtual did_update_fd() no notify subclasses of fd change.
This will allow subclasses to react when the file descriptor changes.
2019-07-27 10:47:46 +02:00
Andreas Kling
b3fe9cde52 LibCore: Add CLocalServer, a server-only local socket class.
Instead of trying to support both client and server in CLocalSocket, let's
have a specialized server class.

The basic usage is:

    CLocalServer server;
    server.listen("/tmp/name-of-portal");
    server.on_ready_to_accept = [&] {
        CLocalSocket* client = server.accept();
        ...
    };

This will make things a lot simpler, since an accepting socket doesn't need
half of the stuff that a regular CIODevice provides. :^)
2019-07-27 10:32:40 +02:00
Andreas Kling
10c35d345a LibCore: Add comment about child events for partially-constructed children.
Since ChildAdded events originate from the CObject constructor, they are not
fully constructed when their parent learns that they were added.
Added a little comment about this to the child_event() declaration.
2019-07-27 09:31:46 +02:00
Andreas Kling
be2b585ca6 LibCore: Add CSocket::bind() (virtual) and CSocket::listen().
These will be useful for implementing server sockets.
2019-07-26 22:39:16 +02:00
Andreas Kling
7da5a04131 CEventLoop: Convert dbgprintf() to dbg(). 2019-07-26 16:00:56 +02:00
Andreas Kling
a599317624 LibCore: Introduce a C_OBJECT macro.
This macro goes at the top of every CObject-derived class like so:

class SomeClass : public CObject {
    C_OBJECT(SomeClass)
public:
    ...

At the moment, all it does is create an override for the class_name() getter
but in the future this will be used to automatically insert member functions
into these classes.
2019-07-25 19:49:28 +02:00
Andreas Kling
d21a4f7518 CEventLoop: Don't re-process already processed events when un-nesting.
If we had already processed a couple of queued events by the time we were
told to un-nest the event loop, we'd put the entire current batch at the
head of the outer queue. This meant that we might end up trying to process
the same events multiple times.

Let's not do that. :^)
2019-07-25 16:12:51 +02:00
Andreas Kling
f46a1377ac CSocket: Add missing <sys/un.h> include to fix host build. 2019-07-25 11:49:08 +02:00
Andreas Kling
16bcaf08a3 CSocket: Fix Clang warning about unused private member m_type. 2019-07-25 11:48:21 +02:00
Andreas Kling
e940d4b07b LibCore: Only build CThread on Serenity platforms. 2019-07-25 11:47:53 +02:00
Andreas Kling
1d0b464618 AK: Make HashMap::get(Key) return an Optional<Value>.
This allows HashMap::get() to be used for value types that cannot be default
constructed (e.g NonnullOwnPtr.)
2019-07-24 10:25:43 +02:00
Andreas Kling
93489fbc4c Convert HashMap<Key, OwnPtr<T>> to HashMap<Key, NonnullOwnPtr<T>>.
In every case I found, we never wanted to support null entry values.
With NonnullOwnPtr, we can encode that at the type level. :^)
2019-07-24 08:42:55 +02:00
Andreas Kling
3c5befde36 CEventLoop: Use NonnullOwnPtr for QueuedEvent::event.
We don't allow null events in the event queue. :^)
2019-07-24 08:38:28 +02:00
Andreas Kling
66646081b7 CEventLoop: Avoid undefined evaluation order in register_timer(). 2019-07-23 14:55:12 +02:00
Andreas Kling
0ef13e60b0 Libraries: Fix wrong paths to "Root" in the various install.sh scripts.
We were installing libraries into /Libraries/Root, rather than in /Root.
This made the ports system behave rather unpredictable, since I had old
versions of things in /Root and new versions of things in /Libraries/Root.
2019-07-21 21:38:30 +02:00
Andreas Kling
c7ea94697e Libraries: Remove unused "install" targets.
We've been using a per-directory "install.sh" for some time, so let's get
rid of the old way of doing things.
2019-07-21 21:28:48 +02:00
Robin Burchell
f2c0e55070 Userspace: Deal with select() returning EINTR on a signal interruption
Add a trivial CSafeSyscall template that calls a callback until it stops
returning EINTR, and use it everywhere we use select() now.

Thanks to Andreas for the suggestion of using a template parameter for
the syscall function to invoke.
2019-07-21 14:27:14 +02:00
Andreas Kling
98b569a702 CEventLoop: Skip over null events in the queue.
Added some FIXME's about correctness issues in nested event loop exiting.
2019-07-21 10:18:00 +02:00
Andreas Kling
046f00f77e CEventLoop: Use Vector::prepend(Vector&&) to shuffle events to outer loop.
When exiting a nested event loop, we prepend any unprocessed events to the
outer loop's event queue.
2019-07-20 16:11:45 +02:00
Andreas Kling
26c29e59ec CEventLoop: Remove some no-longer-used virtuals. 2019-07-20 15:50:03 +02:00
Andreas Kling
1c0669f010 LibDraw: Introduce (formerly known as SharedGraphics.)
Instead of LibGUI and WindowServer building their own copies of the drawing
and graphics code, let's it in a separate LibDraw library.

This avoids building the code twice, and will encourage better separation
of concerns. :^)
2019-07-18 10:18:16 +02:00
Robin Burchell
57da716be0 ps: Port to using CProcessStatisticsReader and /proc/all
Drop /proc/summary in the process.
We only needed one new field here, thankfully, so this was quite straightforward.
2019-07-18 07:23:26 +02:00
Robin Burchell
a9d1a86e6e CProcessStatisticsReader: Be consistent about terminology from the kernel down 2019-07-18 07:23:26 +02:00
Robin Burchell
9c8dd836fc Rename new IPC headers & classes
Sticking these in a namespace allows us to use a more generic
("Connection") term without clashing, which is way easier to understand
than to try to come up with unique names for both.
2019-07-17 20:16:44 +02:00
Robin Burchell
2177594c96 Port LibGUI to use CIPCClientSideConnection
As a consequence, move to use an explicit handshake() method rather than
calling virtuals from the constructor. This seemed to not bother
AClientConnection, but LibGUI crashes (rightfully) because of it.
2019-07-17 20:16:44 +02:00
Robin Burchell
41bece0682 Make AClientConnection generic 2019-07-17 20:16:44 +02:00
Robin Burchell
6eaa6826fa Port WSClientConnection to CIPCServerSideClient 2019-07-17 20:16:44 +02:00
Robin Burchell
edcbba9e98 Introduce CIPCServerSideClient
As a new base class of IPC connections server-side.
Port ASClientConnection to CIPCServerSideClient.
2019-07-17 20:16:44 +02:00
Robin Burchell
d8387f1506 CNotifier: Turn into a CObject and Use the event queue to deliver events
This way, CNotifier can mutate state to its little heart's content
without destroying the world when the global CNotifier hash changes
during delivery.
2019-07-16 20:47:32 +02:00
Robin Burchell
a714fc661d LibCore: Add a way to mark a socket as blocking (or not)
If custom I/O is being done outside CIODevice, we need a way to force blocking sometimes.
This also fixes the default of CLocalSocket to be non-blocking, the same
as CTCPSocket.
2019-07-16 20:22:54 +02:00
Robin Burchell
7bf420d83d CNotifier: Provide a way to unregister a notifier temporarily 2019-07-16 15:23:57 +02:00
Robin Burchell
e922db68d8 CSocket: Also call on_connected for local socket connections 2019-07-16 13:18:37 +02:00
Robin Burchell
14b2f90920 LibCore: Always call on_connected whether the connection was synchronous or not
It's unreasonable to expect the client to have to call it themselves if
the connection was immediate (local).
2019-07-16 13:18:37 +02:00
Robin Burchell
cd497accbe CLocalSocket: Add missing pragma once 2019-07-14 15:29:59 +02:00
Andreas Kling
e8d61bb8c0 CEventLoop: Oops, I had the pipe reader/writer fd's mixed up. 2019-07-14 14:28:24 +02:00
Andreas Kling
4c0c93ce09 LibCore: Oops, fix infinite recursion in LogStream << CSocketAddress. 2019-07-14 14:24:37 +02:00
Andreas Kling
c9ee481cdf LibCore: Port CSocket over to using dbg().
Also added a LogStream operator<< for CSocketAddress.
2019-07-14 11:02:40 +02:00
Andreas Kling
b4329a8eec CObject: Add LogStream operator<< for CObject. 2019-07-14 10:59:26 +02:00