os/persistentdata/loggingservices/eventlogger/LogCli/src/LogViewObserver.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/LogViewObserver.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,166 @@
     1.4 +// Copyright (c) 2002-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 +//
    1.18 +
    1.19 +#include "LogViewObserver.h"
    1.20 +
    1.21 +// System includes
    1.22 +#include <s32mem.h>
    1.23 +
    1.24 +// User includes
    1.25 +#include <logwrap.h>
    1.26 +#include <logcli.h>
    1.27 +#include "logclipanic.h"
    1.28 +#include "logservcli.h"
    1.29 +#include "LogChangeDefinition.h"
    1.30 +#include "LogViewChangeObserverInternal.h"
    1.31 +
    1.32 +/////////////////////////////////////////////////////////////////////////////////////////
    1.33 +// -----> CLogViewObserver (source)
    1.34 +/////////////////////////////////////////////////////////////////////////////////////////
    1.35 +CLogViewObserver::CLogViewObserver(CLogView& aView, CLogClient& aClient, MLogViewChangeObserverInternal& aObserver, TLogViewId aViewId, TInt aPriority)
    1.36 +:	CActive(aPriority), iClient(aClient), iObserver(aObserver), iViewId(aViewId), iView(aView)
    1.37 +	{
    1.38 +	CActiveScheduler::Add(this);
    1.39 +	}
    1.40 +
    1.41 +CLogViewObserver::~CLogViewObserver()
    1.42 +	{
    1.43 +	Cancel();
    1.44 +	//
    1.45 +	delete iChanges;
    1.46 +	}
    1.47 +
    1.48 +void CLogViewObserver::ConstructL()
    1.49 +	{
    1.50 +	iChanges = CLogChangeDefinition::NewL();
    1.51 +	RequestChanges();
    1.52 +	}
    1.53 +
    1.54 +CLogViewObserver* CLogViewObserver::NewL(CLogView& aView, CLogClient& aClient, MLogViewChangeObserverInternal& aObserver, TLogViewId aViewId, TInt aPriority)
    1.55 +	{
    1.56 +	CLogViewObserver* self = new(ELeave) CLogViewObserver(aView, aClient, aObserver, aViewId, aPriority);
    1.57 +	CleanupStack::PushL(self);
    1.58 +	self->ConstructL();
    1.59 +	CleanupStack::Pop(self);
    1.60 +	return self;
    1.61 +	}
    1.62 +
    1.63 +void CLogViewObserver::RequestChanges()
    1.64 +	{
    1.65 +	iClient.Session().Send(ELogViewChangeNotificationsRequest, TIpcArgs(iViewId), iStatus);
    1.66 +	SetActive();
    1.67 +	}
    1.68 +
    1.69 +void CLogViewObserver::RunL()
    1.70 +	{
    1.71 +	const TInt error = iStatus.Int();
    1.72 +	if (error == KErrServerTerminated)
    1.73 +		{
    1.74 +		// Effectively does a "delete this"
    1.75 +		iView.NotifyLogServerTerminatedL();
    1.76 +		}
    1.77 +	else if (error < KErrNone)
    1.78 +		{
    1.79 +		// Don't request any further changes.
    1.80 +		}
    1.81 +	else
    1.82 +		{
    1.83 +		const TInt changesSize = iStatus.Int();
    1.84 +		User::LeaveIfError(changesSize);
    1.85 +		FetchChangesL(changesSize);
    1.86 +		RequestChanges();
    1.87 +		NotifyObserverL();
    1.88 +		}
    1.89 +	}
    1.90 +
    1.91 +TInt CLogViewObserver::RunError(TInt /*aError*/)
    1.92 +	{
    1.93 +	
    1.94 +	// This point can be reached when RequestChanges has already been 
    1.95 +	// called, for example when an observer leaves when it is notified of 
    1.96 +	// a change.
    1.97 +	// Check IsActive() before calling RequestChanges to avoid calling it 
    1.98 +	// twice in a row and causing a E32USER-CBase:42 panic.
    1.99 + 
   1.100 +	if (!IsActive())
   1.101 +		{
   1.102 +		RequestChanges();	
   1.103 +		}
   1.104 + 	 
   1.105 +	return KErrNone;
   1.106 +	}
   1.107 +
   1.108 +void CLogViewObserver::DoCancel()
   1.109 +	{
   1.110 +	RequestChangesCancel();
   1.111 +	}
   1.112 +
   1.113 +void CLogViewObserver::RequestChangesCancel()
   1.114 +	{
   1.115 +	iClient.Session().Send(ELogViewChangeNotificationsCancel, TIpcArgs(iViewId));
   1.116 +	}
   1.117 +
   1.118 +void CLogViewObserver::FetchChangesL(TInt aBufferSizeRequired)
   1.119 +	{
   1.120 +	HBufC8* buffer = HBufC8::NewLC(aBufferSizeRequired);
   1.121 +	TPtr8 pBuffer(buffer->Des());
   1.122 +	//
   1.123 +	User::LeaveIfError(iClient.Session().Send(ELogViewFetchChanges, TIpcArgs(iViewId,aBufferSizeRequired,&pBuffer)));
   1.124 +	//
   1.125 +	iChanges->Reset();
   1.126 +	RDesReadStream stream(*buffer);
   1.127 +	stream >> *iChanges;
   1.128 +	CleanupStack::PopAndDestroy(buffer);
   1.129 +	}
   1.130 +
   1.131 +void CLogViewObserver::NotifyObserverL()
   1.132 +	{
   1.133 +	TLogId id;
   1.134 +	TInt viewIndex;
   1.135 +
   1.136 +	// Copy the changes
   1.137 +	const TInt count = iChanges->Count();
   1.138 +	if	(!count)
   1.139 +		return;
   1.140 +	//
   1.141 +	CLogChangeDefinition* changes = CLogChangeDefinition::NewL(*iChanges);
   1.142 +	CleanupStack::PushL(changes);
   1.143 +	iChanges->Reset();
   1.144 +	//
   1.145 +	for(TInt i=0; i<count; i++)
   1.146 +		{
   1.147 +		const TLogDatabaseChangeType type = changes->At(i, id, viewIndex);
   1.148 +		//
   1.149 +		switch(type)
   1.150 +			{
   1.151 +		case ELogChangeTypeEventAdded:
   1.152 +			iObserver.HandleLogViewChangeEventAddedL(id, viewIndex, i, count);
   1.153 +			break;
   1.154 +		case ELogChangeTypeEventChanged:
   1.155 +			iObserver.HandleLogViewChangeEventChangedL(id, viewIndex, i, count);
   1.156 +			break;
   1.157 +		case ELogChangeTypeEventDeleted:
   1.158 +			iObserver.HandleLogViewChangeEventDeletedL(id, viewIndex, i, count);
   1.159 +			break;
   1.160 +		case ELogChangeTypeLogCleared:
   1.161 +			iObserver.HandleLogViewChangeEventLogClearedL();
   1.162 +			break;
   1.163 +		default:
   1.164 +		case ELogChangeTypeUndefined:
   1.165 +			__ASSERT_DEBUG(EFalse, Panic(ELogUnexpectedChangeType));
   1.166 +			}
   1.167 +		}
   1.168 +	CleanupStack::PopAndDestroy(changes);
   1.169 +	}