how to wait for completion...

Login to reply to this topic.
Thu, 2006-02-02 16:44
Joined: 2003-11-28
Forum posts: 35
hello,

I have the following code:

CMyClass::MyFunction()
{
iMyAnotherClass->AnotherFunction();
// must wait for AnotherFunction() to complete
// and I don't know how to do this
MyNextFunction();
}

...............
CMyAnotherClass::MyCallbackMethod()
{
// do something
}
...................
CMyAnotherClass* iMyAnotherClass;


In MyFunction(), when I call AnotherFunction(), this will trigger the MyCallbackMethod() .

after the MyCallbackMethod() is completed I want to execute the MyNextFunction.

How to do that? I need to use semaphores? or TRequestStatus ?

How to implement those in my case.

Thanks. Any sugestions is welcomed.

Thu, 2006-02-02 18:32
Joined: 2004-11-29
Forum posts: 1233
Re: how to wait for completion...
What is the asyncronous stuff you do in AnotherFunction?

Some active object you fire, that then will call MyCallbackMethod on completion?

if so, all CActive derived classes has a TRequestStatus *iStatus member, wich is the request status it uses.

You should be able to use User::WaitForRequest() to wait for its completion.

...In theory at least...

I just tried this with a CPeriodic, but it turns out User::WaitForRequest stops waiting _before_ my callback function gets to run...
This might be because of how CPeriodic:s RunL function is implemented though...

Well I guess this counts as "any suggestion" at least Smiley

Try it if it works for you.
Thu, 2006-02-02 19:00
Joined: 2005-11-28
Forum posts: 101
Re: how to wait for completion...
mabye u can pass an argument to AnotherFunction(TBool *sem)
and then check if sem is true and in ur call back set it for true when it finish...
Thu, 2006-02-02 21:21
Joined: 2004-05-29
Forum posts: 149
Re: how to wait for completion...
Quote from: lotb
hello,

I have the following code:

CMyClass::MyFunction()
{
iMyAnotherClass->AnotherFunction();
// must wait for AnotherFunction() to complete
// and I don't know how to do this
MyNextFunction();
}

...............
CMyAnotherClass::MyCallbackMethod()
{
// do something
}
...................
CMyAnotherClass* iMyAnotherClass;

First of all, to wait on an asynchronous function the correct way to do this is User::WaitForRequest().  If you want MyAnotherClass->AnotherFunction() to be a "Blocking Call" which means it will never return until it is done, you have to put the User::WaitForRequest(iStatus) at the end of AnotherFunction().  If you want to only wait in this particular instance, then you need to get a copy of the status variable; i.e.

Code:
CMyClass::MyFunction()
{
// AnotherFunction() returns the TRequestStatus to wait on
TRequestStatus status = iMyAnotherClass->AnotherFunction();
// wait for AnotherFunction() to complete
User::WaitForRequest (status);
MyNextFunction();
}

However, I personally believe it's bad programming style to be passing the status variable from one class to another class for this purpose; I recommend waiting in AnotherFunction().
-euroq
  • Login to reply to this topic.