37 #include <pcl/pcl_config.h>
49 #include <pcl/exceptions.h>
50 #include <boost/signals2.hpp>
94 template<typename T>
boost::signals2::connection
95 registerCallback (const std::function<T>& callback);
100 template<typename T>
bool
101 providesCallback () const noexcept;
126 getName () const = 0;
132 isRunning () const = 0;
136 getFramesPerSecond () const = 0;
141 signalsChanged () { }
143 template<
typename T> boost::signals2::signal<T>*
144 find_signal () const noexcept;
146 template<typename T>
int
147 num_slots () const noexcept;
149 template<typename T>
void
150 disconnect_all_slots ();
152 template<typename T>
void
155 template<typename T>
void
164 template<typename T>
boost::signals2::signal<T>*
167 std::map<std::
string, std::unique_ptr<
boost::signals2::signal_base>> signals_;
168 std::map<std::
string, std::vector<
boost::signals2::connection> > connections_;
169 std::map<std::
string, std::vector<
boost::signals2::shared_connection_block> > shared_connections_;
185 template<
typename T> boost::signals2::signal<T>*
188 using Signal = boost::signals2::signal<T>;
190 const auto signal_it = signals_.find (
typeid (T).name ());
191 if (signal_it != signals_.end ())
193 return (
static_cast<Signal*
> (signal_it->second.get ()));
198 template<
typename T>
void
201 const auto signal = find_signal<T> ();
202 if (signal !=
nullptr)
204 signal->disconnect_all_slots ();
208 template<
typename T>
void
211 if (connections_.find (typeid (T).name ()) != connections_.end ())
212 for (
auto &connection : shared_connections_[
typeid (T).name ()])
216 template<
typename T>
void
219 if (connections_.find (typeid (T).name ()) != connections_.end ())
220 for (
auto &connection : shared_connections_[
typeid (T).name ()])
221 connection.unblock ();
227 for (
const auto &signal : signals_)
228 for (
auto &connection : shared_connections_[signal.first])
235 for (
const auto &signal : signals_)
236 for (
auto &connection : shared_connections_[signal.first])
237 connection.unblock ();
240 template<
typename T>
int
243 const auto signal = find_signal<T> ();
244 if (signal !=
nullptr)
246 return static_cast<int> (signal->num_slots ());
251 template<
typename T> boost::signals2::signal<T>*
254 using Signal = boost::signals2::signal<T>;
255 using Base = boost::signals2::signal_base;
262 operator std::unique_ptr<Base>()
const {
return std::make_unique<Signal>(); }
265 std::string signame{
typeid (T).name ()};
266 #ifdef __cpp_structured_bindings
267 const auto [iterator, success] =
269 typename decltype(signals_)::const_iterator iterator;
271 std::tie (iterator, success) =
274 #ifdef __cpp_lib_map_try_emplace
275 signals_.try_emplace (
279 signame, DefferedPtr ());
284 return static_cast<Signal*
> (iterator->second.get ());
287 template<
typename T> boost::signals2::connection
290 const auto signal = find_signal<T> ();
291 if (signal ==
nullptr)
293 std::stringstream sstream;
295 sstream <<
"no callback for type:" <<
typeid (T).name ();
297 PCL_THROW_EXCEPTION (
pcl::IOException,
"[" << getName () <<
"] " << sstream.str ());
300 boost::signals2::connection ret = signal->connect (callback);
302 connections_[
typeid (T).name ()].push_back (ret);
303 shared_connections_[
typeid (T).name ()].emplace_back(connections_[
typeid (T).name ()].back (),
false);
308 template<
typename T>
bool
311 return find_signal<T> ();
Grabber interface for PCL 1.x device drivers.
Grabber(Grabber &&)=default
Move ctor.
Grabber & operator=(Grabber &&)=default
Move assign operator.
bool providesCallback() const noexcept
indicates whether a signal with given parameter-type exists or not
boost::signals2::signal< T > * find_signal() const noexcept
Grabber(const Grabber &)=delete
No copy ctor since Grabber can't be copied.
int num_slots() const noexcept
boost::signals2::signal< T > * createSignal()
Grabber()=default
Default ctor.
Grabber & operator=(const Grabber &)=delete
No copy assign operator since Grabber can't be copied.
virtual ~Grabber() noexcept=default
virtual destructor.
void disconnect_all_slots()
boost::signals2::connection registerCallback(const std::function< T > &callback)
registers a callback function/method to a signal with the corresponding signature
An exception that is thrown during an IO error (typical read/write errors)
Defines all the PCL and non-PCL macros used.