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