CTelephony and CActive problem
| Thu, 2007-01-11 14:35 | |
|
I'm trying to write a simple program.
My CActive methods: Code: void CMyTimer::StartL(TTimeIntervalMicroSeconds32 aDelay) When i first call StartL(1000) from my UI-class command handler i never see KText in emul, i.e. iState==EInitialized {...}statement never call. { Cancel(); // Cancel any request, just to be sure iState = EUninitialized; iTimer.After(iStatus, aDelay); // Set for later SetActive(); // Tell scheduler a request is active } void CMyTimer::RunL() { if (iState == EUninitialized) { iState=EInitialized; CTelephony::TPhoneIdV1Pckg phoneIdPckg(iPhoneId); iTelephony->GetPhoneId(iStatus, phoneIdPckg); SetActive(); } else if (iState==EInitialized) { iState=EUninitialized; User::InfoPrint(KText); iTimer.After(iStatus, 5000000); // Set for 5 sec later SetActive(); } } But whet i call StartL(...) again from my UI-class command handler i see KText info. Where is a problem? |
|






Forum posts: 732
But whet i call StartL(...) again from my UI-class command handler i see KText info.
Where is a problem?
While calling the StartL() you've set the iState to EUninitialized, so first time it will go to the if (iState == EUninitialized) in your RunL(). By the way it's always checking the iStatus before checking your iState in RunL().
Forum posts: 10
But in second step State==EInitialized {...}statement should be called. But it is not called.
By the way it's always checking the iStatus before checking your iState in RunL(). Thanks. But i remove this statements from forum message for conciseness.
Forum posts: 12
What about your DoCancel() implementation? do you cancel pending requests?
plz post also the error handling part in the RunL, that could be the reason.
Forum posts: 10
{
CMyTimer* self = new (ELeave) CMyTimer();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
CMyTimer::CMyTimer() : CActive(EPriorityStandard) // Standard priority
{
}
void CMyTimer::ConstructL()
{
User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer
iTelephony=CTelephony::NewL();
CActiveScheduler::Add(this); // Add to scheduler
}
CMyTimer::~CMyTimer()
{
Cancel(); // Cancel any request, if outstanding
// Delete instance variables if any
delete iTelephony;
iTimer.Close();
}
void CMyTimer::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
iTimer.Cancel();
}
void CMyTimer::StartL(TTimeIntervalMicroSeconds32 aDelay)
{
Cancel(); // Cancel any request, just to be sure
iState = EUninitialized;
iTimer.After(iStatus, aDelay); // Set for later
SetActive(); // Tell scheduler a request is active
}
void CMyTimer::RunL()
{
if(iStatus!=KErrNone)
{
TBuf<8> code;
code.Num(iStatus.Int());
User::InfoPrint(code);// Never showed
}
if (iState == EUninitialized)
{
iState=EInitialized;
CTelephony::TPhoneIdV1Pckg phoneIdPckg(iPhoneId);
iTelephony->GetPhoneId(iStatus, phoneIdPckg);
SetActive();
}
else if (iState==EInitialized)
{
iState=EUninitialized;
User::InfoPrint(KText);
iTimer.After(iStatus, 5000000); // Set for 5 sec later
SetActive();
}
}
I exit from program and start it again. Then (iState==EInitialized){...} statement is called.
Any ideas?
Forum posts: 78
The DoCancel is wrong because you are using one active object but have two asynchronous sources, in the DoCancel you can't cancel them both, you have to know which one to cancel.
Forum posts: 10
{
switch( aCommand )
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ESymbian6Command1:
{
iTimer->StartL(1000000);//Start TASK!
}
break;
default:
Panic( ESymbian6Ui );
break;
}
}
void CSymbian6AppUi::ConstructL()
{
// Initialise app UI with standard value.
BaseConstructL();
// Create view object
iAppView = CSymbian6AppView::NewL( ClientRect() );
iTimer = CMyTimer::NewL(); //Create CMyTimer object
}
CSymbian6AppUi::~CSymbian6AppUi()
{
if ( iAppView )
{
delete iAppView;
iAppView = NULL;
}
if ( iTimer )
{
delete iTimer;
iTimer = NULL;
}
}
{
if(iState==EUninitialized)
iTimer.Cancel();
else if(iState==EInitialized)
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
}
Forum posts: 10
Help me please!
Forum posts: 10
plz post also the error handling part in the RunL, that could be the reason.
Thaks to everybody!