Add plain C operation.

Hi devs.

The manual says

Quote:
Using this mechanism, any method of any class can be added to a task's method interface, not just functions of a TaskContext You can also add plain C functions, just omit the this pointer.

So this code should work ?

#include <rtt/os/main.h>
 
#include <rtt/TaskContext.hpp>
 
struct Bar
{
  std::string foo(void) const
  {
    return "a string";
  }
};
 
 
std::string foo(void)
{
  return "a string";
}
 
int ORO_main(int argc, char** argv)
{
  RTT::TaskContext tc("test");
  Bar bar;
 
  tc.addOperation("foo"      , &foo     , 0   , RTT::ClientThread);
  tc.addOperation("Bar::foo" , &Bar::foo, &bar, RTT::ClientThread);
 
  return 0;
} 

But i get

Quote:
error: no matching function for call to ‘RTT::TaskContext::addOperation(const char [4], std::string (*)(), int, RTT::ExecutionThread)’

Have you had this problem ? What is the correct way of adding a plain C function ?

Thanks for your help.

Paul.

Add plain C operation.

On Tuesday 07 December 2010 18:31:07 paul [dot] chavent [..] ... wrote:
> Hi devs.
>
> The manual says
>

Quote:
Using this mechanism, any method of any class can be added to a
> task's method interface, not just functions of a TaskContext You can also
> add plain C functions, just omit the this pointer.

>
> So this code should work ?
>
#include <rtt/os/main.h>
> 
> #include <rtt/TaskContext.hpp>
> 
> struct Bar
> {
>   std::string foo(void) const
>   {
>     return "a string";
>   }
> };
> 
> 
> std::string foo(void)
> {
>   return "a string";
> }
> 
> int ORO_main(int argc, char** argv)
> {
>   RTT::TaskContext tc("test");
>   Bar bar;
> 
>   tc.addOperation("foo"      , &foo     , 0   , RTT::ClientThread);
 
Just remove the '0':
 
[geshifilter-code]&#10; tc.addOperation(&quot;foo&quot;      , &amp;foo   , RTT::ClientThread);&#10;
Peter[/geshifilter-code]

Hello Peter.Thank you for

Hello Peter.

Thank you for your reply.

I've the same error by removing the third param. Moreover, i don't see the declaration of the function whithout the "third" param.

Paul.

Hello Peter.Thank you for

Hello Peter.

Thank you for your reply.

I've the same error by removing the third param. Moreover, i don't see the declaration of the function whithout the "third" param.

Paul.

Hello Peter.Thank you for

On Wed, Dec 8, 2010 at 8:53 AM, <paul [dot] chavent [..] ...> wrote:
> Hello Peter.
>
> Thank you for your reply.
>
> I've the same error by removing the third param. Moreover, i don't see the declaration of the function whithout the "third" param.

Try to use tc.provides()->addOperation

The issue we're having is that for 'short notation' some of the
functions of the Service class are repeated in the TaskContext class.
note: *some*.

It seems like 'addOperation' for C functions is not one of them.

This *is* documented in the Doxygen API[1]. But it's clear now that
no-one is reading that anymore.

Peter

[1] http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_...

Hello Peter.Thank you for

On Dec 8, 2010, at 03:54 , Peter Soetens wrote:

> On Wed, Dec 8, 2010 at 8:53 AM, <paul [dot] chavent [..] ...> wrote:
>> Hello Peter.
>>
>> Thank you for your reply.
>>
>> I've the same error by removing the third param. Moreover, i don't see the declaration of the function whithout the "third" param.
>
> Try to use tc.provides()->addOperation
>
> The issue we're having is that for 'short notation' some of the
> functions of the Service class are repeated in the TaskContext class.
> note: *some*.
>
> It seems like 'addOperation' for C functions is not one of them.
>
> This *is* documented in the Doxygen API[1]. But it's clear now that
> no-one is reading that anymore.

Hey!!! That is the Orocos Bible for some of us! I use it on a nearly daily basis ...
S

Hello Peter.Thank you for

On 08/12/2010 09:54, Peter Soetens wrote:
> On Wed, Dec 8, 2010 at 8:53 AM,<paul [dot] chavent [..] ...> wrote:
>> Hello Peter.
>>
>> Thank you for your reply.
>>
>> I've the same error by removing the third param. Moreover, i don't see the declaration of the function whithout the "third" param.
> Try to use tc.provides()->addOperation
>
> The issue we're having is that for 'short notation' some of the
> functions of the Service class are repeated in the TaskContext class.
> note: *some*.
>
> It seems like 'addOperation' for C functions is not one of them.
>
> This *is* documented in the Doxygen API[1]. But it's clear now that
> no-one is reading that anymore.
>
> Peter
>
> [1] http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_...
According to the API, you even need to create the Operation object
explicitely:

tc->addOperation(new Operation("foo",&foo, ClientThread))

Charles.

Hello Peter.Thank you for

On Wednesday 08 December 2010 10:54:24 Charles Lesire-Cabaniols wrote:
> On 08/12/2010 09:54, Peter Soetens wrote:
> > On Wed, Dec 8, 2010 at 8:53 AM,<paul [dot] chavent [..] ...> wrote:
> >> Hello Peter.
> >>
> >> Thank you for your reply.
> >>
> >> I've the same error by removing the third param. Moreover, i don't see
> >> the declaration of the function whithout the "third" param.
> >
> > Try to use tc.provides()->addOperation
> >
> > The issue we're having is that for 'short notation' some of the
> > functions of the Service class are repeated in the TaskContext class.
> > note: *some*.
> >
> > It seems like 'addOperation' for C functions is not one of them.
> >
> > This *is* documented in the Doxygen API[1]. But it's clear now that
> > no-one is reading that anymore.
> >
> > Peter
> >
> > [1]
> > http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_
> > 1TaskContext.html
>
> According to the API, you even need to create the Operation object
> explicitely:
>
> tc->addOperation(new Operation("foo",&foo, ClientThread))

This can't work. The variant you're refering to is when you use the 'old' RTT
1.x style of first creating an operation object and then passing a reference to
it:

Operation<void(double)> foo_op("foo",&foo, ClientThread);
tc->addOperation(foo_op);

There is a bug in the Doxygen documentation though :) It should suggest to use
'provides()' instead of 'operations()'.

Peter

Hello Peter.Thank you for

On 08/12/2010 11:51, Peter Soetens wrote:
> On Wednesday 08 December 2010 10:54:24 Charles Lesire-Cabaniols wrote:
>> On 08/12/2010 09:54, Peter Soetens wrote:
>>> On Wed, Dec 8, 2010 at 8:53 AM,<paul [dot] chavent [..] ...> wrote:
>>>> Hello Peter.
>>>>
>>>> Thank you for your reply.
>>>>
>>>> I've the same error by removing the third param. Moreover, i don't see
>>>> the declaration of the function whithout the "third" param.
>>> Try to use tc.provides()->addOperation
>>>
>>> The issue we're having is that for 'short notation' some of the
>>> functions of the Service class are repeated in the TaskContext class.
>>> note: *some*.
>>>
>>> It seems like 'addOperation' for C functions is not one of them.
>>>
>>> This *is* documented in the Doxygen API[1]. But it's clear now that
>>> no-one is reading that anymore.
>>>
>>> Peter
>>>
>>> [1]
>>> http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_
>>> 1TaskContext.html
>> According to the API, you even need to create the Operation object
>> explicitely:
>>
>> tc->addOperation(new Operation("foo",&foo, ClientThread))
> This can't work. The variant you're refering to is when you use the 'old' RTT
> 1.x style of first creating an operation object and then passing a reference to
> it:

You should really tag as deprecated the functions that are RTT1.x-like
but whose use should be avoided!

Charles.

Hello Peter.Thank you for

Indeed, i think it is the only way to do it. But i don't know where you read it in the api doc Charles.

Peter, if i read the api doc for TaskContext::addOperation (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1... the doc doesn't match the signature, but no matter) or Service::addOperation (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1...), i don't see more information on how to use the addOperation method.

You seem to be annoyed that no one read the api doc, but i grep for addOperation in the TaskContext page and i don't found that this should work (or not) with c function from a TaskContext pointer.

I found very usefull to have the API doc and sorry if i'am blind.

Hello Peter.Thank you for

Indeed, i think it is the only way to do it. But i don't know where you read it in the api doc Charles.

Peter, if i read the api doc for TaskContext::addOperation (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1.x/api/html/classRTT_1_1TaskContext.html#a58498e0c313cd13b85fdc5c2d5fc70ff the doc doesn't match the signature, but no matter) or Service::addOperation (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1.x/api/html/classRTT_1_1Service.html#ad9268059997e35308c06edcb1fd9c31b), i don't see more information on how to use the addOperation method.

You seem to be annoyed that no one read the api doc, but i grep for addOperation in the TaskContext page and i don't found that this should work (or not) with c function from a TaskContext pointer.

I found very usefull to have the API doc and sorry if i'am blind.

Hello Peter.Thank you for

On Wednesday 08 December 2010 11:38:23 paul [dot] chavent [..] ... wrote:
> Indeed, i think it is the only way to do it. But i don't know where you
> read it in the api doc Charles.
>
> Peter, if i read the api doc for TaskContext::addOperation
> (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1.
> x/api/html/classRTT_1_1TaskContext.html#a58498e0c313cd13b85fdc5c2d5fc70ff
> the doc doesn't match the signature, but no matter) or
> Service::addOperation
> (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1.
> x/api/html/classRTT_1_1Service.html#ad9268059997e35308c06edcb1fd9c31b), i
> don't see more information on how to use the addOperation method.
>
> You seem to be annoyed that no one read the api doc, but i grep for
> addOperation in the TaskContext page and i don't found that this should
> work (or not) with c function from a TaskContext pointer.
>
> I found very usefull to have the API doc and sorry if i'am blind.

It's the other way around: I was seeing things that weren't there. I'm looking
into it.

Peter

Hello Peter.Thank you for

On Wednesday 08 December 2010 11:56:07 Peter Soetens wrote:
> On Wednesday 08 December 2010 11:38:23 paul [dot] chavent [..] ... wrote:
> > Indeed, i think it is the only way to do it. But i don't know where you
> > read it in the api doc Charles.
> >
> > Peter, if i read the api doc for TaskContext::addOperation
> > (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1
> > .
> > x/api/html/classRTT_1_1TaskContext.html#a58498e0c313cd13b85fdc5c2d5fc70f
> > f the doc doesn't match the signature, but no matter) or
> > Service::addOperation
> > (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1
> > . x/api/html/classRTT_1_1Service.html#ad9268059997e35308c06edcb1fd9c31b),
> > i don't see more information on how to use the addOperation method.
> >
> > You seem to be annoyed that no one read the api doc, but i grep for
> > addOperation in the TaskContext page and i don't found that this should
> > work (or not) with c function from a TaskContext pointer.
> >
> > I found very usefull to have the API doc and sorry if i'am blind.
>
> It's the other way around: I was seeing things that weren't there. I'm
> looking into it.

There's a fix on the master branch for this. The documented usage for C
functions was not working. I added a unit test and now it seems to behave as
expected. The syntax is:

tc.provides()->addOperation("name",&foo,ClientThread);

Thanks for reporting !

Peter

Hello Peter.Thank you for

On 08/12/2010 11:38, paul [dot] chavent [..] ... wrote:
> Indeed, i think it is the only way to do it. But i don't know where you read it in the api doc Charles.

The addOperation method can take an Operation object as an argument:
http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_...

> Peter, if i read the api doc for TaskContext::addOperation (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1... the doc doesn't match the signature, but no matter) or Service::addOperation (http://people.mech.kuleuven.be/~orocos/pub/stable/documentation/rtt/v2.1...), i don't see more information on how to use the addOperation method.
>
> You seem to be annoyed that no one read the api doc, but i grep for addOperation in the TaskContext page and i don't found that this should work (or not) with c function from a TaskContext pointer.
>
> I found very usefull to have the API doc and sorry if i'am blind.
>

Add plain C operation.

Hi devs.

The manual says

Quote:
Using this mechanism, any method of any class can be added to a task's method interface, not just functions of a TaskContext You can also add plain C functions, just omit the this pointer.

So this code should work ?

#include <rtt/os/main.h>
 
#include <rtt/TaskContext.hpp>
 
struct Bar
{
  std::string foo(void) const
  {
    return "a string";
  }
};
 
 
std::string foo(void)
{
  return "a string";
}
 
int ORO_main(int argc, char** argv)
{
  RTT::TaskContext tc("test");
  Bar bar;
 
  tc.addOperation("foo"      , &foo     , 0   , RTT::ClientThread);
  tc.addOperation("Bar::foo" , &Bar::foo, &bar, RTT::ClientThread);
 
  return 0;
} 

But i get

Quote:

error: no matching function for call to ‘RTT::TaskContext::addOperation(const char [4], std::string (*)(), int, RTT::ExecutionThread)’

Have you had this problem ? What is the correct way of adding a plain C function ?

Thanks for your help.

Paul.
--
Orocos-Dev mailing list
Orocos-Dev [..] ...
http://lists.mech.kuleuven.be/mailman/listinfo/orocos-dev