rossvideo / Catena

BSD 3-Clause "New" or "Revised" License
6 stars 2 forks source link

Param accessor setValue fails #120

Closed Mionsz closed 7 months ago

Mionsz commented 7 months ago

Param accessor setValue fails for each type:

C++ exception with description "setValue failed: const Function& catena::patterns::Functory<K, R, Ms>::operator[](K) const [with K = catena::Value::KindCase; R = void; Ms = {void*, const catena::Value*}; catena::patterns::Functory<K, R, Ms>::Function = std::function<void(void*, const catena::Value*)>], key not found 0
void catena::ParamAccessor::getValue(V&) const [with bool Threadsafe = true; V = int]
mejohnnaylor commented 7 months ago

the root cause of this is the static initialization order fiasco. I did put in a fix for it a while ago. let me check it made it into the develop branch...

yes - it's there Param accessor initializes all the Functories on first use:

ParamAccessor::ParamAccessor(DeviceModel &dm, DeviceModel::ParamAccessorData &pad, const std::string& oid)
    : deviceModel_{dm}, param_{*std::get<0>(pad)}, value_{*std::get<1>(pad)}, oid_{oid}, id_{std::hash<std::string>{}(oid)} {
    static bool initialized = false;
    if (!initialized) {
        initialized = true;  // so we only do this once

        // get our functories
        auto &setter = Setter::getInstance();
        auto &getter = Getter::getInstance();
        auto &setterAt = SetterAt::getInstance();
        auto &getterAt = GetterAt::getInstance();
        auto &variantGetter = VariantInfoGetter::getInstance();
        auto &valueGetter = ValueGetter::getInstance();
        auto &valueSetter = ValueSetter::getInstance();

        // register int getter
        REGISTER_GETTER(KindCase::kInt32Value, int32_value, int32_t);

        // register float getter
        REGISTER_GETTER(KindCase::kFloat32Value, float32_value, float);

// etc
mejohnnaylor commented 7 months ago

can you ensure you're up to date with the latest develop branch?

Mionsz commented 7 months ago

I will check it.

Mionsz commented 7 months ago

image

mejohnnaylor commented 7 months ago

I just pulled develop and built from scratch. it runs fine for me. but I'm on macOS with CLANG, not ubuntu with gcc. However, the version of full_service I have doesn't yet have your refactoring in it. Are you building from develop or your PR?

Mionsz commented 7 months ago

I am building from develop first so that I know it works as intended. I am using docker with no-cache flag and commit: image