locationmapnavfw/library/src/mngeocoder.cpp
changeset 0 667063e416a2
child 7 19bff11d6c18
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     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:  CMnGeocoder 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 <lbsposition.h>
       
    27 
       
    28 #include <EPos_CPosLandmark.h>
       
    29 
       
    30 #include "mnprovider.h"
       
    31 #include "mngeocodingserviceclient.h"
       
    32 #include "mngeocoder.h"
       
    33 
       
    34 // ======== LOCAL FUNCTIONS ========
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 //  Copies address information (address and building position fields) from 
       
    38 //  source landmark to target.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 void CopyAddressL( CPosLandmark& aSrc, CPosLandmark& aTrg )
       
    42     {
       
    43     // clean address fields (CMnGeocoder says that "all <data> will be updated")
       
    44     for ( TPositionFieldId fieldId = EPositionFieldAddressCapabilitiesBegin + 1;
       
    45           fieldId < EPositionFieldNMEACapabilitiesBegin;
       
    46           fieldId++ )
       
    47         {
       
    48         aTrg.RemovePositionField( fieldId );
       
    49         }
       
    50     
       
    51     // copy fields
       
    52     TPositionFieldId fieldId = aSrc.FirstPositionFieldId();
       
    53     while ( fieldId != EPositionFieldNone )
       
    54         {
       
    55         if ( fieldId > EPositionFieldAddressCapabilitiesBegin &&
       
    56              fieldId < EPositionFieldNMEACapabilitiesBegin)
       
    57             {
       
    58             TPtrC field;
       
    59             if ( KErrNone == aSrc.GetPositionField( fieldId, field ) )
       
    60                 {
       
    61                 aTrg.SetPositionFieldL( fieldId, field );
       
    62                 }
       
    63             }
       
    64         fieldId = aSrc.NextPositionFieldId( fieldId );            
       
    65         }
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 //  Copies coordinate information (locality and coverage) from 
       
    70 //  source landmark to target. If some fields are empty in source,
       
    71 //  they will also be emptied in result.
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CopyCoordinatesL( CPosLandmark& aSrc, CPosLandmark& aTrg )
       
    75     {
       
    76     TLocality loc;
       
    77     aSrc.GetPosition( loc );
       
    78     aTrg.SetPositionL( loc );
       
    79     
       
    80     TRealX nan;
       
    81     nan.SetNaN();
       
    82     TReal32 coverage( nan );
       
    83     
       
    84     aSrc.GetCoverageRadius( coverage );
       
    85     aTrg.SetCoverageRadius( coverage );
       
    86     }
       
    87 
       
    88 // ======== MEMBER FUNCTIONS ========
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CMnGeocoder::CMnGeocoder()
       
    94     {
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CMnGeocoder::ConstructCommonL( CMnProvider& aProvider )
       
   101     {
       
   102     if ( !( aProvider.SupportedServices() & CMnProvider::EServiceGeocoding ) )
       
   103         {
       
   104         User::Leave( KErrNotSupported );
       
   105         }
       
   106 
       
   107     iSession = new (ELeave) RMnGeocodingServiceClient;
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CMnGeocoder::ConstructNewL( CMnProvider& aProvider )
       
   114     {
       
   115     ConstructCommonL( aProvider );
       
   116     iSession->ConnectL( aProvider.Uid() );
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CMnGeocoder::ConstructChainedL( CMnProvider& aProvider )
       
   123     {
       
   124     ConstructCommonL( aProvider );
       
   125     iSession->ConnectChainedL( aProvider.Uid() );
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C CMnGeocoder* CMnGeocoder::NewL( CMnProvider& aProvider )
       
   132     {
       
   133     CMnGeocoder* self = new (ELeave) CMnGeocoder;
       
   134     CleanupStack::PushL( self );
       
   135     self->ConstructNewL( aProvider );
       
   136     CleanupStack::Pop( self );
       
   137     return self;
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 EXPORT_C CMnGeocoder* CMnGeocoder::NewChainedL( CMnProvider& aProvider )
       
   144     {
       
   145     CMnGeocoder* self = new (ELeave) CMnGeocoder;
       
   146     CleanupStack::PushL( self );
       
   147     self->ConstructChainedL( aProvider );
       
   148     CleanupStack::Pop( self );
       
   149     return self;
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C CMnGeocoder::~CMnGeocoder()
       
   156     {
       
   157 	delete iExitMonitor;
       
   158 
       
   159     if ( iSession )
       
   160         {
       
   161         iSession->Close();
       
   162         delete iSession;
       
   163         }
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C CMnGeocoder::TOptions CMnGeocoder::Options() const
       
   170     {
       
   171     return iOptions;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C void CMnGeocoder::SetOptions( TOptions aOptions )
       
   178     {
       
   179     iOptions = aOptions;
       
   180     }
       
   181         
       
   182 // ---------------------------------------------------------------------------
       
   183 //  1. Get result from session in form of landmark
       
   184 //  2. If last request was for address, copy all position fields from 
       
   185 //     result to target landmark
       
   186 //  3. If last request was for coordinate, copy position data.
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 EXPORT_C void CMnGeocoder::RetrieveGeocodingResultL( CPosLandmark& aTargetLandmark )
       
   190     {
       
   191     CPosLandmark* lm = NULL;
       
   192     TMnGeocodingResultType resultType; 
       
   193     iSession->GetLastResultL( lm, resultType );
       
   194     CleanupStack::PushL( lm );
       
   195     
       
   196     switch ( resultType )
       
   197         {
       
   198         case EMnGeoResultAddress:
       
   199             CopyAddressL( *lm, aTargetLandmark );
       
   200             break;
       
   201         case EMnGeoResultCoordinates:
       
   202             CopyCoordinatesL( *lm, aTargetLandmark );
       
   203             break;
       
   204         }
       
   205     CleanupStack::PopAndDestroy( lm );
       
   206     }
       
   207         
       
   208 // ---------------------------------------------------------------------------
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C void CMnGeocoder::FindCoordinateByAddressL(
       
   212     const CPosLandmark& aLandmark, 
       
   213     TRequestStatus& aRequest)
       
   214     {
       
   215     iSession->CoordinateByAddressL( aLandmark, iOptions, aRequest );
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 EXPORT_C void CMnGeocoder::FindCoordinateByAddressL(
       
   222     const TDesC& aAddress, 
       
   223     TRequestStatus& aRequest)
       
   224     {
       
   225     iSession->CoordinateByAddressL( aAddress, iOptions, aRequest );
       
   226     }
       
   227             
       
   228 // ---------------------------------------------------------------------------
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 EXPORT_C void CMnGeocoder::FindAddressByCoordinateL(
       
   232     const CPosLandmark& aLandmark, 
       
   233     TRequestStatus& aRequest)
       
   234     {
       
   235     iSession->AddressByCoordinateL( aLandmark, iOptions, aRequest );
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 EXPORT_C void CMnGeocoder::Cancel()
       
   242     {
       
   243     iSession->Cancel();
       
   244     }
       
   245 // ---------------------------------------------------------------------------
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C void CMnGeocoder::SetExitObserverL( MAknServerAppExitObserver& aObserver )
       
   249 	{
       
   250 	if ( iExitMonitor )
       
   251 		{
       
   252 		User::Leave( KErrAlreadyExists );
       
   253 		}
       
   254 	else
       
   255 		{
       
   256 		iExitMonitor = CApaServerAppExitMonitor::NewL( 
       
   257 			*iSession, aObserver, CActive::EPriorityStandard );
       
   258 		}
       
   259 	}
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 EXPORT_C void CMnGeocoder::RemoveExitObserver()
       
   265 	{
       
   266 	delete iExitMonitor;
       
   267 	iExitMonitor = NULL;
       
   268 	}