First public contribution.
1 // Copyright (c) 2002-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "LogViewObserver.h"
24 #include "logclipanic.h"
25 #include "logservcli.h"
26 #include "LogChangeDefinition.h"
27 #include "LogViewChangeObserverInternal.h"
29 /////////////////////////////////////////////////////////////////////////////////////////
30 // -----> CLogViewObserver (source)
31 /////////////////////////////////////////////////////////////////////////////////////////
32 CLogViewObserver::CLogViewObserver(CLogView& aView, CLogClient& aClient, MLogViewChangeObserverInternal& aObserver, TLogViewId aViewId, TInt aPriority)
33 : CActive(aPriority), iClient(aClient), iObserver(aObserver), iViewId(aViewId), iView(aView)
35 CActiveScheduler::Add(this);
38 CLogViewObserver::~CLogViewObserver()
45 void CLogViewObserver::ConstructL()
47 iChanges = CLogChangeDefinition::NewL();
51 CLogViewObserver* CLogViewObserver::NewL(CLogView& aView, CLogClient& aClient, MLogViewChangeObserverInternal& aObserver, TLogViewId aViewId, TInt aPriority)
53 CLogViewObserver* self = new(ELeave) CLogViewObserver(aView, aClient, aObserver, aViewId, aPriority);
54 CleanupStack::PushL(self);
56 CleanupStack::Pop(self);
60 void CLogViewObserver::RequestChanges()
62 iClient.Session().Send(ELogViewChangeNotificationsRequest, TIpcArgs(iViewId), iStatus);
66 void CLogViewObserver::RunL()
68 const TInt error = iStatus.Int();
69 if (error == KErrServerTerminated)
71 // Effectively does a "delete this"
72 iView.NotifyLogServerTerminatedL();
74 else if (error < KErrNone)
76 // Don't request any further changes.
80 const TInt changesSize = iStatus.Int();
81 User::LeaveIfError(changesSize);
82 FetchChangesL(changesSize);
88 TInt CLogViewObserver::RunError(TInt /*aError*/)
91 // This point can be reached when RequestChanges has already been
92 // called, for example when an observer leaves when it is notified of
94 // Check IsActive() before calling RequestChanges to avoid calling it
95 // twice in a row and causing a E32USER-CBase:42 panic.
105 void CLogViewObserver::DoCancel()
107 RequestChangesCancel();
110 void CLogViewObserver::RequestChangesCancel()
112 iClient.Session().Send(ELogViewChangeNotificationsCancel, TIpcArgs(iViewId));
115 void CLogViewObserver::FetchChangesL(TInt aBufferSizeRequired)
117 HBufC8* buffer = HBufC8::NewLC(aBufferSizeRequired);
118 TPtr8 pBuffer(buffer->Des());
120 User::LeaveIfError(iClient.Session().Send(ELogViewFetchChanges, TIpcArgs(iViewId,aBufferSizeRequired,&pBuffer)));
123 RDesReadStream stream(*buffer);
125 CleanupStack::PopAndDestroy(buffer);
128 void CLogViewObserver::NotifyObserverL()
134 const TInt count = iChanges->Count();
138 CLogChangeDefinition* changes = CLogChangeDefinition::NewL(*iChanges);
139 CleanupStack::PushL(changes);
142 for(TInt i=0; i<count; i++)
144 const TLogDatabaseChangeType type = changes->At(i, id, viewIndex);
148 case ELogChangeTypeEventAdded:
149 iObserver.HandleLogViewChangeEventAddedL(id, viewIndex, i, count);
151 case ELogChangeTypeEventChanged:
152 iObserver.HandleLogViewChangeEventChangedL(id, viewIndex, i, count);
154 case ELogChangeTypeEventDeleted:
155 iObserver.HandleLogViewChangeEventDeletedL(id, viewIndex, i, count);
157 case ELogChangeTypeLogCleared:
158 iObserver.HandleLogViewChangeEventLogClearedL();
161 case ELogChangeTypeUndefined:
162 __ASSERT_DEBUG(EFalse, Panic(ELogUnexpectedChangeType));
165 CleanupStack::PopAndDestroy(changes);