datasourcemodules/locationapesuplpsy/src/suplpsyinfostoremanager.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Store Manager in SUPL PSY.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "suplpsylogging.h" 
       
    22 #include "suplpsyinfostoremanager.h"
       
    23 #include "suplpsycrkeys.h"
       
    24 
       
    25 
       
    26 //const TUid KCRUidSuplFW = { 0x102750A0 };
       
    27 //const TUint32 KSuplFwCId = 0x0000000c;
       
    28 
       
    29 _LIT(KFileName,"\\private\\101F97b2\\SuplPsyLocationInfo.dat");
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS OF CSuplPsyInfoStoreManager ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CSuplPsyInfoStoreManager::CSuplPsyInfoStoreManager,constructor
       
    35 // (other items were commented in a header).
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 
       
    39 CSuplPsyInfoStoreManager::CSuplPsyInfoStoreManager() 
       
    40 					    : iRepoSuplPsy( NULL ),
       
    41 					      iRepoSuplFw( NULL ) 
       
    42 	{
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CSuplPsyInfoStoreManager::ConstructL,two phase constuctor
       
    47 // (other items were commented in a header).
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CSuplPsyInfoStoreManager::ConstructL()
       
    51     {
       
    52     TRACESTRING( "CSuplPsyInfoStoreManager::ConstructL start" )
       
    53     
       
    54     TRACESTRING( "Opening Supl psy cenrep" )
       
    55     iRepoSuplPsy = CRepository::NewL( KCRUidSuplPsy );
       
    56 
       
    57     
       
    58     TRACESTRING( "Opening Supl fw cenrep" )
       
    59     // TODO put back
       
    60     //iRepoSuplFw = CRepository::NewL( KCRUidSuplFW );
       
    61     
       
    62     TRACESTRING( "Opening File server" )
       
    63     User::LeaveIfError( iFs.Connect() );
       
    64     iFs.CreatePrivatePath( EDriveC );
       
    65     
       
    66     TRACESTRING( "Set session path" )
       
    67     User::LeaveIfError( iFs.SetSessionToPrivate( EDriveC ) );
       
    68 
       
    69     TInt err = iFile.Open( iFs, KFileName, EFileRead|EFileWrite|EFileStream );
       
    70     if ( err )
       
    71         {
       
    72         err = iFile.Create( iFs, KFileName, EFileRead|EFileWrite|EFileStream );
       
    73         TRACESTRING( "File didnt exist,file created" )
       
    74         }
       
    75     User::LeaveIfError( err );
       
    76     TRACESTRING( "CSuplPsyInfoStoreManager::ConstructL end" )
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CSuplPsyInfoStoreManager::NewL,two phase constuctor
       
    81 // (other items were commented in a header).
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CSuplPsyInfoStoreManager* CSuplPsyInfoStoreManager::NewL()
       
    85     {
       
    86     CSuplPsyInfoStoreManager* self = new( ELeave ) CSuplPsyInfoStoreManager();
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop(self);
       
    90     return self;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CSuplPsyInfoStoreManager::~CSuplPsyInfoStoreManager,Destructor
       
    95 // (other items were commented in a header).
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CSuplPsyInfoStoreManager::~CSuplPsyInfoStoreManager()
       
    99     {
       
   100 	TRACESTRING( "CSuplPsyInfoStoreManager::~CSuplPsyInfoStoreManager start" )
       
   101 	delete iRepoSuplPsy;
       
   102 	iRepoSuplPsy = NULL;
       
   103 	
       
   104 	delete iRepoSuplFw;
       
   105 	iRepoSuplFw = NULL;
       
   106 	
       
   107 	iFile.Close();
       
   108     iFs.Close();
       
   109 	TRACESTRING( "CSuplPsyInfoStoreManager::~CSuplPsyInfoStoreManager end" )
       
   110 	}
       
   111             
       
   112 // -----------------------------------------------------------------------------
       
   113 // CSuplPsyInfoStoreManager::ReadSuplPsyLocationInfo,Reads stored Location Information from file.
       
   114 // (other items were commented in a header).
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TInt CSuplPsyInfoStoreManager::ReadSuplPsyLocationInfo( HPositionGenericInfo& aPosInfo )
       
   118     {
       
   119 	TRACESTRING( "CSuplPsyInfoStoreManager::ReadSuplPsyLocationInfo start" )
       
   120 	if ( iFs.Handle() && iFile.SubSessionHandle() )
       
   121         {
       
   122         TPckg<HPositionGenericInfo> positionDes( aPosInfo );
       
   123         TInt pos = 0;
       
   124         TInt seekErr = iFile.Seek( ESeekStart,pos );
       
   125 		if( KErrNone != seekErr )
       
   126 			{
       
   127 			return seekErr;	
       
   128 			}
       
   129 		TInt err = iFile.Read( positionDes );
       
   130 		if( KErrNone == err )
       
   131 			{
       
   132 			TInt size = positionDes.Size();
       
   133 			TRACESTRING2("pos data size=%d",size )
       
   134 			if( positionDes.Size() > 0 )
       
   135 				{
       
   136 				TRACESTRING( "File contains data" )
       
   137 				return KErrNone;	
       
   138 				}	
       
   139 			TRACESTRING( "File doesnt contain any data" )
       
   140 			return KErrNotFound;
       
   141 			}
       
   142 		return err;	
       
   143 		}
       
   144 	
       
   145 	TRACESTRING( "CSuplPsyInfoStoreManager::ReadSuplPsyLocationInfo end" )
       
   146 	return KErrNotFound;
       
   147 	}  
       
   148       
       
   149 // -----------------------------------------------------------------------------
       
   150 // CSuplPsyInfoStoreManager::WriteSuplPsyLocationInfo,Writes Location Information to file.
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CSuplPsyInfoStoreManager::WriteSuplPsyLocationInfo( const HPositionGenericInfo& aPosInfo )
       
   155     {
       
   156 	TRACESTRING( "CSuplPsyInfoStoreManager::WriteSuplPsyLocationInfo start" )
       
   157 	if ( iFs.Handle() && iFile.SubSessionHandle() )
       
   158         {
       
   159         TPckg<HPositionGenericInfo> positionDes( aPosInfo );
       
   160         TInt err1 = iFile.Write( 0, positionDes );
       
   161         TInt err2 = iFile.Flush(); 
       
   162                
       
   163         return ( err1 + err2 );
       
   164         }
       
   165     TRACESTRING( "CSuplPsyInfoStoreManager::WriteSuplPsyLocationInfo end" )
       
   166     return KErrNotFound;       
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CSuplPsyInfoStoreManager::ReadSuplPsyCellIdInfo,Reads stored Cell Id Information from SUPL PSY CR Key.
       
   171 // (other items were commented in a header).
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TInt CSuplPsyInfoStoreManager::ReadSuplPsyCellIdInfo( TCellIdInfo& aCellIdInfo )
       
   175     {
       
   176 	TRACESTRING( "CSuplPsyInfoStoreManager::ReadSuplPsyCellIdInfo start" )
       
   177 	TPckg<TCellIdInfo> positionDes( aCellIdInfo );
       
   178 	TInt err = iRepoSuplPsy->Get( KPSYCIdInfo,positionDes );
       
   179 	TRACESTRING2("Read psy CR key error code=%d",err )
       
   180 	
       
   181 	if( KErrNone == err)
       
   182 		{
       
   183 		if( positionDes.Size() > 0 )
       
   184 			{
       
   185 			TRACESTRING( "CId data present" )
       
   186 			return KErrNone;	
       
   187 			}	
       
   188 		
       
   189 		TRACESTRING( "No CId data" )
       
   190 		return KErrNotFound; 
       
   191 		}
       
   192 		
       
   193 	TRACESTRING( "CSuplPsyInfoStoreManager::ReadSuplPsyCellIdInfo end" )
       
   194 	return err; 
       
   195     }
       
   196     
       
   197 // -----------------------------------------------------------------------------
       
   198 // CSuplPsyInfoStoreManager::WriteSuplPsyCellIdInfo,Writes Cell Id Information to SUPL PSY CR Key.
       
   199 // (other items were commented in a header).
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TInt CSuplPsyInfoStoreManager::WriteSuplPsyCellIdInfo( const TCellIdInfo& aCellIdInfo )
       
   203     {
       
   204 	TRACESTRING( "CSuplPsyInfoStoreManager::WriteSuplPsyCellIdInfo start" )
       
   205 	TPckg<TCellIdInfo> positionDes( aCellIdInfo );
       
   206 	return ( iRepoSuplPsy->Set( KPSYCIdInfo,positionDes ) );
       
   207 	}
       
   208         
       
   209 // -----------------------------------------------------------------------------
       
   210 // CSuplPsyInfoStoreManager::ReadSuplFwCellIdInfo,Reads Cell Id Information from SUPL FW CR key.
       
   211 // (other items were commented in a header).
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TInt CSuplPsyInfoStoreManager::ReadSuplFwCellIdInfo( TCellIdInfo& /*aCellIdInfo*/ )
       
   215     {
       
   216     return KErrNone;
       
   217     //TODO temp removal put back
       
   218    
       
   219 //	TRACESTRING( "CSuplPsyInfoStoreManager::ReadSuplFwCellIdInfoL start" )
       
   220 //	TPckg<TCellIdInfo> positionDes( aCellIdInfo );
       
   221 //	TInt err = iRepoSuplFw->Get( KSuplFwCId,positionDes ); 
       
   222 //	TRACESTRING2("Read fw CR key error code=%d",err )
       
   223 //	
       
   224 //	
       
   225 //	if( KErrNone == err)
       
   226 //		{
       
   227 //		if( positionDes.Size() > 0 )
       
   228 //			{
       
   229 //			TRACESTRING( "CId data present" )
       
   230 //			return KErrNone;	
       
   231 //			}	
       
   232 //		
       
   233 //		TRACESTRING( "No Cid data" )
       
   234 //		return KErrNotFound; 
       
   235 //		}
       
   236 //		
       
   237 //	TRACESTRING( "CSuplPsyInfoStoreManager::ReadSuplFwCellIdInfo end" )
       
   238 //    return err; 
       
   239 	}
       
   240 //  End of File