CTelephony and CActive problem

Login to reply to this topic.
Thu, 2007-01-11 14:35
Joined: 2006-12-24
Forum posts: 10
I'm trying to write a simple program.
My CActive methods:
Code:
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 (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();
}
}
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.
But whet i call StartL(...) again from my UI-class command handler i see KText info.
Where is a problem?

Thu, 2007-01-11 15:01
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: CTelephony and CActive problem
Quote from: tyatya
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.
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().

Thu, 2007-01-11 15:16
Joined: 2006-12-24
Forum posts: 10
Re: CTelephony and CActive 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().
But in second step State==EInitialized {...}statement should be called. But it is not called. Angry
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.
Thu, 2007-01-11 16:23
Joined: 2006-11-07
Forum posts: 12
Re: CTelephony and CActive problem
Hi

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.

Fri, 2007-01-12 13:26
Joined: 2006-12-24
Forum posts: 10
Re: CTelephony and CActive problem
Code:
CMyTimer* CMyTimer::NewL()
{
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();
}
}
When i lanch program first (iState==EInitialized){...} statement never is called.
I exit from program and start it again. Then (iState==EInitialized){...} statement is called.
Any ideas?
Fri, 2007-01-12 18:36
Joined: 2006-05-09
Forum posts: 78
Re: CTelephony and CActive problem
This code in isolation looks ok as far as getting the RunL() to run with the logic you have used (however the DoCancel is wrong). Your description therefore perhaps implies you are possibly using other active objects and the thing as a whole isn't correct.

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.
Fri, 2007-01-12 19:24
Joined: 2006-12-24
Forum posts: 10
Re: CTelephony and CActive problem
This is my client code using CMyTimer (it is HelloWorld template in main):
Code:
void CSymbian6AppUi::HandleCommandL( TInt aCommand )
{
    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;
        }
}
Also i change my DoCancel():
Code:
void CMyTimer::DoCancel()
{
if(iState==EUninitialized)
iTimer.Cancel();
else if(iState==EInitialized)
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
}
I still have same problem. Cry
Mon, 2007-01-15 15:01
Joined: 2006-12-24
Forum posts: 10
Re: CTelephony and CActive problem
any ideas?
Help me please!
Wed, 2007-01-17 12:31
Joined: 2006-12-24
Forum posts: 10
Re: CTelephony and CActive problem
[quote author=Alcoran link=topic=17317.msg51606#msg51606
plz post also the error handling part in the RunL, that could be the reason.
Quote
Thanks. It was the reason.
Thaks to everybody!
  • Login to reply to this topic.