locationmapnavfw/library/src/mnmapimage.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2007 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:  CMnMapImage class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32math.h>
       
    21 #include <AknServerApp.h>
       
    22 #include <apaserverapp.h>
       
    23 #include <ecom/ecom.h>
       
    24 #include <fbs.h>
       
    25 
       
    26 #include "mnappservices.hrh"
       
    27 #include "mnerrors.h"
       
    28 #include "mninternal.h"
       
    29 #include "mnprovider.h"
       
    30 #include "mnmapimageserviceclient.h"
       
    31 #include "mncoordinateconverterbase.h"
       
    32 #include "mnmapimageparams.h"
       
    33 #include "mnactivecallback.h"
       
    34 #include "mnmapimage.h"
       
    35 
       
    36 // ============================== MEMBER FUNCTIONS ===========================
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CMnMapImage::CMnMapImage()
       
    42     {
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C CMnMapImage* CMnMapImage::NewL( CMnProvider& aProvider )
       
    49     {
       
    50     CMnMapImage* self = new (ELeave) CMnMapImage;
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aProvider );
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CMnMapImage::ConstructL( CMnProvider& aProvider )
       
    61     {
       
    62     if ( !( aProvider.SupportedServices() & CMnProvider::EServiceMapImage ) )
       
    63         {
       
    64         User::Leave( KErrNotSupported );
       
    65         }
       
    66 
       
    67     iProviderFeatures = aProvider.SupportedFeatures( CMnProvider::EServiceMapImage );
       
    68     
       
    69     iCoordConverter = CMnCoordinateConverterBase::NewL( aProvider.Uid() );    
       
    70 
       
    71     iSession = new (ELeave) RMnMapImageServiceClient();
       
    72     iSession->ConnectL( aProvider.Uid() );
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CMnMapImage::~CMnMapImage()
       
    79     {
       
    80     if ( iActiveCallback )
       
    81         {
       
    82         iActiveCallback->Cancel();
       
    83         delete iActiveCallback;
       
    84         }
       
    85         
       
    86     delete iExitMonitor;
       
    87     
       
    88     if ( iSession )
       
    89         {
       
    90         iSession->Close();
       
    91         delete iSession;
       
    92         }
       
    93         
       
    94     delete iCoordConverter;
       
    95     REComSession::FinalClose();    
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C TMnMapImageParams::TMapImageTypes CMnMapImage::SupportedImageTypes()
       
   102     {
       
   103     TMnMapImageParams::TMapImageTypes supportedTypes( TMnMapImageParams::ETypeUnspecified );
       
   104 
       
   105     if ( iProviderFeatures & KMnSvcFeatureVectorMap )
       
   106         {
       
   107         supportedTypes |= TMnMapImageParams::ETypeVectorMap;
       
   108         }
       
   109     if ( iProviderFeatures & KMnSvcFeatureSatelliteImage )
       
   110         {
       
   111         supportedTypes |= TMnMapImageParams::ETypeSatelliteImage;
       
   112         }
       
   113     return supportedTypes;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C TMnMapImageParams& CMnMapImage::MapImageParams()
       
   120     {
       
   121     return iMapImageParams;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C const TMnMapImageParams& CMnMapImage::MapImageParams() const    
       
   128     {
       
   129     return iMapImageParams;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C void CMnMapImage::SetMapImageParams( TMnMapImageParams& aImageParams )
       
   136     {
       
   137     iMapImageParams = aImageParams;
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 EXPORT_C void CMnMapImage::SetTargetOrigin( const TPoint& aOrigin )
       
   144     {
       
   145     iTargetOrigin = aOrigin;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C TPoint CMnMapImage::TargetOrigin()
       
   152     {
       
   153     return iTargetOrigin;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C void CMnMapImage::SetShowOptions( const TShowOptions& aOptions )
       
   160     {
       
   161     iShowOptions = aOptions;
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 EXPORT_C CMnMapImage::TShowOptions CMnMapImage::ShowOptions() const
       
   168     {
       
   169     return iShowOptions;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void CMnMapImage::RenderL( CFbsBitmap& aBitmap, TRequestStatus& aStatus )
       
   176     {
       
   177     if ( iTargetOrigin.iX < 0 || iTargetOrigin.iY < 0 )    
       
   178          {
       
   179          User::Leave( KErrArgument );
       
   180          }
       
   181         
       
   182     if ( aBitmap.SizeInPixels().iWidth < 
       
   183          iMapImageParams.Size().iWidth + iTargetOrigin.iX || 
       
   184          aBitmap.SizeInPixels().iHeight < 
       
   185          iMapImageParams.Size().iHeight + iTargetOrigin.iY )
       
   186          {
       
   187          User::Leave( KErrArgument );
       
   188          }
       
   189          
       
   190     if ( iMapImageParams.ImageType() != TMnMapImageParams::ETypeUnspecified &&
       
   191          !( iMapImageParams.ImageType() & SupportedImageTypes() )  )
       
   192         {
       
   193         User::Leave( KErrArgument );
       
   194         }
       
   195 
       
   196     TMnMapImageOptions options;
       
   197     options.iShowOptions = iShowOptions;
       
   198     options.iTargetOrigin = iTargetOrigin;
       
   199     iSession->Render( aBitmap, iMapImageParams, options, aStatus );
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C void CMnMapImage::RenderL( CFbsBitmap& aBitmap, MMnMapImageRenderCallback& aCallback )
       
   206     {
       
   207     if ( !iActiveCallback ) 
       
   208         {
       
   209         iActiveCallback = CMnActiveCallback::NewL( *this, *iSession );
       
   210         }
       
   211 
       
   212     if ( iActiveCallback->IsActive() )
       
   213         {
       
   214         User::Panic( KMnPanicClientFault, KMnPanicDuplicateRequest );
       
   215         }
       
   216 
       
   217     // iActiveCallback member always points to CMnActiveCallback object
       
   218     CMnActiveCallback* activeCallback = reinterpret_cast<CMnActiveCallback*>( iActiveCallback );
       
   219     activeCallback->StartL( aBitmap, aCallback );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 EXPORT_C void CMnMapImage::CancelRendering()
       
   226     {
       
   227     if ( iActiveCallback && iActiveCallback->IsActive() )
       
   228         {
       
   229         iActiveCallback->Cancel();
       
   230         }
       
   231     else
       
   232         {
       
   233         iSession->Cancel();
       
   234         }
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 EXPORT_C TInt CMnMapImage::GetImageCoordinate(
       
   241     const TCoordinate& aWorldCoordinate,
       
   242     TPoint& aImagePoint ) const
       
   243     {
       
   244     iCoordConverter->SetMapImageParams( iMapImageParams );
       
   245     return iCoordConverter->GetImageCoordinate( aWorldCoordinate, aImagePoint );
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 EXPORT_C TInt CMnMapImage::GetWorldCoordinate(
       
   252     const TPoint& aImagePoint,
       
   253     TCoordinate& aWorldCoordinate ) const
       
   254     {
       
   255     iCoordConverter->SetMapImageParams( iMapImageParams );
       
   256     return iCoordConverter->GetWorldCoordinate( aImagePoint, aWorldCoordinate );
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 EXPORT_C void CMnMapImage::SetExitObserverL( MAknServerAppExitObserver& aObserver )
       
   263     {
       
   264     if ( iExitMonitor )
       
   265         {
       
   266         User::Leave( KErrAlreadyExists );
       
   267         }
       
   268     else
       
   269         {
       
   270         iExitMonitor = CApaServerAppExitMonitor::NewL( 
       
   271             *iSession, aObserver, CActive::EPriorityStandard );
       
   272         }
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 EXPORT_C void CMnMapImage::RemoveExitObserver()
       
   279     {
       
   280     delete iExitMonitor;
       
   281     iExitMonitor = NULL;
       
   282     }