Discussion Board

Results 1 to 12 of 12
  1. #1
    Regular Contributor lokesh_kumar_s's Avatar
    Join Date
    Jan 2009
    Location
    India,Karnataka
    Posts
    432
    i am calling an asyncronous function call from main method. but i dont know why it is not returning to main function once it is done.
    you can see the code below. please help.

    this is the file which contains main function

    Code:
    
    //  Include Files  
    
    #include "Track.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h>			// Console
    
    #include "clocationexamplepositionrequestor.h";
    //  Constants
    const TInt KSecond = 1000000;
    const TInt KUpdateInterval = 10*KSecond;
    _LIT(KTextConsoleTitle, "Console");
    _LIT(KTextFailed, " failed, leave code = %d");
    _LIT(KTextPressAnyKey, " [press any key]\n");
    
    //  Global Variables
    
    LOCAL_D CConsoleBase* console; // write all messages to this
    
    
    //  Local Functions
    
    LOCAL_C void MainL()
    	{
    	
    	CLocationExamplePositionRequestor* pos;
    	console->Write(_L("Hello, world!\n"));
    	
    	console->Write(_L("before start"));
    	
    	pos=CLocationExamplePositionRequestor::NewL(KUpdateInterval);
    	console->Write(_L("after pos"));
    	
    	
    	pos->Start();
    	console->Write(_L("after pos start"));
    	scheduler->Start();
    	
    	
    	console->Write(_L("After start"));
    	
    	}
    
    LOCAL_C void DoStartL()
    	{
    	scheduler = new (ELeave) CActiveScheduler();
    	CleanupStack::PushL(scheduler);
    	CActiveScheduler::Install(scheduler);
    	MainL();
    	console->Write(_L("After Main"));
    	console->Write(_L("After Main"));
    	CleanupStack::PopAndDestroy(scheduler);
    	}
    GLDEF_C void clean()
    	{
    		CleanupStack::PopAndDestroy(scheduler);
    		delete console;
    		delete cleanup;
    		__UHEAP_MARKEND;
    		
    	}
    
    GLDEF_C TInt E32Main()
    	{
    	
    	__UHEAP_MARK;
    	cleanup = CTrapCleanup::New();
    	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen, KConsFullScreen)));
    	if (createError)
    		return createError;
    
    	
    	TRAPD(mainError, DoStartL());
    	if (mainError)
    		console->Printf(KTextFailed, mainError);
    	console->Printf(KTextPressAnyKey);
    	console->Getch();
    
    	delete console;
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    	}
    question continued.. in my next request
    Last edited by lokesh_kumar_s; 2009-08-13 at 12:59.
    ---
    Regards
    Lokesh Kumar S.

  2. #2
    Nokia Developer Champion savaj's Avatar
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034
    Where is your Asynchronous request?? Do you know the meaning of Asynchronous request??

  3. #3
    Regular Contributor lokesh_kumar_s's Avatar
    Join Date
    Jan 2009
    Location
    India,Karnataka
    Posts
    432
    continued here...
    and this is the file which contains active object class
    Code:
    #include "clocationexamplepositionrequestor.h"
    
    #include "ClientEngine.h"
    
    const TInt KSecond = 1000000;
    const TInt KMaxAge = KSecond;
    const TInt KErrBuffer = 100;
    
    const TInt KGPSSleepingMinor = KSecond*10;      // GPS sleeping time after error
    
    CLocationExamplePositionRequestor::CLocationExamplePositionRequestor(TInt aInterval)
    : CActive(CActive::EPriorityStandard),
        iInterval(aInterval),
        iPosInfoBase( &iPositionInfo ),
        iGettingLastknownPosition( EFalse )
        {
        }
    
    void CLocationExamplePositionRequestor::ConstructL()
        {
         iUpdateops.SetUpdateInterval(TTimeIntervalMicroSeconds(6*10000000));
       iUpdateTimeout=60*1000000;
        iUpdateops.SetUpdateTimeOut(TTimeIntervalMicroSeconds(65000000));
          iUpdateops.SetMaxUpdateAge(TTimeIntervalMicroSeconds(1000000));
        iUpdateops.SetAcceptPartialUpdates(ETrue);
        CActiveScheduler::Current()->Add( this );
        DoInitialiseL();
        }
    
    
    CLocationExamplePositionRequestor* CLocationExamplePositionRequestor::NewL(TInt aInterval)
        {
        CLocationExamplePositionRequestor* self = new( ELeave ) CLocationExamplePositionRequestor(aInterval);
        CleanupStack::PushL( self );
        self->ConstructL();
        CleanupStack::Pop( self );
        return self;
        }
    
    
    CLocationExamplePositionRequestor::~CLocationExamplePositionRequestor()
        {
         Cancel();
         delete iEngine;    
        iPositioner.Close();
        iPosServer.Close();
        Deque();  
       }
    
    
    void CLocationExamplePositionRequestor::DoCancel()
        {
       CancelWait();
        if ( iGettingLastknownPosition )
            {
               iPositioner.CancelRequest(EPositionerGetLastKnownPosition);
            }
        else
            {
            iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);
            }
        
        iGettingLastknownPosition = ETrue;
        }
    void CLocationExamplePositionRequestor::RunL()
        {
        TBuf<KPositionMaxModuleName> buffer;
       if ( iGettingLastknownPosition )
           {
             iGettingLastknownPosition = EFalse;
           }
       switch ( iStatus.Int() )
            {
              case KErrNone:
                {
                
                PositionUpdatedL();
                break;
                }
            
            case KPositionPartialUpdate:
                {
                
                Wait();
                break;
                }
           
            case KPositionQualityLoss:
                {
                PositionLost();
                break;
                }
           
            case KErrAccessDenied:
                {
                      buffer.Format(KLbsErrAccess, iStatus.Int());
                      break;
                }
            
            case KErrTimedOut:
                {
                PositionLost();
                break;
                }
            
            case KErrCancel:
                {
                    break;
                }
            
            case KErrUnknown:
                {
                PositionLost();
                break;
                }
            default:
                {
                buffer.Format(KLbsErrLocRequest, iStatus.Int());
                break;
                }
            }
        }
    
    
    
    void CLocationExamplePositionRequestor::DoInitialiseL()
        {
        TInt error = iPosServer.Connect( );
        TBuf<KErrBuffer> buffer;
         if ( KErrNone != error )
            {
                buffer.Format(KLbsErrPosServConn, error);
                return;
            }
        error = iPositioner.Open(iPosServer);
        if ( KErrNone != error )
            {
               buffer.Format(KLbsErrOpenPos, error);
               iPosServer.Close();
               return;
            }
        error = iPositioner.SetRequestor( CRequestor::ERequestorService ,CRequestor::EFormatApplication ,_L("Track.exe"));
        if ( KErrNone != error )
            {
            buffer.Format(KLbsErrSetRequestor, error);
            iPositioner.Close();
            iPosServer.Close();
            return;
            }
       error =  iPositioner.SetUpdateOptions( iUpdateops );
       if ( KErrNone != error  )
            {
            buffer.Format(KLbsErrSetUpOpt, error);
           iPositioner.Close();
            iPosServer.Close();
            return;
            }
    
        }
    
    
    TInt CLocationExamplePositionRequestor::RunError(TInt /*aError*/)
        {
        return KErrNone;
        }
    
    
    void CLocationExamplePositionRequestor::Pause()
        {
        if (IsActive())
            {
            Cancel();
            }
        }
    
    
    void CLocationExamplePositionRequestor::Continue()
        {
        if (!IsActive())
            {
            Start();
            }
        }
    
    
    TPositionInfoBase* CLocationExamplePositionRequestor::CurrentPosition()
        {
        return iPosInfoBase;    
        }
    
    
    
    void CLocationExamplePositionRequestor::Wait()
        {
        if (!iPeriodic)
            {
            // Close GPS handles
            Cancel();
            // Sleep
            iPeriodic = CPeriodic::NewL(CActive::EPriorityIdle);
            iPeriodic->Start(KGPSSleepingMinor,KGPSSleepingMinor,TCallBack(PeriodicTick, this));
            }
        }
    
    TInt CLocationExamplePositionRequestor::PeriodicTick(TAny* aObject)
        {
        CLocationExamplePositionRequestor* gpslistener = (CLocationExamplePositionRequestor*)aObject;
        if (gpslistener)
            {
            // Cancel timer running
            gpslistener->CancelWait();
    
            // Start listening GPS again after waiting a while
            gpslistener->Start();
            }
        return EFalse; // Does not continue again (Note: Does not work with this CPeriodic class)
        }
    
    void CLocationExamplePositionRequestor::Start()
        {
        if (!IsActive())
            {
            
            
            if (iGettingLastknownPosition)
                {
                iPositioner.GetLastKnownPosition(*iPosInfoBase,iStatus);
                }
            else
                {
                
                RFileReadStream readStream;
                RFs aFs;
                
                User::LeaveIfError(aFs.Connect());
    
                User::LeaveIfError(readStream.Open(aFs, _L("c:\\data\\nel.txt"), EFileRead));
                CleanupClosePushL(readStream);
               
                TBuf<1000> value;
                TStreamPos eofPos(readStream.Source()->SizeL());
                TStreamPos currentPos(0);
                TBuf<25> eofPosStr;
                eofPosStr.AppendNum(eofPos.Offset());
                
                readStream.ReadL(value,(readStream.Source()->SizeL()/2));
                
                
                
                CleanupStack::PopAndDestroy(&readStream);
                readStream.Release();
                ShowMessage(_L("value"));
                ShowMessage(value);
                aFs.Close();
                
                TBuf<100> bufr=_L("");
                  
                  TBuf<100> status=_L("");
                  ShowMessage(_L("outer before status"));
                    TInt serPos2=value.Find(_L("[status]"));
                    
                    if(serPos2!=KErrNotFound)
                  	  {
                  		  TBuf<800> leftPart=value.MidTPtr(serPos2+8);
                  		  ShowMessage(_L("status1 found"));
                  		  TInt serpos3=leftPart.Find(_L("[status]"));
                  		  if(serpos3!=KErrNotFound)
                  			  {
                  			  ShowMessage(_L("status2 found"));
                  			  status=leftPart.MidTPtr(0,serpos3);
                  			  status.Trim();
                  			  ShowMessage(status);
                  			  }
                  	  }
                    if(status.Compare(_L("Completed"))!=0)
                    	{
    			    ShowMessage(_L("inside not completed----"));
    			    iPositioner.NotifyPositionUpdate(*iPosInfoBase,iStatus);
    			    SetActive();
                    	}
                    else if(status.Compare(_L("Completed"))==0)
                        {
    						ShowMessage(_L("inside completed----"));
    						return;
    		    }
                }
           }
        }
    
    void CLocationExamplePositionRequestor::CancelWait()
        {
        if (iPeriodic)
            {
            iPeriodic->Cancel();
            delete iPeriodic;
            iPeriodic = NULL;
            }
        }
    
    void CLocationExamplePositionRequestor::PositionLost()
        {
         Wait();
        }
    
    
    
    
    void CLocationExamplePositionRequestor::ShowMessage(const TDesC& aMsg) const
        {
        if (aMsg.Length())  // If there's something to show, otherwise do nothing
            {
            // No need to react if this leaves, just trap
            TRAPD(err, ShowMessageL(aMsg));
            if( err != KErrNone )
            	{
            	
            	}
            }
        }
    
    void CLocationExamplePositionRequestor::ShowMessageL(const TDesC& aMsg) const
        {
        CAknGlobalNote* note = CAknGlobalNote::NewLC();
        note->ShowNoteL(EAknGlobalConfirmationNote, aMsg);
        CleanupStack::PopAndDestroy(note);
        }
    see i construct an object of type CLocationExamplePositionRequestor which is used to retrieve the [lat,lon] which inturn calls DoInitializeL() and make all the initializations till there i know it is synchronous and i am getting message in the console after cunstruction of the object of type CLocationExamplePositionRequestor.
    after that see i call start() method from inside main and call CActiveScheduler::Start(). in void CLocationExamplePositionRequestor::Start() i check the status by extracting status content from inside file named nel.txt which is under c:\data. i am sure that i am successfully getting the status from file. now nel.txt contains status as Completed and i am sure i am getting that message.i.e.,
    i am sure that i am coming here
    Code:
    else if(status.Compare(_L("Completed"))==0)
    {
    ShowMessage(_L("inside completed----"));
    return;
    }
    what is happening now is my console application is not exiting by itself.
    i want my console application to exit once it reaches this stage i.e., when i get status as Completed in other words if(status.Compare(_L("Completed"))==0) this satisfies.
    please help
    Last edited by lokesh_kumar_s; 2009-08-13 at 13:00.
    ---
    Regards
    Lokesh Kumar S.

  4. #4
    Regular Contributor lokesh_kumar_s's Avatar
    Join Date
    Jan 2009
    Location
    India,Karnataka
    Posts
    432
    Quote Originally Posted by savaj View Post
    Where is your Asynchronous request?? Do you know the meaning of Asynchronous request??
    hi savaj due to my code had some lot of comments i am not able to send my question in single question. please see i have sent continued question after your response.

    yes i want to make asynchronous request but please see the code before you answer.
    ---
    Regards
    Lokesh Kumar S.

  5. #5
    Registered User jpgustaf's Avatar
    Join Date
    Aug 2007
    Location
    Espoo, Finland
    Posts
    19
    Hi!

    One way to force program execution back to the main class is to call CActiveScheduler::Stop() manually when the prosessing is done.

  6. #6
    Nokia Developer Champion savaj's Avatar
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034
    Open SDK and check CActiveScheduler::Start() method.

    Quote Originally Posted by SDK Class CActiveScheduler
    Start() returns only when a corresponding Stop() or Halt() is issued
    So where is your call stop() method??.

  7. #7
    Regular Contributor lokesh_kumar_s's Avatar
    Join Date
    Jan 2009
    Location
    India,Karnataka
    Posts
    432
    Quote Originally Posted by jpgustaf View Post
    Hi!

    One way to force program execution back to the main class is to call CActiveScheduler::Stop() manually when the prosessing is done.
    if i call CActiveScheduler::Stop() from clocationexamplepositionrequestor.cpp when status is equal to "Completed" which will give me error "E32USER-CBase 45"
    i.e., when i do like this
    Code:
    else if(status.Compare(_L("Completed"))==0)
    {
    ShowMessage(_L("inside completed----"));
    CActiveScheduler::Stop()
    return;
    }
    this will return me "E32USER-CBase 45" error
    45
    This panic is raised by the Stop() member function of an active scheduler, a CActiveScheduler. Calling Stop() terminates the wait loop started by the most recent call to Start(). The panic is caused by a call to Stop() which is not matched by a corresponding call to Start().
    i want to exit from console application smoothly, in correct flow.
    Last edited by lokesh_kumar_s; 2009-08-13 at 13:18.
    ---
    Regards
    Lokesh Kumar S.

  8. #8
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    Since you invoke CActiveScheduler::Start once, you can invoke Stop only once. Make sure that this is what happens.

  9. #9
    Regular Contributor lokesh_kumar_s's Avatar
    Join Date
    Jan 2009
    Location
    India,Karnataka
    Posts
    432
    Quote Originally Posted by wizard_hu_ View Post
    Since you invoke CActiveScheduler::Start once, you can invoke Stop only once. Make sure that this is what happens.
    see i am calling CActiveScheduler::Start at once from within main() after a call to asynchronous function is made. and if i use CActiveScheduler::Stop in that asynchronous function will results in "E32USER-CBase 45" error. i am not calling CActiveScheduler::Stop twice

    Code:
    LOCAL_C void MainL()
    	{
    	CLocationExamplePositionRequestor* pos;
    	console->Write(_L("Hello, world!\n"));
    	pos=CLocationExamplePositionRequestor::NewL(KUpdateInterval);
    	pos->Start();
    	scheduler->Start();
    	}
    and in start i am doing like this
    Code:
    void CLocationExamplePositionRequestor::Start()
    {
    CActiveScheduler::Stop();
    }
    this results in "E32USER-CBase 45" error
    ---
    Regards
    Lokesh Kumar S.

  10. #10
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    WTF!

    Have you even read what you have written??????

    The two methods in your last post! Invoking Stop without Start is the exact description of E32User-CBase 45!

  11. #11
    Registered User jpgustaf's Avatar
    Join Date
    Aug 2007
    Location
    Espoo, Finland
    Posts
    19
    Please try to stop the active scheduler in active object destructor after Cancel() -call instead.

  12. #12
    Regular Contributor lokesh_kumar_s's Avatar
    Join Date
    Jan 2009
    Location
    India,Karnataka
    Posts
    432
    thanks i solved it. i just called CActiveScheduler::Stop after call to CActiveScheduler::Start. wizard told me about correct flow. i called "CActiveScheduler::Start" from within main after call to asynchronous function and then from inside runL i called "CActiveScheduler::Stop" it worked.
    actually i realized that the flow is like this
    1>create and install active scheduler
    2>call asynchronous function.
    3>call CActiveScheduler::Start
    4>called asynchronous function makes asynchronus request call setActive().which will make scheduler active
    5>once setActive() is executed controle returns to main active object. if there is nothing to do waits until iStatus is not KRequestPending. once it is not KRequestPending it executes runL of corresponding active object. and there i have put "CActiveScheduler::Stop()". Thanks
    ---
    Regards
    Lokesh Kumar S.

Similar Threads

  1. Why don't S60 emulator loading?
    By K.John in forum Feedback - Nokia Developer Services
    Replies: 9
    Last Post: 2009-08-11, 11:03
  2. Console application on N70
    By mecva in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 3
    Last Post: 2009-07-25, 06:28
  3. calling console application through GUI app
    By sanjayk84 in forum Symbian C++
    Replies: 1
    Last Post: 2008-06-25, 09:11
  4. Replies: 9
    Last Post: 2006-03-30, 08:36
  5. Replies: 3
    Last Post: 2005-08-16, 03:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved