plugify 1.2.8
Loading...
Searching...
No Matches
provider.hpp
1#pragma once
2
3#include "plugify/global.h"
4#include "plugify/logger.hpp"
5#include "plugify/service_locator.hpp"
6#include "plugify/types.hpp"
7
8namespace plugify {
9 struct Config;
10 class Manager;
11 class Extension;
12
13 // Provider acts as a facade to simplify access to common services
14 class PLUGIFY_API Provider {
15 public:
16 explicit Provider(const ServiceLocator& services, const Config& config, const Manager& manager);
17 ~Provider();
18 Provider(const Provider& other);
19 Provider(Provider&& other) noexcept;
20 Provider& operator=(const Provider& other);
21 Provider& operator=(Provider&& other) noexcept;
22
23 // Logging helpers
24 void Log(
25 std::string_view msg,
26 Severity severity = Severity::Info,
27 const std::source_location& loc = std::source_location::current()
28 ) const;
29
30 void LogVerbose(
31 std::string_view msg,
32 const std::source_location& loc = std::source_location::current()
33 ) const {
34 Log(msg, Severity::Verbose, loc);
35 }
36
37 void LogDebug(
38 std::string_view msg,
39 const std::source_location& loc = std::source_location::current()
40 ) const {
41 Log(msg, Severity::Debug, loc);
42 }
43
44 void LogInfo(
45 std::string_view msg,
46 const std::source_location& loc = std::source_location::current()
47 ) const {
48 Log(msg, Severity::Info, loc);
49 }
50
51 void LogWarning(
52 std::string_view msg,
53 const std::source_location& loc = std::source_location::current()
54 ) const {
55 Log(msg, Severity::Warning, loc);
56 }
57
58 void LogError(
59 std::string_view msg,
60 const std::source_location& loc = std::source_location::current()
61 ) const {
62 Log(msg, Severity::Error, loc);
63 }
64
65 void LogFatal(
66 std::string_view msg,
67 const std::source_location& loc = std::source_location::current()
68 ) const {
69 Log(msg, Severity::Fatal, loc);
70 }
71
72 bool IsPreferOwnSymbols() const noexcept;
73
74 // Path helpers
75 [[nodiscard]] const std::filesystem::path& GetBaseDir() const noexcept;
76 [[nodiscard]] const std::filesystem::path& GetExtensionsDir() const noexcept;
77 [[nodiscard]] const std::filesystem::path& GetConfigsDir() const noexcept;
78 [[nodiscard]] const std::filesystem::path& GetDataDir() const noexcept;
79 [[nodiscard]] const std::filesystem::path& GetLogsDir() const noexcept;
80 [[nodiscard]] const std::filesystem::path& GetCacheDir() const noexcept;
81
82 // Manager
83 [[nodiscard]] bool
84 IsExtensionLoaded(std::string_view name, std::optional<Constraint> constraint = {}) const noexcept;
85 [[nodiscard]] const Extension* FindExtension(std::string_view name) const noexcept;
86 [[nodiscard]] const Extension* FindExtension(UniqueId id) const noexcept;
87 [[nodiscard]] std::vector<const Extension*> GetExtensions() const;
88
89 // Service access helpers
90 template <typename Service>
91 [[nodiscard]] std::shared_ptr<Service> Resolve() const {
92 return GetServices().Resolve<Service>();
93 }
94
95 template <typename Service>
96 [[nodiscard]] std::shared_ptr<Service> TryResolve() const noexcept {
97 return GetServices().TryResolve<Service>();
98 }
99
100 [[nodiscard]] bool operator==(const Provider& other) const noexcept;
101 [[nodiscard]] auto operator<=>(const Provider& other) const noexcept;
102
103 private:
104 // Access to context for advanced use cases
105 [[nodiscard]] const ServiceLocator& GetServices() const noexcept;
106
107 private:
108 struct Impl;
109 PLUGIFY_NO_DLL_EXPORT_WARNING(std::unique_ptr<Impl> _impl;)
110 };
111}
DI Container / Service Locator with PIMPL.