First Commit

This commit is contained in:
Chris Punches
2025-02-17 23:10:35 -05:00
parent 7319217eff
commit 1ce163ef29
10 changed files with 442 additions and 1 deletions

23
include/ModuleLoader.hpp Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include <string>
#include <vector>
#include "error.hpp"
// Forward declaration to avoid circular dependency
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;
// 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;
private:
std::string module_path_;
};

30
include/dpm_interface.hpp Normal file
View File

@@ -0,0 +1,30 @@
#pragma once
#include <iostream>
#include <getopt.h>
#include <vector>
#include "error.hpp"
#include "ModuleLoader.hpp" // This should include ModuleLoader since it's used directly
/*
*
* DPM Interface methods. These are wrappers of DPM functionality that are meant to handle user view, turning
* error codes into human-presentable information, etc. Features are defined internally, these will only ever be
* wrappers of existing features to provide the human/cli interface.
*
*/
// check if the module path exists
int main_check_module_path(const ModuleLoader& loader);
// list the modules
int main_list_modules(const ModuleLoader& loader);
// data structure for supplied arguments
struct CommandArgs {
std::string module_path = "/usr/lib/dpm/modules/";
std::string module_name;
std::string command; // All arguments combined into a single command string
};
// parser for populating data structure for supplied arguments
CommandArgs parse_args(int argc, char* argv[]);

11
include/error.hpp Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
enum class DPMError {
SUCCESS,
PATH_NOT_FOUND,
PATH_NOT_DIRECTORY,
PERMISSION_DENIED,
MODULE_NOT_FOUND,
MODULE_LOAD_FAILED,
INVALID_MODULE
};

View File

@@ -0,0 +1,12 @@
#pragma once
#include <string>
/*
* Provides reserved symbol names we look for in modules.
*/
// 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);
}