- switch(channel->type()->id()) {
- case SR_CHANNEL_LOGIC:
- signal = shared_ptr<view::Signal>(
- new view::LogicSignal(*this, device,
- channel, logic_data_));
- break;
-
- case SR_CHANNEL_ANALOG:
- {
- shared_ptr<data::Analog> data(
- new data::Analog());
- signal = shared_ptr<view::Signal>(
- new view::AnalogSignal(
- *this, channel, data));
- break;
- }
-
- default:
- assert(0);
- break;
+ // Find the channel in the old signals
+ const auto iter = std::find_if(
+ prev_sigs.cbegin(), prev_sigs.cend(),
+ [&](const shared_ptr<view::Signal> &s) {
+ return s->channel() == channel;
+ });
+ if (iter != prev_sigs.end()) {
+ // Copy the signal from the old set to the new
+ signal = *iter;
+ auto logic_signal = dynamic_pointer_cast<
+ view::LogicSignal>(signal);
+ if (logic_signal)
+ logic_signal->set_logic_data(
+ logic_data_);
+ } else {
+ // Create a new signal
+ switch(channel->type()->id()) {
+ case SR_CHANNEL_LOGIC:
+ signal = shared_ptr<view::Signal>(
+ new view::LogicSignal(*this,
+ device_, channel,
+ logic_data_));
+ break;
+
+ case SR_CHANNEL_ANALOG:
+ {
+ shared_ptr<data::Analog> data(
+ new data::Analog());
+ signal = shared_ptr<view::Signal>(
+ new view::AnalogSignal(
+ *this, channel, data));
+ break;
+ }
+
+ default:
+ assert(0);
+ break;
+ }