locationmanager/locationtrail/inc/cgpxconverterao.h
changeset 0 c53acadfccc6
child 12 9f21bab39f42
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:  Active object for converting internal fileformat to GPX
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CGPXCONVERTERAO_H_
       
    20 #define CGPXCONVERTERAO_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32cmn.h>
       
    24 #include <e32property.h>
       
    25 #include <f32file.h>
       
    26 #include <s32file.h>
       
    27 #include "ctracklog.h"
       
    28 
       
    29 const TInt KWriteBufSize = 256;
       
    30 
       
    31 _LIT( KTagXml, "<?xml version=\"1.0\"?>" );
       
    32 _LIT( KTagGpxStart, "<gpx version=\"1.1\" creator=\"Nokia TrackLog\">" );
       
    33 _LIT( KTagGpxEnd, "</gpx>" );
       
    34 _LIT( KTagMetaStart, "<metadata>" );
       
    35 _LIT( KTagMetaEnd, "</metadata>" );
       
    36 _LIT( KTagName, "<name>%S</name>" );
       
    37 _LIT( KTagBounds, "<bounds minlat=\"%f\" minlon=\"%f\" maxlat=\"%f\" maxlon=\"%f\" />" );
       
    38 _LIT( KTagTrackStart, "<trk>" );
       
    39 _LIT( KTagTrackEnd, "</trk>" );
       
    40 _LIT( KTagSegmentStart, "<trkseg>" );
       
    41 _LIT( KTagSegmentEnd, "</trkseg>" );
       
    42 _LIT( KTagTrkPointStart, "<trkpt lat=\"%f\" lon=\"%f\">" );
       
    43 _LIT( KTagTrkPointEnd, "</trkpt>" );
       
    44 _LIT( KTagElevation, "<ele>%f</ele>" );
       
    45 _LIT( KTagTimeStamp, "<time>%d-%02d-%02dT%02d:%02d:%02dZ</time>" );
       
    46 _LIT( KTagCourse, "<course>%f</course>" );
       
    47 _LIT( KTagFix3D, "<fix>3d</fix>" );
       
    48 _LIT( KTagFix2D, "<fix>2d</fix>" );
       
    49 _LIT( KTagSatellites, "<sat>%d</sat>" );
       
    50 _LIT( KTagHdop, "<hdop>%f</hdop>" );
       
    51 _LIT( KTagVdop, "<vdop>%f</vdop>" );
       
    52 
       
    53 class CGpxConverterAO : public CActive
       
    54   	{
       
    55   	private:
       
    56   		enum TProcessingState
       
    57   			{
       
    58   			EIdle,
       
    59   			ENextFile,
       
    60   			ECrashRecovery,
       
    61   			EStartFile,
       
    62   			EProcessing,
       
    63   			ECloseFile
       
    64   			};
       
    65   	
       
    66   	public:
       
    67         /**
       
    68          * Creates and constructs a new instance of CContextBackupSubscriberAO.
       
    69          *
       
    70          * @return A pointer to the new instance.
       
    71          */
       
    72         static CGpxConverterAO* NewL();
       
    73 
       
    74         /**
       
    75          * Destructor.
       
    76          */
       
    77         virtual ~CGpxConverterAO();
       
    78 
       
    79         /**
       
    80          * From CActive.
       
    81          * This method will be called when Backup & Restore state changes.
       
    82          */
       
    83         void RunL();
       
    84 
       
    85         /**
       
    86          * From CActive.
       
    87          * Handles a leave occurring in the request completion event handler RunL().
       
    88          *
       
    89          * @param aError  An error code.
       
    90          * @return An error code.
       
    91          */
       
    92         TInt RunError( TInt aError );
       
    93 
       
    94         /**
       
    95          * From CActive.
       
    96          * Cancels.
       
    97          */
       
    98         void DoCancel();
       
    99         
       
   100         /**
       
   101          * Adds temp-file and possible pre-calculated boundaries
       
   102          * into processing queue
       
   103          */
       
   104         void AddToQueueL( const TDesC& aFileName, TBoundaries* aBoundaries = NULL );
       
   105         
       
   106         /**
       
   107          * Adds observer for GPX file creation notifications
       
   108          */
       
   109         void AddObserver( MGpxConversionObserver* aObserver );
       
   110 
       
   111     private:
       
   112 
       
   113         /**
       
   114          * Default constructor, implicitly called by NewL().
       
   115          */
       
   116     	CGpxConverterAO();
       
   117 
       
   118         /**
       
   119          * 2nd phase construction, called by NewL().
       
   120          */
       
   121         void ConstructL();
       
   122         
       
   123         /**
       
   124          * Set next state for RunL
       
   125          */
       
   126         void SetState( TProcessingState aState );
       
   127         
       
   128         /**
       
   129          * Resolve where to save tracklog file
       
   130          */
       
   131         void GetTrackLogPathL( TDes& aFileName );
       
   132         
       
   133         /**
       
   134          * Read Tag Id from temp-file
       
   135          */
       
   136         void ReadTagIdL();
       
   137         
       
   138         /**
       
   139          * Calculate min and max coordinates for tracklog
       
   140          */
       
   141         void CalculateBoundaries();
       
   142         
       
   143         /**
       
   144          * Writes header tags for GPX file
       
   145          */
       
   146         void WriteStartingTags();
       
   147         
       
   148         /**
       
   149          * Writes single trackpoint to GPX file
       
   150          */
       
   151         void WriteItemToFile();
       
   152         
       
   153         /**
       
   154          * Close GPX file 
       
   155          */
       
   156         void WriteClosingTags();
       
   157         
       
   158     private: // data
       
   159     
       
   160     	TInt iState;
       
   161     	
       
   162     	RPointerArray<TFileName> iFileQueue;
       
   163     	RPointerArray<TBoundaries> iBoundQueue;
       
   164     	
       
   165     	TFileName iTempFile;
       
   166     	TBoundaries* iBoundaries;
       
   167     	TCoordinate* iLastCoords;
       
   168     	TFileName iGpxFileName;
       
   169     	TFileName iGpxPath;
       
   170     	
       
   171     	RFs iFs;
       
   172     	RFileReadStream iReader;
       
   173     	RFile64 iGpxFile;
       
   174     	
       
   175     	TTrackLogItem iTempItem;
       
   176     	
       
   177     	HBufC8* iWriteBuf;
       
   178     	HBufC* iFormatBuf;
       
   179     	
       
   180     	TBool iFixLost;
       
   181     	TItemId iTagId;
       
   182     	
       
   183     	TTime iStartTime;
       
   184     	TTime iEndTime;
       
   185     	
       
   186     	RPointerArray<MGpxConversionObserver> iObservers;
       
   187 
       
   188     };
       
   189 
       
   190 #endif /*CGPXCONVERTERAO_H_*/