EventDataPort data.

Hi,

i was wondering what the best way is to react on a NewDataOnPortEvent.

we currently have something like this:

DataSource<type> datasource;
type data;
 
void callback(PortInterface* port){
  datasource.update(port->connection()->getDataSource().get());
  data=datasource.get();
  //do something with data
}

Is this the way to do this, or am I missing something obvious?

If this is the way to do it, we definitely need to document this,
because it took me more than an hour to figure this out.

If it is not, we definitely need to document the good way of doing
this, because i could not figure that one out.

Ruben

EventDataPort data.

On Mon, Sep 28, 2009 at 15:53, Ruben Smits <ruben [dot] smits [..] ...> wrote:
> Hi,
>
> i was wondering what the best way is to react on a NewDataOnPortEvent.
>
> we currently have something like this:
>
>

>
> DataSource<type> datasource;
> type data;
>
> void callback(PortInterface* port){
>  datasource.update(port->connection()->getDataSource().get());
>  data=datasource.get();
>  //do something with data
> }
>
> 

>
> Is this the way to do this, or am I missing something obvious?
>
> If this is the way to do it, we definitely need to document this,
> because it took me more than an hour to figure this out.
>
> If it is not, we definitely need to document the good way of doing
> this, because i could not figure that one out.

You did it how scripting would do it :-). The callback assumes that
you have a pointer to the port ready:

DataPort<type> myport;
type data;
 
void callback(PortInterface* port){
  if (port == &myport)
     myport.Get( data );
 //do something with data
}

Works for you ?

Peter