From 10234bc422052c844cb4ce2140a6cede0b64b3d6 Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Wed, 10 Jun 2026 21:13:19 -0400 Subject: [PATCH] Add comparator API descriptor and libcomparatorCore scaffold. Introduce ExportedComparatorTypeDesc/ComparatorLibDesc with inline sanity checks, and add a core comparator shlib exporting three stub types. Co-authored-by: Cursor --- CMakeLists.txt | 1 + comparatorLibs/CMakeLists.txt | 1 + comparatorLibs/core/CMakeLists.txt | 21 ++++ comparatorLibs/core/comparatorCore.cpp | 129 +++++++++++++++++++++++++ include/user/comparatorApiDesc.h | 77 +++++++++++++++ 5 files changed, 229 insertions(+) create mode 100644 comparatorLibs/CMakeLists.txt create mode 100644 comparatorLibs/core/CMakeLists.txt create mode 100644 comparatorLibs/core/comparatorCore.cpp create mode 100644 include/user/comparatorApiDesc.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2857398..cb71e8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,6 +196,7 @@ add_subdirectory(libspinscale) # Add core components add_subdirectory(smocore) add_subdirectory(commonLibs) +add_subdirectory(comparatorLibs) add_subdirectory(stimBuffApis) add_subdirectory(wilzorApis) add_subdirectory(devices) diff --git a/comparatorLibs/CMakeLists.txt b/comparatorLibs/CMakeLists.txt new file mode 100644 index 0000000..ad6d478 --- /dev/null +++ b/comparatorLibs/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(core) diff --git a/comparatorLibs/core/CMakeLists.txt b/comparatorLibs/core/CMakeLists.txt new file mode 100644 index 0000000..28b362d --- /dev/null +++ b/comparatorLibs/core/CMakeLists.txt @@ -0,0 +1,21 @@ +add_library(comparatorCore SHARED + comparatorCore.cpp +) + +set_target_properties(comparatorCore PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} +) + +target_include_directories(comparatorCore PUBLIC + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/smocore/include +) + +target_link_libraries(comparatorCore PUBLIC + spinscale +) + +install(TARGETS comparatorCore + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} NAMELINK_SKIP +) diff --git a/comparatorLibs/core/comparatorCore.cpp b/comparatorLibs/core/comparatorCore.cpp new file mode 100644 index 0000000..2ba96c5 --- /dev/null +++ b/comparatorLibs/core/comparatorCore.cpp @@ -0,0 +1,129 @@ +#include +#include + +namespace smo { +namespace comparator_lib { +namespace core { +namespace { + +static const char COMPARATOR_LIB_NAME[] = "comparatorCore"; +static const char BODY_SPOT_COMPARATOR_TYPE_NAME[] = "bodySpot"; +static const char STIM_FEAT_COMPARATOR_TYPE_NAME[] = "stimFeat"; +static const char SIMULTANEITY_STAMP_COMPARATOR_TYPE_NAME[] = + "simultaneityStamp"; + +class BodySpotComparator +: public cologex::Comparator +{ +public: + BodySpotComparator() + : cologex::Comparator(MentalEntity::Id{0}) + {} + + cologex::ComparatorTypeId getTypeId() const override + { + return cologex::ComparatorTypeId{ + cologex::SMO_COMPARATOR_VENDOR_ID, + cologex::SMO_COMPARATOR_TYPE_BODY_SPOT + }; + } +}; + +class StimFeatComparator +: public cologex::Comparator +{ +public: + StimFeatComparator() + : cologex::Comparator(MentalEntity::Id{0}) + {} + + cologex::ComparatorTypeId getTypeId() const override + { + return cologex::ComparatorTypeId{ + cologex::SMO_COMPARATOR_VENDOR_ID, + cologex::SMO_COMPARATOR_TYPE_STIM_FEAT + }; + } +}; + +class SimultaneityStampComparator +: public cologex::Comparator +{ +public: + SimultaneityStampComparator() + : cologex::Comparator(MentalEntity::Id{0}) + {} + + cologex::ComparatorTypeId getTypeId() const override + { + return cologex::ComparatorTypeId{ + cologex::SMO_COMPARATOR_VENDOR_ID, + cologex::SMO_COMPARATOR_TYPE_SIMULTANEITY_STAMP + }; + } +}; + +std::unique_ptr makeBodySpotComparator() +{ + return std::make_unique(); +} + +std::unique_ptr makeStimFeatComparator() +{ + return std::make_unique(); +} + +std::unique_ptr makeSimultaneityStampComparator() +{ + return std::make_unique(); +} + +cologex::ComparatorLibDesc buildComparatorLibDesc() +{ + return cologex::ComparatorLibDesc{ + .name = COMPARATOR_LIB_NAME, + .exportedComparatorTypes = { + cologex::ExportedComparatorTypeDesc{ + .name = BODY_SPOT_COMPARATOR_TYPE_NAME, + .typeId = cologex::ComparatorTypeId{ + cologex::SMO_COMPARATOR_VENDOR_ID, + cologex::SMO_COMPARATOR_TYPE_BODY_SPOT + }, + .getNewInstance = makeBodySpotComparator + }, + cologex::ExportedComparatorTypeDesc{ + .name = STIM_FEAT_COMPARATOR_TYPE_NAME, + .typeId = cologex::ComparatorTypeId{ + cologex::SMO_COMPARATOR_VENDOR_ID, + cologex::SMO_COMPARATOR_TYPE_STIM_FEAT + }, + .getNewInstance = makeStimFeatComparator + }, + cologex::ExportedComparatorTypeDesc{ + .name = SIMULTANEITY_STAMP_COMPARATOR_TYPE_NAME, + .typeId = cologex::ComparatorTypeId{ + cologex::SMO_COMPARATOR_VENDOR_ID, + cologex::SMO_COMPARATOR_TYPE_SIMULTANEITY_STAMP + }, + .getNewInstance = makeSimultaneityStampComparator + } + } + }; +} + +} // namespace +} // namespace core +} // namespace comparator_lib +} // namespace smo + +extern "C" smo::SMO_GET_COMPARATOR_LIB_DESC_FN_TYPEDEF + SMO_GET_COMPARATOR_LIB_DESC_FN_NAME; + +const smo::cologex::ComparatorLibDesc& SMO_GET_COMPARATOR_LIB_DESC_FN_NAME( + const smo::stim_buff::SmoCallbacks& callbacks) +{ + (void)callbacks; + static const smo::cologex::ComparatorLibDesc comparatorLibDesc = + smo::comparator_lib::core::buildComparatorLibDesc(); + return comparatorLibDesc; +} diff --git a/include/user/comparatorApiDesc.h b/include/user/comparatorApiDesc.h new file mode 100644 index 0000000..7ae9049 --- /dev/null +++ b/include/user/comparatorApiDesc.h @@ -0,0 +1,77 @@ +#ifndef _USER_COMPARATOR_API_DESC_H +#define _USER_COMPARATOR_API_DESC_H + +#include +#include +#include +#include +#include +#include + +namespace smo { + +namespace stim_buff { +struct SmoCallbacks; +} + +namespace cologex { + +class ExportedComparatorTypeDesc +{ +public: + typedef std::function()> GetNewInstanceFn; + + static bool sanityCheck(const ExportedComparatorTypeDesc &desc) + { + if (desc.name.empty()) { return false; } + + if (desc.typeId.vendorId == 0u && desc.typeId.typeId == 0u) + { return false; } + + if (!desc.getNewInstance) { return false; } + return true; + } + +public: + std::string name; + ComparatorTypeId typeId; + GetNewInstanceFn getNewInstance; +}; + +class ComparatorLibDesc +{ +public: + static bool sanityCheck(const ComparatorLibDesc &desc) + { + if (desc.name.empty()) { return false; } + if (desc.exportedComparatorTypes.empty()) { return false; } + + for (const auto& exportedType : desc.exportedComparatorTypes) + { + if (!ExportedComparatorTypeDesc::sanityCheck(exportedType)) { + return false; + } + } + + return true; + } + +public: + std::string name; + std::vector exportedComparatorTypes; +}; + +} // namespace cologex + +#define SMO_GET_COMPARATOR_LIB_DESC_FN_NAME getComparatorLibDesc +#define SMO_GET_COMPARATOR_LIB_DESC_FN_NAME_STR \ + SMO_QUOTE(SMO_GET_COMPARATOR_LIB_DESC_FN_NAME) +#define SMO_GET_COMPARATOR_LIB_DESC_FN_TYPEDEF \ + SMO_CONCAT(SMO_GET_COMPARATOR_LIB_DESC_FN_NAME, Fn) + +typedef const cologex::ComparatorLibDesc& (SMO_GET_COMPARATOR_LIB_DESC_FN_TYPEDEF)( + const stim_buff::SmoCallbacks& callbacks); + +} // namespace smo + +#endif // _USER_COMPARATOR_API_DESC_H