os/persistentdata/loggingservices/eventlogger/LogCli/src/LogCliServerShared.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // LOGCLISERVSHARED.CPP
    15 // 
    16 //
    17 
    18 #include "LogCliServShared.h"
    19 
    20 
    21 
    22 /////////////////////////////////////////////////////////////////////////////////////////
    23 // -----> TLogWindow (source)
    24 /////////////////////////////////////////////////////////////////////////////////////////
    25 
    26 EXPORT_C TLogWindow::TLogWindow()
    27 	{
    28 	Reset();
    29 	}
    30 
    31 /////////////////////////////////////////////////////////////////////////////////////////
    32 /////////////////////////////////////////////////////////////////////////////////////////
    33 /////////////////////////////////////////////////////////////////////////////////////////
    34 
    35 EXPORT_C TBool TLogWindow::Contains(TInt aPosition) const
    36 	{
    37 	return (aPosition >= iLower && aPosition <= iUpper);
    38 	}
    39 
    40 EXPORT_C TInt TLogWindow::Range() const
    41 	{
    42 	if	(iUpper < 0)
    43 		return 0;
    44 	return (iUpper - iLower) + 1;
    45 	}
    46 
    47 EXPORT_C TInt TLogWindow::WindowIndexFromCursorPosition(TInt aCursorPosition) const
    48 	{
    49 	const TInt mapped = aCursorPosition - iLower;
    50 	return mapped;
    51 	}
    52 
    53 EXPORT_C void TLogWindow::Reset()
    54 	{
    55 	iLower = -1;
    56 	iUpper = -1;
    57 	}
    58 
    59 void TLogWindow::Normalize()
    60 	{
    61 	if	(iLower > iUpper)
    62 		iLower = iUpper;
    63 	}
    64 
    65 
    66 
    67 
    68 
    69 
    70 
    71 /////////////////////////////////////////////////////////////////////////////////////////
    72 // -----> TLogWindowAndCursor (source)
    73 /////////////////////////////////////////////////////////////////////////////////////////
    74 
    75 TLogWindowAndCursor::TLogWindowAndCursor()
    76 	{
    77 	Reset();
    78 	}
    79 
    80 TLogWindowAndCursor::TLogWindowAndCursor(const TLogWindow& aWindow, TInt aCursorPosition)
    81 :	TLogWindow(aWindow), iCursorPosition(aCursorPosition)
    82 	{
    83 	}
    84 
    85 /////////////////////////////////////////////////////////////////////////////////////////
    86 /////////////////////////////////////////////////////////////////////////////////////////
    87 /////////////////////////////////////////////////////////////////////////////////////////
    88 
    89 TLogWindowAndCursor::TAffected TLogWindowAndCursor::AdjustForItemDeletion(TInt aItemIndex)
    90 	{
    91 	const TInt KDelta = -1;
    92 	//
    93 	TAffected changed = EWindowUnaffected;
    94 	if	(aItemIndex <= iUpper)
    95 		{
    96 		changed = EWindowAffected;
    97 
    98 		if	(aItemIndex < iCursorPosition)
    99 			--iCursorPosition;
   100 		else if (aItemIndex == iCursorPosition && iCursorPosition == iUpper)
   101 			--iCursorPosition;
   102 
   103 		iUpper += KDelta;
   104 		if	(aItemIndex < iLower)
   105 			iLower += KDelta;
   106 		//
   107 		TLogWindow::Normalize();
   108 		}
   109 	return changed;
   110 	}
   111 
   112 TLogWindowAndCursor::TAffected TLogWindowAndCursor::AdjustForItemAddition(TInt aItemIndex)
   113 	{
   114 	///////////////////////////////////////
   115 	// USE CASE 1:
   116 	///////////////////////////////////////
   117 	// Cursor position:  *
   118 	// Window:			 ---------
   119 	// View Index:       0 1 2 3 4 5 6
   120 	// View Contents:    A B C D E F G
   121 	//
   122 	// Then, item X is added => 
   123 	// 
   124 	// Cursor position:    *
   125 	// Window:			   ---------
   126 	// View Index:       0 1 2 3 4 5 6 7
   127 	// View Contents:    X A B C D E F G
   128 	// 
   129 	///////////////////////////////////////
   130 	// USE CASE 2:
   131 	///////////////////////////////////////
   132 	// Cursor position:    *
   133 	// Window:			   ---------
   134 	// View Index:       0 1 2 3 4 5 6
   135 	// View Contents:    A B C D E F G
   136 	//
   137 	// Then, item X is added => 
   138 	// 
   139 	// Cursor position:      *
   140 	// Window:			     ---------
   141 	// View Index:       0 1 2 3 4 5 6 7
   142 	// View Contents:    X A B C D E F G
   143 	// 
   144 	///////////////////////////////////////
   145 	// USE CASE 3:
   146 	///////////////////////////////////////
   147 	// Cursor position:          *
   148 	// Window:			 ---------
   149 	// View Index:       0 1 2 3 4 5 6
   150 	// View Contents:    A B C D E F G
   151 	//
   152 	// Then, item X is added => 
   153 	// 
   154 	// Cursor position:            *
   155 	// Window:			 -----------
   156 	// View Index:       0 1 2 3 4 5 6 7
   157 	// View Contents:    A B C D X E F G
   158 	// 
   159 	///////////////////////////////////////
   160 	// USE CASE 4:
   161 	///////////////////////////////////////
   162 	// Cursor position:        *  
   163 	// Window:			 ---------
   164 	// View Index:       0 1 2 3 4 5 6
   165 	// View Contents:    A B C D E F G
   166 	//
   167 	// Then, item X is added => 
   168 	// 
   169 	// Cursor position:        *   
   170 	// Window:			 ---------
   171 	// View Index:       0 1 2 3 4 5 6 7
   172 	// View Contents:    A B C D E X F G
   173 	// 
   174 	///////////////////////////////////////
   175 	const TInt KDelta = 1;
   176 	//
   177 	TAffected changed = EWindowUnaffected;
   178 	if	(aItemIndex <= iUpper) // UC4
   179 		{
   180 		changed = EWindowAffected;
   181 
   182 		if	(aItemIndex <= iCursorPosition) // UC1
   183 			++iCursorPosition;
   184 		//
   185 		iUpper += KDelta; // UC1
   186 		if	(aItemIndex <= iLower) // UC1
   187 			iLower += KDelta;
   188 		//
   189 		TLogWindow::Normalize();
   190 		}
   191 	return changed;
   192 	}
   193 
   194 TInt TLogWindowAndCursor::WindowIndexFromCursorPosition() const
   195 	{
   196 	return TLogWindow::WindowIndexFromCursorPosition(iCursorPosition);
   197 	}
   198 
   199 void TLogWindowAndCursor::Reset()
   200 	{
   201 	TLogWindow::Reset();
   202 	iCursorPosition = -1;
   203 	iValid = EFalse;
   204 	}
   205 
   206 void TLogWindowAndCursor::NormalizeWindowAndCursor()
   207 	{
   208 	TLogWindow::Normalize();
   209 	if	(iCursorPosition < iLower)
   210 		iCursorPosition = iLower;
   211 	if	(iCursorPosition > iUpper)
   212 		iCursorPosition = iUpper;
   213 	}
   214 
   215 
   216 
   217 
   218 
   219 
   220 
   221 
   222 
   223 
   224 
   225 
   226 
   227 
   228 /////////////////////////////////////////////////////////////////////////////////////////
   229 // -----> TLogTransferWindow (source)
   230 /////////////////////////////////////////////////////////////////////////////////////////
   231 
   232 EXPORT_C TLogTransferWindow::TLogTransferWindow() :
   233 	iBufferSize(0),
   234 	iServerDataSize(0)
   235 	{
   236 	}
   237 
   238 EXPORT_C void TLogTransferWindow::Reset()
   239 	{
   240 	TLogWindow::Reset();
   241 	iBufferSize = iServerDataSize = 0;
   242 	}
   243 
   244 
   245 /////////////////////////////////////////////////////////////////////////////////////////
   246 // -----> LogUtils (source)
   247 /////////////////////////////////////////////////////////////////////////////////////////
   248 /**  Retrieves appropriate date format string for the current locale.
   249 
   250 @return    Format string for this locale. */
   251 EXPORT_C const TDesC& LogUtils::DateFormatForLocale()
   252 	{
   253     _LIT(KSQLDateFormatColon,"%D%*M%Y%1 %2 %3 %H:%T:%S%.%C"); 
   254     _LIT(KSQLDateFormatDot,"%D%*M%Y%1 %2 %3 %H.%T.%S%.%C");
   255 
   256 	TLocale current; 
   257 	TBool dateSeparatorIsColon=EFalse;
   258 	for (TInt i=0; i<4; i++)
   259 		{
   260 		TChar c = current.DateSeparator(i);
   261 		if (c==':')
   262 			{
   263 			dateSeparatorIsColon=ETrue;
   264 			break;
   265 			}
   266 		}
   267 
   268 	if (dateSeparatorIsColon)
   269 		return KSQLDateFormatDot;
   270 	return KSQLDateFormatColon;
   271 	}
   272 
   273