yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
extension_manager.cc
Go to the documentation of this file.
1#include "extension_manager.h"
2
3#if defined(__unix__) || defined(__unix) || defined(unix) || \
4 defined(__APPLE__) && defined(__MACH__)
5#include <dlfcn.h>
6#endif
7
8#include <iostream>
9#include <vector>
10
11#include "incl/extension.h"
12
13namespace yaze {
14namespace app {
15namespace editor {
16
17void ExtensionManager::LoadExtension(const std::string& filename,
18 yaze_editor_context* context) {
19#if defined(__unix__) || defined(__unix) || defined(unix) || \
20 defined(__APPLE__) && defined(__MACH__)
21 auto extension_path = filename.c_str();
22 void* handle = dlopen(extension_path, RTLD_LAZY);
23 if (!handle) {
24 std::cerr << "Cannot open extension: " << dlerror() << std::endl;
25 return;
26 }
27 dlerror(); // Clear any existing error
28
29 // Load the symbol to retrieve the extension
30 auto get_extension = reinterpret_cast<yaze_extension* (*)()>(
31 dlsym(handle, "get_yaze_extension"));
32 const char* dlsym_error = dlerror();
33 if (dlsym_error) {
34 std::cerr << "Cannot load symbol 'get_yaze_extension': " << dlsym_error
35 << std::endl;
36 dlclose(handle);
37 return;
38 }
39
40 yaze_extension* extension = get_extension();
41 if (extension && extension->initialize) {
42 extension->initialize(context);
43 } else {
44 std::cerr << "Failed to initialize the extension." << std::endl;
45 dlclose(handle);
46 return;
47 }
48
49 extensions_.push_back(extension);
50#endif
51}
52
54 extensions_.push_back(extension);
55}
56
58 for (auto& extension : extensions_) {
59 extension->initialize(context);
60 }
61}
62
64 for (auto& extension : extensions_) {
65 extension->cleanup();
66 }
67
68 // if (handle) {
69 // dlclose(handle);
70 // handle = nullptr;
71 // extension = nullptr;
72 // }
73}
74
76 for (auto& extension : extensions_) {
77 if (extension->extend_ui) {
78 extension->extend_ui(context);
79 }
80 }
81}
82
83} // namespace editor
84} // namespace app
85} // namespace yaze
void RegisterExtension(yaze_extension *extension)
std::vector< yaze_extension * > extensions_
void InitializeExtensions(yaze_editor_context *context)
void ExecuteExtensionUI(yaze_editor_context *context)
void LoadExtension(const std::string &filename, yaze_editor_context *context)
Definition common.cc:21
Extension editor context.
Definition yaze.h:42
Extension interface for Yaze.
Definition extension.h:29
yaze_initialize_func initialize
Function to initialize the extension.
Definition extension.h:39