function pointer to port's read/write call

Hey folks,

I've got a Boost.Statechart FSM that I'd like to use in one of my components. One of the requirements is that the FSM be able to (at least) write to ports. Having had previous luck with boost::functions and OperationCallers, I assumed I'd have the same luck with port methods. No such luck, yet. And the Boost compiler errors are cryptic at best. So here's what I'd like.

In the FSM, I have:
boost::function<void(const my_types::my_type& msg)> send;

And then in my component, that HasA FSM, I have something similar to this:
RTT::OutputPort <my_types::my_type> outputPort;
fsm->send = boost::bind(static_cast<void (RTT::OutputPort

I've tried various combinations of boost::bind, static_cast and template parameters… I'm just missing something. Does anyone have a working example of what I'm trying to do?

--
Dustin Gooding
NASA/JSC Robotics
IM: dgooding [..] ...<xmpp:dgooding [..] ...>

function pointer to port's read/write call

Hi Dustin,

On Tue, May 28, 2013 at 4:00 PM, Gooding, Dustin R. (JSC-ER411)
<dustin [dot] r [dot] gooding [..] ...> wrote:
> Hey folks,
>
> I've got a Boost.Statechart FSM that I'd like to use in one of my
> components. One of the requirements is that the FSM be able to (at least)
> write to ports. Having had previous luck with boost::functions and
> OperationCallers, I assumed I'd have the same luck with port methods. No
> such luck, yet. And the Boost compiler errors are cryptic at best. So
> here's what I'd like.
>
> In the FSM, I have:
> boost::function<void(const my_types::my_type& msg)> send;
>
> And then in my component, that HasA FSM, I have something similar to this:
> RTT::OutputPort <my_types::my_type> outputPort;
> fsm->send = boost::bind(static_cast<void
> (RTT::OutputPort<my_types::my_type>::*) (const my_types::my_type& msg) >
> (&RTT::OutputPort<my_types::my_type>::write), outputPort);
>
> I've tried various combinations of boost::bind, static_cast and template
> parameters… I'm just missing something. Does anyone have a working
> example of what I'm trying to do?

You're pretty close to the correct syntax...I'd try to leave out the
'msg' argument though, and pass outputPort as a pointer, not a
reference in the last line. Finally, you need to pass _1 (or
boost::_1) to fill up the missing argument :

boost::function<void(const my_types::my_type&)> send;
 
RTT::OutputPort <my_types::my_type> outputPort;
 
fsm->send = boost::bind(static_cast<void
(RTT::OutputPort<my_types::my_type>::*) (const my_types::my_type& ) >
(&RTT::OutputPort<my_types::my_type>::write), &outputPort, _1);

Didn't test, but it should be pretty close...

Peter

function pointer to port's read/write call

On May 29, 2013, at 4:33 AM, Peter Soetens <peter [..] ...> wrote:

> Hi Dustin,
>
> On Tue, May 28, 2013 at 4:00 PM, Gooding, Dustin R. (JSC-ER411)
> <dustin [dot] r [dot] gooding [..] ...> wrote:
>> Hey folks,
>>
>> I've got a Boost.Statechart FSM that I'd like to use in one of my
>> components. One of the requirements is that the FSM be able to (at least)
>> write to ports. Having had previous luck with boost::functions and
>> OperationCallers, I assumed I'd have the same luck with port methods. No
>> such luck, yet. And the Boost compiler errors are cryptic at best. So
>> here's what I'd like.
>>
>> In the FSM, I have:
>> boost::function<void(const my_types::my_type& msg)> send;
>>
>> And then in my component, that HasA FSM, I have something similar to this:
>> RTT::OutputPort <my_types::my_type> outputPort;
>> fsm->send = boost::bind(static_cast<void
>> (RTT::OutputPort<my_types::my_type>::*) (const my_types::my_type& msg) >
>> (&RTT::OutputPort<my_types::my_type>::write), outputPort);
>>
>> I've tried various combinations of boost::bind, static_cast and template
>> parameters… I'm just missing something. Does anyone have a working
>> example of what I'm trying to do?
>
> You're pretty close to the correct syntax...I'd try to leave out the
> 'msg' argument though, and pass outputPort as a pointer, not a
> reference in the last line. Finally, you need to pass _1 (or
> boost::_1) to fill up the missing argument :
>
>

> boost::function<void(const my_types::my_type&)> send;
> 
> RTT::OutputPort <my_types::my_type> outputPort;
> 
> fsm->send = boost::bind(static_cast<void
> (RTT::OutputPort<my_types::my_type>::*) (const my_types::my_type& ) >
> (&RTT::OutputPort<my_types::my_type>::write), &outputPort, _1);
> 

>
> Didn't test, but it should be pretty close...
>
> Peter

Most excellent! Thank you, Peter.

FWIW, the 'msg' argument was fine to leave in, but I've taken it out as it's not necessary. The pointer to outputPort was the key, as was the _1.

-dustin