Commit Graph

95 Commits

Author SHA1 Message Date
Andreas Kling
fcc3745b02 LibCore+LibGUI+WindowServer: Make events bubble up through ancestors
With this patch, CEvents no longer stop at the target object, but will
bubble up the ancestor chain as long as CEvent::is_accepted() is false.

To the set accepted flag, call CEvent::accept().
To clear the accepted flag, call CEvent::ignore().

Events start out in the accepted state, so if you want them to bubble
up, you have to call ignore() on them.

Using this mechanism, we now ignore non-tabbing keydown events in
GWidget, causing them to bubble up through the widget's ancestors. :^)
2019-09-20 20:37:31 +02:00
Andreas Kling
d1bacb9885 LibCore: Convert CNotifier to ObjectPtr 2019-09-20 15:39:15 +02:00
Andreas Kling
50a6560413 LibCore: Convert CTimer to ObjectPtr 2019-09-20 15:20:10 +02:00
Andreas Kling
c34fd10b5b LibCore: Introduce ObjectPtr, a step towards reference-counted CObject
Long-term we should use reference counting for the CObject hierarchy.
Since we've already accumulated a fair amount of code, this is quite a
large task, so I'm breaking it into some steps.

So, ObjectPtr is a "smart" pointer for CObject-derived types.
It becomes null when moved from, and will destroy unparented CObjects
in its destructor.

The idea here is to convert the codebase over to ObjectPtr piece by
piece, and then when everything is moved and CObject itself refactored
for ref-counting, we can just replace ObjectPtr with RefPtr everywhere.
2019-09-20 15:19:11 +02:00
Andreas Kling
f89944e804 Inspector+LibCore+rpcdump: Rework the RPC stuff to be request/response
RPC clients now send JSON-encoded requests to the RPC server.
The connection also stays alive instead of disconnecting automatically
after the initial CObject graph dump.

JSON payloads are preceded by a single host-order encoded 32-bit int
containing the length of the payload.

So far, we have three RPC commands:

    - Identify
    - GetAllObjects
    - Disconnect

We'll be adding more of these as we go along. :^)
2019-09-11 21:19:23 +02:00
Andreas Kling
38b75d2a97 CIODevice: read(u8*, int) overload should return 0 on EOF 2019-09-11 21:13:14 +02:00
Andreas Kling
99970d7d4b CSocket: Share code between connect() overloads
Both overloads should know how to set up a notifier callback in case
we get EINPROGRESS from connect().

It might be even better to merge the connect() overloads into a single
function..
2019-09-11 19:44:15 +02:00
Andreas Kling
b305a51c90 CIODevice: read_all() should return a null ByteBuffer when nothing read
We were returning a zero-length ByteBuffer in some cases. We should be
consistent about this and always return a null ByteBuffer if nothing
was read at all.
2019-09-11 19:33:51 +02:00
Andreas Kling
73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00
Andreas Kling
16de02cce0 CIODevice: Add is_open() 2019-09-04 15:13:55 +02:00
Sergey Bugaev
3439a479af LibThread: Move CLock to LibThread::Lock
And adapt all the code that uses it.
2019-08-26 11:31:14 +02:00
Sergey Bugaev
0826cc5a35 LibCore: Remove CThread
It's been replaced with Thread::Thread.
2019-08-26 11:31:14 +02:00
Andreas Kling
c2213449c0 LibCore: Move CObject serialization into CObject::save_to(JsonObject&)
The idea is for subclasses to override this and add whatever properties
are relevant for them, then call up to their base class, etc.
2019-08-19 16:34:53 +02:00
Andreas Kling
8aa3b74f80 LibCore: Make it possible to pass a parent to CFile constructors 2019-08-18 12:55:56 +02:00
Andreas Kling
fc6bd52e0d LibCore: Childify children of CLocalServer and IPC::Connection
Inspecting a "TextEditor" process with Inspector now looks awesome. :^)
2019-08-18 12:15:06 +02:00
Andreas Kling
1b3599fbbc LibCore: Make CSocket's notifiers into children of the CSocket
The Inspector app quickly exposes crappy flat object hiearchies without
parent/child relationships. This is one of many commits that improves
the situation by making parent/child CObject relationships explicit.
2019-08-18 11:54:39 +02:00
Sergey Bugaev
e0e1be8c33 LibCore: Fix a crash in CArgsParser 2019-08-17 12:07:55 +02:00
Andreas Kling
1febd59f83 LibCore+rpcdump: Publish CObject graph to on-demand RPC socket
All programs that have a CEventLoop now allow local socket connections
via /tmp/rpc.PID and will dump a serialized JSON array of all the live
CObjects in the program onto connecting sockets.

Also added a small /bin/rpcdump tool that connects to an RPC socket and
produces a raw dump of the JSON that comes out.
2019-08-17 11:39:26 +02:00
Andreas Kling
2fa2d72761 CObject: Put all CObjects on a global IntrusiveList for introspection
This will allow us to easily traverse the entire CObject graph.
2019-08-17 11:26:19 +02:00
Andreas Kling
7127c4fdbb LibCore: CIODevice::set_error() is meant to be called with the 'errno'
The point of this function is to stash away the innermost error code
so that we don't lose it by the time we get back to the client code.
2019-08-17 11:07:15 +02:00
Andreas Kling
ee83b1bcf4 LibCore: Use URL in CHttpRequest
Now there's just CHttpRequest::set_url(URL), no need to specify the
host, port and path manually anymore.

Updated ChanViewer and Downloader for the API change.
2019-08-10 19:32:03 +02:00
Conrad Pankoff
da615e46cd LibCore: Initialise m_port as zero in CSocketAddress 2019-08-06 15:06:20 +02:00
Sergey Bugaev
211b51dab7 CEventLoop: Create the wake pipe with O_CLOEXEC
This ensures the pipe fds don't leak into child processes.
This manifested as the Shell (and all processes started
from the shell) having two mysterious FIFOs open. This
was happening because of the Terminal, which the shell
was spawned form, leaking its CEventLoop wake pipe fds.
2019-08-05 16:04:31 +02:00
Conrad Pankoff
ed66f1d6d4 LibCore: Add CTCPServer
This is pretty much a find/replace copy of CLocalServer, and some
modifications to CTCPSocket and CSocketAddress to support it.
2019-08-05 12:53:07 +02:00
Andreas Kling
54ed6a888d LibCore: Move CHttpJob and CNetworkJob output to the right places
Errors go to stderr, debug output goes to the debug console. :^)
2019-08-04 22:10:54 +02:00
Andreas Kling
948c2657d6 CSocket: Close the underlying socket on destruction
Otherwise we leak the file descriptor.
2019-08-04 22:02:25 +02:00
Andreas Kling
b5aac9c44b CHttpJob: Drive response download via on_ready_read instead of blocking
This allows the event loop to service events while an HTTP download is
happening. Pretty cool :^)
2019-08-04 18:59:06 +02:00
Andreas Kling
a8740f82eb CHttpJob: Collect the payload as a list of buffers during download
Instead of growing the payload buffer as-we-go. This avoids wasting a
ton of time on buffer reallocation for non-trivial payloads.
2019-08-04 14:54:25 +02:00
Andreas Kling
273d9d6cf5 CHttpJob: If no "Content-Length" header was received, read until EOF
Instead of aborting after receiving the first chunk, we have to keep
reading until EOF.
2019-08-04 09:26:08 +02:00
Andreas Kling
8e684f0959 AudioServer: Port to the new generated IPC mechanism
Fork the IPC Connection classes into Server:: and Client::ConnectionNG.
The new IPC messages are serialized very snugly instead of using the
same generic data structure for all messages.

Remove ASAPI.h since we now generate all of it from AudioServer.ipc :^)
2019-08-03 19:49:19 +02:00
Andreas Kling
7f25959fa2 LibCore: Make get_current_user_home_path() return String & close passwd
This API was returning a "const char*" and it was unclear who took care
of the underlying memory. Returning a String makes that obvious.

Also make sure we close the /etc/passwd file when we're done with it.
2019-08-03 08:32:07 +02:00
Andreas Kling
3f91d2d0cc CEventLoop: Devirtualize take_pending_events_from(CEventLoop) 2019-08-02 13:58:55 +02:00
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