directory restructure and documentation cleanup
This commit is contained in:
137
modules/info/dpmdk/include/CommonModuleAPI.hpp
Normal file
137
modules/info/dpmdk/include/CommonModuleAPI.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* @file CommonModuleAPI.hpp
|
||||
* @brief Common module interface for DPM modules
|
||||
*
|
||||
* Defines the required interface that all DPM modules must implement,
|
||||
* including the function declarations and constants that every module needs.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief Fatal log level constant
|
||||
*
|
||||
* Used for critical errors that require immediate attention and
|
||||
* typically result in program termination.
|
||||
*/
|
||||
const int LOG_FATAL = 0;
|
||||
|
||||
/**
|
||||
* @brief Error log level constant
|
||||
*
|
||||
* Used for error conditions that may allow the program to continue
|
||||
* execution but indicate a failure in some operation.
|
||||
*/
|
||||
const int LOG_ERROR = 1;
|
||||
|
||||
/**
|
||||
* @brief Warning log level constant
|
||||
*
|
||||
* Used for potentially harmful situations that don't affect normal
|
||||
* program execution but may indicate problems.
|
||||
*/
|
||||
const int LOG_WARN = 2;
|
||||
|
||||
/**
|
||||
* @brief Informational log level constant
|
||||
*
|
||||
* Used for general informational messages about program execution.
|
||||
*/
|
||||
const int LOG_INFO = 3;
|
||||
|
||||
/**
|
||||
* @brief Debug log level constant
|
||||
*
|
||||
* Used for detailed debugging information during development or
|
||||
* troubleshooting.
|
||||
*/
|
||||
const int LOG_DEBUG = 4;
|
||||
|
||||
// Required functions that every DPM module must implement
|
||||
extern "C" {
|
||||
/**
|
||||
* @brief Required module execution entry point
|
||||
*
|
||||
* Main entry point that is called by the DPM core when the module
|
||||
* is executed. Modules must implement this function to handle
|
||||
* commands and perform their specific functionality.
|
||||
*
|
||||
* @param command The command string to execute
|
||||
* @param argc Number of arguments
|
||||
* @param argv Array of argument strings
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int dpm_module_execute(const char* command, int argc, char** argv);
|
||||
|
||||
/**
|
||||
* @brief Module version information function
|
||||
*
|
||||
* Returns the version information for the module. This information
|
||||
* is displayed when listing available modules.
|
||||
*
|
||||
* @return A string containing the module's version
|
||||
*/
|
||||
const char* dpm_module_get_version(void);
|
||||
|
||||
/**
|
||||
* @brief Module description function
|
||||
*
|
||||
* Returns a human-readable description of the module's functionality.
|
||||
* This information is displayed when listing available modules.
|
||||
*
|
||||
* @return A string containing the module's description
|
||||
*/
|
||||
const char* dpm_get_description(void);
|
||||
}
|
||||
|
||||
// DPM core functions available for modules to call
|
||||
extern "C" {
|
||||
/**
|
||||
* @brief Configuration access function
|
||||
*
|
||||
* Allows modules to access DPM's configuration values by section and key.
|
||||
*
|
||||
* @param section The configuration section name
|
||||
* @param key The configuration key within the section
|
||||
* @return The configuration value as a string, or NULL if not found
|
||||
*/
|
||||
const char* dpm_get_config(const char* section, const char* key);
|
||||
|
||||
/**
|
||||
* @brief Logging function
|
||||
*
|
||||
* Allows modules to log messages through DPM's logging system.
|
||||
*
|
||||
* @param level The log level (LOG_FATAL, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG)
|
||||
* @param message The message to log
|
||||
*/
|
||||
void dpm_log(int level, const char* message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DPM core version definition
|
||||
*
|
||||
* Defines the version string for the DPM core system.
|
||||
*/
|
||||
#define DPM_VERSION "0.1.0"
|
||||
37
modules/info/dpmdk/src/CommonModuleAPI.cpp
Normal file
37
modules/info/dpmdk/src/CommonModuleAPI.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file CommonModuleAPI.cpp
|
||||
* @brief Implementation stub for DPM module interface
|
||||
*
|
||||
* This file serves primarily as a documentation reference for the module
|
||||
* interface. The actual implementations of dpm_get_config and dpm_log are
|
||||
* provided by the DPM core, while dpm_module_execute, dpm_module_get_version,
|
||||
* and dpm_get_description must be implemented by each module.
|
||||
*
|
||||
* @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.hpp"
|
||||
|
||||
/**
|
||||
* @note The implementation of dpm_get_config and dpm_log are provided by the DPM core.
|
||||
* Each module must implement dpm_module_execute, dpm_module_get_version, and dpm_get_description.
|
||||
*/
|
||||
119
modules/info/include/infoFuncs.hpp
Normal file
119
modules/info/include/infoFuncs.hpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @file infoFuncs.hpp
|
||||
* @brief Header file for the info module support functions
|
||||
*
|
||||
* Defines functions and enumerations for the info module which provides
|
||||
* information about the DPM system, including version, system details,
|
||||
* and configuration information.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <sys/utsname.h>
|
||||
#include "dpmdk/include/CommonModuleAPI.hpp"
|
||||
|
||||
/**
|
||||
* @enum Command
|
||||
* @brief Enumeration of supported commands for the info module
|
||||
*/
|
||||
enum Command {
|
||||
CMD_UNKNOWN, /**< Unknown or unsupported command */
|
||||
CMD_HELP, /**< Display help information */
|
||||
CMD_VERSION, /**< Display version information */
|
||||
CMD_SYSTEM, /**< Display system information */
|
||||
CMD_CONFIG /**< Display configuration information */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Detects the system architecture
|
||||
*
|
||||
* Uses the uname system call to determine the current system architecture.
|
||||
*
|
||||
* @return String representation of the system architecture
|
||||
*/
|
||||
std::string detect_architecture();
|
||||
|
||||
/**
|
||||
* @brief Detects the operating system information
|
||||
*
|
||||
* Uses the uname system call to determine the OS, and on Linux systems,
|
||||
* attempts to get distribution information from /etc/os-release.
|
||||
*
|
||||
* @return Detailed string of the operating system
|
||||
*/
|
||||
std::string detect_os();
|
||||
|
||||
/**
|
||||
* @brief Handler for the help command
|
||||
*
|
||||
* Displays information about available commands in the info module.
|
||||
*
|
||||
* @param argc Number of arguments
|
||||
* @param argv Array of arguments
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int cmd_help(int argc, char** argv);
|
||||
|
||||
/**
|
||||
* @brief Handler for the version command
|
||||
*
|
||||
* Displays DPM version information, build date, and build time.
|
||||
*
|
||||
* @param argc Number of arguments
|
||||
* @param argv Array of arguments
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int cmd_version(int argc, char** argv);
|
||||
|
||||
/**
|
||||
* @brief Handler for the system command
|
||||
*
|
||||
* Displays information about the system on which DPM is running,
|
||||
* including OS details and architecture.
|
||||
*
|
||||
* @param argc Number of arguments
|
||||
* @param argv Array of arguments
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int cmd_system(int argc, char** argv);
|
||||
|
||||
/**
|
||||
* @brief Handler for the config command
|
||||
*
|
||||
* Displays configuration information about the DPM system.
|
||||
*
|
||||
* @param argc Number of arguments
|
||||
* @param argv Array of arguments
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int cmd_config(int argc, char** argv);
|
||||
|
||||
/**
|
||||
* @brief Handler for unknown commands
|
||||
*
|
||||
* Displays an error message for unrecognized commands.
|
||||
*
|
||||
* @param command The unrecognized command string
|
||||
* @param argc Number of arguments
|
||||
* @param argv Array of arguments
|
||||
* @return 1 to indicate failure
|
||||
*/
|
||||
int cmd_unknown(const char* command, int argc, char** argv);
|
||||
|
||||
/**
|
||||
* @brief Parses a command string into a Command enum value
|
||||
*
|
||||
* Converts a command string to the appropriate Command enum value
|
||||
* for internal routing.
|
||||
*
|
||||
* @param cmd_str The command string to parse
|
||||
* @return The corresponding Command enum value
|
||||
*/
|
||||
Command parse_command(const char* cmd_str);
|
||||
111
modules/info/info.cpp
Normal file
111
modules/info/info.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @file info.cpp
|
||||
* @brief Example DPM info module implementation
|
||||
*
|
||||
* Implements a simple DPM module that provides information about the DPM system.
|
||||
* This module demonstrates how to implement the required module interface and
|
||||
* interact with the DPM core through configuration functions.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
// Implementation of the info module
|
||||
// This module provides information about the DPM system
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "dpmdk/include/CommonModuleAPI.hpp"
|
||||
#include "include/infoFuncs.hpp"
|
||||
|
||||
/**
|
||||
* @def MODULE_VERSION
|
||||
* @brief Version information for the info module
|
||||
*
|
||||
* Defines the version string that will be returned by dpm_module_get_version()
|
||||
*/
|
||||
#define MODULE_VERSION "0.1.0"
|
||||
|
||||
/**
|
||||
* @brief Returns the module version string
|
||||
*
|
||||
* Required implementation of the DPM module interface that provides
|
||||
* version information for the info module.
|
||||
*
|
||||
* @return Const char pointer to the module version string
|
||||
*/
|
||||
extern "C" const char* dpm_module_get_version(void) {
|
||||
return MODULE_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the module description string
|
||||
*
|
||||
* Required implementation of the DPM module interface that provides
|
||||
* a human-readable description of the info module and its functionality.
|
||||
*
|
||||
* @return Const char pointer to the module description string
|
||||
*/
|
||||
extern "C" const char* dpm_get_description(void) {
|
||||
return "DPM Info Module - Provides information about the DPM system";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Main entry point for the info module
|
||||
*
|
||||
* Required implementation of the DPM module interface that serves as the
|
||||
* primary execution point for the module. Parses the command and routes
|
||||
* execution to the appropriate handler function.
|
||||
*
|
||||
* @param command The command string to execute
|
||||
* @param argc Number of arguments
|
||||
* @param argv Array of argument strings
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "Info module execution started");
|
||||
|
||||
Command cmd = parse_command(command);
|
||||
|
||||
switch (cmd) {
|
||||
case CMD_VERSION:
|
||||
return cmd_version(argc, argv);
|
||||
|
||||
case CMD_SYSTEM:
|
||||
return cmd_system(argc, argv);
|
||||
|
||||
case CMD_CONFIG:
|
||||
return cmd_config(argc, argv);
|
||||
|
||||
case CMD_HELP:
|
||||
return cmd_help(argc, argv);
|
||||
|
||||
case CMD_UNKNOWN:
|
||||
default:
|
||||
return cmd_unknown(command, argc, argv);
|
||||
}
|
||||
}
|
||||
@@ -1,80 +1,22 @@
|
||||
/**
|
||||
* @file info.cpp
|
||||
* @brief Example DPM info module implementation
|
||||
* @file infoFuncs.cpp
|
||||
* @brief Implementation of the info module support functions
|
||||
*
|
||||
* Implements a simple DPM module that provides information about the DPM system.
|
||||
* This module demonstrates how to implement the required module interface and
|
||||
* interact with the DPM core through configuration functions.
|
||||
* Implements functions for the info module that provide information about
|
||||
* the DPM system, including version, system details, and configuration.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
// Implementation of the info module
|
||||
// This module provides information about the DPM system
|
||||
#include "infoFuncs.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
// Define version macros
|
||||
#define MODULE_VERSION "0.1.0"
|
||||
#define DPM_VERSION "0.1.0"
|
||||
|
||||
// Define constants for logging levels
|
||||
// These must match.
|
||||
const int LOG_FATAL = 0;
|
||||
const int LOG_ERROR = 1;
|
||||
const int LOG_WARN = 2;
|
||||
const int LOG_INFO = 3;
|
||||
const int LOG_DEBUG = 4;
|
||||
|
||||
// Declaration of the DPM config function we want to call
|
||||
extern "C" const char* dpm_get_config(const char* section, const char* key);
|
||||
|
||||
// Declaration of the DPM log function
|
||||
extern "C" void dpm_log(int level, const char* message);
|
||||
|
||||
// Version information
|
||||
extern "C" const char* dpm_module_get_version(void) {
|
||||
return MODULE_VERSION;
|
||||
}
|
||||
|
||||
// Module description
|
||||
extern "C" const char* dpm_get_description(void) {
|
||||
return "DPM Info Module - Provides information about the DPM system";
|
||||
}
|
||||
|
||||
// Command enum for switch case
|
||||
enum Command {
|
||||
CMD_UNKNOWN,
|
||||
CMD_HELP,
|
||||
CMD_VERSION,
|
||||
CMD_SYSTEM,
|
||||
CMD_CONFIG
|
||||
};
|
||||
|
||||
// Function to detect architecture using uname
|
||||
/**
|
||||
* Function to detect architecture using uname
|
||||
*/
|
||||
std::string detect_architecture() {
|
||||
struct utsname system_info;
|
||||
|
||||
@@ -86,7 +28,9 @@ std::string detect_architecture() {
|
||||
return system_info.machine;
|
||||
}
|
||||
|
||||
// Function to detect OS
|
||||
/**
|
||||
* Function to detect OS details
|
||||
*/
|
||||
std::string detect_os() {
|
||||
struct utsname system_info;
|
||||
|
||||
@@ -135,7 +79,9 @@ std::string detect_os() {
|
||||
return os;
|
||||
}
|
||||
|
||||
// Command handler functions
|
||||
/**
|
||||
* Command handler for help command
|
||||
*/
|
||||
int cmd_help(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "DPM Info Module - Provides information about the DPM system");
|
||||
dpm_log(LOG_INFO, "Available commands:");
|
||||
@@ -146,6 +92,9 @@ int cmd_help(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command handler for version command
|
||||
*/
|
||||
int cmd_version(int argc, char** argv) {
|
||||
std::string version_msg = "DPM Version: ";
|
||||
version_msg += DPM_VERSION;
|
||||
@@ -162,6 +111,9 @@ int cmd_version(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command handler for system command
|
||||
*/
|
||||
int cmd_system(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "System Information:");
|
||||
|
||||
@@ -176,6 +128,9 @@ int cmd_system(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command handler for config command
|
||||
*/
|
||||
int cmd_config(int argc, char** argv) {
|
||||
const char* module_path = dpm_get_config("modules", "module_path");
|
||||
|
||||
@@ -188,6 +143,9 @@ int cmd_config(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command handler for unknown commands
|
||||
*/
|
||||
int cmd_unknown(const char* command, int argc, char** argv) {
|
||||
std::string msg = "Unknown command: ";
|
||||
msg += (command ? command : "");
|
||||
@@ -196,7 +154,9 @@ int cmd_unknown(const char* command, int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Function to parse command string to enum
|
||||
/**
|
||||
* Function to parse command string to enum
|
||||
*/
|
||||
Command parse_command(const char* cmd_str) {
|
||||
if (cmd_str == nullptr || strlen(cmd_str) == 0) {
|
||||
return CMD_HELP;
|
||||
@@ -217,28 +177,3 @@ Command parse_command(const char* cmd_str) {
|
||||
|
||||
return CMD_UNKNOWN;
|
||||
}
|
||||
|
||||
// Main entry point that will be called by DPM
|
||||
extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "Info module execution started");
|
||||
|
||||
Command cmd = parse_command(command);
|
||||
|
||||
switch (cmd) {
|
||||
case CMD_VERSION:
|
||||
return cmd_version(argc, argv);
|
||||
|
||||
case CMD_SYSTEM:
|
||||
return cmd_system(argc, argv);
|
||||
|
||||
case CMD_CONFIG:
|
||||
return cmd_config(argc, argv);
|
||||
|
||||
case CMD_HELP:
|
||||
return cmd_help(argc, argv);
|
||||
|
||||
case CMD_UNKNOWN:
|
||||
default:
|
||||
return cmd_unknown(command, argc, argv);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user