From: Aleksandra Krkoleva on
Hi,
I'm trying to initiate messaging between objects of two classes. The objects are created in handle subclasses. Object from class A sends notification to listener from class B. Object form class B is a registered listener, receives the notification and executes a callback. In the callback function, there is another notify message which should be sent to the initiator (the object from class A). Up to this point, it all works fine. I've tried to addlistener to the class A, so the object which started the communication has to execute a callback itself. I receive the following message: Undefined function or method 'ListenToB' for input arguments of type 'ClassB'. 'ListenToB' is a method used to register the listener:
function ListenToB(bobj)
lh2 = addlistener(bobj,'ForFurtherNotif', @(src, evnt)ReceivedInfo(src));
end

ReceivedInfo is a call back function which has one input argument, and that is the sorce of the message, i.e. the object "bobj". When I try to execue it, it gives the same answer.
As I'm new to OOP in general, so maybe I'm missiong some point. I'd appreciate some help on the topic.

Thanks, Alex
From: Steven Lord on

"Aleksandra Krkoleva" <alekk_02(a)yahoo.com> wrote in message
news:hsj31g$kk6$1(a)fred.mathworks.com...
> Hi,
> I'm trying to initiate messaging between objects of two classes. The
> objects are created in handle subclasses. Object from class A sends
> notification to listener from class B. Object form class B is a registered
> listener, receives the notification and executes a callback. In the
> callback function, there is another notify message which should be sent to
> the initiator (the object from class A). Up to this point, it all works
> fine. I've tried to addlistener to the class A, so the object which
> started the communication has to execute a callback itself. I receive the
> following message: Undefined function or method 'ListenToB' for input
> arguments of type 'ClassB'. 'ListenToB' is a method used to register the
> listener:
> function ListenToB(bobj)
> lh2 = addlistener(bobj,'ForFurtherNotif', @(src,
> evnt)ReceivedInfo(src));
> end

So which class defines ListenToB as a method, class A or class B?

If it's class A, then ListenToB will only be invoked if you pass in _an
object of class A_ as the one and only input. In that case, you should
modify it to accept _two_ inputs, one of class A and the second of class B.
Then you can add the listener object created by ADDLISTENER to the object of
class A (so it is not destroyed when the ListenToB function finishes
executing and its workspace goes away.)

If it's class B, then ListenToB should have been invoked when you called it
with an instance of class B, so I don't believe this is the case.

And if ListenToB is a regular function (not a method) then it also should
have worked, so I don't believe this is the case either.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Aleksandra Krkoleva on
"Steven Lord" <slord(a)mathworks.com> wrote in message <hsjjaq$fpr$1(a)fred.mathworks.com>...
>
> "Aleksandra Krkoleva" <alekk_02(a)yahoo.com> wrote in message
> news:hsj31g$kk6$1(a)fred.mathworks.com...
> > Hi,
> > I'm trying to initiate messaging between objects of two classes. The
> > objects are created in handle subclasses. Object from class A sends
> > notification to listener from class B. Object form class B is a registered
> > listener, receives the notification and executes a callback. In the
> > callback function, there is another notify message which should be sent to
> > the initiator (the object from class A). Up to this point, it all works
> > fine. I've tried to addlistener to the class A, so the object which
> > started the communication has to execute a callback itself. I receive the
> > following message: Undefined function or method 'ListenToB' for input
> > arguments of type 'ClassB'. 'ListenToB' is a method used to register the
> > listener:
> > function ListenToB(bobj)
> > lh2 = addlistener(bobj,'ForFurtherNotif', @(src,
> > evnt)ReceivedInfo(src));
> > end
>
> So which class defines ListenToB as a method, class A or class B?
>
> If it's class A, then ListenToB will only be invoked if you pass in _an
> object of class A_ as the one and only input. In that case, you should
> modify it to accept _two_ inputs, one of class A and the second of class B.
> Then you can add the listener object created by ADDLISTENER to the object of
> class A (so it is not destroyed when the ListenToB function finishes
> executing and its workspace goes away.)
>
> If it's class B, then ListenToB should have been invoked when you called it
> with an instance of class B, so I don't believe this is the case.
>
> And if ListenToB is a regular function (not a method) then it also should
> have worked, so I don't believe this is the case either.
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
From: Aleksandra Krkoleva on
"Steven Lord" <slord(a)mathworks.com> wrote in message <hsjjaq$fpr$1(a)fred.mathworks.com>...
>
> "Aleksandra Krkoleva" <alekk_02(a)yahoo.com> wrote in message
> news:hsj31g$kk6$1(a)fred.mathworks.com...
> > Hi,
> > I'm trying to initiate messaging between objects of two classes. The
> > objects are created in handle subclasses. Object from class A sends
> > notification to listener from class B. Object form class B is a registered
> > listener, receives the notification and executes a callback. In the
> > callback function, there is another notify message which should be sent to
> > the initiator (the object from class A). Up to this point, it all works
> > fine. I've tried to addlistener to the class A, so the object which
> > started the communication has to execute a callback itself. I receive the
> > following message: Undefined function or method 'ListenToB' for input
> > arguments of type 'ClassB'. 'ListenToB' is a method used to register the
> > listener:
> > function ListenToB(bobj)
> > lh2 = addlistener(bobj,'ForFurtherNotif', @(src,
> > evnt)ReceivedInfo(src));
> > end
>
> So which class defines ListenToB as a method, class A or class B?
>
> If it's class A, then ListenToB will only be invoked if you pass in _an
> object of class A_ as the one and only input. In that case, you should
> modify it to accept _two_ inputs, one of class A and the second of class B.
> Then you can add the listener object created by ADDLISTENER to the object of
> class A (so it is not destroyed when the ListenToB function finishes
> executing and its workspace goes away.)
>
> If it's class B, then ListenToB should have been invoked when you called it
> with an instance of class B, so I don't believe this is the case.
>
> And if ListenToB is a regular function (not a method) then it also should
> have worked, so I don't believe this is the case either.
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
Thanks,
As you've guessed, Class A defines ListenToB and now it works fine. If anyone else has similar problem, the syntax can be:
function ListenToB(bobj, aobj) %bobj is obj in classB and is source, aobj is obj in classA
aobj.lh = addlistener(bobj, 'ForFurtherNotif', (src, evnt)@ReceivedInfo(aobj, src)
end
where ReceivedInfo is the callback, and is again method with two arguments, aobj and src.
Regards
From: Aleksandra Krkoleva on
"Aleksandra Krkoleva" <alekk_02(a)yahoo.com> wrote in message <hspe7v$qoq$1(a)fred.mathworks.com>...
> "Steven Lord" <slord(a)mathworks.com> wrote in message <hsjjaq$fpr$1(a)fred.mathworks.com>...
> >
> > "Aleksandra Krkoleva" <alekk_02(a)yahoo.com> wrote in message
> > news:hsj31g$kk6$1(a)fred.mathworks.com...
> > > Hi,
> > > I'm trying to initiate messaging between objects of two classes. The
> > > objects are created in handle subclasses. Object from class A sends
> > > notification to listener from class B. Object form class B is a registered
> > > listener, receives the notification and executes a callback. In the
> > > callback function, there is another notify message which should be sent to
> > > the initiator (the object from class A). Up to this point, it all works
> > > fine. I've tried to addlistener to the class A, so the object which
> > > started the communication has to execute a callback itself. I receive the
> > > following message: Undefined function or method 'ListenToB' for input
> > > arguments of type 'ClassB'. 'ListenToB' is a method used to register the
> > > listener:
> > > function ListenToB(bobj)
> > > lh2 = addlistener(bobj,'ForFurtherNotif', @(src,
> > > evnt)ReceivedInfo(src));
> > > end
> >
> > So which class defines ListenToB as a method, class A or class B?
> >
> > If it's class A, then ListenToB will only be invoked if you pass in _an
> > object of class A_ as the one and only input. In that case, you should
> > modify it to accept _two_ inputs, one of class A and the second of class B.
> > Then you can add the listener object created by ADDLISTENER to the object of
> > class A (so it is not destroyed when the ListenToB function finishes
> > executing and its workspace goes away.)
> >
> > If it's class B, then ListenToB should have been invoked when you called it
> > with an instance of class B, so I don't believe this is the case.
> >
> > And if ListenToB is a regular function (not a method) then it also should
> > have worked, so I don't believe this is the case either.
> >
> > --
> > Steve Lord
> > slord(a)mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
> Thanks,
> As you've guessed, Class A defines ListenToB and now it works fine. If anyone else has similar problem, the syntax can be:
> function ListenToB(bobj, aobj) %bobj is obj in classB and is source, aobj is obj in classA
> aobj.lh = addlistener(bobj, 'ForFurtherNotif', @(src, evnt)ReceivedInfo(aobj, src)
> end
> where ReceivedInfo is the callback, and is again method with two arguments, aobj and src.
> Regards
 |  Next  |  Last
Pages: 1 2
Prev: 2d matrix compare
Next: saveas eps level 2?