implemented initial dpm core call functionality from module perspective
parent
a5e2c86882
commit
6220653d10
|
@ -15,15 +15,19 @@ add_executable(
|
|||
include/dpm_interface_helpers.hpp
|
||||
src/dpm_interface_helpers.cpp
|
||||
src/handlers.cpp
|
||||
src/module_interface.cpp
|
||||
)
|
||||
|
||||
target_include_directories(dpm PRIVATE include)
|
||||
target_link_libraries(dpm dl)
|
||||
|
||||
# Export symbols for dynamic loading
|
||||
target_link_options(dpm PRIVATE -rdynamic)
|
||||
|
||||
# Add the info module
|
||||
add_library(info MODULE modules/info.cpp)
|
||||
set_target_properties(info PROPERTIES
|
||||
PREFIX ""
|
||||
SUFFIX ".so"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/modules"
|
||||
)
|
||||
)
|
|
@ -56,4 +56,7 @@ extern "C" {
|
|||
|
||||
// Module description information
|
||||
const char* dpm_get_description(void);
|
||||
|
||||
// Callback function exposed by DPM core for modules to use
|
||||
int dpm_core_callback(const char* action, const char* data);
|
||||
}
|
|
@ -1,38 +1,12 @@
|
|||
/**
|
||||
* @file info.cpp
|
||||
* @brief Implementation of the DPM info module
|
||||
*
|
||||
* Provides information about the DPM system through a module interface.
|
||||
* This module supports commands for displaying version information,
|
||||
* system details, and module help documentation.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
*/
|
||||
|
||||
// info.cpp
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
// Declaration of the DPM core function we want to call
|
||||
extern "C" int dpm_core_callback(const char* action, const char* data);
|
||||
|
||||
// Implementation of the info module
|
||||
// This module provides information about the DPM system
|
||||
|
||||
|
@ -56,6 +30,8 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
|||
std::cout << " version - Display DPM version information\n";
|
||||
std::cout << " system - Display system information\n";
|
||||
std::cout << " help - Display this help message\n";
|
||||
|
||||
dpm_core_callback("log", "No command specified, displayed help");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -63,12 +39,19 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
|||
std::string cmd(command);
|
||||
|
||||
if (cmd == "version") {
|
||||
dpm_core_callback("log", "Executing 'version' command");
|
||||
|
||||
std::cout << "DPM Version: 0.1.0\n";
|
||||
std::cout << "Build Date: " << __DATE__ << "\n";
|
||||
std::cout << "Build Time: " << __TIME__ << "\n";
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == "system") {
|
||||
dpm_core_callback("log", "Executing 'system' command");
|
||||
|
||||
// Request config information
|
||||
dpm_core_callback("get_config", "system.arch");
|
||||
|
||||
std::cout << "System Information:\n";
|
||||
std::cout << " OS: "
|
||||
#ifdef _WIN32
|
||||
|
@ -97,6 +80,8 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
else if (cmd == "help") {
|
||||
dpm_core_callback("log", "Executing 'help' command");
|
||||
|
||||
std::cout << "DPM Info Module - Provides information about the DPM system\n";
|
||||
std::cout << "Available commands:\n";
|
||||
std::cout << " version - Display DPM version information\n";
|
||||
|
@ -105,6 +90,9 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
else {
|
||||
std::string error_msg = "Unknown command: " + cmd;
|
||||
dpm_core_callback("log", error_msg.c_str());
|
||||
|
||||
std::cerr << "Unknown command: " << cmd << "\n";
|
||||
std::cerr << "Run 'dpm info help' for a list of available commands\n";
|
||||
return 1;
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* @file module_interface.cpp
|
||||
* @brief Implementation of the module interface functions
|
||||
*
|
||||
* Provides the implementation of functions declared in the module interface
|
||||
* that are part of the DPM core, such as callback functions available to modules.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
*/
|
||||
|
||||
#include "module_interface.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief Function that modules can call to access DPM core functionality
|
||||
*
|
||||
* This function is exported by the DPM executable and can be called by
|
||||
* dynamically loaded modules to access services or features of the core application.
|
||||
*
|
||||
* Note: In order for a module to use this functionality, it requires a forward declaration in the module:
|
||||
* // Example:
|
||||
* // Declaration of the DPM core function we want to call
|
||||
* extern "C" int dpm_core_callback(const char* action, const char* data);
|
||||
*
|
||||
* @param action The specific action or operation being requested
|
||||
* @param data Additional data or parameters needed for the action
|
||||
* @return Result code indicating success (0) or failure (non-zero)
|
||||
*/
|
||||
extern "C" int dpm_core_callback(const char* action, const char* data) {
|
||||
// Implementation here
|
||||
if (!action) {
|
||||
std::cerr << "Error: Module callback received null action" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string action_str(action);
|
||||
|
||||
if (action_str == "log") {
|
||||
if (data) {
|
||||
std::cout << "Module log: " << data << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (action_str == "get_config") {
|
||||
if (data) {
|
||||
std::cout << "Module requested config: " << data << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Unknown module callback action: " << action_str << std::endl;
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue