×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 26

Hybrid View

  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,169

    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,751

    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,562

    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.

    I just checked it i hit the options button menu and when i exit it the p is being updated. So this timer works but i can't get the values in realtime. I must select a menu from options menu and click it in order to see any changes.


    also if (p >= 5) iTimer.Cancel(); is not executeh since i have p = 107 now


    i choosed active object becvause i read
    As a consequence, data shared by threads must be protected with access synchronization primitives such as mutexes or semaphores, as opposed to active objects where no synchronization is needed.


    Old post:
    Container
    global var (public)
    CTMobEyeTh* PC_EYE;



    the code in drawing routine:
    Code:
    AnsiString question;
    question = IntToStr(PC_EYE->p);
    question = question + " :)";
    gc.DrawText(*question.AnsiStringToHBufLC(),TPoint(30,90));
    CleanupStack::PopAndDestroy();

    the CActive
    Code:
    public:
    	int p;

    code:

    Code:
    void CTMobEyeTh::ConstructL()
    	{
    	p = 1;
    	User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer
    	CActiveScheduler::Add(this); // Add to scheduler
    	}
    
    
    
    void CTMobEyeTh::RunL()
    	{
    	if (iState == EUninitialized)
    		{
    		// Do something the first time RunL() is called
    		iState = EInitialized;
    		}
    	else if (iState != EError)
    		{
    	if (p >= 5) iTimer.Cancel();
    		// Do something
    		}
    	p = p + 1;
    	iTimer.After(iStatus, 1000000); // Set for 1 sec later
    	SetActive(); // Tell scheduler a request is active
    	}

    I always get p = 1

    update

    even
    Code:
    int s = PC_EYE->p;
    // question = IntToStr(PC_EYE->p);
    
     if (s < 6) question = "less than 6";
     if (s >= 6) question = "more than 6";
    gc.DrawText(*question.AnsiStringToHBufLC(),TPoint(30,90));
    CleanupStack::PopAndDestroy();
    needs to be refreshed by hitting menu item...
    Last edited by melepeta; 2013-10-16 at 14:30.

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,751

    Re: Can't force CActive to run.

    iTimer.Cancel would shut down the ongoing timer activity. However RunL was invoked explicitly because the timer has finished. And at the end you initialize it again (iTimer.After+SetActive). It works fine.
    If your problem is that the value of p does not appear automatically on the screen, you should invoke DrawNow or DrawDeferred (redraw-requesting methods of CCoeControl, so the AppView class) from RunL. Just modify the NewL and constructor to accept a reference/pointer of your AppView object.

  7. #7
    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;
    }

  8. #8
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,089

    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)

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

    Re: Can't force CActive to run.

    I did what you have told me i think i did it wrong because it does not work for me, however now i faced strange problem that did not occur before:
    when i add to my container class a var
    int lolu;

    i cant compile
    lolu = lolu + 1;
    inside Draw function of my container (yeah ccoecontrol)
    [but when i define int lolu; inside Draw funcxtion everything works]

    But that shouldn't be the problem if i find the loop that is responsible for calling Draw method.
    I am unable to find it so it must be system dependent then i could check if i the data from CActive is properly displayed.

    It would be better if i could handle main application loop by myslef and call draw when i want. Well actually it should stop my stupid problems with this application and then i could get work done.



    Maybe this could help: I am trying to make an application that processes images on realtime, in example my cat wants to go back home, but i dont hear her and i am far away from the door, but i could use my old nokia that could inform me that my cat sits near door, actually i want to do some more serious things with RT image processing.
    I have made such thing on my PC (notebook) but i damaged cable that connects touchpad to the mainboard (when chanigng keybioard) and i cant run it since, i have no money for such things, so i decided to use other computer and develop same application on mobile then i will just simply port it onto pc) I use a thread in a thread that gets images from camera, adds them into an array and processes them(second thread), i want to do similar thing here.
    Last edited by melepeta; 2013-10-16 at 18:57.

  10. #10
    Registered User
    Join Date
    May 2008
    Location
    Surat Thani
    Posts
    260

    Re: Can't force CActive to run.

    Quote Originally Posted by melepeta View Post
    I did what you have told me i think i did it wrong because it does not work for me, however now i faced strange problem that did not occur before:
    when i add to my container class a var
    int lolu;

    i cant compile
    inside Draw function of my container (yeah ccoecontrol)
    [but when i define int lolu; inside Draw funcxtion everything works]
    Hi,

    Draw is a const function, so it's not possible to modify normal member variables there. You can either make the member variable mutable (so it can be modified in const functions), or cast the this (const) pointer in Draw function to a normal non-const pointer and modify the variable through that pointer - that would be a bit hacky though.

    Btw, take a look at CPeriodic, it's probably the easiest way to use timers on Symbian. No need to subclass anything or implement an interface, just create a CPeriodic instance and request callback(s) after specified delay(s) to the function of your choosing.

  11. #11
    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.

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

    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.

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

    Re: Can't force CActive to run.

    Well that coudl be good if not i will use Threads instead, but i don;'t know if CPeriodic is async or sync if its sync it is useless

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

    Re: Can't force CActive to run.

    Quote Originally Posted by melepeta View Post
    Well that coudl be good if not i will use Threads instead, but i don;'t know if CPeriodic is async or sync if its sync it is useless
    You can check usage in http://developer.nokia.com/Community...tream_of_ticks

    Ofcourse you have SDK documentation which tells it all

  15. #15
    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

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
  •  
×