mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
RequestServer: Transfer ownership of Protocols to all_protocols map
It's no change in application behavior to have these objects owned by the function-scope static map in Protocol.cpp, while allowing us to remove some ugly FIXMEs from time immemorial.
This commit is contained in:
parent
5b69413c4b
commit
4dd2ec68fc
11 changed files with 55 additions and 36 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <RequestServer/Protocol.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -13,26 +14,20 @@
|
|||
|
||||
namespace RequestServer {
|
||||
|
||||
static HashMap<ByteString, Protocol*>& all_protocols()
|
||||
static HashMap<ByteString, NonnullOwnPtr<Protocol>>& all_protocols()
|
||||
{
|
||||
static HashMap<ByteString, Protocol*> map;
|
||||
static HashMap<ByteString, NonnullOwnPtr<Protocol>> map;
|
||||
return map;
|
||||
}
|
||||
|
||||
Protocol* Protocol::find_by_name(ByteString const& name)
|
||||
{
|
||||
return all_protocols().get(name).value_or(nullptr);
|
||||
return all_protocols().get(name).map([](auto& p) -> Protocol* { return p; }).value_or(nullptr);
|
||||
}
|
||||
|
||||
Protocol::Protocol(ByteString const& name)
|
||||
: m_name(name)
|
||||
{
|
||||
all_protocols().set(name, this);
|
||||
}
|
||||
|
||||
Protocol::~Protocol()
|
||||
{
|
||||
// FIXME: Do proper de-registration.
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<Protocol::Pipe> Protocol::get_pipe_for_request()
|
||||
|
@ -47,4 +42,10 @@ ErrorOr<Protocol::Pipe> Protocol::get_pipe_for_request()
|
|||
return Pipe { fd_pair[0], fd_pair[1] };
|
||||
}
|
||||
|
||||
void Protocol::install(NonnullOwnPtr<Protocol> protocol)
|
||||
{
|
||||
auto name = protocol->name();
|
||||
all_protocols().set(move(name), move(protocol));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue