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::server::ServiceRegisterEvent,
51 event::server::ServiceUnregisterEvent>::create([fn](
auto&& event) {
52 if (event.service()->getServiceId() == T::ServiceId) {
54 std::is_same_v<std::remove_cvref_t<
decltype((event))>, event::server::ServiceUnregisterEvent>
58 fn(std::static_pointer_cast<T>(event.service()));
62 event::EventBus::getInstance().addListener(listener);
66 template <IsService T>
67 Expected<std::shared_ptr<T>> getService() {
68 auto res = getService(getServiceId<T>);
70 return forwardError(res.error());
72 return std::static_pointer_cast<T>(*res);
75 LLNDAPI Expected<std::shared_ptr<Service>> getService(
ServiceIdView const&
id);
77 LLNDAPI std::optional<QueryServiceResult> queryService(std::string_view name);
78 LLNDAPI std::vector<QueryServiceResult> queryServices(std::string_view name);
80 LLAPI
bool registerService(
81 std::shared_ptr<Service>
const& service,
82 std::shared_ptr<mod::Mod>
const& mod = mod::NativeMod::current()
87 LLAPI
void unregisterService(
mod::Mod const& mod);
89 ServiceManager(ServiceManager
const&) =
delete;
90 ServiceManager(ServiceManager&&) =
delete;
91 ServiceManager& operator=(ServiceManager
const&) =
delete;
92 ServiceManager& operator=(ServiceManager&&) =
delete;
96 std::unique_ptr<Impl> impl;