locationmapnavfw/library/src/mnnavigator.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     1 /*
       
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CMnNavigator class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32math.h>
       
    21 #include <AknServerApp.h>
       
    22 #include <apaserverapp.h>
       
    23 
       
    24 #include <lbsfields.h>
       
    25 #include <lbsfieldids.h>
       
    26 #include <EPos_CPosLandmark.h>
       
    27 
       
    28 #include "mnprovider.h"
       
    29 #include "mnnavigationserviceclient.h"
       
    30 #include "mnnavigator.h"
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CMnNavigator::CMnNavigator()
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CMnNavigator* CMnNavigator::NewL( CMnProvider& aProvider )
       
    45     {
       
    46     CMnNavigator* self = new (ELeave) CMnNavigator;
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructNewL( aProvider );
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CMnNavigator* CMnNavigator::NewChainedL( CMnProvider& aProvider )
       
    57     {
       
    58     CMnNavigator* self = new (ELeave) CMnNavigator;
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructChainedL( aProvider );
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CMnNavigator::ConstructCommonL( CMnProvider& aProvider )
       
    69     {
       
    70     if ( !( aProvider.SupportedServices() & CMnProvider::EServiceNavigation ) )
       
    71         {
       
    72         User::Leave( KErrNotSupported );
       
    73         }
       
    74 
       
    75     iSession = new (ELeave) RMnNavigationServiceClient;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CMnNavigator::ConstructNewL( CMnProvider& aProvider )
       
    82     {
       
    83     ConstructCommonL( aProvider );
       
    84     iSession->ConnectL( aProvider.Uid() );
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CMnNavigator::ConstructChainedL( CMnProvider& aProvider )
       
    91     {
       
    92     ConstructCommonL( aProvider );
       
    93     iSession->ConnectChainedL( aProvider.Uid() );
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C CMnNavigator::~CMnNavigator()
       
   100     {
       
   101     delete iExitMonitor;
       
   102     if ( iSession )
       
   103         {
       
   104         iSession->Close();
       
   105         delete iSession;
       
   106         }
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void CMnNavigator::NavigateToL(const CPosLandmark& aDestination)
       
   113     {
       
   114     // verify that destination landmark has coordinates
       
   115     TLocality loc;
       
   116     TBool valid = (KErrNone == aDestination.GetPosition( loc ) );
       
   117     valid &= !Math::IsNaN( loc.Latitude() ) && !Math::IsNaN( loc.Longitude() );
       
   118     
       
   119     if ( !valid )
       
   120         {
       
   121         // verify that destination landmark has address info
       
   122         TPositionFieldId fieldId = aDestination.FirstPositionFieldId();
       
   123         while ( fieldId != EPositionFieldNone )
       
   124             {
       
   125             if ( fieldId > EPositionFieldAddressCapabilitiesBegin &&
       
   126                  fieldId < EPositionFieldNMEACapabilitiesBegin)
       
   127                 {
       
   128                 TPtrC field;
       
   129                 aDestination.GetPositionField( fieldId, field );
       
   130                 if ( field.Length() )
       
   131                     {
       
   132                     valid = ETrue;
       
   133                     break;
       
   134                     }
       
   135                 }
       
   136             fieldId = aDestination.NextPositionFieldId( fieldId );            
       
   137             }
       
   138         }
       
   139         
       
   140     if ( valid )
       
   141         {
       
   142         iSession->NavigateToL( aDestination );
       
   143         }
       
   144     else
       
   145         {
       
   146         User::Leave( KErrArgument );
       
   147         }
       
   148     }
       
   149         
       
   150 // ---------------------------------------------------------------------------
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void CMnNavigator::SetExitObserverL( MAknServerAppExitObserver& aObserver )
       
   154 	{
       
   155 	if ( iExitMonitor )
       
   156 		{
       
   157 		User::Leave( KErrAlreadyExists );
       
   158 		}
       
   159 	else
       
   160 		{
       
   161 		iExitMonitor = CApaServerAppExitMonitor::NewL( 
       
   162 			*iSession, aObserver, CActive::EPriorityStandard );
       
   163 		}
       
   164 	}
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C void CMnNavigator::RemoveExitObserver()
       
   170 	{
       
   171 	delete iExitMonitor;
       
   172 	iExitMonitor = NULL;
       
   173 	}