I don't know if this is a stupid question, but I can't find an answer to it.
When calling a component's method from another component, the component builder's manual suggests that you should do it like this:
// create a method:
TaskContext* a_task_ptr;
Method<void(void)> my_reset_meth
= a_task_ptr->methods()->getMethod<void(void)>("reset");
// Call 'reset' of a_task:
reset_meth();
But the thing is that simply calling the method through the pointer also works.
TaskContext* a_task_ptr;
a_task_ptr->reset_meth();
I guess that there must be a reason to do it the first way, but I can't find it. Moreover, doing it the second way I don't have to create a Method instance in the calling task.
What's the reason for doing it the first way?
Miguel.
calling methods directly
On Monday 30 June 2008 15:54:43 Miguel Prada Sarasola wrote: my_reset_meth("reset");
> Hi,
>
> I don't know if this is a stupid question, but I can't find an answer
> to it.
>
> When calling a component's method from another component, the
> component builder's manual suggests that you should do it like this:
>
> // create a method:
> TaskContext* a_task_ptr;
> Method
> = a_task_ptr->methods()->getMethod
>
> // Call 'reset' of a_task:
> reset_meth();
>
> But the thing is that simply calling the method through the pointer
> also works.
>
> TaskContext* a_task_ptr;
> a_task_ptr->reset_meth();
I'm 100% sure this does not work if reset_meth() is not defined in the
TaskContext class. The Method api is necessary to call subclass functions on
a 'TaskContext' pointer, thus without having a pointer to the subclass
providing the function. Accidently, if you tested the example
with 'a_task_ptr->reset()', it would have worked as TaskContext::reset()
exists.
Another advantage is that the Method allows you to call functions over a
network (using CORBA) transparantly.
Peter
calling methods directly
El 30/06/2008, a las 16:01, Peter Soetens escribió:
> On Monday 30 June 2008 15:54:43 Miguel Prada Sarasola wrote: my_reset_meth("reset");
>> Hi,
>>
>> I don't know if this is a stupid question, but I can't find an answer
>> to it.
>>
>> When calling a component's method from another component, the
>> component builder's manual suggests that you should do it like this:
>>
>> // create a method:
>> TaskContext* a_task_ptr;
>> Method
>> = a_task_ptr->methods()->getMethod
>>
>> // Call 'reset' of a_task:
>> reset_meth();
>>
>> But the thing is that simply calling the method through the pointer
>> also works.
>>
>> TaskContext* a_task_ptr;
>> a_task_ptr->reset_meth();
>
> I'm 100% sure this does not work if reset_meth() is not defined in the
> TaskContext class. The Method api is necessary to call subclass
> functions on
> a 'TaskContext' pointer, thus without having a pointer to the subclass
> providing the function. Accidently, if you tested the example
> with 'a_task_ptr->reset()', it would have worked as
> TaskContext::reset()
> exists.
You're right, in some places I've used it to call start and stop,
which are both declared in TaskContext. In other places I've used a
pointer to my_class derived from TaskContext and called methods not
declared in TaskContext.
>
> Another advantage is that the Method allows you to call functions
> over a
> network (using CORBA) transparantly.
>
Ok, this is more the kind of advantage I was thinking of.
Thanks.