how to wait for completion...
| Thu, 2006-02-02 16:44 | |
|
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. |
|






Forum posts: 1233
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
Try it if it works for you.
Forum posts: 101
and then check if sem is true and in ur call back set it for true when it finish...
Forum posts: 149
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.
{
// 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