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<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?

--
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 :

&#10;boost::function&lt;void(const my_types::my_type&amp;)&gt; send;&#10;&#10;RTT::OutputPort &lt;my_types::my_type&gt; outputPort;&#10;&#10;fsm-&gt;send = boost::bind(static_cast&lt;void&#10;(RTT::OutputPort&lt;my_types::my_type&gt;::*) (const my_types::my_type&amp; ) &gt;&#10;(&amp;RTT::OutputPort&lt;my_types::my_type&gt;::write), &amp;outputPort, _1);&#10;

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 :
>
> &#10;&gt; boost::function&lt;void(const my_types::my_type&amp;)&gt; send;&#10;&gt; &#10;&gt; RTT::OutputPort &lt;my_types::my_type&gt; outputPort;&#10;&gt; &#10;&gt; fsm-&gt;send = boost::bind(static_cast&lt;void&#10;&gt; (RTT::OutputPort&lt;my_types::my_type&gt;::*) (const my_types::my_type&amp; ) &gt;&#10;&gt; (&amp;RTT::OutputPort&lt;my_types::my_type&gt;::write), &amp;outputPort, _1);&#10;&gt;
>
> 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