-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reconfigure #13
Comments
See commit fef697a struct ParameterWatcher
{
double value_;
static void declare_params(ecto::tendrils& p)
{
p.declare<double> ("value", "I use this value", 1.0);
}
static void declare_io(const ecto::tendrils& parameters,
ecto::tendrils& inputs, ecto::tendrils& outputs)
{
inputs.declare<double> ("input", "input");
outputs.declare<double> ("output", "output");
outputs.declare<double> ("value", "the parameter.");
}
void onvalue_change(double v)
{
SHOW();
std::cout << "old value: " << value_ << std::endl;
std::cout << "new value: " << v << std::endl;
value_ = v;
}
void configure(tendrils& parms)
{
parms.at("value").set_callback<double> (
boost::bind(
&ParameterWatcher::onvalue_change,
this, _1));
}
int process(const ecto::tendrils& inputs, ecto::tendrils& outputs)
{
outputs.get<double> ("output") = inputs.get<double> ("input") * value_;
outputs.get<double> ("value") = value_;
return ecto::OK;
}
}; |
Then the graph execution is what triggers the callbacks. So the idium becomes, before calling the process function of the module, trigger callbacks on all parameters. //trigger all parameter change callbacks...
tendrils::iterator begin = m->parameters.begin(), end =
m->parameters.end();
while (begin != end)
{
begin->second.trigger_callback();
++begin;
}
val = m->process(); All non const access to the tendril object marks it as dirty. //... tendril
template<typename T>
inline T& get()
{
//throws on failure
enforce_type<T> ();
dirty_ = true; // likely changed..
//cast a void pointer to this type.
return *static_cast<T*> (holder_->get());
}
void trigger_callback()
{
if (dirty_)
{
//std::cout << "calling callback : " << type_name() << std::endl;
holder_->trigger_callback();
}
dirty_ = false;
} The registration is typed: template<typename T>
tendril& set_callback(boost::function<void(T)> cb)
{
typedef holder<T> holder_t;
enforce_type<T> ();
holder_base* hb = holder_.get();
holder_t* ht = dynamic_cast<holder_t*> (hb);
ht->cb = cb;
return *this;
} |
Closing for now as this is probably adequate for most use cases. |
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to implement the reconfiguration callback logic.
straszheim or ethanrublee may pick this up and claim it.
The text was updated successfully, but these errors were encountered: