Skip to content

Commit

Permalink
Add mola::MinimalModuleContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 25, 2024
1 parent a190aca commit c117d15
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 48 deletions.
98 changes: 50 additions & 48 deletions mola_kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,74 +22,76 @@ find_package(MRPT 2.1.0 REQUIRED COMPONENTS gui obs maps topography)

# define lib:
set(LIB_SRCS
src/entities/EntityBase.cpp
src/entities/LandmarkPoint3.cpp
src/entities/RefPose3.cpp
src/entities/RelDynPose3KF.cpp
src/entities/RelPose3.cpp
src/entities/RelPose3KF.cpp
src/Entity.cpp
src/Factor.cpp
src/factors/FactorBase.cpp
src/factors/FactorConstVelKinematics.cpp
src/factors/FactorRelativePose3.cpp
src/factors/FactorStereoProjectionPose.cpp
src/factors/SmartFactorIMU.cpp
src/factors/SmartFactorStereoProjectionPose.cpp
src/factors/FactorConstVelKinematics.cpp
src/factors/FactorStereoProjectionPose.cpp
src/register.cpp
src/WorldModel.cpp
src/interfaces/NavStateFilter.cpp
src/interfaces/RawDataSourceBase.cpp
src/interfaces/Dataset_UI.cpp
src/interfaces/FrontEndBase.cpp
src/interfaces/BackEndBase.cpp
src/interfaces/FilterBase.cpp
src/interfaces/Dataset_UI.cpp
src/interfaces/ExecutableBase.cpp
src/interfaces/Relocalization.cpp
src/interfaces/FilterBase.cpp
src/interfaces/FrontEndBase.cpp
src/interfaces/MapServer.cpp
src/Entity.cpp
src/Factor.cpp
src/entities/RelPose3.cpp
src/entities/RefPose3.cpp
src/entities/RelDynPose3KF.cpp
src/entities/LandmarkPoint3.cpp
src/entities/EntityBase.cpp
src/entities/RelPose3KF.cpp
src/pretty_print_exception.cpp
src/interfaces/NavStateFilter.cpp
src/interfaces/RawDataSourceBase.cpp
src/interfaces/Relocalization.cpp
src/LazyLoadResource.cpp
src/MinimalModuleContainer.cpp
src/pretty_print_exception.cpp
src/register.cpp
src/WorldModel.cpp
)

set(LIB_PUBLIC_HDRS
include/mola_kernel/entities/entities-common.h
include/mola_kernel/entities/EntityBase.h
include/mola_kernel/entities/EntityRelativeBase.h
include/mola_kernel/entities/KeyFrameBase.h
include/mola_kernel/entities/LandmarkPoint3.h
include/mola_kernel/entities/RefPose3.h
include/mola_kernel/entities/RelDynPose3KF.h
include/mola_kernel/entities/RelPose3.h
include/mola_kernel/entities/RelPose3KF.h
include/mola_kernel/Entity.h
include/mola_kernel/Factor.h
include/mola_kernel/factors/FactorBase.h
include/mola_kernel/factors/FactorConstVelKinematics.h
include/mola_kernel/factors/SmartFactorStereoProjectionPose.h
include/mola_kernel/factors/FactorStereoProjectionPose.h
include/mola_kernel/factors/SmartFactorIMU.h
include/mola_kernel/factors/FactorRelativePose3.h
include/mola_kernel/factors/factors-common.h
include/mola_kernel/factors/FactorBase.h
include/mola_kernel/LazyLoadResource.h
include/mola_kernel/pretty_print_exception.h
include/mola_kernel/WorldModel.h
include/mola_kernel/variant_helper.h
include/mola_kernel/factors/FactorStereoProjectionPose.h
include/mola_kernel/factors/SmartFactorIMU.h
include/mola_kernel/factors/SmartFactorStereoProjectionPose.h
include/mola_kernel/FastAllocator.h
include/mola_kernel/Entity.h
include/mola_kernel/id.h
include/mola_kernel/interfaces/BackEndBase.h
include/mola_kernel/interfaces/FrontEndBase.h
include/mola_kernel/interfaces/VizInterface.h
include/mola_kernel/interfaces/Dataset_UI.h
include/mola_kernel/interfaces/ExecutableBase.h
include/mola_kernel/interfaces/Relocalization.h
include/mola_kernel/interfaces/MapServer.h
include/mola_kernel/interfaces/NavStateFilter.h
include/mola_kernel/interfaces/FilterBase.h
include/mola_kernel/interfaces/RawDataSourceBase.h
include/mola_kernel/interfaces/RawDataConsumer.h
include/mola_kernel/interfaces/OfflineDatasetSource.h
include/mola_kernel/interfaces/FrontEndBase.h
include/mola_kernel/interfaces/LocalizationSourceBase.h
include/mola_kernel/interfaces/MapServer.h
include/mola_kernel/interfaces/MapSourceBase.h
include/mola_kernel/interfaces/Dataset_UI.h
include/mola_kernel/Factor.h
include/mola_kernel/entities/KeyFrameBase.h
include/mola_kernel/entities/EntityBase.h
include/mola_kernel/entities/RelPose3KF.h
include/mola_kernel/entities/RelPose3.h
include/mola_kernel/entities/EntityRelativeBase.h
include/mola_kernel/entities/RelDynPose3KF.h
include/mola_kernel/entities/LandmarkPoint3.h
include/mola_kernel/entities/RefPose3.h
include/mola_kernel/entities/entities-common.h
include/mola_kernel/id.h
include/mola_kernel/interfaces/NavStateFilter.h
include/mola_kernel/interfaces/OfflineDatasetSource.h
include/mola_kernel/interfaces/RawDataConsumer.h
include/mola_kernel/interfaces/RawDataSourceBase.h
include/mola_kernel/interfaces/Relocalization.h
include/mola_kernel/interfaces/VizInterface.h
include/mola_kernel/LazyLoadResource.h
include/mola_kernel/MinimalModuleContainer.h
include/mola_kernel/pretty_print_exception.h
include/mola_kernel/variant_helper.h
include/mola_kernel/WorldModel.h
include/mola_kernel/Yaml.h
)

Expand Down
66 changes: 66 additions & 0 deletions mola_kernel/include/mola_kernel/MinimalModuleContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* -------------------------------------------------------------------------
* A Modular Optimization framework for Localization and mApping (MOLA)
* Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
* See LICENSE for license information.
* ------------------------------------------------------------------------- */
/**
* @file MinimalModuleContainer.h
* @brief A simple module container for use without mola_launcher
* @author Jose Luis Blanco Claraco
* @date Dec 26, 2024
*/
#pragma once

#include <mola_kernel/interfaces/ExecutableBase.h>

#include <string>
#include <vector>

namespace mola
{
/** \addtogroup mola_kernel_grp
* @{ */

/**
* A minimal MOLA application container, for use programatically when it is
* not advisable to use the mola-cli application.
*
* This implements basic discoverability and visibility between modules.
*/
class MinimalModuleContainer
{
public:
MinimalModuleContainer() = default;
~MinimalModuleContainer();

explicit MinimalModuleContainer(
const std::vector<mola::ExecutableBase::Ptr>& mods)
: modules_(mods)
{
for (auto& m : modules_)
{
ASSERT_(m);
installNameServer(*m);
}
}

void add(const mola::ExecutableBase::Ptr& m)
{
ASSERT_(m);
modules_.push_back(m);
installNameServer(*m);
}

const auto& modules() const { return modules_; }

private:
std::vector<mola::ExecutableBase::Ptr> modules_;

void installNameServer(mola::ExecutableBase& m);

ExecutableBase::Ptr nameServerImpl(const std::string& name);
};

/** @} */

} // namespace mola
47 changes: 47 additions & 0 deletions mola_kernel/src/MinimalModuleContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* -------------------------------------------------------------------------
* A Modular Optimization framework for Localization and mApping (MOLA)
* Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
* See LICENSE for license information.
* ------------------------------------------------------------------------- */
/**
* @file MinimalModuleContainer.cpp
* @brief A simple module container for use without mola_launcher
* @author Jose Luis Blanco Claraco
* @date Dec 26, 2024
*/

#include <mola_kernel/MinimalModuleContainer.h>

namespace mola
{
MinimalModuleContainer::~MinimalModuleContainer() = default;

void MinimalModuleContainer::installNameServer(ExecutableBase& m)
{
m.nameServer_ = std::bind(
&MinimalModuleContainer::nameServerImpl, this, std::placeholders::_1);
}

ExecutableBase::Ptr MinimalModuleContainer::nameServerImpl(
const std::string& name)
{
// Special syntax to sequentially access all existing modules:
// If the requested name has the format: "[" + <i>, return the i-th
// module, or nullptr if out of range.
// This is used by ExecutableBase::findService()
if (name.size() >= 2 && name[0] == '[')
{
const auto idx = std::stoul(name.substr(1));
if (idx >= modules_.size()) { return ExecutableBase::Ptr(); }
else
{
auto it = modules_.begin();
std::advance(it, idx);
return *it;
}
}
// non numeric search not implemented in this minimal container
return ExecutableBase::Ptr();
}

} // namespace mola

0 comments on commit c117d15

Please sign in to comment.