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
std::shared_ptr< RemoteInterface > Ptr
const std::atomic_bool & any_failed() const
void add(ThreadedStream::Ptr stream)
const std::string & name() const
ros::NodeHandle _nh
std::shared_ptr< ThreadedStream > Ptr
std::atomic_bool _requested
std::shared_ptr< Manager > Ptr
rc::dynamics::RemoteInterface::Ptr _rcdyn
Convenience classes to implement and manage different types of data streams in separate threads...
std::atomic_bool _any_failed
std::list< ThreadedStream::Ptr > _streams
const std::atomic_bool & requested() const
Manager::Ptr _manager
virtual void work()
std::atomic_bool _stop
const std::atomic_bool & succeeded() const
std::atomic_bool _success
virtual bool startReceivingAndPublishingAsRos()=0


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Sat Feb 13 2021 03:42:55