locsrv_plat/map_image_api/tsrc/testprovider/src/testprovidermapimageservice.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:  ÑTestProviderMapImageServiceBase class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32math.h>
       
    21 #include <e32property.h>
       
    22 
       
    23 #include <lbsposition.h>
       
    24 
       
    25 #include <epos_cposlandmark.h>
       
    26 #include <epos_poslandmarkserialization.h>
       
    27 
       
    28 #include <mnmapimage.h>
       
    29 #include <mnmapimageparams.h>
       
    30 #include <mnmapimageservicebase.h>
       
    31 
       
    32 #include "debug.h"
       
    33 #include "testproviderdump.h"
       
    34 #include "testproviderappui.h"
       
    35 #include "testproviderappserver.h"
       
    36 #include "testprovidermapimageservice.h"
       
    37 
       
    38 const TInt KMaxCoordStrSize = KMaxPrecision + 5;
       
    39 const TTimeIntervalMicroSeconds32 KProcessingDelay = 200 * 1000;
       
    40 
       
    41 // ======== LOCAL FUNCTIONS ========
       
    42 
       
    43 extern void CoordinateToString( TReal aCoord, TDes& aStr );
       
    44     
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CTestProviderMapImageService* CTestProviderMapImageService::NewL()
       
    51     {
       
    52     CTestProviderMapImageService* self = new (ELeave) CTestProviderMapImageService();
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58     
       
    59 // ---------------------------------------------------------------------------
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CTestProviderMapImageService::CTestProviderMapImageService()
       
    63     {
       
    64     }
       
    65     
       
    66 // ---------------------------------------------------------------------------
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CTestProviderMapImageService::~CTestProviderMapImageService()
       
    70     {
       
    71     iProcessor->Cancel();
       
    72     delete iProcessor;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CTestProviderMapImageService::ConstructL()
       
    79     {
       
    80     BaseConstructL();
       
    81     
       
    82     iProcessor = CPeriodic::NewL( CActive::EPriorityIdle );
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CTestProviderMapImageService::LeaveIfBusyL()
       
    89     {
       
    90     if ( iProcessor->IsActive() )
       
    91         {
       
    92         LOG("CTestProviderMapViewService::LeaveIfBusyL BUSY");
       
    93         User::Leave( KErrInUse );
       
    94         }
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CTestProviderMapImageService::LeaveIfInstructedL()
       
   101     {
       
   102     RProperty property;
       
   103     TInt code = KErrNone;
       
   104     TInt err = property.Get( TUid::Uid( KPropCategoryUid ), KPropKeyErrorCode, code );
       
   105     if ( err == KErrNone )
       
   106         {
       
   107         User::LeaveIfError( code );
       
   108         }
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CTestProviderMapImageService::StartProcessingL()
       
   115     {
       
   116     iProcessor->Start( KProcessingDelay, KProcessingDelay,
       
   117         TCallBack( CTestProviderMapImageService::MapImageProcessingCallBack, this ) );
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 TInt CTestProviderMapImageService::MapImageProcessingCallBack( TAny* aPtr )
       
   124     {
       
   125     CTestProviderMapImageService* self =    
       
   126         static_cast<CTestProviderMapImageService*> ( aPtr );
       
   127         
       
   128     TRAP_IGNORE( self->HandleMapImageCompletedL() );
       
   129     return EFalse;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CTestProviderMapImageService::HandleMapImageCompletedL()
       
   136     {
       
   137     if ( GetTestCommand() != EServerActionDelayCompletion )
       
   138         {
       
   139         iProcessor->Cancel();
       
   140         TInt err = KErrNone;
       
   141         TRAP( err, FinishProcessingL() );
       
   142         if ( err )
       
   143             {
       
   144             CompleteRequest( err );
       
   145             }
       
   146         }
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 TInt CTestProviderMapImageService::GetTestCommand()
       
   153     {
       
   154     CTestProviderAppServer* server = (CTestProviderAppServer*) Server();
       
   155     return server->GetTestCommand();
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CTestProviderMapImageService::RenderL()
       
   162     {
       
   163     TMnMapImageParams& params = MapImageParams();
       
   164 
       
   165     if ( params.Direction() != 0 )
       
   166         {
       
   167         User::Leave( KErrNotSupported );
       
   168         }
       
   169 
       
   170     CFbsBitmap& bitmap = TargetBitmap();
       
   171 
       
   172     CFbsBitmapDevice* bitmapDevice = 
       
   173       CFbsBitmapDevice::NewL( &( bitmap ) );
       
   174     CleanupStack::PushL( bitmapDevice );
       
   175 
       
   176     CFbsBitGc* gc = NULL;
       
   177     User::LeaveIfError( bitmapDevice->CreateContext( gc ) );
       
   178     CleanupStack::PushL( gc );
       
   179 
       
   180     switch ( params.ImageType() ) 
       
   181         {
       
   182         case TMnMapImageParams::ETypeSatelliteImage:
       
   183             gc->SetBrushColor( KRgbGreen );
       
   184             break;  
       
   185         default:
       
   186             params.SetImageType( TMnMapImageParams::ETypeVectorMap );
       
   187         case TMnMapImageParams::ETypeVectorMap:
       
   188             gc->SetBrushColor( KRgbYellow );
       
   189             break;
       
   190         }
       
   191         
       
   192     // Very simple map example
       
   193     gc->Clear( TargetRect() ); // clear the area
       
   194 
       
   195     // cleanup
       
   196     CleanupStack::PopAndDestroy( gc );
       
   197     CleanupStack::PopAndDestroy( bitmapDevice );
       
   198 
       
   199     // complete request
       
   200     params.SetProjectionId(0);
       
   201     }
       
   202     
       
   203 // ---------------------------------------------------------------------------
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CTestProviderMapImageService::FinishProcessingL()
       
   207     {
       
   208     LOG1("FinishProcessingL in, cursvc %d", iCurrentService);
       
   209     TCoordinate coord;
       
   210     switch ( iCurrentService )
       
   211         {
       
   212         case ERender:
       
   213             {
       
   214             RenderL();
       
   215             //TargetBitmap().Clear();
       
   216             }
       
   217             break;
       
   218 
       
   219         default:            
       
   220             User::Leave( KErrGeneral );
       
   221         }
       
   222 
       
   223     iCurrentService = ENone;        
       
   224     CompleteRendering();
       
   225     LOG("FinishProcessingL out");
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void CTestProviderMapImageService::HandleTestCommandL( TInt aCommand )
       
   232     {
       
   233     LOG1("CTestProviderMapImageService::HandleTestCommandL in, %d", aCommand );
       
   234     switch ( aCommand )
       
   235         {
       
   236         case EServerActionCompleteRendering:
       
   237             {
       
   238             MapImageParams().SetImageType( TMnMapImageParams::ETypeVectorMap );
       
   239             CompleteRendering();
       
   240             }
       
   241             break;
       
   242             
       
   243         case EServerActionBaseComplete:
       
   244             {
       
   245             CompleteRequest( KErrCompletion );
       
   246             }
       
   247             break;
       
   248 
       
   249         default:
       
   250             break;    
       
   251         }
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 void CTestProviderMapImageService::DumpDataL()
       
   258     {
       
   259     LOG("DumpDataL in");
       
   260     if ( GetTestCommand() == EServerActionDisableDump )
       
   261         {
       
   262         LOG("DumpDataL disabled, out");
       
   263         return;
       
   264         }
       
   265 
       
   266     CTestProviderDump* dump = CTestProviderDump::NewLC();
       
   267     
       
   268     CTestProviderAppServer* server = ( CTestProviderAppServer* ) Server();
       
   269     CTestProviderAppUi* ui = server->AppUi();
       
   270     dump->AddRunModeL( ui->IsChainedMode() );
       
   271 
       
   272     TMapImageOptions options;
       
   273     options.iParams = MapImageParams();
       
   274     options.iBitmapHandle = TargetBitmap().Handle();
       
   275     options.iBitmapSize = TargetBitmap().SizeInPixels();
       
   276     options.iTargetOrigin = TargetRect().iTl;
       
   277     options.iShowOptions = ShowOptions();
       
   278 
       
   279     dump->AddMapImageOptionsL( options );
       
   280 
       
   281     dump->CommitL();
       
   282     CleanupStack::PopAndDestroy( dump );
       
   283     LOG("DumpDataL out");
       
   284     }
       
   285     
       
   286 // ---------------------------------------------------------------------------
       
   287 // From class CMnMapImageServiceBase
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CTestProviderMapImageService::HandleRenderingL()
       
   291     {
       
   292     LeaveIfInstructedL();
       
   293     LeaveIfBusyL();
       
   294 
       
   295     DumpDataL();
       
   296 
       
   297     iCurrentService = ERender;
       
   298     StartProcessingL();
       
   299     }
       
   300         
       
   301 // ---------------------------------------------------------------------------
       
   302 // From class CMnServiceBase
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 void CTestProviderMapImageService::DoCancel()
       
   306     {
       
   307     iProcessor->Cancel();
       
   308     iCurrentService = ENone;
       
   309     }
       
   310