Use shared pointer when binding callback for serial read (#38)
* Resolves an issue with ROS Melodic on 18.04.
This commit is contained in:
parent
070550e655
commit
2442ba209c
2 changed files with 4 additions and 3 deletions
|
@ -40,13 +40,14 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <boost/thread/condition_variable.hpp>
|
#include <boost/thread/condition_variable.hpp>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
|
|
||||||
#include "create/data.h"
|
#include "create/data.h"
|
||||||
#include "create/types.h"
|
#include "create/types.h"
|
||||||
#include "create/util.h"
|
#include "create/util.h"
|
||||||
|
|
||||||
namespace create {
|
namespace create {
|
||||||
class Serial {
|
class Serial : public boost::enable_shared_from_this<Serial> {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
boost::asio::io_service io;
|
boost::asio::io_service io;
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace create {
|
||||||
// Start continuously reading one byte at a time
|
// Start continuously reading one byte at a time
|
||||||
boost::asio::async_read(port,
|
boost::asio::async_read(port,
|
||||||
boost::asio::buffer(&byteRead, 1),
|
boost::asio::buffer(&byteRead, 1),
|
||||||
boost::bind(&Serial::onData, this, _1, _2));
|
boost::bind(&Serial::onData, shared_from_this(), _1, _2));
|
||||||
|
|
||||||
ioThread = boost::thread(boost::bind(&boost::asio::io_service::run, &io));
|
ioThread = boost::thread(boost::bind(&boost::asio::io_service::run, &io));
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ namespace create {
|
||||||
// Read the next byte
|
// Read the next byte
|
||||||
boost::asio::async_read(port,
|
boost::asio::async_read(port,
|
||||||
boost::asio::buffer(&byteRead, 1),
|
boost::asio::buffer(&byteRead, 1),
|
||||||
boost::bind(&Serial::onData, this, _1, _2));
|
boost::bind(&Serial::onData, shared_from_this(), _1, _2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Serial::send(const uint8_t* bytes, unsigned int numBytes) {
|
bool Serial::send(const uint8_t* bytes, unsigned int numBytes) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue