summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'signal-composer-binding/signal.cpp')
-rw-r--r--signal-composer-binding/signal.cpp99
1 files changed, 27 insertions, 72 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 2dcc552..a74889d 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -184,52 +184,6 @@ void Signal::attachToSourceSignals(Composer& composer)
}
}
-/// @brief Call update() method on observer Signal with
-/// current Signal timestamp and value
-/*void Signal::notify() const
-{
- for (int i = 0; i < Observers_.size(); ++i)
- Observers_[i]->update(timestamp_, value_);
-}
-
-/// @brief Inner recursion check. Argument is the Signal id coming
-/// from the original Signal that made a recursion check.
-///
-/// @param[in] origId - name of the origine of the recursion check
-///
-/// @return 0 if no infinite loop detected, -1 if not.
-int Signal::recursionCheck(const std::string& origId) const
-{
- for (const auto& obs: observersList_)
- {
- if( id_ == obs->id())
- {return -1;}
- if( origId == obs->id())
- {return -1;}
- if(! obs->recursionCheck(origId))
- {return -1;}
- }
- return 0;
-}
-
-/// @brief Recursion check to ensure that there is no infinite loop
-/// in the Observers/Observables structure.
-/// This will check that observer signal is not the same than itself
-/// then trigger the check against the following eventuals observers
-///
-/// @return 0 if no infinite loop detected, -1 if not.
-int Signal::recursionCheck() const
-{
- for (const auto& obs: observersList_)
- {
- if( id_ == obs->id())
- {return -1;}
- if( obs->recursionCheck(id_))
- {return -1;}
- }
- return 0;
-}*/
-
/// @brief Make an average over the last X 'seconds'
///
/// @param[in] seconds - period to calculate the average
@@ -339,39 +293,40 @@ struct SignalValue Signal::last() const
return history_.rbegin()->second;
}
-/*
-template<class Signal>
-Observable<Signal>::~Observable()
-{
- iterator_ itb = observerList_.begin();
- const_iterator_ ite = observerList_.end();
-
- for(;itb!=ite;++itb)
- {
- (*itb)->delObservable(this);
- }
-}
-template <class Signal>
-Observer<Signal>::~Observer()
+/// @brief Recursion check to ensure that there is no infinite loop
+/// in the Observers/Observables structure.
+/// This will check that observer signal is not the same than itself
+/// then trigger the check against the following eventuals observers
+///
+/// @return 0 if no infinite loop detected, -1 if not.
+int Signal::initialRecursionCheck()
{
- const_iterator_ ite = observableList_.end();
-
- for(iterator_ itb=observableList_.begin();itb!=ite;++itb)
+ for (auto& obs: observerList_)
{
- (*itb)->delObserver(this);
+ if(obs == this)
+ {return -1;}
+ if(static_cast<Signal*>(obs)->recursionCheck(static_cast<Signal*>(obs)))
+ {return -1;}
}
+ return 0;
}
-template <class Signal>
-void Observable<Signal>::notify()
+/// @brief Inner recursion check. Argument is the Signal id coming
+/// from the original Signal that made a recursion check.
+///
+/// @param[in] origId - name of the origine of the recursion check
+///
+/// @return 0 if no infinite loop detected, -1 if not.
+int Signal::recursionCheck(Signal* parentSig)
{
- iterator_ itb=observerList_.begin();
- const_iterator_ ite=observerList_.end();
-
- for(;itb!=ite;++itb)
+ for (const auto& obs: observerList_)
{
- (*itb)->update(static_cast<Signal*>(this));
+ Signal* obsSig = static_cast<Signal*>(obs);
+ if(parentSig->id() == static_cast<Signal*>(obsSig)->id())
+ {return -1;}
+ if(! obsSig->recursionCheck(obsSig))
+ {return -1;}
}
+ return 0;
}
-*/