hmm, i dont think i explained it right, lemme try again.
iGrabber is the active object, it works fine, IssueRequest starts the active object and it does a few async operations with SetActive called after each one, and RunL in iGrabber gets called. But what I want to do is in the thread that started/created the iGrabber active object, I want to wait for it to finish.
Here is some more code:
Here is the code thats starts the PageGrabber active object:
[code:1]
// create a pagegrabber object
PageGrabber* iGrabber;
iGrabber = PageGrabber::NewL();
// setup form vars
iGrabber->SetNumFormVars(3);
iGrabber->SetFormVar(0, _L8("username"), aUsername);
iGrabber->SetFormVar(1, _L8("password"), aPassword);
iGrabber->SetFormVar(2, _L8("t"), _L8("1"));
TRequestStatus status;
// then issue the request for the page
iGrabber->IssueRequest(aURL, aFilename, status);
[/code:1]
from the above code you can see that iGrabber is an instance of PageGrabber, which is an active object
Below is some code from the PageGrabber active object:
[code:1]
void PageGrabber::IssueRequest(const TDesC& aURLstring, TDes& aFilename) {
// init the url object
webpage.Set(aURLstring);
// validate filename, setting it if needed
ValidateFilename(aFilename);
// format post data
SetPostDataL();
// format header data
SetPostHeadersL();
// open socket server
// connect to the socket server
User::LeaveIfError(iSocketServ.Connect());
// now resolve the name given in the URL
iHostResolver.Open(iSocketServ, KAfInet, KProtocolInetUdp);
iHostResolver.GetByName(webpage.host, iNameEntry, iStatus);
// set the connection state and tell the active object to wait for the async operation
iConnectState = ENameResolved;
SetActive();
}
.. RunL function ommited, typical active object RunL that performs async operations setting SetActive with a big switch statement for different connect states ....
TBool PageGrabber::IsFinished()
{
return (iConnectState == EDataReady);
}
[/code:1]
Now the above code starts off the scheduler and causes RunL to run after the GetByName function has finished. This all works fine, the problem is, if at the place where I created the active object I try and wait for it to finish using the WaitForAnyRequest it seems to eat up the async operation that the active object is going to use.
Surely there is a simple way for a program to create an active object, have it go do its thing in the background, then for the program that created the active object to wait for a certain state of the active object (ie finished). I could put a timer in the loop instead of WaitForAnyRequest, but that is not the symbian way, I need a way to tell the main program that it should wait for the completion of the active object that it created so that it can manipulate data from the active object, and then ultimatly destroy it when finished with it.
I tried to make my active object behave like the symbian async function, and put a TRequestStatus parameter in and setting that to KResultPending at the start and then setting it to KErrNone when completed with User::RequestComplete. But when I tried waiting for that with WaitForRequest, it had the same result, after the active object did its first SetActive, it never ran RunL.