×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    105

    Question My application err-exit with E32USER-CBase 40 after keep running for some time.

    Hello,Guys,help me with this problem:
    my application have this function:detect the state of charger per 5 seconds,and it changes then send me a message.when it starts,it seems works well,however after about half hour it exit with E32USER-CBase 40,I can not find out what's wrong,my code as follow:

    //////////////////////////MyChargerGuard.h
    Code:
    #ifndef MYCHARGERGUARD_H
    #define MYCHARGERGUARD_H
    
    #include "MyMsgHandler.h"//here provide a message sender,it works well,there is no problem about it
    #include <saclient.h>
    #include <My.rsg>
    #include <AknQueryDialog.h>
    #include <aknnotewrappers.h>
    #include "My.hrh"
    
    class MyChargerGuard:public CActive
    {
    public:
    	static MyChargerGuard* NewL(MyMsgHandler* aMsgSender);
    	static MyChargerGuard* NewLC(MyMsgHandler* aMsgSender);
    private:
    	void ConstructL();
    	void DoCancel();
    public:
    	MyChargerGuard(MyMsgHandler* aMsgSender);
    	~MyChargerGuard();
    	void RunL();
    	void Cancel();
    	//start here to monitor charger state
    	void StartChargerGuardL();
    public:
    	enum TState {EChargerNone,EChargerConnecting,EChargerDisConnecting,EChargerNoChargering};
    private:
    	//send message when the power state change
    	MyMsgHandler* iMsgSender;
    	//Be used to detect the state of power
    	RSystemAgent			        iSystemAgent;
    	TState					iState;
    	TInt					iChargerStatus;
    	RTimer					iTimer;
    	CActiveSchedulerWait	iWait;
    };
    
    #endif
    //////////////////////////MyChargerGuard.cpp
    Code:
    #include "MyChargerGuard.h"
    
    MyChargerGuard* MyChargerGuard::NewL(MyMsgHandler* aMsgSender)
    {
    	MyChargerGuard* self=NewLC(aMsgSender);
    	CleanupStack::Pop(self);
    	return self;
    }
    
    MyChargerGuard* MyChargerGuard::NewLC(MyMsgHandler* aMsgSender)
    {
    	MyChargerGuard* self=new(ELeave) MyChargerGuard(aMsgSender);
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    }
    
    void MyChargerGuard::ConstructL()
    {
    	CActiveScheduler::Add(this);
    	User::LeaveIfError(iSystemAgent.Connect());
    	iChargerStatus=iSystemAgent.GetState(KUidChargerStatus);
    	if(ESAChargerDisconnected==iChargerStatus)
    	{
    		iState=EChargerDisConnecting;
    	}
    	else if (ESAChargerConnected==iChargerStatus)
    	{
    		iState=EChargerConnecting;
    	}
    	User::LeaveIfError(iTimer.CreateLocal());
    }
    
    MyChargerGuard::MyChargerGuard(MyMsgHandler* aMsgSender):CActive(EPriorityStandard),iMsgSender(aMsgSender)
    {
    	
    }
    
    MyChargerGuard::~MyChargerGuard()
    {
    	if (IsActive())
    	{
    		Cancel();
    	}
    	iSystemAgent.Close();
    	iTimer.Close();
    }
    
    void MyChargerGuard::StartChargerGuardL()
    {
    	if(IsActive())
    		Cancel();
    	iTimer.After(iStatus, 1000*5000);
    	SetActive();
    }
    
    void MyChargerGuard::RunL()
    {
    	if(iStatus.Int()!=KErrNone)
    		return;
    	iChargerStatus=iSystemAgent.GetState(KUidChargerStatus);
    	switch(iChargerStatus)
    	{
    	case ESAChargerConnected:
    		{
    			if(iState==EChargerDisConnecting)
    			{
    				iState=EChargerConnecting;
    				iMsgSender->SendMessageL(_L("1xxxxxxxxx3"),_L("Power on"));//Send Message that power on
    			}
    		}
    		break;
    	case ESAChargerDisconnected:
    		{
    			if(iState==EChargerConnecting)
    			{
    				iState=EChargerDisConnecting;
    				iMsgSender->SendMessageL(_L("1xxxxxxxxx3"),_L("Power off"));//Send Message that power on
    			}
    		}
    		break;
    	default:
    		break;
    	}
    	StartChargerGuardL();
    }
    
    void MyChargerGuard::Cancel()
    {
    	DoCancel();
    }
    
    void MyChargerGuard::DoCancel()
    {
    	
    }
    Here I use "MyMsgHandler* iMsgSender" to send me message when the charger state changes.But you should know that it's not his problem,because I always keep the charger connected with power,so it have not sent me any message.But the application still exit with panic.Please help me.

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    from Docs

    The active object must not have an outstanding request when the destructor is called, otherwise an E32USER-CBase 40 panic is raised
    so check where you are face same

  3. #3
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    105

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Quote Originally Posted by skumar_rao View Post
    from Docs

    so check where you are face same
    I haven't do anything about destructor,maybe it is because something else to cause that.

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Quote Originally Posted by suiying0792 View Post
    I haven't do anything about destructor,maybe it is because something else to cause that.
    Well if at anytime your MyChargerGuard is destroyed/deleted the dtor would be called from where you are calling the Cancel() which is fine. However do not over-ride the default Cancel() function what you should be doing is to implement the DoCancel() which would be called by the CActive base class when it goes out of scope.

    In the DoCancel you should cancel the outstanding RTimer request doing something like iTimer.Cancel(), once you have done that you wont be facing the CBase 40 issue that u r facing now.

    Cheers,
    Mayank

    P.S. you would do well to read more about AO from the SDK or through some of the docs published by both Symbian/Nokia on AO.

  5. #5
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    105

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Quote Originally Posted by mayankkedia View Post
    Well if at anytime your MyChargerGuard is destroyed/deleted the dtor would be called from where you are calling the Cancel() which is fine. However do not over-ride the default Cancel() function what you should be doing is to implement the DoCancel() which would be called by the CActive base class when it goes out of scope.

    In the DoCancel you should cancel the outstanding RTimer request doing something like iTimer.Cancel(), once you have done that you wont be facing the CBase 40 issue that u r facing now.

    Cheers,
    Mayank

    P.S. you would do well to read more about AO from the SDK or through some of the docs published by both Symbian/Nokia on AO.
    What I only want to say to you is : Thanks very much ,but why can't I over-ride the default Cancel() ? Is there some other things Cancel() does except DoCancel()?

  6. #6
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Read any documentation on active objects (how can you write one without fully reading the documentation anyway ?) and it'll give you an explanation of Cancel() - it consumes a TRequestSignal calcel event if necessary.

  7. #7
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    146

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Quote Originally Posted by suiying0792 View Post
    What I only want to say to you is : Thanks very much ,but why can't I over-ride the default Cancel() ? Is there some other things Cancel() does except DoCancel()?
    CActive::Cancel is not virtual - not meant to be overridden. It basically looks something like this:

    Code:
    void CActive::Cancel()
       {
       IF IsActive
          DoCancel();
          WAIT FOR REQUEST CANCEL
       ENDIF
       }
    There's nothing there to change. Cancel checks if there is an outstanding request, and waits for the request to be cancelled. Actually, it may be that the request has already been served but that has to be handled that too.

  8. #8
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Just to add to what has already been so rightly said here, straight from Jo SticBury's Book, which incidentally I would recommend you definitely read through for a good overview of Symbian basics :-

    Every request issued by an active object must complete exactly once.
    It can complete normally or complete early as a result of an error
    or a call to Cancel(). Let’s first examine what happens in a call to
    CActive::Cancel() and return to the other completion scenarios
    later.

    CActive::Cancel() first determines if there is an outstanding
    request and, if so, it calls the DoCancel() method, a pure virtual
    function in CActive, implemented by the derived class (which
    should not override the non-virtual base class Cancel() method).
    DoCancel() does not need to check if there is an outstanding request; if
    there is no outstanding request, Cancel() does not call it. The encapsulated
    asynchronous service provider should provide a method to cancel
    an outstanding request and DoCancel() should call this method.

    DoCancel() can include other processing, but it should not leave
    or allocate resources and it should not carry out any lengthy operations.
    This is because Cancel() is itself a synchronous function which does
    not return until both DoCancel() has returned and the original asynchronous
    request has completed. That is, having called DoCancel(),
    CActive::Cancel() then calls User::WaitForRequest(), passing
    in a reference to its iStatus member variable. It is blocked until
    the asynchronous service provider posts a result (KErrCancel) into it,
    which should happen immediately, as described above.

    The cancellation event is thus handled by the Cancel() method of
    the active object rather than by the active scheduler.

    Finally, Cancel() resets the iActive member of the active object
    to reflect that there is no longer an asynchronous request outstanding.

    The Cancel() method of the CActive base class performs all
    this generic cancellation code. When implementing a derived active
    object class, you only need to implement DoCancel() to call the
    appropriate cancellation function on the asynchronous service provider
    and perform any cleanup necessary. You most certainly should not
    call User::WaitForRequest(), since this will upset the thread
    semaphore count. Internally, the active object must not call the protected
    DoCancel() method to cancel a request; it should call
    CActive::Cancel(), which invokes DoCancel() and handles the
    resulting cancellation event.
    Cheers,
    Mayank

  9. #9
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    105

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Quote Originally Posted by mayankkedia View Post
    Just to add to what has already been so rightly said here, straight from Jo SticBury's Book, which incidentally I would recommend you definitely read through for a good overview of Symbian basics :-



    Cheers,
    Mayank
    Thanks Mayank,You helped me a lot , the document is very useful,I understand it now.

  10. #10
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    105

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Quote Originally Posted by anttijuu View Post
    CActive::Cancel is not virtual - not meant to be overridden. It basically looks something like this:

    Code:
    void CActive::Cancel()
       {
       IF IsActive
          DoCancel();
          WAIT FOR REQUEST CANCEL
       ENDIF
       }
    There's nothing there to change. Cancel checks if there is an outstanding request, and waits for the request to be cancelled. Actually, it may be that the request has already been served but that has to be handled that too.
    Thank you,my friend,You teached me a lot.

  11. #11
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    105

    Re: My application err-exit with E32USER-CBase 40 after keep running for some time.

    Quote Originally Posted by hotcheese View Post
    Read any documentation on active objects (how can you write one without fully reading the documentation anyway ?) and it'll give you an explanation of Cancel() - it consumes a TRequestSignal calcel event if necessary.
    Thanks for your advice.

Similar Threads

  1. Replies: 4
    Last Post: 2007-01-17, 22:28
  2. What time in our application i use cbase
    By pistha in forum Symbian
    Replies: 1
    Last Post: 2006-09-18, 06:37
  3. Replies: 2
    Last Post: 2005-06-10, 06:41
  4. Memory Full Error on Nokia6600 running MIDlet Application
    By tbechnati in forum Mobile Java General
    Replies: 0
    Last Post: 2004-05-02, 14:19
  5. 3650 second time application launch
    By MartinVerville in forum Mobile Java General
    Replies: 4
    Last Post: 2004-03-29, 15:25

Posting Permissions

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