ThreadedStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Roboception GmbH
3  * All rights reserved
4  *
5  * Author: Christian Emmerich
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its contributors
18  * may be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef RC_VISARD_DRIVER_THREADEDSTREAMER_H
35 #define RC_VISARD_DRIVER_THREADEDSTREAMER_H
36 
37 #include <memory>
38 #include <thread>
39 #include <atomic>
40 
42 #include <ros/ros.h>
43 
44 namespace rc
45 {
60 {
61 public:
62  typedef std::shared_ptr<ThreadedStream> Ptr;
63 
64  class Manager : public std::enable_shared_from_this<Manager>
65  {
66  public:
67  typedef std::shared_ptr<Manager> Ptr;
68 
69  static Ptr create();
70 
71  void add(ThreadedStream::Ptr stream);
72  const std::list<ThreadedStream::Ptr>& get();
73 
74  void start_all();
75  void stop_all();
76  void join_all();
77 
78  bool all_succeeded() const;
79  inline const std::atomic_bool& any_failed() const
80  {
81  return _any_failed;
82  }
83 
84  protected:
85  Manager();
86 
87  std::atomic_bool _any_failed;
88  std::list<ThreadedStream::Ptr> _streams;
89 
91  };
92 
93  void start();
94  void stop();
95  void join();
96 
97  inline const std::string& name() const
98  {
99  return _stream;
100  }
101  inline const std::atomic_bool& requested() const
102  {
103  return _requested;
104  }
105  inline const std::atomic_bool& succeeded() const
106  {
107  return _success;
108  }
109 
110 protected:
111  ThreadedStream(rc::dynamics::RemoteInterface::Ptr rcdIface, const std::string& stream, ros::NodeHandle& nh);
112 
116  virtual bool startReceivingAndPublishingAsRos() = 0;
117 
118  virtual void work();
119 
120  std::atomic_bool _stop, _requested, _success;
121 
122  std::thread _thread;
124 
126  std::string _stream;
128 };
129 }
130 
131 #endif // RC_VISARD_DRIVER_THREADEDSTREAMER_H
rc::ThreadedStream::startReceivingAndPublishingAsRos
virtual bool startReceivingAndPublishingAsRos()=0
rc::ThreadedStream::Manager
Definition: ThreadedStream.h:64
rc::ThreadedStream::Manager::all_succeeded
bool all_succeeded() const
Definition: ThreadedStream.cc:116
rc::ThreadedStream::Manager::Manager
Manager()
Definition: ThreadedStream.cc:83
rc::ThreadedStream::_manager
Manager::Ptr _manager
Definition: ThreadedStream.h:123
rc::ThreadedStream::start
void start()
Definition: ThreadedStream.cc:48
rc::ThreadedStream::Manager::_any_failed
std::atomic_bool _any_failed
Definition: ThreadedStream.h:87
ros.h
rc::ThreadedStream::_thread
std::thread _thread
Definition: ThreadedStream.h:122
rc::ThreadedStream::Manager::any_failed
const std::atomic_bool & any_failed() const
Definition: ThreadedStream.h:79
rc::ThreadedStream::succeeded
const std::atomic_bool & succeeded() const
Definition: ThreadedStream.h:105
rc::ThreadedStream::Ptr
std::shared_ptr< ThreadedStream > Ptr
Definition: ThreadedStream.h:62
rc::dynamics::RemoteInterface::Ptr
std::shared_ptr< RemoteInterface > Ptr
remote_interface.h
rc
rc::ThreadedStream::name
const std::string & name() const
Definition: ThreadedStream.h:97
rc::ThreadedStream::Manager::stop_all
void stop_all()
Definition: ThreadedStream.cc:104
rc::ThreadedStream::Manager::add
void add(ThreadedStream::Ptr stream)
Definition: ThreadedStream.cc:87
rc::ThreadedStream::_requested
std::atomic_bool _requested
Definition: ThreadedStream.h:120
rc::ThreadedStream::stop
void stop()
Definition: ThreadedStream.cc:56
rc::ThreadedStream::Manager::ThreadedStream
friend ThreadedStream
Definition: ThreadedStream.h:90
rc::ThreadedStream::Manager::get
const std::list< ThreadedStream::Ptr > & get()
Definition: ThreadedStream.cc:93
rc::ThreadedStream::_stop
std::atomic_bool _stop
Definition: ThreadedStream.h:120
rc::ThreadedStream::_success
std::atomic_bool _success
Definition: ThreadedStream.h:120
rc::ThreadedStream::_nh
ros::NodeHandle _nh
Definition: ThreadedStream.h:127
rc::ThreadedStream::_rcdyn
rc::dynamics::RemoteInterface::Ptr _rcdyn
Definition: ThreadedStream.h:125
rc::ThreadedStream::Manager::Ptr
std::shared_ptr< Manager > Ptr
Definition: ThreadedStream.h:67
rc::ThreadedStream::work
virtual void work()
Definition: ThreadedStream.cc:67
rc::ThreadedStream::Manager::join_all
void join_all()
Definition: ThreadedStream.cc:110
rc::ThreadedStream::Manager::_streams
std::list< ThreadedStream::Ptr > _streams
Definition: ThreadedStream.h:88
rc::ThreadedStream::Manager::start_all
void start_all()
Definition: ThreadedStream.cc:98
rc::ThreadedStream::join
void join()
Definition: ThreadedStream.cc:61
rc::ThreadedStream::ThreadedStream
ThreadedStream(rc::dynamics::RemoteInterface::Ptr rcdIface, const std::string &stream, ros::NodeHandle &nh)
Definition: ThreadedStream.cc:42
rc::ThreadedStream
Convenience classes to implement and manage different types of data streams in separate threads.
Definition: ThreadedStream.h:59
ros::NodeHandle
rc::ThreadedStream::_stream
std::string _stream
Definition: ThreadedStream.h:126
rc::ThreadedStream::requested
const std::atomic_bool & requested() const
Definition: ThreadedStream.h:101
rc::ThreadedStream::Manager::create
static Ptr create()
Definition: ThreadedStream.cc:78


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Sun May 15 2022 02:25:43