dbgagents/trkagent/tcbclient/TrkTcbCliSession.cpp
author ravikurupati
Tue, 02 Mar 2010 10:33:16 +0530
changeset 0 c6b0df440bee
permissions -rw-r--r--
Initial contribution of EPL licensed sources
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     1
/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     3
* All rights reserved.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     4
* This component and the accompanying materials are made available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     6
* which accompanies this distribution, and is available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     8
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     9
* Initial Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    11
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    12
* Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    13
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    14
* Description: 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    15
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    16
*/
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    17
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    18
#include "TrkTcbCliSession.h"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    19
#include "TrkTcbClientDefs.h"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    20
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    21
// System includes
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    22
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    23
// User includes
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    24
#include "TrkTcbCmdCodes.h"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    25
#include "TrkTcbClientUtils.h"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    26
// Type definitions
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    27
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    28
// Constants
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    29
const TInt KNumberOfServerStartupAttempts = 2;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    30
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    31
// Enumerations
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    32
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    33
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    34
// RTrkTcbCliSession (source)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    35
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    36
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    37
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    38
// RTrkTcbCliSession::RTrkTcbCliSession
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    39
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    40
// Constructor
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    41
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    42
RTrkTcbCliSession::RTrkTcbCliSession()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    43
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    44
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    45
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    46
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    47
//RTrkTcbCliSession::Connect()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    48
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    49
// Connects the client process to the TrkTcb server, starting the server 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    50
// if it is not already running.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    51
// return KErrNone if successful, otherwise one of the system-wide errors.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    52
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    53
TInt RTrkTcbCliSession::Connect()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    54
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    55
	TInt startupAttempts = KNumberOfServerStartupAttempts;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    56
	for(;;)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    57
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    58
		TInt ret = CreateSession(TrkTcbClientDefs::ServerAndThreadName(), TrkTcbClientDefs::Version(), KTrkTcbServerAsynchronousSlotCount);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    59
		if (ret != KErrNotFound && ret != KErrServerTerminated)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    60
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    61
			return ret;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    62
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    63
		
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    64
		if	(startupAttempts-- == 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    65
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    66
			return ret;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    67
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    68
		
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    69
		ret = TrkTcbClientUtils::StartTrkTcbServer();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    70
		if	(ret != KErrNone && ret != KErrAlreadyExists)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    71
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    72
			return ret;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    73
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    74
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    75
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    76
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    77
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    78
// RTrkTcbCliSession::Version()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    79
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    80
// Provides the version number of the TrkTcb server.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    81
// @return The version number. 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    82
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    83
TVersion RTrkTcbCliSession::Version() const
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    84
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    85
	return TrkTcbClientDefs::Version();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    86
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    87
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    88
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    89
// RTrkTcbCliSession::OpenFile()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    90
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    91
// Opens the specified file in the specified mode.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    92
// @return KErrNone - if succesful
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    93
//		   Negative - if failed.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    94
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    95
TInt RTrkTcbCliSession::OpenFile(const TDesC& aFilePath, TUint aMode, TTime& aModifiedTime)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    96
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    97
	TPckg<TTime> package(aModifiedTime);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    98
	TInt length = aFilePath.Length();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    99
	TIpcArgs args(length, &aFilePath, aMode, &package);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   100
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   101
	return SendReceive(ETrkTcbCmdCodeOpenFile, args);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   102
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   103
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   104
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   105
// RTrkTcbCliSession::ReadFile()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   106
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   107
// Reads data from the already opened file.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   108
// @return KErrNone - if succesful
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   109
//		   Negative - if failed.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   110
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   111
TInt RTrkTcbCliSession::ReadFile(TUint16 aLength, TDes8& aFileData)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   112
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   113
	TIpcArgs args(aLength, &aFileData);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   114
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   115
	return SendReceive(ETrkTcbCmdCodeReadFile, args);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   116
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   117
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   118
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   119
// RTrkTcbCliSession::WriteFile()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   120
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   121
// Writes data into the already opened file.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   122
// @return KErrNone - if succesful
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   123
//		   Negative - if failed.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   124
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   125
TInt RTrkTcbCliSession::WriteFile(const TDesC8& aFileData)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   126
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   127
	TIpcArgs args(aFileData.Length(), &aFileData);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   128
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   129
	return SendReceive(ETrkTcbCmdCodeWriteFile, args);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   130
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   131
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   132
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   133
// RTrkTcbCliSession::CloseFile()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   134
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   135
// Closes data into the already opened file.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   136
// @return KErrNone - if succesful
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   137
//		   Negative - if failed.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   138
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   139
TInt RTrkTcbCliSession::CloseFile(const TTime& aTime)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   140
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   141
	TPckg<TTime> package(aTime);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   142
	TIpcArgs args(&package);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   143
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   144
	return SendReceive(ETrkTcbCmdCodeCloseFile, args);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   145
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   146
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   147
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   148
// RTrkTcbCliSession::PositionFile()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   149
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   150
// Changes the current postion in the already opened file
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   151
// @return KErrNone - if succesful
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   152
//		   Negative - if failed.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   153
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   154
TInt RTrkTcbCliSession::PositionFile(TSeek aSeek, TInt& aOffset)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   155
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   156
	TPckg<TSeek>  package(aSeek);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   157
	TIpcArgs args(&package, aOffset);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   158
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   159
	return SendReceive(ETrkTcbCmdCodePositionFile, args);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   160
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   161
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   162
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   163
// RTrkTcbCliSession::ShutDownServer()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   164
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   165
// Closes the server.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   166
// @return KErrNone - if succesful
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   167
//		   Negative - if failed.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   168
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   169
TInt RTrkTcbCliSession::ShutDownServer()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   170
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   171
	TIpcArgs args;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   172
	return SendReceive(ETrkTcbCmdCodeShutDownServer, args);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   173
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   174