|
1 // btrace_domainevent.cpp |
|
2 // |
|
3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include "btrace_parser.h" |
|
14 |
|
15 EXPORT_C CBtraceDomainEvent* CBtraceDomainEvent::NewL(CBtraceReader& aReader) |
|
16 { |
|
17 CBtraceDomainEvent* self = new (ELeave) CBtraceDomainEvent(aReader); |
|
18 CleanupStack::PushL(self); |
|
19 self->ConstructL(); |
|
20 CleanupStack::Pop(self); |
|
21 return self; |
|
22 } |
|
23 |
|
24 CBtraceDomainEvent::CBtraceDomainEvent(CBtraceReader& aReader) |
|
25 : iReader(aReader) |
|
26 { |
|
27 } |
|
28 |
|
29 EXPORT_C CBtraceDomainEvent::~CBtraceDomainEvent() |
|
30 { |
|
31 iReader.RemoveObserver(KAmTraceCategory, *this); |
|
32 iNotifs.Close(); |
|
33 } |
|
34 |
|
35 void CBtraceDomainEvent::ConstructL() |
|
36 { |
|
37 iReader.AddObserverL(KAmTraceCategory, *this); |
|
38 } |
|
39 |
|
40 EXPORT_C void CBtraceDomainEvent::NotifyDomainEventL(TUint aSubCategory, MBtraceDomainEventObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
41 { |
|
42 TDomainEventNotif notif(aSubCategory, aObserver, aPersistence); |
|
43 iNotifs.AppendL(notif); |
|
44 } |
|
45 |
|
46 EXPORT_C void CBtraceDomainEvent::NotifyDomainEventL(TUint aSubCategory, TUint aData1, MBtraceDomainEventObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
47 { |
|
48 TDomainEventNotif notif(aSubCategory, aObserver, aPersistence); |
|
49 notif.AddDataItem(aData1); |
|
50 iNotifs.AppendL(notif); |
|
51 } |
|
52 |
|
53 EXPORT_C void CBtraceDomainEvent::NotifyDomainEventL(TUint aSubCategory, TUint aData1, TUint aData2, MBtraceDomainEventObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
54 { |
|
55 TDomainEventNotif notif(aSubCategory, aObserver, aPersistence); |
|
56 notif.AddDataItem(aData1); |
|
57 notif.AddDataItem(aData2); |
|
58 iNotifs.AppendL(notif); |
|
59 } |
|
60 |
|
61 EXPORT_C void CBtraceDomainEvent::NotifyDomainEventL(TUint aSubCategory, TUint aData1, TUint aData2, TUint aData3, MBtraceDomainEventObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
62 { |
|
63 TDomainEventNotif notif(aSubCategory, aObserver, aPersistence); |
|
64 notif.AddDataItem(aData1); |
|
65 notif.AddDataItem(aData2); |
|
66 notif.AddDataItem(aData3); |
|
67 iNotifs.AppendL(notif); |
|
68 } |
|
69 |
|
70 EXPORT_C void CBtraceDomainEvent::CancelNotifyDomainEvent(MBtraceDomainEventObserver& aObserver) |
|
71 { |
|
72 for (TInt i = (iNotifs.Count() - 1); i >= 0; --i) |
|
73 { |
|
74 const TDomainEventNotif& thisNotif = iNotifs[i]; |
|
75 if (thisNotif.iObserver == &aObserver) |
|
76 { |
|
77 iNotifs.Remove(i); |
|
78 } |
|
79 } |
|
80 } |
|
81 |
|
82 void CBtraceDomainEvent::HandleBtraceFrameL(const TBtraceFrame& aFrame) |
|
83 { |
|
84 if (aFrame.iCategory == KAmTraceCategory && aFrame.iSubCategory > EAmTraceSubCategoryDomainEventBase) |
|
85 { |
|
86 const TInt numDataItems = (aFrame.iData.Length() / sizeof(TUint)); |
|
87 if (numDataItems <= TDomainEventNotif::KMaxNumDataItems) |
|
88 { |
|
89 const TUint* data = reinterpret_cast<const TUint*>(aFrame.iData.Ptr()); |
|
90 TDomainEventNotif notif(aFrame.iSubCategory); |
|
91 for (TInt i = 0; i < numDataItems; ++i) |
|
92 { |
|
93 notif.AddDataItem(*(data + i)); |
|
94 } |
|
95 |
|
96 for (TInt i = (iNotifs.Count() - 1); i >= 0; --i) |
|
97 { |
|
98 const TDomainEventNotif& thisNotif = iNotifs[i]; |
|
99 if (thisNotif == notif) |
|
100 { |
|
101 MBtraceDomainEventObserver* observer = thisNotif.iObserver; |
|
102 if (thisNotif.iPersistence == ENotificationOneShot) |
|
103 { |
|
104 iNotifs.Remove(i); |
|
105 } |
|
106 observer->HandleDomainEventL(aFrame.iTickCount, *observer); |
|
107 } |
|
108 } |
|
109 } |
|
110 } |
|
111 } |
|
112 |
|
113 CBtraceDomainEvent::TDomainEventNotif::TDomainEventNotif(TUint aSubCategory) |
|
114 : iSubCategory(aSubCategory), iObserver(NULL), iPersistence(ENotificationOneShot), iDataCount(0) |
|
115 { |
|
116 } |
|
117 |
|
118 CBtraceDomainEvent::TDomainEventNotif::TDomainEventNotif(TUint aSubCategory, MBtraceDomainEventObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
119 : iSubCategory(aSubCategory), iObserver(&aObserver), iPersistence(aPersistence), iDataCount(0) |
|
120 { |
|
121 } |
|
122 |
|
123 void CBtraceDomainEvent::TDomainEventNotif::AddDataItem(TUint aData) |
|
124 { |
|
125 __ASSERT_ALWAYS(iDataCount < KMaxNumDataItems, Panic(EBtpPanicTooManyDomainEventDataItems)); |
|
126 iData[iDataCount++] = aData; |
|
127 } |
|
128 |
|
129 TBool CBtraceDomainEvent::TDomainEventNotif::operator==(const TDomainEventNotif& aNotif) const |
|
130 { |
|
131 if ((aNotif.iSubCategory == iSubCategory) && (aNotif.iDataCount == iDataCount)) |
|
132 { |
|
133 for (TInt i = 0; i < iDataCount; ++i) |
|
134 { |
|
135 if (aNotif.iData[i] != iData[i]) |
|
136 { |
|
137 return EFalse; |
|
138 } |
|
139 } |
|
140 return ETrue; |
|
141 } |
|
142 else |
|
143 { |
|
144 return EFalse; |
|
145 } |
|
146 } |
|
147 |