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:
>
> &#10;&gt;&#10;&gt; DataSource&lt;type&gt; datasource;&#10;&gt; type data;&#10;&gt;&#10;&gt; void callback(PortInterface* port){&#10;&gt;  datasource.update(port-&gt;connection()-&gt;getDataSource().get());&#10;&gt;  data=datasource.get();&#10;&gt;  //do something with data&#10;&gt; }&#10;&gt;&#10;&gt;
>
> 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:

&#10;&#10;DataPort&lt;type&gt; myport;&#10;type data;&#10;&#10;void callback(PortInterface* port){&#10;  if (port == &amp;myport)&#10;     myport.Get( data );&#10; //do something with data&#10;}&#10;&#10;

Works for you ?

Peter