os/persistentdata/loggingservices/eventlogger/LogCli/src/LogCliServerShared.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/loggingservices/eventlogger/LogCli/src/LogCliServerShared.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,273 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// LOGCLISERVSHARED.CPP
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "LogCliServShared.h"
    1.22 +
    1.23 +
    1.24 +
    1.25 +/////////////////////////////////////////////////////////////////////////////////////////
    1.26 +// -----> TLogWindow (source)
    1.27 +/////////////////////////////////////////////////////////////////////////////////////////
    1.28 +
    1.29 +EXPORT_C TLogWindow::TLogWindow()
    1.30 +	{
    1.31 +	Reset();
    1.32 +	}
    1.33 +
    1.34 +/////////////////////////////////////////////////////////////////////////////////////////
    1.35 +/////////////////////////////////////////////////////////////////////////////////////////
    1.36 +/////////////////////////////////////////////////////////////////////////////////////////
    1.37 +
    1.38 +EXPORT_C TBool TLogWindow::Contains(TInt aPosition) const
    1.39 +	{
    1.40 +	return (aPosition >= iLower && aPosition <= iUpper);
    1.41 +	}
    1.42 +
    1.43 +EXPORT_C TInt TLogWindow::Range() const
    1.44 +	{
    1.45 +	if	(iUpper < 0)
    1.46 +		return 0;
    1.47 +	return (iUpper - iLower) + 1;
    1.48 +	}
    1.49 +
    1.50 +EXPORT_C TInt TLogWindow::WindowIndexFromCursorPosition(TInt aCursorPosition) const
    1.51 +	{
    1.52 +	const TInt mapped = aCursorPosition - iLower;
    1.53 +	return mapped;
    1.54 +	}
    1.55 +
    1.56 +EXPORT_C void TLogWindow::Reset()
    1.57 +	{
    1.58 +	iLower = -1;
    1.59 +	iUpper = -1;
    1.60 +	}
    1.61 +
    1.62 +void TLogWindow::Normalize()
    1.63 +	{
    1.64 +	if	(iLower > iUpper)
    1.65 +		iLower = iUpper;
    1.66 +	}
    1.67 +
    1.68 +
    1.69 +
    1.70 +
    1.71 +
    1.72 +
    1.73 +
    1.74 +/////////////////////////////////////////////////////////////////////////////////////////
    1.75 +// -----> TLogWindowAndCursor (source)
    1.76 +/////////////////////////////////////////////////////////////////////////////////////////
    1.77 +
    1.78 +TLogWindowAndCursor::TLogWindowAndCursor()
    1.79 +	{
    1.80 +	Reset();
    1.81 +	}
    1.82 +
    1.83 +TLogWindowAndCursor::TLogWindowAndCursor(const TLogWindow& aWindow, TInt aCursorPosition)
    1.84 +:	TLogWindow(aWindow), iCursorPosition(aCursorPosition)
    1.85 +	{
    1.86 +	}
    1.87 +
    1.88 +/////////////////////////////////////////////////////////////////////////////////////////
    1.89 +/////////////////////////////////////////////////////////////////////////////////////////
    1.90 +/////////////////////////////////////////////////////////////////////////////////////////
    1.91 +
    1.92 +TLogWindowAndCursor::TAffected TLogWindowAndCursor::AdjustForItemDeletion(TInt aItemIndex)
    1.93 +	{
    1.94 +	const TInt KDelta = -1;
    1.95 +	//
    1.96 +	TAffected changed = EWindowUnaffected;
    1.97 +	if	(aItemIndex <= iUpper)
    1.98 +		{
    1.99 +		changed = EWindowAffected;
   1.100 +
   1.101 +		if	(aItemIndex < iCursorPosition)
   1.102 +			--iCursorPosition;
   1.103 +		else if (aItemIndex == iCursorPosition && iCursorPosition == iUpper)
   1.104 +			--iCursorPosition;
   1.105 +
   1.106 +		iUpper += KDelta;
   1.107 +		if	(aItemIndex < iLower)
   1.108 +			iLower += KDelta;
   1.109 +		//
   1.110 +		TLogWindow::Normalize();
   1.111 +		}
   1.112 +	return changed;
   1.113 +	}
   1.114 +
   1.115 +TLogWindowAndCursor::TAffected TLogWindowAndCursor::AdjustForItemAddition(TInt aItemIndex)
   1.116 +	{
   1.117 +	///////////////////////////////////////
   1.118 +	// USE CASE 1:
   1.119 +	///////////////////////////////////////
   1.120 +	// Cursor position:  *
   1.121 +	// Window:			 ---------
   1.122 +	// View Index:       0 1 2 3 4 5 6
   1.123 +	// View Contents:    A B C D E F G
   1.124 +	//
   1.125 +	// Then, item X is added => 
   1.126 +	// 
   1.127 +	// Cursor position:    *
   1.128 +	// Window:			   ---------
   1.129 +	// View Index:       0 1 2 3 4 5 6 7
   1.130 +	// View Contents:    X A B C D E F G
   1.131 +	// 
   1.132 +	///////////////////////////////////////
   1.133 +	// USE CASE 2:
   1.134 +	///////////////////////////////////////
   1.135 +	// Cursor position:    *
   1.136 +	// Window:			   ---------
   1.137 +	// View Index:       0 1 2 3 4 5 6
   1.138 +	// View Contents:    A B C D E F G
   1.139 +	//
   1.140 +	// Then, item X is added => 
   1.141 +	// 
   1.142 +	// Cursor position:      *
   1.143 +	// Window:			     ---------
   1.144 +	// View Index:       0 1 2 3 4 5 6 7
   1.145 +	// View Contents:    X A B C D E F G
   1.146 +	// 
   1.147 +	///////////////////////////////////////
   1.148 +	// USE CASE 3:
   1.149 +	///////////////////////////////////////
   1.150 +	// Cursor position:          *
   1.151 +	// Window:			 ---------
   1.152 +	// View Index:       0 1 2 3 4 5 6
   1.153 +	// View Contents:    A B C D E F G
   1.154 +	//
   1.155 +	// Then, item X is added => 
   1.156 +	// 
   1.157 +	// Cursor position:            *
   1.158 +	// Window:			 -----------
   1.159 +	// View Index:       0 1 2 3 4 5 6 7
   1.160 +	// View Contents:    A B C D X E F G
   1.161 +	// 
   1.162 +	///////////////////////////////////////
   1.163 +	// USE CASE 4:
   1.164 +	///////////////////////////////////////
   1.165 +	// Cursor position:        *  
   1.166 +	// Window:			 ---------
   1.167 +	// View Index:       0 1 2 3 4 5 6
   1.168 +	// View Contents:    A B C D E F G
   1.169 +	//
   1.170 +	// Then, item X is added => 
   1.171 +	// 
   1.172 +	// Cursor position:        *   
   1.173 +	// Window:			 ---------
   1.174 +	// View Index:       0 1 2 3 4 5 6 7
   1.175 +	// View Contents:    A B C D E X F G
   1.176 +	// 
   1.177 +	///////////////////////////////////////
   1.178 +	const TInt KDelta = 1;
   1.179 +	//
   1.180 +	TAffected changed = EWindowUnaffected;
   1.181 +	if	(aItemIndex <= iUpper) // UC4
   1.182 +		{
   1.183 +		changed = EWindowAffected;
   1.184 +
   1.185 +		if	(aItemIndex <= iCursorPosition) // UC1
   1.186 +			++iCursorPosition;
   1.187 +		//
   1.188 +		iUpper += KDelta; // UC1
   1.189 +		if	(aItemIndex <= iLower) // UC1
   1.190 +			iLower += KDelta;
   1.191 +		//
   1.192 +		TLogWindow::Normalize();
   1.193 +		}
   1.194 +	return changed;
   1.195 +	}
   1.196 +
   1.197 +TInt TLogWindowAndCursor::WindowIndexFromCursorPosition() const
   1.198 +	{
   1.199 +	return TLogWindow::WindowIndexFromCursorPosition(iCursorPosition);
   1.200 +	}
   1.201 +
   1.202 +void TLogWindowAndCursor::Reset()
   1.203 +	{
   1.204 +	TLogWindow::Reset();
   1.205 +	iCursorPosition = -1;
   1.206 +	iValid = EFalse;
   1.207 +	}
   1.208 +
   1.209 +void TLogWindowAndCursor::NormalizeWindowAndCursor()
   1.210 +	{
   1.211 +	TLogWindow::Normalize();
   1.212 +	if	(iCursorPosition < iLower)
   1.213 +		iCursorPosition = iLower;
   1.214 +	if	(iCursorPosition > iUpper)
   1.215 +		iCursorPosition = iUpper;
   1.216 +	}
   1.217 +
   1.218 +
   1.219 +
   1.220 +
   1.221 +
   1.222 +
   1.223 +
   1.224 +
   1.225 +
   1.226 +
   1.227 +
   1.228 +
   1.229 +
   1.230 +
   1.231 +/////////////////////////////////////////////////////////////////////////////////////////
   1.232 +// -----> TLogTransferWindow (source)
   1.233 +/////////////////////////////////////////////////////////////////////////////////////////
   1.234 +
   1.235 +EXPORT_C TLogTransferWindow::TLogTransferWindow() :
   1.236 +	iBufferSize(0),
   1.237 +	iServerDataSize(0)
   1.238 +	{
   1.239 +	}
   1.240 +
   1.241 +EXPORT_C void TLogTransferWindow::Reset()
   1.242 +	{
   1.243 +	TLogWindow::Reset();
   1.244 +	iBufferSize = iServerDataSize = 0;
   1.245 +	}
   1.246 +
   1.247 +
   1.248 +/////////////////////////////////////////////////////////////////////////////////////////
   1.249 +// -----> LogUtils (source)
   1.250 +/////////////////////////////////////////////////////////////////////////////////////////
   1.251 +/**  Retrieves appropriate date format string for the current locale.
   1.252 +
   1.253 +@return    Format string for this locale. */
   1.254 +EXPORT_C const TDesC& LogUtils::DateFormatForLocale()
   1.255 +	{
   1.256 +    _LIT(KSQLDateFormatColon,"%D%*M%Y%1 %2 %3 %H:%T:%S%.%C"); 
   1.257 +    _LIT(KSQLDateFormatDot,"%D%*M%Y%1 %2 %3 %H.%T.%S%.%C");
   1.258 +
   1.259 +	TLocale current; 
   1.260 +	TBool dateSeparatorIsColon=EFalse;
   1.261 +	for (TInt i=0; i<4; i++)
   1.262 +		{
   1.263 +		TChar c = current.DateSeparator(i);
   1.264 +		if (c==':')
   1.265 +			{
   1.266 +			dateSeparatorIsColon=ETrue;
   1.267 +			break;
   1.268 +			}
   1.269 +		}
   1.270 +
   1.271 +	if (dateSeparatorIsColon)
   1.272 +		return KSQLDateFormatDot;
   1.273 +	return KSQLDateFormatColon;
   1.274 +	}
   1.275 +
   1.276 +