plugify 1.0.0.0
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 PluginDescriptorHandle GetDescriptor() const noexcept;
78
83 PluginState GetState() const noexcept;
84
89 std::string_view GetError() const noexcept;
90
95 std::span<const MethodData> GetMethods() const noexcept;
96
101 MemAddr GetData() const noexcept;
102
124 std::optional<std::filesystem::path_view> FindResource(std::filesystem::path_view path) const;
125 };
126
130 namespace PluginUtils {
136 constexpr std::string_view ToString(PluginState state) {
137 switch (state) {
138 case PluginState::NotLoaded: return "NotLoaded";
139 case PluginState::Error: return "Error";
140 case PluginState::Loaded: return "Loaded";
141 case PluginState::Running: return "Running";
142 case PluginState::Terminating: return "Terminating";
143 default: return "Unknown";
144 }
145 }
146
152 constexpr PluginState FromString(std::string_view state) {
153 if (state == "NotLoaded") {
154 return PluginState::NotLoaded;
155 } else if (state == "Error") {
156 return PluginState::Error;
157 } else if (state == "Loaded") {
158 return PluginState::Loaded;
159 } else if (state == "Running") {
160 return PluginState::Running;
161 } else if (state == "Terminating") {
162 return PluginState::Terminating;
163 }
164 return PluginState::Unknown;
165 }
166 } // namespace PluginUtils
167
168} // 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:11
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