×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    73

    Why i can't make RThread global

    i make a thread by something like this:

    Code:
     RThread iThread;
    TInt err = iThread.Create(
    	 KThreadName,
             afunc,
             KStackSize,
             NULL,
             NULL
            );
    It compuiles and no errors are returned


    but when i put RThread iThread; into header, the errors occur like its forbidden to use it outside creation func.
    So this is a reason that i cant then execute iThread.Resum(); from other func.



    First i will show the code then i will tell you that i included a header in onther file and that causes the problem

    thread header
    Code:
    
    #ifndef TMOBEYETH_H
    #define TMOBEYETH_H
    
    #include <e32def.h>
    #include <e32base.h>	// For CActive, link against: euser.lib
    #include <e32std.h>		// For RTimer, link against: euser.lib
    #include "stringunit.h"
    
    
    
     const TInt KStackSize = 32000;
    
     RThread iThread;
     
     RThread * iThreadPtr;        
             
    #endif

    source
    Code:
    #include "TMobEyeTh.h"
    
    
     
     
     TInt  afunc(TAny *obj)
    	 {
    	 return 1;
    	 }
     
    
     
     
     void LELO()
    	 {
     
     _LIT(KThreadName, "MyFirstThread"); 
    
    TInt err = iThread.Create(
    	 KThreadName,
             afunc,
             KStackSize,
             NULL,
             NULL
            );
    
    (*iThreadPtr) = iThread;
    
    }

    it compiles w/o errors

    but when i add "#include "TMobEyeTh.h" - this header shown before (to other file like mysamplefile.cpp", compiler tells me that
    mwldsym2.exe: Multiply defined symbol: class RThread iThread (?iThread@@3VRThread@@A) in
    mwldsym2.exe: files TMobEyeTh.o, MobEyeContainer.o
    mwldsym2.exe: Multiply defined symbol: class RThread * iThreadPtr (?iThreadPtr@@3PAVRThread@@A) in
    mwldsym2.exe: files TMobEyeTh.o, MobEyeContainer.o


    x_X

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,748

    Re: Why i can't make RThread global

    Read the message: Multiply defined symbol: class RThread iThread
    Wherever you #include the given header file, its contents are going to appear (this case: TMobEyeTh.cpp and MobEyeContainer.cpp). This is why the keyword extern is invented in C/C++: in the header file you could write
    Code:
    extern RThread GlobalThread;
    , and put the line
    Code:
    RThread GlobalThread;
    into exactly one .c/pp file, preferably int TMobEyeTh.cpp.

    Otherwise, are you familiar with the saying "Some people, when facing a problem, think "I know, I will use a multi-threaded framework." Now they have two problems." ?
    Note that communicating with your thread can be done via active objects, so make sure that you are familiar with them already.

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

    Re: Why i can't make RThread global

    This kind of message never appeared in RAD studio so i just asked ;P
    I am writing a game that uses different threads for drawing, collision etc. so don't worry ;p
    Ah and yes it works, thank you.


    ===
    Wizard hu i have another question for you, in the topic named "cant force CActive to run, i had a problem with displaying values on the screen in real time and you wrote.

    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.
    If i have a container class and have such code in it:
    Code:
    CMobEyeContainer* CMobEyeContainer::NewL( 
    		const TRect& aRect, 
    		const CCoeControl* aParent, 
    		MEikCommandObserver* aCommandObserver )
    	{
    
    	CMobEyeContainer* self = CMobEyeContainer::NewLC( 
    			aRect, 
    			aParent, 
    			aCommandObserver );
    	self->DrawNow(); i added this
    	CleanupStack::Pop( self );
    	return self;
    	}
    not quite sure what means: reference/pointer of your AppView object
    Now i want to draw a simple integer that is

    Code:
    int yyy;
     yyy = ap;
     TBuf<20> klop;
     klop.Num(yyy);
    
     ThreadActive = true;
    
    gc.DrawText(klop,TPoint(30,90));
    Last edited by melepeta; 2013-10-20 at 18:14.

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

    Re: Why i can't make RThread global

    No need to call the DrawNow() from the constructor of container. Refering to your previous thread, calling the DrawNow(or DrawDeferred) is pointed towards calling it from timer class(from inside the RunL()),i.e. when timer expires & you want to update the UI with integer value & to accomplish this you obviously need to have the reference/pointer to the view class(derived from CAknView) on which container is drawn.

    So when you allocate the memory for timer class (i.e. call its NewL()), simply pass the reference to view class to it, so that you can later access container(& thereby call DrawNow()).

    Ex : iTimer = CTimerClass::NewL(iView) ; //where iView is CmobEyeView*iView ;

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

    Re: Why i can't make RThread global

    I don't get it - So do I need to create my own Timer class with my own NewL and will it automatically set the reference to DrawNow just like that?
    Or should i add a timer to container class and call DrawNow in callback function.

    Or sth else, now i am writing that timer that will call DrawNow() (the timer is in container class) i'll see if it will work..
    ================================================ the next stage ;]===========================================
    I managed to make inherited CTimer class that is put in AppUi header file (class CMobEyeAppUi : public CAknViewAppUi)
    pls see the bolded and underlined text

    in CMobEyeAppUi i have public: TRedrawTimer * RedrawContainerThread;

    Code:
    class TRedrawTimer : public CTimer
        {
    	
    public:
    	CMobEyeContainerView * aParent;   
        static TRedrawTimer* NewL(CMobEyeContainerView * parent);
        void ConstructL(CMobEyeContainerView * parent);
     TRedrawTimer();
     ~TRedrawTimer();
     
    	 void StartThread();
        
    protected:
     
        virtual void RunL();          
        virtual void DoCancel();  
      
        };
    then in cpp file



    Code:
    void CMobEyeAppUi::InitializeContainersL() //its auto generated
    	{
    	iMobEyeContainerView = CMobEyeContainerView::NewL();
    	AddViewL( iMobEyeContainerView );
    	SetDefaultViewL( *iMobEyeContainerView );
    	}
    
    
    void CMobEyeAppUi::ConstructL()
    	{
    	BaseConstructL( EAknEnableSkin ); 
    	InitializeContainersL();
    
    	RedrawContainerThread = TRedrawTimer::NewL(iMobEyeContainerView);
    	RedrawContainerThread->StartThread(); - this line causes KERN-EXEC 0 without it app does not crash. Maybe i messed up with timer class? Or this control is not being initialized even after creation.
    	
    	}
    
    
    TRedrawTimer *TRedrawTimer::NewL(CMobEyeContainerView * parent)
    {
    	TRedrawTimer *diz=new (ELeave) TRedrawTimer(); 
        CleanupStack::PushL(diz);
        diz->ConstructL(parent); 
        CleanupStack::Pop();
        return diz; /
    }
    
    void TRedrawTimer::ConstructL(CMobEyeContainerView * parent)
    {
    	aParent = parent;
    }
    
    TRedrawTimer::TRedrawTimer() : CTimer(EPriorityStandard)
    { 
    CActiveScheduler::Add(this); 
    }
    		 
    void TRedrawTimer::StartThread()
        { 
    
    
    	After(33);
        SetActive();              
        }
    
    TRedrawTimer::~TRedrawTimer()
    {
    	Cancel();
    }
    
    void TRedrawTimer::RunL()
    {
    //	aParent->DrawNow(); //  well it compiled when i put that class [TRedrawTimer] into ContainerView header but i thought this KERN EXEC 0 was caused because not the whole app was created. Now it wont compile even if i make Container in containerView public (not private) it says that this is illegal use of incomplete struct/union/class 'CMobEyeContainer'
    
    since its only 
    
    class CMobEyeContainer;
    	
    class CMobEyeContainerView : public CAknView {
    
    
    	SetActive();
    }
    
    void TRedrawTimer::DoCancel()
    {
    	Cancel();
    }
    
    
    cheers.
    Last edited by melepeta; 2013-10-20 at 23:44.

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

    Re: Why i can't make RThread global

    I was only referring to the timer class pasted in Post#19(& then Post #20) here : http://developer.nokia.com/Community...CActive-to-run & not making a new timer class.

    Plus, you have the view(derived from CAknView) - Container(derived from CCoentrol) pair of classes right?, then call to DrawNow() would be something like this:

    Void CYourTimerClass::RunL()
    {
    parent->iContainerObject(CMobEyeContainer object which is created inside DoActivate of view class)->DrawNow();
    }

    to get the above code compile, you need to include the header class of CMobEyeContainer.

    Note: The KERN-EXEC 0 in the newly created timer class is probably due of absence of the following statement : iTimer.CreateLocal() in the constructor/ConstructL().

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

    Re: Why i can't make RThread global

    Thanks, it works.
    I had to make auto generated CActive class.

Similar Threads

  1. how to make appuifw global
    By zezier in forum Symbian
    Replies: 2
    Last Post: 2008-11-04, 09:48
  2. Replies: 1
    Last Post: 2008-04-30, 23:04
  3. can't make global arrays as the same object
    By noanyx in forum Symbian
    Replies: 2
    Last Post: 2006-08-25, 09:43
  4. Replies: 1
    Last Post: 2004-01-02, 17:48
  5. How can to make global or static data ?
    By comb in forum Symbian
    Replies: 2
    Last Post: 2003-08-11, 18:19

Posting Permissions

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