Update contrib.
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.
21 #include "logclipanic.h"
22 #include "logservcli.h"
23 #include "logpackage.h"
24 #include "logclientop.h"
25 #include "LogViewObserver.h"
26 #include "LogViewWindow.h"
29 const TInt KLogDefaultWindowSize = 10;
31 //**********************************
33 //**********************************
35 CLogView::CLogView(CLogClient& aClient, TInt aPriority/* = CActive:EPriorityStandard*/)
36 : CLogActive(aPriority), iClient(aClient)
39 iViewId = iClient.Session().AllocateIdView();
42 EXPORT_C CLogView::~CLogView()
43 /** Frees all resources owned by this object prior to its destruction. In particular,
44 any outstanding asynchronous request is cancelled. */
51 delete iLogViewObserver;
55 iClient.Session().Send(ELogViewDelete, TIpcArgs(iViewId)); // Not much we can do if this goes wrong
58 void CLogView::ConstructL(TInt aType, MLogViewChangeObserver* aObserver)
61 iLogViewChangeObserver = aObserver;
62 iPackage = CLogPackage::NewL();
63 iEvent = CLogEvent::NewL();
64 iMaintain = new(ELeave)CLogMaintainClientOp(iClient.Session(), *iPackage, Priority());
66 PrepareViewChildrenL();
69 void CLogView::NotifyLogServerTerminatedL()
71 PrepareViewChildrenL();
74 void CLogView::PrepareViewChildrenL()
76 // Construct the view in the server
78 aArgs.Set(0, iViewId);
81 User::LeaveIfError(iClient.Session().Send(ELogViewCreate, aArgs));
82 CLogViewWindow* window = new(ELeave)
83 CLogViewWindow(iClient.Session(), iViewId, KLogDefaultWindowSize,
84 iLogViewChangeObserver, CActive::EPriorityIdle);
88 iWindow->ConstructL(*iPackage);
90 // The Log view observer receives all events from the log server. It then cascades them to an object owned by
91 // the log window. In turn this object (CLogViewWindowChangeObserver) cascades them back to the log window.
92 // Finally, the log window passes them back up to the client of the log engine, i.e aObserver.
93 CLogViewObserver* observer = CLogViewObserver::NewL(*this, iClient, iWindow->ChangeObserver(), iViewId, Priority());
94 delete iLogViewObserver;
95 iLogViewObserver = observer;
98 EXPORT_C TBool CLogView::FirstL(TRequestStatus& aStatus)
99 /** Moves the current position in the view to the first event. The first event
100 is the most recent event.
102 This is an asynchronous request.
104 @param aStatus The request status. On request completion, contains:KErrNone,
105 if the position in the view has been successfully moved; otherwise, one of
106 the other system wide error codes.
107 @return ETrue, if the function has successfully issued the asynchronous request.
108 EFalse, if there are no events in the view. */
110 return NavigateL(ELogNavigateFirst, aStatus);
113 EXPORT_C TBool CLogView::LastL(TRequestStatus& aStatus)
114 /** Moves the current position in the view to the last event. The last event is
117 This is an asynchronous request.
119 @param aStatus The request status. On request completion, contains:KErrNone,
120 if the position in the view has been successfully moved; otherwise, one of
121 the other system wide error codes.
122 @return ETrue, if the function has successfully issued the asynchronous request.
123 EFalse, if there are no events in the view. */
125 return NavigateL(ELogNavigateLast, aStatus);
128 EXPORT_C TBool CLogView::NextL(TRequestStatus& aStatus)
129 /** Moves the current position in the view to the next event. The next event is
130 always older than the current event, i.e. next implies movement in the first
133 @param aStatus The request status. On request completion, contains:KErrNone,
134 if the position in the view has been successfully moved; otherwise, one of
135 the other system wide error codes.
136 @return ETrue, if the function has successfully issued the asynchronous request.
137 EFalse, if there are no events in the view. */
139 return NavigateL(ELogNavigateForwards, aStatus);
142 EXPORT_C TBool CLogView::PreviousL(TRequestStatus& aStatus)
143 /** Moves the current position in the view to the previous event. The previous
144 event is always more recent than the current event, i.e. previous implies
145 movement in the last to first direction.
147 @param aStatus The request status. On request completion, contains:KErrNone,
148 if the position in the view has been successfully moved; otherwise, one of
149 the other system wide error codes.
150 @return ETrue, if the function has successfully issued the asynchronous request.
151 EFalse, if there are no events in the view. */
153 return NavigateL(ELogNavigateBackwards, aStatus);
156 EXPORT_C TInt CLogView::CountL()
157 /** Gets the number of events in the view.
159 @return The number of events in the view. */
161 // Just return zero if the view isn't setup
162 if (!IsValid() && !LogViewRecordCount())
167 // Ask the server the number of events in this view
168 const TInt count = iClient.Session().Send(ELogViewCount, TIpcArgs(iViewId));
170 User::LeaveIfError(count);
174 EXPORT_C void CLogView::SetFlagsL(TLogFlags aFlags)
176 @capability Note For built-in event types, the required capability level is defined in
177 the event type's write access policy. */
179 // To preserve the same server side interface as an operation
180 TPckgBuf<TLogClientServerData> data;
181 data().iOperationType = ELogOperationViewSetFlags;
182 data().iOperationId = KLogNullOperationId;
184 User::LeaveIfError(iClient.Session().Send(ELogViewOperationInitiate, TIpcArgs(&data,iViewId,aFlags)));
187 TBool CLogView::NavigateL(TInt aPosition, TRequestStatus& aStatus)
189 __ASSERT_ALWAYS(!IsActive(), Panic(ELogAlreadyActive1));
190 if (!IsValid() && !LogViewRecordCount())
195 const TLogNavigation navigationPosition = static_cast<TLogNavigation>(aPosition);
196 const TBool requestIssued = iWindow->NavigateL(navigationPosition, iStatus);
202 // iValid is false if at time of SetFilterL there is no event.
203 // If iWindow->NavigateL returns ETrue then there are always
204 // events in the view.
208 return requestIssued;
211 void CLogView::DoRunL()
213 if (iStatus.Int() == KErrNone)
214 ReadEventFromWindowL();
217 void CLogView::DoCancel()
220 CLogActive::DoCancel();
223 void CLogView::ReadEventFromWindowL()
225 CLogEvent* event = CLogEvent::NewL();
228 iEvent->CopyL(iWindow->CurrsorEvent());
231 void CLogView::ReawaitForChanges()
233 iLogViewObserver->Cancel();
234 iLogViewObserver->RequestChanges();
238 // The CLogViewWindow member has an observer to receive changes
239 // in events. If events are added to database after SetFilterL then
240 // iWindow would know about them.
241 TInt CLogView::LogViewRecordCount() const
245 return iWindow->ViewRecordCount();
265 //**********************************
267 //**********************************
269 CLogViewEvent::CLogViewEvent(CLogClient& aClient, TInt aPriority)
270 : CLogView(aClient, aPriority)
274 EXPORT_C CLogViewEvent::~CLogViewEvent()
275 /** Frees all resources owned by the object prior to its destruction. In particular,
276 any outstanding asynchronous request is cancelled */
281 void CLogViewEvent::ConstructL(MLogViewChangeObserver* aObserver)
283 CLogView::ConstructL(ELogViewTypeEvent, aObserver);
286 EXPORT_C CLogViewEvent* CLogViewEvent::NewL(CLogClient& aClient, TInt aPriority)
288 CLogViewEvent* self = new(ELeave)CLogViewEvent(aClient, aPriority);
289 CleanupStack::PushL(self);
291 CleanupStack::Pop(self);
295 EXPORT_C CLogViewEvent* CLogViewEvent::NewL(CLogClient& aClient, MLogViewChangeObserver& aObserver, TInt aPriority)
297 CLogViewEvent* self = new(ELeave)CLogViewEvent(aClient, aPriority);
298 CleanupStack::PushL(self);
299 self->ConstructL(&aObserver);
300 CleanupStack::Pop(self);
304 EXPORT_C TBool CLogViewEvent::SetFilterL(const CLogFilter& aFilter, TRequestStatus& aStatus)
305 /** Initialises or refreshes the event view defined by the specified filter.
307 The view can only be used after the request completes successfully.
309 @param aFilter The filter.
310 @param aStatus The request status. On request completion, contains:KErrNone,
311 if the view has been successfully initialised or refreshed;one of the other
312 system wide error codes, otherwise.
313 @return ETrue, if the function has successfully issued the asynchronous request.
314 EFalse, if there are no events in the view.
315 @capability Note None required.*/
317 CLogFilterList* list = new(ELeave)CLogFilterList;
318 CleanupStack::PushL(list);
319 list->AppendL(&aFilter);
320 TBool result = SetFilterL(*list, aStatus);
321 CleanupStack::PopAndDestroy(); // list
325 EXPORT_C TBool CLogViewEvent::SetFilterL(const CLogFilterList& aFilterList, TRequestStatus& aStatus)
326 /** Initialises or refreshes the event view defined by the set of specified filters.
328 The view can only be used after the request completes successfully.
330 @param aFilterList The set of filters.
331 @param aStatus The request status. On request completion, contains:KErrNone,
332 if the view has been successfully initialised or refreshed;one of the other
333 system wide error codes, otherwise.
334 @return ETrue, if the function has successfully issued the asynchronous request.
335 EFalse, if there are no events in the view.
336 @capability Note None required. */
338 // Start maintenance of the database - ignore errors
341 // Package the parameters
342 iPackage->SetLogFilterListL(aFilterList);
345 const TInt count = iWindow->Setup(aFilterList, 0, ELogFilterConstructFilterByFilterFieldByField);
346 User::LeaveIfError(count);
352 // Get the required event
353 iValid = FirstL(aStatus);
359 EXPORT_C TBool CLogViewEvent::SetFilterParseFilterByFilterL(const CLogFilterList& aFilterList, TRequestStatus& aStatus)
361 @capability Note None required. */
363 // Start maintenance of the database - ignore errors
366 // Package the parameters
367 iPackage->SetLogFilterListL(aFilterList);
370 const TInt count = iWindow->Setup(aFilterList, 0, ELogFilterConstructFieldByFieldFilterByFilter);
371 User::LeaveIfError(count);
377 // Get the required event
378 iValid = FirstL(aStatus);
406 //**********************************
408 //**********************************
410 CLogViewRecent::CLogViewRecent(CLogClient& aClient, TInt aPriority)
411 : CLogView(aClient, aPriority)
415 EXPORT_C CLogViewRecent::~CLogViewRecent()
416 /** Frees resources owned by the object priot to its destruction. */
422 void CLogViewRecent::ConstructL(MLogViewChangeObserver* aObserver)
424 // Construct the view
425 CLogView::ConstructL(ELogViewTypeRecent, aObserver);
427 iRemove = new(ELeave) CLogViewRemoveEventClientOp(iClient.Session(), *iPackage, Priority());
430 EXPORT_C CLogViewRecent* CLogViewRecent::NewL(CLogClient& aClient, TInt aPriority)
432 CLogViewRecent* self = new(ELeave) CLogViewRecent(aClient, aPriority);
433 CleanupStack::PushL(self);
435 CleanupStack::Pop(); // self
439 EXPORT_C CLogViewRecent* CLogViewRecent::NewL(CLogClient& aClient, MLogViewChangeObserver& aObserver, TInt aPriority)
441 CLogViewRecent* self = new(ELeave) CLogViewRecent(aClient, aPriority);
442 CleanupStack::PushL(self);
443 self->ConstructL(&aObserver);
444 CleanupStack::Pop(self);
448 EXPORT_C TBool CLogViewRecent::SetRecentListL(TLogRecentList aList, TRequestStatus& aStatus)
449 /** Initialises or refreshes the view for the specified recent event list. This
450 is an asynchronous request.
452 On successful completion, the view is positioned at the first, i.e. most recent,
453 event within the recent event list.
455 @param aList The recent event list specifier. A value of KLogNullRecentList
456 indicates that the view is to include events from all of the recent event
458 @param aStatus The request status. On request completion, contains:KErrNone,
459 if the view has been successfully initialised or refreshed; otherwise, one
460 of the other system wide error codes.
461 @return ETrue, if the function has successfully issued the asynchronous request.
462 EFalse, if there are no events in the view.
463 @capability Note None required. */
465 CLogFilter* filter = CLogFilter::NewL();
466 CleanupStack::PushL(filter);
467 TBool result = SetRecentListL(aList, *filter, aStatus);
468 CleanupStack::PopAndDestroy(); // filter
472 EXPORT_C TBool CLogViewRecent::SetRecentListL(TLogRecentList aList, const CLogFilter& aFilter, TRequestStatus& aStatus)
473 /** Initialises or refreshes the view for the specified recent event list, conforming
474 to the specified filter. This is an asynchronous request.
476 On successful completion, the view is positioned at the first, i.e. most recent,
477 event in the recent event list.
479 @param aList The recent event list specifier. A value of KLogNullRecentList
480 indicates that the view is to include events from all of the recent event
482 @param aFilter The filter.
483 @param aStatus The request status. On request completion, contains:KErrNone,
484 if the view has been successfully initialised or refreshed; otherwise, one
485 of the other system wide error codes.
486 @return ETrue, if the function has successfully issued the asynchronous request.
487 EFalse, if there are no events in the view.
488 @capability Note None required. */
490 CLogFilterList* list = new(ELeave)CLogFilterList;
491 CleanupStack::PushL(list);
492 list->AppendL(&aFilter);
493 TBool result = SetRecentListL(aList, *list, aStatus);
494 CleanupStack::PopAndDestroy(); // list
498 EXPORT_C TBool CLogViewRecent::SetRecentListL(TLogRecentList aList, const CLogFilterList& aFilterList, TRequestStatus& aStatus)
499 /** Initialises or refreshes the view for the specified recent event list, conforming
500 to the set of specified filters. This is an asynchronous request.
502 On successful completion, the view is positioned at the first, i.e. most recent,
503 event in the recent event list.
505 @param aList The recent event list specifier. A value of KLogNullRecentList
506 indicates that the view is to include events from all of the recent event
508 @param aFilterList The set of filters.
509 @param aStatus The request status. On request completion, contains:KErrNone,
510 if the view has been successfully initialised or refreshed; otherwise, one
511 of the other system wide error codes.
512 @return ETrue, if the function has successfully issued the asynchronous request.
513 EFalse, if there are no events in the view.
514 @capability Note None required. */
516 // Start maintenance of the database - ignore errors
519 // Package the parameters
520 iPackage->SetLogFilterListL(aFilterList);
523 TInt count = iWindow->Setup(aFilterList, aList, ELogFilterConstructFilterByFilterFieldByField);
524 User::LeaveIfError(count);
528 // Initialise list ids
530 iCurrentList = aList;
532 // This receives the current recent list id from the server
533 iCurrentListBuf() = iCurrentList;
534 iData = &iCurrentListBuf;
538 // Get the required event
539 iValid = FirstL(aStatus);
545 EXPORT_C void CLogViewRecent::RemoveL(TLogId aId)
546 /** Removes the event with the specified unique event ID from the view. This does
547 not delete the event from the main event log.
549 @param aId The unique event ID.
550 @capability WriteDeviceData */
552 User::LeaveIfError(iRemove->Start(iViewId, aId));
553 iWindow->RemoveFromWindowIfPresentL(aId);
556 EXPORT_C TBool CLogViewRecent::RemoveL(TRequestStatus& aStatus)
557 /** Removes the current event from its recent event list. This is an asynchronous
560 This does not delete the event from the main event log.
562 The function moves the current position in the view to the first, i.e. most
565 Note that removing a recent event from a recent event list also removes all
568 @param aStatus The request status. On request completion, contains:KErrNone,
569 if the view has been successfully initialised or refreshed; otherwise, one
570 of the other system wide error codes.
571 @return ETrue, if the function has successfully issued the asynchronous request.
572 EFalse, if there are no events in the view.
573 @capability WriteDeviceData */
575 __ASSERT_DEBUG(IsValid(), Panic(ELogNotValid1));
576 RemoveL(Event().Id());
577 return FirstL(aStatus);
580 EXPORT_C TBool CLogViewRecent::DuplicatesL(CLogViewDuplicate& aView, TRequestStatus& aStatus)
581 /** Refreshes the specified duplicate event view with the duplicates of the current
582 event in the recent event list view. This is an asynchronous request.
584 On successful completion, the view is positioned at the first, i.e. most recent,
585 event within the view.
587 @param aView The duplicates view to be refreshed.
588 @param aStatus The request status. On request completion, contains:KErrNone,
589 if the view has been successfully refreshed; otherwise, one of the other system
591 @return ETrue, if the function has successfully issued the asynchronous request.
592 EFalse, if there are no events in the view.
593 @capability Note None required. */
595 __ASSERT_ALWAYS(!IsActive(), Panic(ELogAlreadyActive5));
596 return IsValid() && aView.SetEventL(Event().Id(), aStatus);
599 EXPORT_C TBool CLogViewRecent::DuplicatesL(CLogViewDuplicate& aView, const CLogFilter& aFilter, TRequestStatus& aStatus)
600 /** Refreshes the specified duplicate event view with the duplicates of the current
601 event in the recent event list view and conforming to the specified filter.
602 This is an asynchronous request.
604 On successful completion, the view is positioned at the first, i.e. most recent,
605 event within the view.
607 @param aView The duplicates view to be refreshed.
608 @param aFilter The filter.
609 @param aStatus The request status. On request completion, contains:KErrNone,
610 if the view has been successfully refreshed; otherwise, one of the other system
612 @return ETrue, if the function has successfully issued the asynchronous request.
613 EFalse, if there are no events in the view.
614 @capability Note None required.*/
616 __ASSERT_ALWAYS(!IsActive(), Panic(ELogAlreadyActive6));
617 return IsValid() && aView.SetEventL(Event().Id(), aFilter, aStatus);
620 EXPORT_C TBool CLogViewRecent::DuplicatesL(CLogViewDuplicate& aView, const CLogFilterList& aFilterList, TRequestStatus& aStatus)
621 /** Refreshes the specified duplicate event view with the duplicates of the current
622 event in the recent event list view and conforming to the set of specified
623 filters. This is an asynchronous request.
625 On successful completion, the view is positioned at the first, i.e. most recent,
626 event within the view.
628 @param aView The duplicates view to be refreshed.
629 @param aFilterList The set of filters.
630 @param aStatus The request status. On request completion, contains:KErrNone,
631 if the view has been successfully refreshed; otherwise, one of the other system
633 @return ETrue, if the function has successfully issued the asynchronous request.
634 EFalse, if there are no events in the view.
635 @capability Note None required.*/
637 __ASSERT_ALWAYS(!IsActive(), Panic(ELogAlreadyActive7));
638 return IsValid() && aView.SetEventL(Event().Id(), aFilterList, aStatus);
641 EXPORT_C void CLogViewRecent::ClearDuplicatesL()
643 @capability WriteDeviceData */
645 __ASSERT_DEBUG(IsValid(), Panic(ELogNotValid3));
647 // To preserve the same server side interface as an operation
648 TPckgBuf<TLogClientServerData> data;
649 data().iOperationType = ELogOperationViewClearDuplicates;
650 data().iOperationId = KLogNullOperationId;
652 User::LeaveIfError(iClient.Session().Send(ELogViewOperationInitiate, TIpcArgs(&data,iViewId)));
655 void CLogViewRecent::DoRunL()
657 // To fetch the event
658 ReadEventFromWindowL();
660 // A fix to maintain source compatibility
661 iCurrentList = iCurrentListBuf();
681 //**********************************
683 //**********************************
685 CLogViewDuplicate::CLogViewDuplicate(CLogClient& aClient, TInt aPriority)
686 : CLogView(aClient, aPriority)
690 EXPORT_C CLogViewDuplicate::~CLogViewDuplicate()
696 void CLogViewDuplicate::ConstructL(MLogViewChangeObserver* aObserver)
698 CLogView::ConstructL(ELogViewTypeDuplicate, aObserver);
700 iRemove = new(ELeave) CLogViewRemoveEventClientOp(iClient.Session(), *iPackage, Priority());
703 EXPORT_C CLogViewDuplicate* CLogViewDuplicate::NewL(CLogClient& aClient, TInt aPriority)
705 CLogViewDuplicate* self = new(ELeave)CLogViewDuplicate(aClient, aPriority);
706 CleanupStack::PushL(self);
712 EXPORT_C CLogViewDuplicate* CLogViewDuplicate::NewL(CLogClient& aClient, MLogViewChangeObserver& aObserver, TInt aPriority)
714 CLogViewDuplicate* self = new(ELeave) CLogViewDuplicate(aClient, aPriority);
715 CleanupStack::PushL(self);
716 self->ConstructL(&aObserver);
717 CleanupStack::Pop(self);
721 TBool CLogViewDuplicate::SetEventL(TLogId aId, TRequestStatus& aStatus)
723 CLogFilter* filter = CLogFilter::NewL();
724 CleanupStack::PushL(filter);
725 TBool result = SetEventL(aId, *filter, aStatus);
726 CleanupStack::PopAndDestroy(); // filter
730 TBool CLogViewDuplicate::SetEventL(TLogId aId, const CLogFilter& aFilter, TRequestStatus& aStatus)
732 CLogFilterList* list = new(ELeave)CLogFilterList;
733 CleanupStack::PushL(list);
734 list->AppendL(&aFilter);
735 TBool result = SetEventL(aId, *list, aStatus);
736 CleanupStack::PopAndDestroy(); // list
740 TBool CLogViewDuplicate::SetEventL(TLogId aId, const CLogFilterList& aFilterList, TRequestStatus& aStatus)
742 // Start maintenance of the database - ignore errors
745 // Package the parameters
746 iPackage->SetLogFilterListL(aFilterList);
749 TInt count = iWindow->Setup(aFilterList, aId, ELogFilterConstructFilterByFilterFieldByField);
750 User::LeaveIfError(count);
757 // Get the required event
758 iValid = FirstL(aStatus);
764 EXPORT_C void CLogViewDuplicate::RemoveL(TLogId aId)
765 /** Removes the event with the specified unique event ID from the view. This does
766 not delete the event from the main event log.
768 @param aId The unique event ID.
769 @capability WriteDeviceData */
771 // Note: Duplicate views reset themselves
772 __ASSERT_DEBUG(IsValid(), Panic(ELogNotValid2));
773 User::LeaveIfError(iRemove->Start(iViewId, aId));
774 iWindow->RemoveFromWindowIfPresentL(aId);
777 EXPORT_C TBool CLogViewDuplicate::RemoveL(TRequestStatus& aStatus)
778 /** Removes the current event from the duplicate list. This is an asynchronous
781 This does not delete the event from the main event log.
783 The function moves the current position in the view to the first, i.e. most
786 @param aStatus The request status. On request completion, contains: KErrNone,
787 if the view has been successfully initialised or refreshed; otherwise, one
788 of the other system wide error codes.
789 @return ETrue, if the function has successfully issued the asynchronous request.
790 EFalse, if there are no events in the view.
791 @capability WriteDeviceData */
793 RemoveL(Event().Id());
794 return FirstL(aStatus);