Specifying ports in configuration file

Hi everybody!

I am trying to develop a component that have its ports specified in a .cpf file, i.e. created when configured.

My cpf file looks like:

mapstring
posdouble

specifying that I have two ports: port "map" of type "string" and port "pos" of type "double".

I succeeded in loading the cpf file and iterating over the "Ports" bag.

However, I can't create the ports, that should be DataPort for "map" and DataPort for "pos".
I get the desired types with RTT::types()->type(myPortType: string) but I don't know what to do with the resulting TypeInfo!

Something like addPort(DataPort) could be great!

Any idea to help me?

Thanks.

Charles.

Specifying ports in configuration file

On Thursday 26 February 2009 16:28:18 charles [dot] lesire [..] ... wrote:
> Hi everybody!
>
> I am trying to develop a component that have its ports specified in a .cpf
> file, i.e. created when configured.

Ok.

>
> My cpf file looks like:
> <struct name="Ports" type="PropertyBag">
> <simple name="port"
> type="string"><description>map</description><value>string</value></simple>
> <simple name="port"
> type="string"><description>pos</description><value>double</value></simple>
> </struct>
> specifying that I have two ports: port "map" of type "string" and port
> "pos" of type "double".

Just a side-note: Why don't you write:

<struct name="Ports" type="PropertyBag">
<simple name="map" type="string"><value>string</value></simple>
<simple name="pos" type="string"><value>double</value></simple>
</struct>

?

>
> I succeeded in loading the cpf file and iterating over the "Ports" bag.

Ok.

>
> However, I can't create the ports, that should be DataPort<string> for
> "map" and DataPort<double> for "pos". I get the desired types with
> RTT::types()->type(myPortType: string) but I don't know what to do with the
> resulting TypeInfo!
>
> Something like addPort(DataPort<t:TypeInfo>) could be great!

TypeInfo is a low-level infrastructure class for RTT, it's not meant for
building components dynamically. Your only option is to use:

if ( p.value() == "string" )
this->ports()->addPort( new DataPort<string>( p.getName() ) );
if (p.value() == "int")
this->ports()->addPort( new DataPort<int>( p.getName() ) );

etc. Inside your component or in a 'component factory' helper class.

If you plan to stretch/use this a lot, there might be better XML tags or just
plain text formats to describe a component interface.

Peter

Specifying ports in configuration file

I hope I could avoid switching...

Thanks !

---
Charles.