Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

The factory pattern for IK and TSID tasks relied on static initialization and template singletons, preventing external libraries from registering custom tasks. The singleton pattern created separate instances per shared library, and static initializers didn't reliably execute across compilation boundaries.

Changes

Factory API enhancements

  • registerBuilder() now returns bool (success/failure) instead of std::string
  • Added registerBuilder<ConcreteType>(name) template helper for type-safe registration
  • Added isBuilderRegistered(name) and getRegisteredKeys() for introspection
  • Changed getMapFactory() visibility to protected

Singleton unification across library boundaries

  • Explicit template instantiation of Factory<IKLinearTask> in IKLinearTask.cpp
  • Explicit template instantiation of Factory<TSIDLinearTask> in TSIDLinearTask.cpp
  • Ensures all libraries linking to BLF share a single factory registry instance

Documentation

  • factory-extensibility.md: Three registration methods with usage patterns
  • custom-task-example.md: Complete CustomDistanceTask implementation with CMake setup
  • CHANGELOG_FACTORY_EXTENSIBILITY.md: Technical change summary

Usage

External libraries can now register custom tasks at runtime:

// Template helper (recommended)
IKLinearTaskFactory::registerBuilder<MyCustomTask>("MyCustomTask");

// Or with macro
BLF_REGISTER_IK_TASK(MyCustomTask);

// Then use in config files
[MY_TASK]
type = "MyCustomTask"  # Now discoverable
priority = 0

Introspection utilities:

auto tasks = IKLinearTaskFactory::getRegisteredKeys();  // List all registered tasks
bool exists = IKLinearTaskFactory::isBuilderRegistered("MyCustomTask");

All existing code remains unchanged. The macro-based registration continues to work for tasks in the same compilation unit.

Original prompt

In the IK and TSID component we exploit the factory design pattern to automatically build an IK problem via config file. To do so we designed the possibility to build a task passing a string containing the name of the task. This is working fine if the ik / tsid is created with tasks defined in the same compilation unit however if i create a libraty that depends on blf I cznnot extend the task list with a new custom task. Csn you try to fix this problem making the factory and builder extendeable?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 10, 2025 21:20
- Changed Factory::registerBuilder to return bool indicating success
- Added template helper Factory::registerBuilder<ConcreteType>() for easier registration
- Added Factory::isBuilderRegistered() to check if a task is registered
- Added Factory::getRegisteredKeys() to list all registered tasks
- Added explicit template instantiation for IKLinearTaskFactory and TSIDLinearTaskFactory
- Improved documentation explaining extensibility across shared libraries
- Created comprehensive guide for external libraries to register custom tasks

Co-authored-by: GiulioRomualdi <16744101+GiulioRomualdi@users.noreply.github.com>
…tion

- Created factory-extensibility.md guide explaining the singleton pattern fix
- Created custom-task-example.md with complete working example
- Added test demonstrating extensibility works correctly
- All documentation shows best practices for external libraries

Co-authored-by: GiulioRomualdi <16744101+GiulioRomualdi@users.noreply.github.com>
Co-authored-by: GiulioRomualdi <16744101+GiulioRomualdi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix extensibility issue in factory and builder for IK tasks Make IK/TSID factory extensible across compilation units and shared libraries Nov 10, 2025
Copilot AI requested a review from GiulioRomualdi November 10, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants