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 <cursoragent@cursor.com>
This commit is contained in:
@@ -196,6 +196,7 @@ add_subdirectory(libspinscale)
|
|||||||
# Add core components
|
# Add core components
|
||||||
add_subdirectory(smocore)
|
add_subdirectory(smocore)
|
||||||
add_subdirectory(commonLibs)
|
add_subdirectory(commonLibs)
|
||||||
|
add_subdirectory(comparatorLibs)
|
||||||
add_subdirectory(stimBuffApis)
|
add_subdirectory(stimBuffApis)
|
||||||
add_subdirectory(wilzorApis)
|
add_subdirectory(wilzorApis)
|
||||||
add_subdirectory(devices)
|
add_subdirectory(devices)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
add_subdirectory(core)
|
||||||
@@ -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
|
||||||
|
)
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
#include <user/comparatorApiDesc.h>
|
||||||
|
#include <user/senseApiDesc.h>
|
||||||
|
|
||||||
|
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<cologex::Comparator> makeBodySpotComparator()
|
||||||
|
{
|
||||||
|
return std::make_unique<BodySpotComparator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<cologex::Comparator> makeStimFeatComparator()
|
||||||
|
{
|
||||||
|
return std::make_unique<StimFeatComparator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<cologex::Comparator> makeSimultaneityStampComparator()
|
||||||
|
{
|
||||||
|
return std::make_unique<SimultaneityStampComparator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
#ifndef _USER_COMPARATOR_API_DESC_H
|
||||||
|
#define _USER_COMPARATOR_API_DESC_H
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <preprocessor.h>
|
||||||
|
#include <user/comparator.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
|
||||||
|
namespace stim_buff {
|
||||||
|
struct SmoCallbacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace cologex {
|
||||||
|
|
||||||
|
class ExportedComparatorTypeDesc
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::function<std::unique_ptr<Comparator>()> 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<ExportedComparatorTypeDesc> 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
|
||||||
Reference in New Issue
Block a user