-
Notifications
You must be signed in to change notification settings - Fork 0
Add iterator-based API to list loaded and available modules #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
047de93
Initial plan
Copilot 02f0acc
Add Dmod_ReadModules API to list loaded and available modules
Copilot 9b52ff0
Add list_modules example and fix package slot validation
Copilot a71af90
Add unit tests and fix null pointer crash in Dmod_Hlp_AddSearchNode
Copilot 0601708
Refactor to iterator-based API pattern and add documentation
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| { | ||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ta struktura też powinna mieć dokumentację
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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ł
There was a problem hiding this comment.
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