How to get a reference to a program in C++ ?

Hi all,

from :
http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-compo...

here I read I have to use this to get a reference on a pre-loaded program :

ProgramInterfacePtr p = dynamic_cast<ScriptingAccess
<http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_1scripting_1_1ScriptingAccess.html>*>(this->getService("scripting"))->getProgram("progname");

But this failed to compile, did I missed something ?

[ 8%] Building CXX object src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp: In
member function ‘bool HML::CanOpenNode::configureNode()’:
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
error: expected type-specifier before ‘ScriptingAccess’
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
error: expected ‘>’ before ‘ScriptingAccess’
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
error: expected ‘(’ before ‘ScriptingAccess’
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
error: ‘ScriptingAccess’ was not declared in this scope
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
error: expected primary-expression before ‘>’ token
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
error: ‘class HML::CanOpenNode’ has no member named ‘getService’
/media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
error: expected ‘)’ before ‘;’ token
make[3]: *** [src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o] Erreur 1

How to get a reference to a program in C++ ?

On Friday 25 March 2011 01:20:07 Willy Lambert wrote:
> Hi all,
>
> from :
> http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-componen
> ts-manual.html#program-syntax
>
> here I read I have to use this to get a reference on a pre-loaded program :
>
> ProgramInterfacePtr p = dynamic_cast<ScriptingAccess
> <http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_1s
> cripting_1_1ScriptingAccess.html>*>(this->getService("scripting"))->getProg
> ram("progname");
>
> But this failed to compile, did I missed something ?
>
> [ 8%] Building CXX object
> src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp: In
> member function ‘bool HML::CanOpenNode::configureNode()’:
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> error: expected type-specifier before ‘ScriptingAccess’
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> error: expected ‘>’ before ‘ScriptingAccess’
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> error: expected ‘(’ before ‘ScriptingAccess’
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> error: ‘ScriptingAccess’ was not declared in this scope
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> error: expected primary-expression before ‘>’ token
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> error: ‘class HML::CanOpenNode’ has no member named ‘getService’
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> error: expected ‘)’ before ‘;’ token
> make[3]: *** [src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o] Erreur 1

It's a typo in the manual. It should have been: 'RTT::ScriptingService'
instead of 'ScriptingAccess'. Also, it returns a shared_ptr and getService()
is a function of Service, not of TaskContext:

&#10;ProgramInterfacePtr p = &#10;boost::dynamic_pointer_cast&lt;RTT::scripting::ScriptingService::shared_ptr&gt;(this-&#10;&gt;provides()-&gt;getService(&quot;scripting&quot;))-&gt;getProgram(&quot;progname&quot;);  &#10;

I've updated the manual, it should be updated online shortly...

Peter
--
Orocos-Users mailing list
Orocos-Users [..] ...
http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users

How to get a reference to a program in C++ ?

2011/3/25 Peter Soetens <peter [..] ...>

> On Friday 25 March 2011 01:20:07 Willy Lambert wrote:
> > Hi all,
> >
> > from :
> >
> http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-componen
> > ts-manual.html#program-syntax
> >
> > here I read I have to use this to get a reference on a pre-loaded program
> :
> >
> > ProgramInterfacePtr p = dynamic_cast<ScriptingAccess
> > <
> http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_1s
> >
> cripting_1_1ScriptingAccess.html>*>(this->getService("scripting"))->getProg
> > ram("progname");
> >
> > But this failed to compile, did I missed something ?
> >
> > [ 8%] Building CXX object
> > src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp: In
> > member function ‘bool HML::CanOpenNode::configureNode()’:
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> > error: expected type-specifier before ‘ScriptingAccess’
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> > error: expected ‘>’ before ‘ScriptingAccess’
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> > error: expected ‘(’ before ‘ScriptingAccess’
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> > error: ‘ScriptingAccess’ was not declared in this scope
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> > error: expected primary-expression before ‘>’ token
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> > error: ‘class HML::CanOpenNode’ has no member named ‘getService’
> > /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181:
> > error: expected ‘)’ before ‘;’ token
> > make[3]: *** [src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o] Erreur
> 1
>
> It's a typo in the manual. It should have been: 'RTT::ScriptingService'
> instead of 'ScriptingAccess'. Also, it returns a shared_ptr and
> getService()
> is a function of Service, not of TaskContext:
>
> &#10;&gt; ProgramInterfacePtr p =&#10;&gt;&#10;&gt; boost::dynamic_pointer_cast&lt;RTT::scripting::ScriptingService::shared_ptr&gt;(this-&#10;&gt; &gt;provides()-&gt;getService(&quot;scripting&quot;))-&gt;getProgram(&quot;progname&quot;);&#10;&gt;
>
>
thanks :)

> I've updated the manual, it should be updated online shortly...
>
> Peter
>

How to get a reference to a program in C++ ?

2011/3/25 Willy Lambert <lambert [dot] willy [..] ...>:
> Hi all,
>
> from :
> http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-compo...
>
>
> here I read I have to use this to get a reference on a pre-loaded program :
>
> ProgramInterfacePtr p =
> dynamic_cast<ScriptingAccess*>(this->getService("scripting"))->getProgram("progname");
>
>
> But this failed to compile, did I missed something ?
>
> [ 8%] Building CXX object
> src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp: In member
> function ‘bool HML::CanOpenNode::configureNode()’:
>
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181: error:
> expected type-specifier before ‘ScriptingAccess’
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181: error:
> expected ‘>’ before ‘ScriptingAccess’
>
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181: error:
> expected ‘(’ before ‘ScriptingAccess’
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181: error:
> ‘ScriptingAccess’ was not declared in this scope
>
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181: error:
> expected primary-expression before ‘>’ token
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181: error:
> ‘class HML::CanOpenNode’ has no member named ‘getService’
>
> /media/DD_data/opt/ros/ard/arp_hml/src/can/CanOpenNode.cpp:181: error:
> expected ‘)’ before ‘;’ token
> make[3]: *** [src/CMakeFiles/arp-hml.dir/can/CanOpenNode.cpp.o] Erreur 1
>
>

This looks like a namespace issue,

try
using namespace RTT

or put RTT: in front of the ScriptingService

assuming it is in the RTT namespace - it might be a bit better hidden
in e.g. RTT:scripting:

Regards,

Steven