plugify 1.2.6
Loading...
Searching...
No Matches
plugin.hpp
1#pragma once
2
3#include <cstdint>
4#include <optional>
5#include <span>
6#include <string>
7
8#include "handle.hpp"
9#include "mem_addr.hpp"
10#include "method.hpp"
11#include "path.hpp"
12
13#include <plugify_export.h>
14
15namespace plugify {
16 class Plugin;
17 class PluginDescriptorHandle;
18 class MethodHandle;
19
27 enum class PluginState {
28 NotLoaded,
29 Error,
30 Loaded,
31 Running,
32 Terminating,
33 Unknown,
34 };
35
40 using UniqueId = std::ptrdiff_t;
41
46 class PLUGIFY_API PluginHandle : public Handle<const Plugin> {
47 using Handle::Handle;
48 public:
53 UniqueId GetId() const noexcept;
54
59 std::string_view GetName() const noexcept;
60
65 std::string_view GetFriendlyName() const noexcept;
66
71 std::filesystem::path_view GetBaseDir() const noexcept;
72
77 std::filesystem::path_view GetConfigsDir() const noexcept;
78
83 std::filesystem::path_view GetDataDir() const noexcept;
84
89 std::filesystem::path_view GetLogsDir() const noexcept;
90
95 PluginDescriptorHandle GetDescriptor() const noexcept;
96
101 PluginState GetState() const noexcept;
102
107 std::string_view GetError() const noexcept;
108
113 std::span<const MethodData> GetMethods() const noexcept;
114
119 MemAddr GetData() const noexcept;
120
142 std::optional<std::filesystem::path_view> FindResource(std::filesystem::path_view path) const;
143 };
144
148 namespace PluginUtils {
154 constexpr std::string_view ToString(PluginState state) {
155 switch (state) {
156 case PluginState::NotLoaded: return "NotLoaded";
157 case PluginState::Error: return "Error";
158 case PluginState::Loaded: return "Loaded";
159 case PluginState::Running: return "Running";
160 case PluginState::Terminating: return "Terminating";
161 default: return "Unknown";
162 }
163 }
164
170 constexpr PluginState FromString(std::string_view state) {
171 if (state == "NotLoaded") {
172 return PluginState::NotLoaded;
173 } else if (state == "Error") {
174 return PluginState::Error;
175 } else if (state == "Loaded") {
176 return PluginState::Loaded;
177 } else if (state == "Running") {
178 return PluginState::Running;
179 } else if (state == "Terminating") {
180 return PluginState::Terminating;
181 }
182 return PluginState::Unknown;
183 }
184 } // namespace PluginUtils
185
186} // namespace plugify
A generic handle class that manages a pointer to an object of type T.
Definition handle.hpp:18
A wrapper class for memory addresses, providing utility functions for pointer manipulation.
Definition mem_addr.hpp:10
A handle class for the PluginDescriptor structure.
Handle wrapper to access plugin's information.
Definition plugin.hpp:46
UniqueId GetId() const noexcept
Get the unique identifier of the plugin.
Represents data related to a plugin method.
Definition method.hpp:182