dbgagents/trkagent/tcbserver/TrkTcbSrvSessionEngine.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 /*
       
     2 * Copyright (c) 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "TrkTcbSrvSessionEngine.h"
       
    19 
       
    20 // System includes
       
    21 #include <e32debug.h>
       
    22 
       
    23 // User includes
       
    24 
       
    25 // Type definitions
       
    26 
       
    27 // Constants
       
    28 
       
    29 // Enumerations
       
    30 
       
    31 // Classes referenced
       
    32 
       
    33 
       
    34 //
       
    35 // CTrkTcbSrvSessionEngine (source)
       
    36 //
       
    37 
       
    38 //
       
    39 // CTrkTcbSrvScheduler::CTrkTcbSrvSessionEngine()
       
    40 //
       
    41 // Constructor
       
    42 //
       
    43 CTrkTcbSrvSessionEngine::CTrkTcbSrvSessionEngine() : iFileState(EFileUnknown)
       
    44 {
       
    45 }
       
    46 
       
    47 //
       
    48 // CTrkTcbSrvScheduler::~CTrkTcbSrvSessionEngine()
       
    49 //
       
    50 // Destructor
       
    51 //
       
    52 CTrkTcbSrvSessionEngine::~CTrkTcbSrvSessionEngine()
       
    53 {
       
    54 }
       
    55 
       
    56 //
       
    57 // CTrkTcbSrvScheduler::ConstructL()
       
    58 //
       
    59 // Second level constructor
       
    60 //
       
    61 void CTrkTcbSrvSessionEngine::ConstructL()
       
    62 {
       
    63 	//nothing right now
       
    64 }
       
    65 
       
    66 //
       
    67 // CTrkTcbSrvScheduler::NewL()
       
    68 //
       
    69 // Creates an instance of CTrkTcbSrvSessionEngine
       
    70 //
       
    71 CTrkTcbSrvSessionEngine* CTrkTcbSrvSessionEngine::NewL()
       
    72 {
       
    73 	CTrkTcbSrvSessionEngine* self = new(ELeave) CTrkTcbSrvSessionEngine();
       
    74 	CleanupStack::PushL(self);
       
    75 	self->ConstructL();
       
    76 	CleanupStack::Pop(self);
       
    77 	return self;
       
    78 }
       
    79 
       
    80 //
       
    81 // CTrkTcbSrvScheduler::OpenFileL()
       
    82 //
       
    83 // Opens the specified file
       
    84 //
       
    85 void CTrkTcbSrvSessionEngine::OpenFileL(const TDesC& aFilePath, TUint aMode, TTime& aModifiedTime)
       
    86 {	
       
    87 	//just for testing
       
    88 	TBuf8<KMaxPath> fileName;
       
    89 	fileName.Copy(aFilePath);
       
    90 
       
    91 	iMode = aMode; //copy  the mode, for properly closing the file.
       
    92 	
       
    93 	User::LeaveIfError(iFs.Connect());
       
    94 
       
    95 	TInt error = iFs.MkDirAll(aFilePath);
       
    96 
       
    97 	if ((KErrNone != error) && (KErrAlreadyExists != error))
       
    98 	{
       
    99 		iFs.Close();
       
   100 		User::Leave(error);
       
   101 	}
       
   102 	
       
   103 	error = iFile.Open(iFs, aFilePath, aMode);
       
   104 	if (KErrNone != error)
       
   105 		User::LeaveIfError(iFile.Replace(iFs, aFilePath, aMode));
       
   106 
       
   107 	// get the modification date
       
   108 	User::LeaveIfError(iFile.Modified(aModifiedTime));
       
   109 	iFileState = EFileOpened;
       
   110 }
       
   111 
       
   112 //
       
   113 // CTrkTcbSrvScheduler::ReadFileL()
       
   114 //
       
   115 // Reads from the already opened file
       
   116 //
       
   117 void CTrkTcbSrvSessionEngine::ReadFileL(TDes8& aFileData)
       
   118 {
       
   119 	iFileState = EFileReading;
       
   120 	User::LeaveIfError(iFile.Read(aFileData));
       
   121 }
       
   122 
       
   123 //
       
   124 // CTrkTcbSrvScheduler::WriteFileL()
       
   125 //
       
   126 // Writes to an already opened file
       
   127 //
       
   128 void CTrkTcbSrvSessionEngine::WriteFileL(const TDesC8& aFileData)
       
   129 {
       
   130 	if (iFileState == EFileOpened)
       
   131 	{
       
   132 		iFile.SetSize(0);
       
   133 		iFileState = EFileWriting;
       
   134 	}
       
   135 	User::LeaveIfError(iFile.Write(aFileData));	
       
   136 	User::LeaveIfError(iFile.Flush());
       
   137 }
       
   138 
       
   139 //
       
   140 // CTrkTcbSrvScheduler::CloseFileL()
       
   141 //
       
   142 // Closes an already opened file
       
   143 //
       
   144 void CTrkTcbSrvSessionEngine::CloseFileL(const TTime& aModifiedTime)
       
   145 {
       
   146 	//set the modification time only if the file is opened in write mode
       
   147 	if (iMode & EFileWrite)
       
   148 	{
       
   149 		User::LeaveIfError(iFile.SetModified(aModifiedTime));
       
   150 		User::LeaveIfError(iFile.Flush());
       
   151 	}
       
   152 	
       
   153 	iFile.Close();
       
   154 	iFs.Close();
       
   155 	iFileState = EFileClosed;
       
   156 }
       
   157 
       
   158 //
       
   159 // CTrkTcbSrvScheduler::PositionFileL()
       
   160 //
       
   161 // Changes the positions in an already opened file
       
   162 //
       
   163 void CTrkTcbSrvSessionEngine::PositionFileL(TSeek aSeek, TInt& aOffset)
       
   164 {
       
   165 	User::LeaveIfError(iFile.Seek(aSeek, aOffset));
       
   166 }
       
   167 
       
   168