pub struct Registry {
items: RwLock<FixedVec<RegistryItem>>,
counter: AtomicU32,
service_added: WaitQueue,
}
Expand description
The driver registry used by the kernel.
Fields§
§items: RwLock<FixedVec<RegistryItem>>
§counter: AtomicU32
§service_added: WaitQueue
Implementations§
source§impl Registry
impl Registry
sourcepub fn new(max_items: usize) -> Self
pub fn new(max_items: usize) -> Self
Create a new registry with room for up to max_items
registered drivers.
sourcepub async fn bind_konly<RD>(
&self,
capacity: usize,
) -> Result<Listener<RD>, RegistrationError>where
RD: RegisteredDriver,
pub async fn bind_konly<RD>(
&self,
capacity: usize,
) -> Result<Listener<RD>, RegistrationError>where
RD: RegisteredDriver,
Bind a kernel-only Listener
for a driver service of type RD
.
This is a helper method which creates a Listener
using
Listener::new
and then registers that Listener
’s
listener::Registration
with the registry using
Registry::register_konly
.
Driver services registered with Registry::bind_konly
can NOT be queried
or interfaced with from Userspace. If a registered service has request
and response types that are serializable, it can instead be registered
with Registry::bind
which allows for userspace access.
sourcepub async fn bind<RD>(
&self,
capacity: usize,
) -> Result<Listener<RD>, RegistrationError>where
RD: RegisteredDriver + 'static,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
pub async fn bind<RD>(
&self,
capacity: usize,
) -> Result<Listener<RD>, RegistrationError>where
RD: RegisteredDriver + 'static,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
Bind a Listener
for a driver service of type RD
.
This is a helper method which creates a Listener
using
Listener::new
and then registers that Listener
’s
listener::Registration
with the registry using
Registry::register
.
Driver services registered with Registry::bind
can be accessed both
by the kernel and by userspace. This requires that the
RegisteredDriver
’s message types implement Serialize
and
DeserializeOwned
. Driver services whose message types are not
serializable may still bind listeners using Registry::bind_konly
,
but these listeners will not be accessible from userspace.
sourcepub async fn register_konly<RD: RegisteredDriver>(
&self,
registration: Registration<RD>,
) -> Result<(), RegistrationError>
pub async fn register_konly<RD: RegisteredDriver>( &self, registration: Registration<RD>, ) -> Result<(), RegistrationError>
Register a driver service ONLY for use in the kernel, including drivers.
Driver services registered with Registry::register_konly can NOT be queried or interfaced with from Userspace. If a registered service has request and response types that are serializable, it can instead be registered with Registry::register which allows for userspace access.
sourcepub async fn register<RD>(
&self,
registration: Registration<RD>,
) -> Result<(), RegistrationError>where
RD: RegisteredDriver + 'static,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
pub async fn register<RD>(
&self,
registration: Registration<RD>,
) -> Result<(), RegistrationError>where
RD: RegisteredDriver + 'static,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
Register a driver service for use in the kernel (including drivers) as well as in userspace.
See Registry::register_konly if the request and response types are not serializable.
sourcepub async fn try_connect<RD: RegisteredDriver>(
&self,
hello: RD::Hello,
) -> Result<KernelHandle<RD>, ConnectError<RD>>
pub async fn try_connect<RD: RegisteredDriver>( &self, hello: RD::Hello, ) -> Result<KernelHandle<RD>, ConnectError<RD>>
Attempt to get a kernelspace (including drivers) handle of a given driver service,
which does not require sending a RegisteredDriver::Hello
message.
This can be used by drivers and tasks to interface with a registered driver service.
The driver service MUST have already been registered using Registry::register or
Registry::register_konly prior to making this call, otherwise no handle will
be returned. To wait until a driver is registered, use
Registry::connect
instead.
§Returns
-
Ok
(
[KernelHandle]
)` if the requested service was found and a connection was successfully established. -
Ok
(
[KernelHandle]
)` if the requested service was found and a connection was successfully established. -
Err
(
ConnectError::Rejected
)
if the service rejected the incoming connection. -
Err
(
ConnectError::DriverDead
)
if the service has been registered but is no longer running. -
Err
(
ConnectError::NotFound
)
if no service matching the requestedRegisteredDriver
type exists in the registry.
sourcepub async fn connect<RD>(
&self,
hello: RD::Hello,
) -> Result<KernelHandle<RD>, ConnectError<RD>>where
RD: RegisteredDriver,
pub async fn connect<RD>(
&self,
hello: RD::Hello,
) -> Result<KernelHandle<RD>, ConnectError<RD>>where
RD: RegisteredDriver,
Get a kernelspace (including drivers) handle of a given driver service, waiting until the service is registered if it does not already exist.
This can be used by drivers and tasks to interface with a registered driver service.
If no service matching the requested RegisteredDriver
type has been
registered, this method will wait until that service is added to the
registry, unless the registry becomes full.
§Returns
-
Ok
(
[KernelHandle]
)` if the requested service was found and a connection was successfully established. -
Err
(
ConnectError::Rejected
)
if the service rejected the incoming connection. -
Err
(
ConnectError::DriverDead
)
if the service has been registered but is no longer running. -
Err
(
ConnectError::NotFound
)
if no service matching the requestedRegisteredDriver
type exists and the registry was full.
sourcepub async fn connect_userspace<RD>(
&self,
scheduler: &LocalScheduler,
user_hello: &[u8],
) -> Result<UserspaceHandle, UserConnectError<RD>>where
RD: RegisteredDriver,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
pub async fn connect_userspace<RD>(
&self,
scheduler: &LocalScheduler,
user_hello: &[u8],
) -> Result<UserspaceHandle, UserConnectError<RD>>where
RD: RegisteredDriver,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
Get a kernelspace (including drivers) handle of a given driver service, waiting until the service is registered if it does not already exist.
This can be used by drivers and tasks to interface with a registered driver service.
§Returns
-
Ok
(
[KernelHandle]
)` if the requested service was found and a connection was successfully established. -
Err
(
ConnectError
)
if the requested service was not found in the registry, or if the service rejected the incoming connection. Note thatConnectError::NotFound
is not returned unless the registry is full and no more services will be added.
sourcepub async fn try_connect_userspace<RD>(
&self,
scheduler: &LocalScheduler,
user_hello: &[u8],
) -> Result<UserspaceHandle, UserConnectError<RD>>where
RD: RegisteredDriver,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
pub async fn try_connect_userspace<RD>(
&self,
scheduler: &LocalScheduler,
user_hello: &[u8],
) -> Result<UserspaceHandle, UserConnectError<RD>>where
RD: RegisteredDriver,
RD::Hello: Serialize + DeserializeOwned,
RD::ConnectError: Serialize + DeserializeOwned,
RD::Request: Serialize + DeserializeOwned,
RD::Response: Serialize + DeserializeOwned,
Try to get a handle capable of processing serialized userspace messages to a
registered driver service, given a byte buffer for the userspace
RegisteredDriver::Hello
message.
The driver service MUST have already been registered using Registry::register or prior to making this call, otherwise no handle will be returned.
Driver services registered with Registry::register_konly
cannot be
retrieved via a call to Registry::try_connect_userspace
.