Esempio n. 1
0
void RawVariable::internalCb(const CSI::ValueChangedEventArgs &val)
{
    m_insideInternalCb = true;

    // store the value
    std::string stdstr = val.NewValue().ConvertOr<std::string>("");
    m_cachedValue = stdstr.c_str();
    dbg(1) << "cached(" << m_fullPath << ")=" << m_cachedValue;

    // TODO: is this necessary? the reasoning is that a callback might be removed
    // while we are iterating through callbacks...
    auto cbcopy = m_cbmap;
    // call all our callbacks
    for( auto c : cbcopy) {
        dbg(1) << "Calling cb " << c.first;
//        CallbackParams parms;
//        parms.postfix = m_postfix;
//        parms.prefix = m_prefix;
//        parms.val = val.NewValue().ConvertOr<std::string>("").c_str();

        c.second( * this);
        dbg(1) << "Calling cb done" << c.first;
    }

    m_insideInternalCb = false;
}
Esempio n. 2
0
void ServerConnector::pureWebValueChangedCB(const CSI::ValueChangedEventArgs &val)
{

    // here we call the actual callbacks
    QString path = val.Path().ToAscii().begin();
    QString newVal;
    if( val.NewValue().HasValue()) {
        newVal = val.NewValue().Value().ToAscii().begin();
    }

    // Note: DON'T DO THIS:
    //    QString path = val.Path().As< QString >();
    // As it would use ostream operator << overloading, breaking at spaces...

    // Pureweb could be calling this method directly from inside SetValue()...
    // which is not what we want. So instead we do the real work using defer()
    defer( [ path, newVal, this ] () {
        auto & callbacks = m_stateCallbackList[ path];
        for( auto & cb : callbacks) {
            cb( path, newVal);
        }
    });
}