examples/sfexamples/findme/src/FindMeActive.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 #include "FindMeActive.h"
00018 #include "FindMeAppView.h"
00019 
00020 
00021 // Name of requestor
00022 _LIT(KRequestor,"FindMe App");
00023 //Update interval
00024 const TInt KUpdateInterval = 1000000;
00025 // Timeout interval
00026 const TInt KUpdateTimeOut = 15000000;
00027 // Chache age
00028 const TInt KCacheAge = 500000;
00029 
00030 
00031 CFindMeActive* CFindMeActive::NewL(CFindMeAppView* aView)
00032         {
00033         CFindMeActive* self = new (ELeave) CFindMeActive();
00034         CleanupStack::PushL(self);
00035         self->ConstructL(aView);
00036         CleanupStack::Pop();
00037         return self;
00038         }
00039 
00040 
00041 CFindMeActive::CFindMeActive() : CActive(EPriorityStandard)
00042         {
00043         CActiveScheduler::Add( this );
00044         }
00045                 
00046         
00047 void CFindMeActive::ConstructL(CFindMeAppView* aView)
00048         {
00049         // Set the pointer to our application view
00050         iView = aView;
00051     
00052         // Connect to the position server
00053         User::LeaveIfError(iPosServer.Connect());
00054   
00055         // Open the subsession to the server
00056         User::LeaveIfError(iPositioner.Open(iPosServer));
00057   
00058     // Set requestor
00059         User::LeaveIfError(iPositioner.SetRequestor(CRequestor::ERequestorService ,
00060                                                                                                 CRequestor::EFormatApplication , 
00061                                                                                                 KRequestor) );
00062  
00063     // Set update interval to receive one position information every 1 second.
00064     TPositionUpdateOptions udOpt;
00065     udOpt.SetUpdateInterval(TTimeIntervalMicroSeconds(KUpdateInterval));
00066 
00067     // The position server will terminate the request by the requestor 
00068     // in case it could not retreive position info in 1 minute.
00069     udOpt.SetUpdateTimeOut(TTimeIntervalMicroSeconds(KUpdateTimeOut));
00070 
00071     // Maximum age for cached information by which to be used.
00072     udOpt.SetMaxUpdateAge(TTimeIntervalMicroSeconds(KCacheAge));
00073 
00074     // Do not allow location server to send partial position data.
00075     udOpt.SetAcceptPartialUpdates(EFalse);
00076        
00077     // Set the update options.
00078     User::LeaveIfError(iPositioner.SetUpdateOptions(udOpt) );
00079   
00080     // Set the active object to start getting position information.
00081     iPositioner.NotifyPositionUpdate(iPositionInfo,iStatus);
00082         SetActive();
00083         }
00084                 
00085 
00086 CFindMeActive::~CFindMeActive()
00087         {
00088         Cancel();                               // Cancel any outstanding active object requests
00089         iPositioner.Close();    // Close RPositioner
00090         iPosServer.Close();             // Cloase RPositionerServer
00091         }
00092 
00093 
00094 void CFindMeActive::DoCancel()
00095         {
00096         iPositioner.CancelRequest(EPositionerNotifyPositionUpdate );
00097         }
00098 
00099 
00100 void CFindMeActive::RunL()
00101         {
00102         // If successfully received position info
00103         if( iStatus.Int() == KErrNone || 
00104                 iStatus.Int() == KPositionPartialUpdate )
00105                 {
00106                 // Update the view
00107                 iView->PrintPos();
00108                 }
00109         
00110         // Request the next position
00111     iPositioner.NotifyPositionUpdate( iPositionInfo, iStatus );
00112         SetActive();
00113         }
00114                 

Generated by  doxygen 1.6.2