×

Discussion Board

Results 1 to 10 of 10

Thread: Anyone?

  1. #1
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322

    Anyone?

    Hi
    I can't figure this out :-(
    I try this code (it is different then my previous post) ,
    and don't understand the consept of the event listener ...
    My code is supposed to :
    1) detect that a call is initiated.
    2) hang it up , the initiate another call.
    3) after 5 seconds , hang up the last initiated call also.
    I did many tests with many changes.
    In the best case I get to initiate the second call.after that , no events are detected by the RunL().
    I always end up getting to the RunL() with some error (-2,-9 ...) , and with the app closed ...

    Can someone please explain a bit about the right way to handle such events without errors and without "loosing" the event listener ?

    I added below the constructor , destructor etc , so actually there is not so much code here :-)

    Any help and ideas would be very much appritiated ,
    till now searching for the answer and lots of tests didnt solve the problem ...

    Thank you

    Code:
    void CActiveClass::RunL()
    {
    	if (iStatus == KErrNone) 
    	{ 
    		if(iCallStatus == RCall::EStatusDialling)
    		{ 	
    			if (iMyState == PStatusPending) // this status is set in the constructL ...
    			{
    				// *** HangUp the call initiated by the User ***
    				RLine::TLineInfo lineInfo; 
    				iLine.GetInfo(lineInfo); 
    				TInt openExisting = User::LeaveIfError(iCall.OpenExistingCall(iLine, lineInfo.iNameOfLastCallAdded));
    				// here I deleted some lines where I get info about the call ...
    				if (iAppUi->iController->IsDirectCall() == EFalse)
    				{
    					iMyState = PStatusAfterFirstDial;
    					iAppUi->CreateEndEvent(); // ending the call by simulating pressing the "End Call"
    				}
    				iCall.Close();// good place ???
    			}
    		}
    		else if (iCallStatus == RCall::EStatusIdle)
    		{
    			iCall.Close(); // good place ???
    			if (iMyState == PStatusAfterFirstDial) 
    			{
    				// *** Dial a number ***
    				User::LeaveIfError(iCall.OpenNewCall(iLine, newCallName));
    				_LIT(PhoneNum,"a valid phone number");
    				iMyState = PStatusAfterSecondDial;
    				iCall.Dial(iStatus,PhoneNum); // the call is initiated when testing on device
    			}
    		}
    		else if (iCallStatus == RCall::EStatusConnecting)
    		{
    			if (iMyState == PStatusAfterSecondDial)
    			{
    				// *** Hang the call after 5 seconds ***
    				RTimer timer; 
    				TRequestStatus timerStatus; 
    				timer.CreateLocal(); 
    				timer.After(timerStatus,50000000); 
    				User::WaitForRequest(timerStatus); 
    				timer.Close();
    				iMyState = PStatusWaitForReturn;	
    				iCall.DialCancel();
    			}
    		}
    		else if (iCallStatus == RCall::EStatusHangingUp)
    		{
    			iCall.Close(); // good place ???
    		}
    		iLine.NotifyStatusChange(iStatus, iCallStatus); 
    		SetActive();
    	}
    	else
    	{
    		// here I got error codes -2 (General ?) and -9 (overflow ?) during tests
    	}
    }
    
    CActiveClass* CActiveClass::NewL(CMyAppUi * aAppUi)
    	{
    	CActiveClass* self = new (ELeave) CActiveClass();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	CleanupStack::Pop(self);
    	return self;
    	}
    
    CActiveClass::CActiveClass()
    : CActive(CActive::EPriorityStandard)
    {
    	CActiveScheduler::Add(this);
    	iLineInitiated = EFalse; 
    	iCallActive = EFalse; 
    }
    
    void CActiveClass::ConstructL()
    {
    	iMyState = PStatusPending;
    	StartObserver();
    }
    
    CActiveClass::~CActiveClass()
    {
    	if (IsActive()) { Cancel(); } 
    	ReleasePhone(); 
    }
    
    void CActiveClass::StartObserver() 
    { 
    	if (InitializePhone() == KErrNone) 
    	{ 
    		iLine.NotifyStatusChange(iStatus, iCallStatus); 
    		SetActive(); 
    	} 
    } 
    
    void CActiveClass::DoCancel()
    {
    	iLine.NotifyStatusChangeCancel();
    }

  2. #2
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328

    User::WaitForRequest

    I would recommend you change the following bit of code. Remove the WaitForRequest, and move your RTimer object to be a member of the class. Then put its CreateLocal in your ContructL. Finally, add an extra state to your state machine which will handle the 5 second timer...

    if (iMyState == PStatusAfterSecondDial)
    {
    // *** Hang the call after 5 seconds ***
    RTimer timer;
    TRequestStatus timerStatus;
    timer.CreateLocal();
    timer.After(timerStatus,50000000);
    User::WaitForRequest(timerStatus);
    timer.Close();
    iMyState = PStatusWaitForReturn;
    iCall.DialCancel();
    }

  3. #3
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322
    Thanks a lot , Template60
    I should also put the iStatus as a param to the After() method and delete the Close of the Timer , right ?
    should I add iCall.Close ?
    (I want to verify these issues cause I still get app fall ...)

    Tell me please , is it a problem to use the Dial() method from within the RunL ?


    Best regards

  4. #4
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328
    Yes, use:

    iTimer.After(iStatus);

    and in your destructor

    iTimer.Close();

    And in your RunL (something like)

    if (iMyState == PStatusAfterSecondDialWait5Secs)
    {
    // *** Hang the call after 5 seconds ***
    iMyState = PStatusWaitForReturn;
    iCall.DialCancel();
    }

    And you do have a RunError method... right?

  5. #5
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322
    thanks again
    no , I dont have a RunError method :-|
    how should I use it ?
    is this related to the iCall.Dial(istatus,iPhoneNumber) also ?

    again , thanks for your help

  6. #6
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328
    If your RunL method can leave, then its a good idea to implement RunError. RunError may then be used to handle RunL leaves instead of the CActive default RunError which will invoke a framework error.

    virtual Int RunError(TInt aError); // from CActive

    This is not related to dialling, but it may help you catch some of the errors that you are experiencing (eg put some debug in your RunError).

  7. #7
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322
    Great , Thanks
    please tell me , do you think that there might be a problem by Dialing from within the RunL() method ?

  8. #8
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328
    Dialling should be possible from RunL

  9. #9
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322
    Thank you very much for your advice.

    I wrote here 3 options I tried and the results I got ,
    Please take a look :
    (these options are in the RunL() in the relevant place when iCallStatus == EStatusIdle)
    1)
    iCall.Dial(iStatus,KDefault);
    SetActive ();
    result : call is initiated , app doesnt fall , no more states are detected.

    2)
    iCall.Dial(iStatus,KDefault);
    iLin e.NotifyStatusChange(iStatus,iCallStatus);
    SetActiv e();
    result : app falls

    3)
    iCall.Dial(KDefault);

    result : call is initiated , states are detected , app falls after I hang up (manually) the call

    till now . no option works as I need (which means without falling and continues to listen to Dialling states)

    Best Regards

  10. #10
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322

    correction

    the third option is :
    iCall.Dial(iStatus , KDefault);

    result : call is initiated , states are detected , app falls after I hang up (manually) the call

    Best Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×