ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxxm
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/sys/service.cxxm
3/// @brief Service registry — lightweight name-to-capability directory for
4/// the DGP kernel's service discovery model.
5
6export module zxfoundation.sys.service.core;
7import zxfoundation.base.types;
8import zxfoundation.scoms.kobject.base;
9import zxfoundation.memory.objects;
10import zxfoundation.dgp.cap.types;
11import lib.error;
12import lib.stl;
13
14#define __zxmacro_want_assert
15#include macro_extensions
16
17export {
18
19namespace zxfoundation::sys::service {
20
21 /// @brief Maximum number of services that can be registered simultaneously.
22 constexpr u32 MAX_SERVICES = 64;
23
24 /// @brief Maximum length of a service name, including NUL terminator.
25 constexpr u32 SERVICE_NAME_MAX_LEN = 64;
26
27 /// @brief A single entry in the service registry.
28 struct service_entry {
29 scoms::kobject::bobject ko{};
30 char name[SERVICE_NAME_MAX_LEN]{};
31 dgp::cap::cap_token token{};
32 memory::objects::memory_object_ref authority{};
33
34 service_entry() noexcept = default;
35 };
36 assert_offset(service_entry, ko, 0);
37
38 /// @brief Initialize the service registry.
39 auto init() noexcept -> void;
40
41 /// @brief Remove service entries owned by a domain entering teardown.
42 auto destroy_for_domain(u32 domain_id) noexcept -> void;
43
44 auto register_service_cap_lookup() noexcept -> void;
45
46 /// @brief Register a service.
47 /// @param[in] name Service name (max 63 chars).
48 /// @param[in] token Capability token for the service.
49 /// @param[in] owner_id Domain ID of the registering domain.
50 /// @return service_id on success, kernel_error on failure.
51 [[nodiscard]] auto register_service(
52 std::string_view name,
53 dgp::cap::cap_token token,
54 u32 owner_id
55 ) noexcept -> std::expected<u32, lib::kernel_error>;
56
57 /// @brief Look up a service by name.
58 /// @param[in] name NUL-terminated service name.
59 /// @return Capability token on success, kernel_error if not found.
60 /// @note The returned token is a new capability acquired from the
61 /// registry entry.
62 [[nodiscard]] auto lookup_service(
63 std::string_view name,
64 u32 caller_id
65 ) noexcept -> std::expected<dgp::cap::cap_token, lib::kernel_error>;
66
67 /// @brief Unregister a service.
68 /// @param[in] service_id The service ID returned by register_service.
69 /// @param[in] caller_id Domain ID of the caller (must match owner).
70 /// @return Success, or kernel_error if not found / wrong owner.
71 [[nodiscard]] auto unregister_service(
72 u32 service_id,
73 u32 caller_id
74 ) noexcept -> std::expected<void, lib::kernel_error>;
75
76 /// @brief Return the number of currently registered services.
77 [[nodiscard]] auto service_count() noexcept -> u32;
78
79} // namespace zxfoundation::sys::service
80
81} // end export