Cleaning up initial commit and restructured some of the execution flow, fixed returns and reference mgmt
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "error.hpp"
|
||||
#include "dpm_interface.hpp"
|
||||
#include <filesystem>
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <module_interface.hpp>
|
||||
|
||||
// Forward declaration to avoid circular dependency
|
||||
struct CommandArgs;
|
||||
@@ -9,14 +14,22 @@ struct CommandArgs;
|
||||
class ModuleLoader {
|
||||
public:
|
||||
explicit ModuleLoader(std::string module_path = "/usr/lib/dpm/modules/");
|
||||
DPMError check_module_path() const;
|
||||
std::pair<std::vector<std::string>, DPMError> list_available_modules() const;
|
||||
const std::string& get_module_path() const { return module_path_; }
|
||||
std::string get_absolute_module_path() const;
|
||||
DPMError list_available_modules(std::vector<std::string>& modules) const;
|
||||
DPMError get_module_path(std::string& path) const;
|
||||
DPMError get_absolute_module_path(std::string& abs_path) const;
|
||||
|
||||
// Split into two separate methods
|
||||
void* load_module(const std::string& module_name) const;
|
||||
int execute_module(void* module_handle, const std::string& command) const;
|
||||
// Load and execute methods
|
||||
DPMError load_module(const std::string& module_name, void*& module_handle) const;
|
||||
DPMError execute_module(void* module_handle, const std::string& command) const;
|
||||
|
||||
// Get module version
|
||||
DPMError get_module_version(void* module_handle, std::string& version) const;
|
||||
|
||||
// Get module description
|
||||
DPMError get_module_description(void* module_handle, std::string& description) const;
|
||||
|
||||
// Check if all required symbols from module_interface.hpp are exported by the module
|
||||
DPMError validate_module_interface(void* module_handle, std::vector<std::string>& missing_symbols) const;
|
||||
|
||||
private:
|
||||
std::string module_path_;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <getopt.h>
|
||||
#include <vector>
|
||||
#include "error.hpp"
|
||||
#include <dlfcn.h>
|
||||
#include <iomanip>
|
||||
#include "ModuleLoader.hpp" // This should include ModuleLoader since it's used directly
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,12 +1,29 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* Provides reserved symbol names we look for in modules.
|
||||
*/
|
||||
|
||||
// Define required symbols in one place
|
||||
namespace module_interface {
|
||||
// This is the single source of truth for required module symbols
|
||||
static const std::vector<std::string> required_symbols = {
|
||||
"dpm_module_execute",
|
||||
"dpm_module_get_version",
|
||||
"dpm_get_description"
|
||||
};
|
||||
}
|
||||
|
||||
// Common interface for all DPM modules
|
||||
extern "C" {
|
||||
// Module must export this symbol to be considered valid
|
||||
int dpm_module_execute(const char* command, int argc, char** argv);
|
||||
|
||||
// Module version information
|
||||
const char* dpm_module_get_version(void);
|
||||
|
||||
// Module description information
|
||||
const char* dpm_get_description(void);
|
||||
}
|
||||
Reference in New Issue
Block a user