yaze 0.2.2
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 <yaze.h>
9
10#include <iostream>
11#include <vector>
12
13namespace yaze {
14namespace editor {
15
16void ExtensionManager::LoadExtension(const std::string& filename,
17 yaze_editor_context* context) {
18#if defined(__unix__) || defined(__unix) || defined(unix) || \
19 defined(__APPLE__) && defined(__MACH__)
20 auto extension_path = filename.c_str();
21 void* handle = dlopen(extension_path, RTLD_LAZY);
22 if (!handle) {
23 std::cerr << "Cannot open extension: " << dlerror() << std::endl;
24 return;
25 }
26 dlerror(); // Clear any existing error
27
28 // Load the symbol to retrieve the extension
29 auto get_extension = reinterpret_cast<yaze_extension* (*)()>(
30 dlsym(handle, "get_yaze_extension"));
31 const char* dlsym_error = dlerror();
32 if (dlsym_error) {
33 std::cerr << "Cannot load symbol 'get_yaze_extension': " << dlsym_error
34 << std::endl;
35 dlclose(handle);
36 return;
37 }
38
39 yaze_extension* extension = get_extension();
40 if (extension && extension->initialize) {
41 extension->initialize(context);
42 } else {
43 std::cerr << "Failed to initialize the extension." << std::endl;
44 dlclose(handle);
45 return;
46 }
47
48 extensions_.push_back(extension);
49#endif
50}
51
53 extensions_.push_back(extension);
54}
55
57 for (auto& extension : extensions_) {
58 extension->initialize(context);
59 }
60}
61
63 for (auto& extension : extensions_) {
64 extension->cleanup();
65 }
66
67 // if (handle) {
68 // dlclose(handle);
69 // handle = nullptr;
70 // extension = nullptr;
71 // }
72}
73
74} // namespace editor
75} // namespace yaze
std::vector< yaze_extension * > extensions_
void LoadExtension(const std::string &filename, yaze_editor_context *context)
void RegisterExtension(yaze_extension *extension)
void InitializeExtensions(yaze_editor_context *context)
Editors are the view controllers for the application.
Main namespace for the application.
Definition controller.cc:18
Extension interface for Yaze.
Definition yaze.h:70
yaze_initialize_func initialize
Function to initialize the extension.
Definition yaze.h:80