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 "LogViewObserver.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 <logwrap.h>
|
sl@0
|
23 |
#include <logcli.h>
|
sl@0
|
24 |
#include "logclipanic.h"
|
sl@0
|
25 |
#include "logservcli.h"
|
sl@0
|
26 |
#include "LogChangeDefinition.h"
|
sl@0
|
27 |
#include "LogViewChangeObserverInternal.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
30 |
// -----> CLogViewObserver (source)
|
sl@0
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
32 |
CLogViewObserver::CLogViewObserver(CLogView& aView, CLogClient& aClient, MLogViewChangeObserverInternal& aObserver, TLogViewId aViewId, TInt aPriority)
|
sl@0
|
33 |
: CActive(aPriority), iClient(aClient), iObserver(aObserver), iViewId(aViewId), iView(aView)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
CActiveScheduler::Add(this);
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
CLogViewObserver::~CLogViewObserver()
|
sl@0
|
39 |
{
|
sl@0
|
40 |
Cancel();
|
sl@0
|
41 |
//
|
sl@0
|
42 |
delete iChanges;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
void CLogViewObserver::ConstructL()
|
sl@0
|
46 |
{
|
sl@0
|
47 |
iChanges = CLogChangeDefinition::NewL();
|
sl@0
|
48 |
RequestChanges();
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
CLogViewObserver* CLogViewObserver::NewL(CLogView& aView, CLogClient& aClient, MLogViewChangeObserverInternal& aObserver, TLogViewId aViewId, TInt aPriority)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
CLogViewObserver* self = new(ELeave) CLogViewObserver(aView, aClient, aObserver, aViewId, aPriority);
|
sl@0
|
54 |
CleanupStack::PushL(self);
|
sl@0
|
55 |
self->ConstructL();
|
sl@0
|
56 |
CleanupStack::Pop(self);
|
sl@0
|
57 |
return self;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
void CLogViewObserver::RequestChanges()
|
sl@0
|
61 |
{
|
sl@0
|
62 |
iClient.Session().Send(ELogViewChangeNotificationsRequest, TIpcArgs(iViewId), iStatus);
|
sl@0
|
63 |
SetActive();
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void CLogViewObserver::RunL()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
const TInt error = iStatus.Int();
|
sl@0
|
69 |
if (error == KErrServerTerminated)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
// Effectively does a "delete this"
|
sl@0
|
72 |
iView.NotifyLogServerTerminatedL();
|
sl@0
|
73 |
}
|
sl@0
|
74 |
else if (error < KErrNone)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
// Don't request any further changes.
|
sl@0
|
77 |
}
|
sl@0
|
78 |
else
|
sl@0
|
79 |
{
|
sl@0
|
80 |
const TInt changesSize = iStatus.Int();
|
sl@0
|
81 |
User::LeaveIfError(changesSize);
|
sl@0
|
82 |
FetchChangesL(changesSize);
|
sl@0
|
83 |
RequestChanges();
|
sl@0
|
84 |
NotifyObserverL();
|
sl@0
|
85 |
}
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
TInt CLogViewObserver::RunError(TInt /*aError*/)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
|
sl@0
|
91 |
// This point can be reached when RequestChanges has already been
|
sl@0
|
92 |
// called, for example when an observer leaves when it is notified of
|
sl@0
|
93 |
// a change.
|
sl@0
|
94 |
// Check IsActive() before calling RequestChanges to avoid calling it
|
sl@0
|
95 |
// twice in a row and causing a E32USER-CBase:42 panic.
|
sl@0
|
96 |
|
sl@0
|
97 |
if (!IsActive())
|
sl@0
|
98 |
{
|
sl@0
|
99 |
RequestChanges();
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
return KErrNone;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
void CLogViewObserver::DoCancel()
|
sl@0
|
106 |
{
|
sl@0
|
107 |
RequestChangesCancel();
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
void CLogViewObserver::RequestChangesCancel()
|
sl@0
|
111 |
{
|
sl@0
|
112 |
iClient.Session().Send(ELogViewChangeNotificationsCancel, TIpcArgs(iViewId));
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
void CLogViewObserver::FetchChangesL(TInt aBufferSizeRequired)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
HBufC8* buffer = HBufC8::NewLC(aBufferSizeRequired);
|
sl@0
|
118 |
TPtr8 pBuffer(buffer->Des());
|
sl@0
|
119 |
//
|
sl@0
|
120 |
User::LeaveIfError(iClient.Session().Send(ELogViewFetchChanges, TIpcArgs(iViewId,aBufferSizeRequired,&pBuffer)));
|
sl@0
|
121 |
//
|
sl@0
|
122 |
iChanges->Reset();
|
sl@0
|
123 |
RDesReadStream stream(*buffer);
|
sl@0
|
124 |
stream >> *iChanges;
|
sl@0
|
125 |
CleanupStack::PopAndDestroy(buffer);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
void CLogViewObserver::NotifyObserverL()
|
sl@0
|
129 |
{
|
sl@0
|
130 |
TLogId id;
|
sl@0
|
131 |
TInt viewIndex;
|
sl@0
|
132 |
|
sl@0
|
133 |
// Copy the changes
|
sl@0
|
134 |
const TInt count = iChanges->Count();
|
sl@0
|
135 |
if (!count)
|
sl@0
|
136 |
return;
|
sl@0
|
137 |
//
|
sl@0
|
138 |
CLogChangeDefinition* changes = CLogChangeDefinition::NewL(*iChanges);
|
sl@0
|
139 |
CleanupStack::PushL(changes);
|
sl@0
|
140 |
iChanges->Reset();
|
sl@0
|
141 |
//
|
sl@0
|
142 |
for(TInt i=0; i<count; i++)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
const TLogDatabaseChangeType type = changes->At(i, id, viewIndex);
|
sl@0
|
145 |
//
|
sl@0
|
146 |
switch(type)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
case ELogChangeTypeEventAdded:
|
sl@0
|
149 |
iObserver.HandleLogViewChangeEventAddedL(id, viewIndex, i, count);
|
sl@0
|
150 |
break;
|
sl@0
|
151 |
case ELogChangeTypeEventChanged:
|
sl@0
|
152 |
iObserver.HandleLogViewChangeEventChangedL(id, viewIndex, i, count);
|
sl@0
|
153 |
break;
|
sl@0
|
154 |
case ELogChangeTypeEventDeleted:
|
sl@0
|
155 |
iObserver.HandleLogViewChangeEventDeletedL(id, viewIndex, i, count);
|
sl@0
|
156 |
break;
|
sl@0
|
157 |
case ELogChangeTypeLogCleared:
|
sl@0
|
158 |
iObserver.HandleLogViewChangeEventLogClearedL();
|
sl@0
|
159 |
break;
|
sl@0
|
160 |
default:
|
sl@0
|
161 |
case ELogChangeTypeUndefined:
|
sl@0
|
162 |
__ASSERT_DEBUG(EFalse, Panic(ELogUnexpectedChangeType));
|
sl@0
|
163 |
}
|
sl@0
|
164 |
}
|
sl@0
|
165 |
CleanupStack::PopAndDestroy(changes);
|
sl@0
|
166 |
}
|