Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(dif_test)
add_subdirectory(dmod_loader)
add_subdirectory(dmod_loader)
add_subdirectory(list_modules)
26 changes: 26 additions & 0 deletions examples/system/list_modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.10)

# Set the project name
project(list_modules VERSION ${dmod_VERSION_MAJOR}.${dmod_VERSION_MINOR})

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Add the executable
add_executable(${PROJECT_NAME} main.c)

# Include directories
include_directories(${PROJECT_SOURCE_DIR})

# Link libraries
target_link_libraries(${PROJECT_NAME} dmod)

target_link_options(${PROJECT_NAME} PRIVATE -L ${DMOD_DIR}/scripts)
target_link_options(${PROJECT_NAME} PRIVATE -T ${DMOD_DIR}/examples/system/dmod_loader/main.ld)

# Install the tool to the system bin directory
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
COMPONENT tools
)
99 changes: 99 additions & 0 deletions examples/system/list_modules/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <stdio.h>
#include <string.h>
#include "dmod.h"

/**
* @brief Simple test application to list all modules
*
* This application demonstrates the usage of Dmod_OpenModules/ReadModule/CloseModules API
*/
int main( int argc, char *argv[] )
{
// Initialize Dmod system
if (!Dmod_Initialize())
{
printf("Error: Failed to initialize Dmod system\n");
return -1;
}

printf("=== DMOD Module Lister ===\n\n");

// If a module name is provided, try to load it first
if( argc > 1 )
{
for( int i = 1; i < argc; i++ )
{
printf("Loading module: %s\n", argv[i]);
if( Dmod_LoadModuleByName( argv[i] ) )
{
printf(" Successfully loaded module: %s\n", argv[i]);
}
else
{
printf(" Failed to load module: %s\n", argv[i]);
}
}
printf("\n");
}

// Open modules iterator
Dmod_ModulesIterator_t iterator = Dmod_OpenModules();
if( iterator == NULL )
{
printf("Error: Failed to open modules iterator\n");
return -1;
}

printf("Listing modules:\n\n");
printf("%-30s %-15s %-15s\n", "Module Name", "Version", "State");
printf("%-30s %-15s %-15s\n", "--------------------------------", "---------------", "---------------");

// Iterate through modules
size_t count = 0;
const Dmod_ModuleInfo_t* module;
while( (module = Dmod_ReadModule( iterator )) != NULL )
{
const char* stateStr = "Unknown";
switch( module->State )
{
case Dmod_ModuleState_Available:
stateStr = "Available";
break;
case Dmod_ModuleState_Loaded:
stateStr = "Loaded";
break;
case Dmod_ModuleState_Enabled:
stateStr = "Enabled";
break;
case Dmod_ModuleState_Running:
stateStr = "Running";
break;
default:
stateStr = "Unknown";
break;
}

printf("%-30s %-15s %-15s\n",
module->ModuleName,
module->Version[0] != '\0' ? module->Version : "N/A",
stateStr);
count++;
}

// Close iterator
Dmod_CloseModules( iterator );

if( count == 0 )
{
printf("\nNo modules found. Try:\n");
printf(" - Setting DMOD_REPO_PATHS environment variable to a directory with .dmf/.dmfc files\n");
printf(" - Running with module name arguments: %s <module_name>\n", argv[0]);
}
else
{
printf("\nTotal modules found: %zu\n", count);
}

printf("\n");
return 0;
}
4 changes: 4 additions & 0 deletions inc/dmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ DMOD_BUILTIN_API( Dmod, 1.0, size_t , _GetNumberOfPackages, ( void ) );
DMOD_BUILTIN_API( Dmod, 1.0, bool , _GetPackageInfo, ( uint32_t PackageIndex, char* outName, size_t NameMaxLength, size_t* outSize ) );
DMOD_BUILTIN_API( Dmod, 1.0, uint32_t , _GetMainIndexFromPackage, ( const char* PackageName ) );

DMOD_BUILTIN_API( Dmod, 1.0, Dmod_ModulesIterator_t, _OpenModules, ( void ) );
DMOD_BUILTIN_API( Dmod, 1.0, const Dmod_ModuleInfo_t*, _ReadModule, ( Dmod_ModulesIterator_t Iterator ) );
DMOD_BUILTIN_API( Dmod, 1.0, void , _CloseModules, ( Dmod_ModulesIterator_t Iterator ) );

//! @}

#ifdef __cplusplus
Expand Down
34 changes: 34 additions & 0 deletions inc/dmod_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@ typedef enum
Dmod_ModuleType_Count,
} Dmod_ModuleType_t;

/**
* @brief Module state enumeration
*
* Describes the current state of a module in the system.
*/
typedef enum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jakiś doxygen do tego enuma też by się przydał

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Doxygen documentation for the enum. Commit: 0601708

{
Dmod_ModuleState_Available, //!< Module is available but not loaded
Dmod_ModuleState_Loaded, //!< Module is loaded but not enabled
Dmod_ModuleState_Enabled, //!< Module is enabled (library modules)
Dmod_ModuleState_Running, //!< Module is running (application modules)

Dmod_ModuleState_Count,
} Dmod_ModuleState_t;

/**
* @brief Module information structure
*
* Contains information about a module including its name, version, and current state.
*/
typedef struct
{
char ModuleName[DMOD_MAX_MODULE_NAME_LENGTH]; //!< Name of the module
char Version[DMOD_MAX_VERSION_LENGTH]; //!< Version string of the module
Dmod_ModuleState_t State; //!< Current state of the module
} Dmod_ModuleInfo_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ta struktura też powinna mieć dokumentację

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Doxygen documentation for the struct with field descriptions. Commit: 0601708


/**
* @brief Modules iterator handle
*
* @note Opaque handle for iterating through modules. Use Dmod_OpenModules, Dmod_ReadModule, and Dmod_CloseModules.
*/
typedef void* Dmod_ModulesIterator_t;

typedef struct
{
uint32_t Size;
Expand Down
Loading