os/persistentdata/loggingservices/eventlogger/LogCli/src/LogViewWindowFetcher.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "LogViewWindowFetcher.h"
sl@0
    17
sl@0
    18
// System includes
sl@0
    19
#include <s32mem.h>
sl@0
    20
sl@0
    21
// User includes
sl@0
    22
#include "logservcli.h"
sl@0
    23
sl@0
    24
// Constants
sl@0
    25
const TInt KLogSizeOfEventGuess = 200;
sl@0
    26
const TInt KLogWindowFetchBufferGranularity = KLogSizeOfEventGuess * 2;
sl@0
    27
const TInt KLogWindowFetchBufferMinimumBufferSize = 4;
sl@0
    28
sl@0
    29
sl@0
    30
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    31
// -----> CLogViewWindowFetcher (source)
sl@0
    32
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    33
sl@0
    34
CLogViewWindowFetcher::CLogViewWindowFetcher(RLogSession& aSession, TLogViewId aViewId, MLogViewWindowFetcherObserver& aObserver, TInt aPriority)
sl@0
    35
:	CActive(aPriority), iSession(aSession), iViewId(aViewId), iObserver(aObserver), iBufferPointer(NULL, 0)
sl@0
    36
	{
sl@0
    37
	CActiveScheduler::Add(this);
sl@0
    38
	iData().iOperationType = ELogOperationViewWindowFetch;
sl@0
    39
	}
sl@0
    40
sl@0
    41
CLogViewWindowFetcher::~CLogViewWindowFetcher()
sl@0
    42
	{
sl@0
    43
	Cancel();
sl@0
    44
	//
sl@0
    45
	delete iBuffer;
sl@0
    46
	}
sl@0
    47
sl@0
    48
void CLogViewWindowFetcher::ConstructL()
sl@0
    49
	{
sl@0
    50
	iBuffer = CBufFlat::NewL(KLogWindowFetchBufferGranularity);
sl@0
    51
	}
sl@0
    52
sl@0
    53
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    54
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    55
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    56
sl@0
    57
void CLogViewWindowFetcher::PrepareToFetchWindowL(const TLogWindowAndCursor& aRequestedWindow)
sl@0
    58
	{
sl@0
    59
	iRequestedWindow = aRequestedWindow;
sl@0
    60
	iRequestedWindow.iValid = EFalse;
sl@0
    61
	iWindowReq = iRequestedWindow; // Initialise window
sl@0
    62
	// Setup the buffer so that its the right size to receive the events
sl@0
    63
	const TInt range = Max(1, iRequestedWindow.iUpper - iRequestedWindow.iLower + 1);
sl@0
    64
	const TInt size = KLogSizeOfEventGuess * range;
sl@0
    65
	iBuffer->ResizeL(size);
sl@0
    66
	iBufferPointer.Set(iBuffer->Ptr(0));
sl@0
    67
	//
sl@0
    68
	iFetchWindowData().iBufferSize = size;
sl@0
    69
	}
sl@0
    70
sl@0
    71
void CLogViewWindowFetcher::Start(TRequestStatus& aObserver)
sl@0
    72
	{
sl@0
    73
	iObserverRequestStatus = &aObserver;
sl@0
    74
	*iObserverRequestStatus = KRequestPending;
sl@0
    75
	if	(iRequestedWindow.Range())
sl@0
    76
		Fetch(iRequestedWindow);
sl@0
    77
	else
sl@0
    78
		{
sl@0
    79
		// Nothing to fetch
sl@0
    80
		iRequestedWindow.NormalizeWindowAndCursor();
sl@0
    81
		User::RequestComplete(iObserverRequestStatus, KErrNone);
sl@0
    82
		}
sl@0
    83
	}
sl@0
    84
sl@0
    85
void CLogViewWindowFetcher::SilentCancel()
sl@0
    86
	{
sl@0
    87
	if	(iObserverRequestStatus)
sl@0
    88
		User::RequestComplete(iObserverRequestStatus, KErrNone);
sl@0
    89
	Cancel();
sl@0
    90
	}
sl@0
    91
sl@0
    92
sl@0
    93
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    94
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    95
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    96
sl@0
    97
void CLogViewWindowFetcher::RunL()
sl@0
    98
	{
sl@0
    99
	const TInt sentByServer = iStatus.Int();
sl@0
   100
	User::LeaveIfError(sentByServer);
sl@0
   101
	//The server has completed the operation without any error, but there is no returned data
sl@0
   102
	//(sentByServer == 0). Then the client has to check if iFetchWindowData().iServerDataSize
sl@0
   103
	//data member is set, which means that the server wants to send more data than the client
sl@0
   104
	//side buffer can accept. The client has to increase the buffer size and then execute 
sl@0
   105
	//the operation again.
sl@0
   106
	TInt newSize = iFetchWindowData().iServerDataSize;
sl@0
   107
	//newSize was initialized, so iFetchWindowData().iServerDataSize can be set to 0.
sl@0
   108
	iFetchWindowData().iServerDataSize = 0;
sl@0
   109
	if(sentByServer == 0 && newSize > 0)
sl@0
   110
		{
sl@0
   111
		iBuffer->ResizeL(newSize);
sl@0
   112
		iBufferPointer.Set(iBuffer->Ptr(0));
sl@0
   113
		iFetchWindowData().iBufferSize = newSize;
sl@0
   114
		//The operation will be executed again later - see "Fetch(iWindowReq)" call.
sl@0
   115
		}
sl@0
   116
	RBufReadStream stream(*iBuffer);
sl@0
   117
	for(TInt i=0; i<sentByServer; i++)
sl@0
   118
		{
sl@0
   119
		// Give the event to the observer
sl@0
   120
		CLogEvent* event = CLogEvent::NewL();
sl@0
   121
		CleanupStack::PushL(event);
sl@0
   122
		//
sl@0
   123
		stream >> *event;
sl@0
   124
		iObserver.HandleFetchedWindowItemL(i, event);
sl@0
   125
		CleanupStack::Pop(event);
sl@0
   126
		}
sl@0
   127
sl@0
   128
	// Do we need to fetch the next batch?
sl@0
   129
	iWindowReq.iLower += sentByServer; // the lower array index for next request
sl@0
   130
sl@0
   131
	if(iWindowReq.iLower <= iWindowReq.iUpper)
sl@0
   132
		{
sl@0
   133
		// Fetch some more
sl@0
   134
		Fetch(iWindowReq);
sl@0
   135
		}
sl@0
   136
	else
sl@0
   137
		{
sl@0
   138
		// All done?
sl@0
   139
		iBuffer->ResizeL(KLogWindowFetchBufferMinimumBufferSize);
sl@0
   140
		iRequestedWindow.iValid = ETrue;
sl@0
   141
		CompleteObserver(KErrNone);
sl@0
   142
		}
sl@0
   143
	}
sl@0
   144
sl@0
   145
void CLogViewWindowFetcher::DoCancel()
sl@0
   146
	{
sl@0
   147
	if	(iData().iOperationId > 0)
sl@0
   148
		{
sl@0
   149
		const TInt errorIgnored = iSession.Send(ELogOperationCancel, TIpcArgs(&iData));
sl@0
   150
		(void) errorIgnored;
sl@0
   151
		//
sl@0
   152
		iData().iOperationId = KLogNullOperationId;
sl@0
   153
		}
sl@0
   154
sl@0
   155
	CompleteObserver(KErrCancel);
sl@0
   156
	}
sl@0
   157
sl@0
   158
TInt CLogViewWindowFetcher::RunError(TInt aError)
sl@0
   159
	{
sl@0
   160
	CompleteObserver(aError);
sl@0
   161
	return KErrNone;
sl@0
   162
	}
sl@0
   163
sl@0
   164
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   165
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   166
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   167
sl@0
   168
void CLogViewWindowFetcher::Fetch(const TLogWindow& aWindow)
sl@0
   169
	{
sl@0
   170
	iFetchWindowData().iLower = aWindow.iLower;
sl@0
   171
	iFetchWindowData().iUpper = aWindow.iUpper;
sl@0
   172
	//
sl@0
   173
	iData().iOperationId = iSession.AllocateIdOperation();
sl@0
   174
	//
sl@0
   175
	iSession.Send(ELogViewOperationInitiate, TIpcArgs(&iData,iViewId,&iFetchWindowData,&iBufferPointer), iStatus);
sl@0
   176
	SetActive();
sl@0
   177
	}
sl@0
   178
sl@0
   179
void CLogViewWindowFetcher::CompleteObserver(TInt aError)
sl@0
   180
	{
sl@0
   181
	if	(iObserverRequestStatus)
sl@0
   182
		User::RequestComplete(iObserverRequestStatus, aError);
sl@0
   183
	}