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 std;
13
14export {
15
16namespace zxfoundation::sys::service {
17
18 /// @brief Maximum number of services that can be registered simultaneously.
19 constexpr u32 MAX_SERVICES = 64;
20
21 /// @brief Maximum length of a service name, including NUL terminator.
22 constexpr u32 SERVICE_NAME_MAX_LEN = 64;
23
24 /// @brief A single entry in the service registry.
25 struct service_entry {
26 scoms::kobject::bobject ko{};
27 char name[SERVICE_NAME_MAX_LEN]{};
28 dgp::cap::cap_token token{};
29 memory::objects::memory_object_ref authority{};
30
31 service_entry() noexcept = default;
32 };
33 assert_offset(service_entry, ko, 0);
34
35 /// @brief Initialize the service registry.
36 auto init() noexcept -> void;
37
38 /// @brief Remove service entries owned by a domain entering teardown.
39 auto destroy_for_domain(u32 domain_id) noexcept -> void;
40
41 auto register_service_cap_lookup() noexcept -> void;
42
43 /// @brief Register a service.
44 /// @param[in] name Service name (max 63 chars).
45 /// @param[in] token Capability token for the service.
46 /// @param[in] owner_id Domain ID of the registering domain.
47 /// @return service_id on success, kernel_error on failure.
48 [[nodiscard]] auto register_service(
49 std::string_view name,
50 dgp::cap::cap_token token,
51 u32 owner_id
52 ) noexcept -> std::expected<u32, lib::kernel_error>;
53
54 /// @brief Look up a service by name.
55 /// @param[in] name NUL-terminated service name.
56 /// @return Capability token on success, kernel_error if not found.
57 /// @note The returned token is a new capability acquired from the
58 /// registry entry.
59 [[nodiscard]] auto lookup_service(
60 std::string_view name,
61 u32 caller_id
62 ) noexcept -> std::expected<dgp::cap::cap_token, lib::kernel_error>;
63
64 /// @brief Unregister a service.
65 /// @param[in] service_id The service ID returned by register_service.
66 /// @param[in] caller_id Domain ID of the caller (must match owner).
67 /// @return Success, or kernel_error if not found / wrong owner.
68 [[nodiscard]] auto unregister_service(
69 u32 service_id,
70 u32 caller_id
71 ) noexcept -> std::expected<void, lib::kernel_error>;
72
73 /// @brief Return the number of currently registered services.
74 [[nodiscard]] auto service_count() noexcept -> u32;
75
76} // namespace zxfoundation::sys::service
77
78} // end export