18struct GetServiceError : ErrorInfoBase {
19 enum class ErrorType :
char {
28 GetServiceError(ErrorType code,
size_t version = 0) : code(code), version(version) {}
30 LLAPI std::string message(std::string_view locale)
const noexcept override;
42 LLNDAPI
static ServiceManager& getInstance();
44 template <IsService T>
45 event::ListenerPtr subscribeService(std::function<
void(std::shared_ptr<T>
const&)>
const& fn) {
46 if (
auto service = getService<T>(); service) {
50 event::MultiListener<event::server::ServiceRegisterEvent, event::server::ServiceUnregisterEvent>::create(
52 if (event.service()->getServiceId() == T::ServiceId) {
53 if constexpr (std::is_same_v<
54 std::remove_cvref_t<
decltype((event))>,
55 event::server::ServiceUnregisterEvent>) {
58 fn(std::static_pointer_cast<T>(event.service()));
63 event::EventBus::getInstance().addListener(listener);
67 template <IsService T>
68 Expected<std::shared_ptr<T>> getService() {
69 auto res = getService(getServiceId<T>);
71 return forwardError(res.error());
73 return std::static_pointer_cast<T>(*res);
76 LLNDAPI Expected<std::shared_ptr<Service>> getService(
ServiceIdView const&
id);
78 LLNDAPI std::optional<QueryServiceResult> queryService(std::string_view name);
79 LLNDAPI std::vector<QueryServiceResult> queryServices(std::string_view name);
81 LLAPI
bool registerService(
82 std::shared_ptr<Service>
const& service,
83 std::shared_ptr<mod::Mod>
const& mod = mod::NativeMod::current()
88 LLAPI
void unregisterService(
mod::Mod const& mod);
90 ServiceManager(ServiceManager
const&) =
delete;
91 ServiceManager(ServiceManager&&) =
delete;
92 ServiceManager& operator=(ServiceManager
const&) =
delete;
93 ServiceManager& operator=(ServiceManager&&) =
delete;
97 std::unique_ptr<Impl> impl;