Go to the documentation of this file. 1 #ifndef H_CANOPEN_LAYER
2 #define H_CANOPEN_LAYER
6 #include <boost/thread/shared_mutex.hpp>
8 #include <boost/exception/diagnostic_information.hpp>
20 virtual void set(
const State &s,
const std::string &r){
35 template<
typename T>
bool bounded()
const{
return state <= T::state; }
36 template<
typename T>
bool equals()
const{
return state == T::state; }
49 std::vector<std::pair<std::string, std::string> >
values_;
51 const std::vector<std::pair<std::string, std::string> > &
values()
const {
return values_; }
52 template<
typename T>
void add(
const std::string &key,
const T &value) {
53 std::stringstream str;
55 values_.push_back(std::make_pair(key,str.str()));
59 #define CATCH_LAYER_HANDLER_EXCEPTIONS(command, status) \
61 catch(std::exception &e) {status.error(boost::diagnostic_information(e)); }
153 template<
typename Bound,
typename Data,
typename FuncType>
typename vector_type::iterator
call(FuncType func, Data &status){
154 boost::shared_lock<boost::shared_mutex> lock(
mutex);
155 return call<Bound>(func, status,
layers.begin(),
layers.end());
157 template<
typename Data,
typename FuncType>
typename vector_type::iterator
call(FuncType func, Data &status){
158 boost::shared_lock<boost::shared_mutex> lock(
mutex);
159 return call<LayerStatus::Unbounded>(func, status,
layers.begin(),
layers.end());
161 template<
typename Bound,
typename Data,
typename FuncType>
typename vector_type::reverse_iterator
call_rev(FuncType func, Data &status){
162 boost::shared_lock<boost::shared_mutex> lock(
mutex);
163 return call<Bound>(func, status,
layers.rbegin(),
layers.rend());
165 template<
typename Data,
typename FuncType>
typename vector_type::reverse_iterator
call_rev(FuncType func, Data &status){
166 boost::shared_lock<boost::shared_mutex> lock(
mutex);
167 return call<LayerStatus::Unbounded>(func, status,
layers.rbegin(),
layers.rend());
174 template<
typename Bound,
typename Data,
typename FuncType>
bool callFunc(FuncType func, Data &status){
175 boost::shared_lock<boost::shared_mutex> lock(
mutex);
182 template<
typename Bound,
typename Iterator,
typename Data,
typename FuncType> Iterator
call(FuncType func, Data &status,
const Iterator &begin,
const Iterator &end){
183 bool okay_on_start = status.template bounded<Bound>();
185 for(Iterator it = begin; it != end; ++it){
186 ((**it).*func)(status);
187 if(okay_on_start && !status.template bounded<Bound>()){
193 template<
typename Iterator,
typename Data,
typename FuncType> Iterator
call(FuncType func, Data &status,
const Iterator &begin,
const Iterator &end){
194 return call<LayerStatus::Unbounded, Iterator, Data>(func, status, begin, end);
200 template<
typename Data,
typename FuncType,
typename FailType>
void call_or_fail(FuncType func, FailType fail, Data &status){
201 this->
template call(func, status);
202 if(!status.template bounded<LayerStatus::Warn>()){
203 this->
template call(fail, status);
204 (this->*fail)(status);
207 template<
typename Data,
typename FuncType,
typename FailType>
void call_or_fail_rev(FuncType func, FailType fail, Data &status){
208 this->
template call_rev(func, status);
209 if(!status.template bounded<LayerStatus::Warn>()){
210 this->
template call_rev(fail, status);
211 (this->*fail)(status);
LayerGroupNoDiag(const std::string &n)
virtual void handleDiag(LayerReport &report)
void shutdown(LayerStatus &status)
void write(LayerStatus &status)
void call_or_fail_rev(FuncType func, FailType fail, Data &status)
virtual void handleWrite(LayerStatus &status, const LayerState ¤t_state)=0
virtual void handleShutdown(LayerStatus &status)=0
Iterator call(FuncType func, Data &status, const Iterator &begin, const Iterator &end)
void call_or_fail(FuncType func, FailType fail, Data &status)
void diag(LayerReport &report)
vector_type::iterator call(FuncType func, Data &status)
virtual void add(const VectorMemberSharedPtr &l)
virtual void handleWrite(LayerStatus &status, const LayerState ¤t_state)
const void error(const std::string &r)
Layer(const std::string &n)
void add(const std::string &key, const T &value)
const void warn(const std::string &r)
LayerState getLayerState()
const std::string reason() const
void halt(LayerStatus &status)
bool callFunc(FuncType func, Data &status)
virtual void handleHalt(LayerStatus &status)=0
void recover(LayerStatus &status)
#define CATCH_LAYER_HANDLER_EXCEPTIONS(command, status)
virtual void handleRecover(LayerStatus &status)
void read(LayerStatus &status)
LayerStack(const std::string &n)
virtual void handleShutdown(LayerStatus &status)
virtual void handleRecover(LayerStatus &status)=0
LayerGroup(const std::string &n)
virtual void handleDiag(LayerReport &report)
virtual void set(const State &s, const std::string &r)
std::vector< std::pair< std::string, std::string > > values_
virtual void handleInit(LayerStatus &status)=0
std::shared_ptr< T > VectorMemberSharedPtr
virtual void handleRead(LayerStatus &status, const LayerState ¤t_state)
void init(LayerStatus &status)
std::atomic< LayerState > state
virtual void handleDiag(LayerReport &report)=0
virtual void handleInit(LayerStatus &status)
boost::mutex write_mutex_
vector_type::iterator call(FuncType func, Data &status)
virtual void diag(LayerReport &report)
virtual void handleHalt(LayerStatus &status)
const void stale(const std::string &r)
const std::vector< std::pair< std::string, std::string > > & values() const
std::vector< VectorMemberSharedPtr > vector_type
vector_type::reverse_iterator call_rev(FuncType func, Data &status)
virtual void handleWrite(LayerStatus &status, const LayerState ¤t_state)
Iterator call(FuncType func, Data &status, const Iterator &begin, const Iterator &end)
vector_type::reverse_iterator call_rev(FuncType func, Data &status)
virtual void handleShutdown(LayerStatus &status)
boost::shared_mutex mutex
std::atomic< State > state
virtual void handleRead(LayerStatus &status, const LayerState ¤t_state)=0
canopen_master
Author(s): Mathias Lüdtke
autogenerated on Wed Mar 2 2022 00:52:26