×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    73

    Can't force CActive to run.

    Hello, i have created an CActive Object, now i want to use it as a async thread. (So i need to make it execute some code repeadly)
    But i don't know how, i found that it need CActiveScheduler, but the descriptions and codes provided over internet are useless for me (they do not work)
    all i get is
    E32USER-CBASE 43 error


    here is my code:

    Code:
     PC_EYE = TMobEyeThread::NewL(); //CActive object class
    scheduler = new (ELeave) CActiveScheduler(); //CActiveScheduler public variable in container class
    
    
    
    	 CleanupStack::PushL(scheduler);
    	 CActiveScheduler::Install(scheduler);
    	
    		scheduler->Add(PC_EYE); 
    		PC_EYE->StartThread();
    	 CActiveScheduler::Start(); 
    	 CleanupStack::PopAndDestroy(scheduler);
    and another thing that could be important
    this is PC_EYE var
    Code:
    TMobEyeThread::TMobEyeThread() : CActive(EPriorityStandard)
        { 
    	CActiveScheduler::Add(this); 
        }
    anyway i am not sure if its executed during creation, and i dont know why the namespace of CActiveScheduler:: is used instead of other variable

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Can't force CActive to run.

    Basically it means that your thread already has active scheduler installed. Thus do not need to install new one.

    So it is GUI application you are running, or something else ? As you have active scheduler, I would suppose you also can get rid of CActiveScheduler::Start(); from teh code. and simply try what happens if you try using the CActive derived class of yours in your thread.

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,692

    Re: Can't force CActive to run.

    You can find a very simple active object with timer in #2 of http://developer.nokia.com/Community...bout-CActive!). That may be something you could refine for your needs.

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,542

    Re: Can't force CActive to run.

    Quote Originally Posted by melepeta View Post
    but the descriptions and codes provided over internet are useless for me
    There are a few examples articles in the wiki, have you checked those? for example here is one http://developer.nokia.com/Community/Wiki/Active_object

  5. #5
    Registered User
    Join Date
    Jul 2013
    Posts
    73

    Re: Can't force CActive to run.

    None of the examples work.

    in http://developer.nokia.com/Community/Wiki/Active_object
    is RMyAsyncServiceProvider iServiceProvider; that i am not quite sure how to use ( i used RTimer but it seems not to work)

    i cant compile such code like
    __ASSERT_ALWAYS(!IsActive(), User::Panic(KMyActivePanic, EAlreadyActive));
    Another thing is that i get after some miliseconds after app start error: KERN EXEC 3 i searched over forum and found that it could be the NULL pointer problem.

    but i define a class without constructor iObserver and a class without pointer (just static)


    i will drive you mad :P
    Code:
    #include <e32std.h>
    #include <e32cons.h>
    #include <e32base.h>
    #include "stringunit.h"
    
    
    class MMyActiveObjectObserver
    {
    public:
    
    //Pure virtual function that shall be implemented by every user of CMyActiveObject object. It is called when async service provider completes the request. 
    // 
    	virtual void HandleRequestCompleted(TInt aError) = 0;
    };
    
    
    class TMobEyeThread : public CActive
        {
    	//EPriorityStandard
    public:
    	TMobEyeThread(TInt aPriority);
    	static TMobEyeThread* NewL(TInt aPriority);
        ~TMobEyeThread();
        
        void StartThread();
        void StopThread();  
        void DoAsyncAction(MMyActiveObjectObserver* aObserver);
     AnsiString k;
     int p;
    
     
    
        void ConstructL();
     
    protected:
     
        virtual void RunL();            // Inherited from CActive.
        virtual void DoCancel();  
        TInt RunError(TInt aError);
        
    private:
        
        RTimer * iServiceProvider; 
     
    	MMyActiveObjectObserver* iObserver; // Observer
      
     
        };



    Code:
    #include "MobEyeThread.h"
    
    
    /*
    EPriorityStandard
    */
    TMobEyeThread::TMobEyeThread(TInt aPriority) : CActive(aPriority)
        { 
    	iServiceProvider = new RTimer();
        }
     
    void TMobEyeThread::ConstructL()
        {    
    	
    CActiveScheduler::Add(this);
    iServiceProvider->CreateLocal();
    	//User::LeaveIfError(iServiceProvider.Connect());	
    k = "";
    p = 1;
    
        }
     
    TMobEyeThread* TMobEyeThread::NewL(TInt aPriority)
        {
    	  TMobEyeThread *diz=new (ELeave) TMobEyeThread(aPriority); // first phase
    	    CleanupStack::PushL(diz);
    	    diz->ConstructL();
    	    CleanupStack::Pop(); 
    	    return diz;    
        } 
    
    TMobEyeThread::~TMobEyeThread()
        {
    	Cancel();
    	iServiceProvider->Close();
        }
     
    void TMobEyeThread::StartThread()
        { 
    	iServiceProvider->After(iStatus,1); // 10 seconds
        SetActive();              
        }
    
    void TMobEyeThread::StopThread()
    	{
    	iServiceProvider->Cancel();
    	Cancel();
    	}
    
    
    
    void TMobEyeThread::DoCancel()
    	{
    	iServiceProvider->Cancel();
    	}
    
    void TMobEyeThread::RunL()
        {
    	if (!IsActive())
    	{
    User::LeaveIfError(iStatus.Int());
    
    //	k = k + "*";
    // p = p + 1;
     
    
    iObserver->HandleRequestCompleted(KErrNone);
    	}
        }
    
    
    void TMobEyeThread::DoAsyncAction(MMyActiveObjectObserver* aObserver)
    {
    	//__ASSERT_ALWAYS(!IsActive(), User::Panic(KMyActivePanic, EAlreadyActive));
    
    	//__ASSERT_ALWAYS(aObserver, User::Panic(KMyActivePanic, ENoObserver));
    
    //	iServiceProvider.DoService(iStatus);
    	SetActive();
    }
     
    
    TInt TMobEyeThread::RunError(TInt aError)
    {
    	iObserver->HandleRequestCompleted(aError);
    	return KErrNone;
    }

  6. #6
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,026

    Re: Can't force CActive to run.

    Quote Originally Posted by melepeta View Post
    Code:
    #include <e32std.h>
    #include <e32cons.h>
    #include <e32base.h>
    #include "stringunit.h"
    
    
    class MMyActiveObjectObserver
    {
    public:
    
    //Pure virtual function that shall be implemented by every user of CMyActiveObject object. It is called when async service provider completes the request. 
    // 
    	virtual void HandleRequestCompleted(TInt aError) = 0;
    };
    
    
    class TMobEyeThread : public CActive
        {
    	//EPriorityStandard
    public:
    	TMobEyeThread(TInt aPriority);
    	static TMobEyeThread* NewL(TInt aPriority);
        ~TMobEyeThread();
        
        void StartThread();
        void StopThread();  
        void DoAsyncAction(MMyActiveObjectObserver* aObserver);
     AnsiString k;
     int p;
    
     
    
        void ConstructL();
     
    protected:
     
        virtual void RunL();            // Inherited from CActive.
        virtual void DoCancel();  
        TInt RunError(TInt aError);
        
    private:
        
        RTimer * iServiceProvider; 
     
    	MMyActiveObjectObserver* iObserver; // Observer
      
     
        };



    Code:
    #include "MobEyeThread.h"
    
    
    /*
    EPriorityStandard
    */
    TMobEyeThread::TMobEyeThread(TInt aPriority) : CActive(aPriority)
        { 
    	iServiceProvider = new RTimer();      //////// This is not needed ( R classes do not need initialization with new)
        }
     
    void TMobEyeThread::ConstructL()
        {    
    	
    CActiveScheduler::Add(this);
    iServiceProvider->CreateLocal();
    	//User::LeaveIfError(iServiceProvider.Connect());	
    k = "";
    p = 1;
    
        }
     
    TMobEyeThread* TMobEyeThread::NewL(TInt aPriority)
        {
    	  TMobEyeThread *diz=new (ELeave) TMobEyeThread(aPriority); // first phase
    	    CleanupStack::PushL(diz);
    	    diz->ConstructL();
    	    CleanupStack::Pop(); 
    	    return diz;    
        } 
    
    TMobEyeThread::~TMobEyeThread()
        {
    	Cancel();
    	iServiceProvider->Close();
        }
     
    void TMobEyeThread::StartThread()
        { 
    	iServiceProvider->After(iStatus,1); // 10 seconds -------- That's 1 microsecond, 10 seconds would be : 10000000
        SetActive();              
        }
    
    void TMobEyeThread::StopThread()
    	{
    	iServiceProvider->Cancel();  /// not needed , only calling Cancel() is enough which would then call DoCancel() by itself
    	Cancel();
    	}
    
    
    
    void TMobEyeThread::DoCancel()
    	{
    	iServiceProvider->Cancel();
    	}
    
    void TMobEyeThread::RunL()
        {
    	if (!IsActive())          //// remove this( this is checked before calling SetActive(), to make sure there's no pending Async request)
    	{
    User::LeaveIfError(iStatus.Int()); // remove this & try checking with iStatus code (check if its 0 or else, obviously if it reaches here before KERN EXEC 3)
    
    //	k = k + "*";
    // p = p + 1;
     
    
    iObserver->HandleRequestCompleted(KErrNone);
    	}
        }
    
    
    void TMobEyeThread::DoAsyncAction(MMyActiveObjectObserver* aObserver)
    {
    	//__ASSERT_ALWAYS(!IsActive(), User::Panic(KMyActivePanic, EAlreadyActive));
    
    	//__ASSERT_ALWAYS(aObserver, User::Panic(KMyActivePanic, ENoObserver));
    
    //	iServiceProvider.DoService(iStatus);
    	SetActive();
    }
     
    
    TInt TMobEyeThread::RunError(TInt aError)
    {
    	iObserver->HandleRequestCompleted(aError);
    	return KErrNone;
    }
    Not sure about KERN EXEC 3, but firstly you might want to do changes as highlighted in bold above( in .cpp)

  7. #7
    Registered User
    Join Date
    Jul 2013
    Posts
    73

    Re: Can't force CActive to run.

    No no that won't work i have changed it because i thought it was the problem (changed RTimer sth; to RTimer * sth; then added new operator and changed from . to ->, but the same problem still exists.

  8. #8
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Can't force CActive to run.

    You actually have tons of problems there. For example your iObserver is always invalid, since it is newer set to any value. So you might want to implement the interface for it, and give the pointer to the class when you call teh fucntion where you are passing it in.

    This would actually make the Kern-Exec 3 panic if your RunL would ever be called.

    secondly you never ever call SetActive(); without having active request set pending before, if you do, your RunL is never called, but you simply get stray signal panic.

  9. #9
    Registered User
    Join Date
    Jul 2013
    Posts
    73

    Re: Can't force CActive to run.

    Yeah but how, sorry i might drive you mad now. I completely don't understand it.

    There is CActive class

    there in it i have: RTimer and
    class MMyActiveObjectObserver
    {
    public:
    virtual void HandleRequestCompleted(TInt aError) = 0;
    };
    That is even not used

    I initialize RTimer but how it is supposed to run desired command when i cant find any function that will attach RunL or any other function.
    And that magic iObserver omg what is that, more i read less i understand.

    Found now this:
    http://developer.nokia.com/Community...implementation

    class MExampleTimerNotify
    {
    public:
    virtual void TimerExpired(TAny* aTimer,TInt aError) = 0;
    };
    where
    void CYourTimerController::TimerExpired(TAny* aTimer,TInt aError)
    {
    if(aError == KErrNone)
    {
    // Timer successfully completed, handle it
    CExampleTimer* timer = (CExampleTimer*)aTimer;
    TTimeIntervalSeconds seconds(10);
    timer->Inactivity(seconds); //Notify inactivity after 10 seconds
    }
    }
    it looks like create a timer with this notifycontroller then in this notify controlle create another timer now its a black magic x_X

  10. #10
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Can't force CActive to run.

    You should really first study the basics of programming. Basically if you don't know the difference of instantiating & defining something, then we can not really help.

    Also, knowing about object orientation, and C-language would be must for requirements when even thinking of starting Symbian programming. Thus you would need to know what you should do with pure virtual function definitions, i.e. you should derive the interface in your class, and implement all of the pure-virtual functions.

    Once you get the basics sorted out, then we could start with the actual Symbian C++, and implementation discussions.

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,692

    Re: Can't force CActive to run.

    (When talking about "pure virtual", Jukka means the "virtual SomeMethod()=0;" construct, they are callback methods which are specified - like it id knoen that a timer will call them -, but you have to implement them - as you are the one who knows what should happen when the timer expires. If you have some Java or C# background, it is the counterpart for "abstract")

  12. #12
    Registered User
    Join Date
    Jul 2013
    Posts
    73

    Re: Can't force CActive to run.

    I will try to rewrite the class and make it almost the same like in the link i showed in my last post.
    Well i don't think its actually the basics of programming problem that i have, its more like teaching a monkey to bend two pieces of wood with hammer and a nail, monkey see monkey do :P

    I don't have proper knowledge about symbian, so i have hard times understanding the behaviour and processes, anyway i have different term for a timer and its hard for me to switch, and i never thought i would be programming on lower level (almost like for instancing for selfmade computers) if you know what i mean ;]
    but with back to the sample in wiki.

    crap i didnt read it carefully TimerExpired function is the callback - its commented and the line
    CExampleTimer* timer = (CExampleTimer*)aTimer; is a simple casting x_X

    anyway i dont close the topic i need to do some thing then i will change the code and i will tell you if it works ;]

    When yucca told me that i should teach basics of programming i treated it as a personal fail ;p Don't bother about this post. See you soon ;p
    Last edited by melepeta; 2013-10-15 at 19:51.

  13. #13
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Can't force CActive to run.

    Quote Originally Posted by melepeta View Post
    When yucca told me that i should teach basics of programming i treated it as a personal fail ;p Don't bother about this post. See you soon ;p
    You would be doing a great favor to yourself, by not trying to climb the three from top-down, but actually taking time to understanding the basics. I been in this forum longer than anybody else here, and seen people hitting their heads to the wall for simply not taking time to do the groundwork. Anyway, you of course can take my humble advice or choose not to take it. It is indeed up-to you on how you want to spend your time.

  14. #14
    Registered User
    Join Date
    Jul 2013
    Posts
    73

    Re: Can't force CActive to run.

    OK so i copy / past the code from http://developer.nokia.com/Community...implementation
    it does not work as i expected (doesn't work at all ;p)

    I have few questions

    How to use this class ?
    1) Inherit your application class from MExampleTimerNotify, your class can be any view or the AppUi class.
    2) Add the TimerExpired method to your class as it has been declared pure virtual you need to implement that.
    3) Declare the variable of CExampleTimer class in your class.
    4) In example below it has been created in ConstructL
    5) Call After() method with appropriate time and wait for the callback even i.e. TimerExpired.

    please see bold text
    steps 1 2 and 3

    class CYourTimerController : public CBase, public MExampleTimerNotify
    {
    public:
    since it inherit from MExampleNotify i dont need to declere it here, but i did, without it i see like the timer is not enabled and when i add
    virtual void TimerExpired(TAny* aTimer,TInt aError) = 0; it makes KERN EXEC 3

    void TimerExpired(TAny* aTimer,TInt aError);
    void ConstructL(); i added it
    private :
    CExampleTimer* iYourTimer;
    };


    void CYourTimerController::ConstructL()
    {
    iYourTimer = CExampleTimer::NewL(*this);
    TTimeIntervalMicroSeconds32 someInterVal(200000); //you can call After/At/Inactivity depending on what you want to do
    iYourTimer->After(someInterVal);
    }


    /**
    * Callback implementation when the timer activity happens in the CExampleTimer class
    **/
    void CYourTimerController::TimerExpired(TAny* aTimer,TInt aError)
    {
    if(aError == KErrNone)
    {
    // Timer successfully completed, handle it
    CExampleTimer* timer = (CExampleTimer*)aTimer;
    TTimeIntervalSeconds seconds(10);
    timer->Inactivity(seconds); //Notify inactivity after 10 seconds
    }
    }
    //The NewL/NewLC and other functions have been omitted as the implementation details would vary from case to case.

    And now i just have global

    CYourTimerController * THREAD; //with * if i insert virtual void TimerExpired(TAny* aTimer,TInt aError) = 0; in it

    and i initiate the whole thing. by
    THREAD->ConstructL(); then it should start


    however i miss something


    even the information that i should learn basics will point me into right direction. (So i will study code from different approach).
    But maybe i still do not attach timer to a specific function.

  15. #15
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,026

    Re: Can't force CActive to run.

    Not sure if it would make the things a bit simple, you can try adding a new 'Active Object' class to your project(right click project->new->Symbian os c++ class ->choose Active object class)) which by default implements a timer only, so probably you might be able to understand from there, though it has no involvement of 'M'(MExampleNotify in this case) class so no virtual methods implemented.

Similar Threads

  1. Help with CActive
    By wagonli in forum Symbian
    Replies: 13
    Last Post: 2008-02-29, 07:10
  2. CActive in an exe
    By ceehira in forum Symbian
    Replies: 6
    Last Post: 2006-07-19, 14:29
  3. CActive
    By shadow-2005 in forum Symbian
    Replies: 1
    Last Post: 2006-03-20, 09:06

Posting Permissions

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