|
1 // btrace_pubsub.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 CBtracePubSub* CBtracePubSub::NewL(CBtraceReader& aReader) |
|
16 { |
|
17 CBtracePubSub* self = new(ELeave) CBtracePubSub(aReader); |
|
18 CleanupStack::PushL(self); |
|
19 self->ConstructL(); |
|
20 CleanupStack::Pop(self); |
|
21 return self; |
|
22 } |
|
23 |
|
24 CBtracePubSub::CBtracePubSub(CBtraceReader& aReader) |
|
25 : iReader(aReader) |
|
26 { |
|
27 } |
|
28 |
|
29 EXPORT_C CBtracePubSub::~CBtracePubSub() |
|
30 { |
|
31 iNotifs.Close(); |
|
32 iReader.RemoveObserver(ExtraBTrace::EPubSub, *this); |
|
33 } |
|
34 |
|
35 void CBtracePubSub::ConstructL() |
|
36 { |
|
37 iReader.AddObserverL(ExtraBTrace::EPubSub, *this); |
|
38 } |
|
39 |
|
40 EXPORT_C void CBtracePubSub::NotifyPropertyChangedL(MBtracePubSubObserver& aObserver) |
|
41 { |
|
42 iNotifs.AppendL(TPubSubNotif(NULL, NULL, NULL, NULL, aObserver, ENotificationOneShot)); |
|
43 } |
|
44 |
|
45 EXPORT_C void CBtracePubSub::NotifyPropertyChangedL(TUint* aCategory, TUint* aKey, MBtracePubSubObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
46 { |
|
47 iNotifs.AppendL(TPubSubNotif(aCategory, aKey, NULL, NULL, aObserver, aPersistence)); |
|
48 } |
|
49 |
|
50 EXPORT_C void CBtracePubSub::NotifyIntegerPropertyChangedL(TUint* aCategory, TUint* aKey, TInt* aValue, MBtracePubSubObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
51 { |
|
52 iNotifs.AppendL(TPubSubNotif(aCategory, aKey, aValue, NULL, aObserver, aPersistence)); |
|
53 } |
|
54 |
|
55 EXPORT_C void CBtracePubSub::NotifyDataPropertyChangedL(TUint* aCategory, TUint* aKey, const TDesC8* aValue, MBtracePubSubObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
56 { |
|
57 iNotifs.AppendL(TPubSubNotif(aCategory, aKey, NULL, aValue, aObserver, aPersistence)); |
|
58 } |
|
59 |
|
60 EXPORT_C void CBtracePubSub::CancelNotifyPropertyChanged(MBtracePubSubObserver& aObserver) |
|
61 { |
|
62 for (TInt i = (iNotifs.Count() - 1); i >= 0; --i) |
|
63 { |
|
64 if (&iNotifs[i].iObserver == &aObserver) |
|
65 { |
|
66 iNotifs.Remove(i); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 void CBtracePubSub::HandleBtraceFrameL(const TBtraceFrame& aFrame) |
|
72 { |
|
73 if (aFrame.iCategory != ExtraBTrace::EPubSub) return; |
|
74 |
|
75 const TUint8* data = aFrame.iData.Ptr(); |
|
76 TUint cat = *(TUint32*)data; |
|
77 TUint key = *((TUint32*)data + 1); |
|
78 |
|
79 switch (aFrame.iSubCategory) |
|
80 { |
|
81 case ExtraBTrace::EPubSubIntPropertyChanged: |
|
82 { |
|
83 TInt val = *((TUint32*)data + 2); |
|
84 for (TInt i = 0; i < iNotifs.Count(); i++) |
|
85 { |
|
86 if (iNotifs[i].Matches(cat, key, val)) |
|
87 { |
|
88 iNotifs[i].iObserver.HandlePropertyChangedL(aFrame.iTickCount, cat, key, val); |
|
89 } |
|
90 } |
|
91 break; |
|
92 } |
|
93 case ExtraBTrace::EPubSubDataPropertyChanged: |
|
94 { |
|
95 TPtrC8 val = aFrame.iData.Mid(8); |
|
96 for (TInt i = 0; i < iNotifs.Count(); i++) |
|
97 { |
|
98 if (iNotifs[i].Matches(cat, key, val)) |
|
99 { |
|
100 iNotifs[i].iObserver.HandlePropertyChangedL(aFrame.iTickCount, cat, key, val); |
|
101 } |
|
102 } |
|
103 break; |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 CBtracePubSub::TPubSubNotif::TPubSubNotif(TUint* aCategory, TUint* aKey, TInt* aIntegerValue, const TDesC8* aDataValue, MBtracePubSubObserver& aObserver, TBtraceNotificationPersistence aPersistence) |
|
109 : iCategory(aCategory), iKey(aKey), iIntegerValue(aIntegerValue), iDataValue(aDataValue), iObserver(aObserver), iPersistence(aPersistence) |
|
110 { |
|
111 __ASSERT_ALWAYS(!(iIntegerValue && iDataValue), Panic(EBtpPanicIncompatiblePubSubArgs)); |
|
112 } |
|
113 |
|
114 TBool CBtracePubSub::TPubSubNotif::Matches(TUint aCategory, TUint aKey, TInt aIntegerValue) const |
|
115 { |
|
116 if ((iCategory == NULL) || (*iCategory == aCategory)) |
|
117 { |
|
118 if ((iKey == NULL) || (*iKey == aKey)) |
|
119 { |
|
120 if (((iIntegerValue == NULL) && (iDataValue == NULL)) || (*iIntegerValue == aIntegerValue)) |
|
121 { |
|
122 return ETrue; |
|
123 } |
|
124 } |
|
125 } |
|
126 return EFalse; |
|
127 } |
|
128 |
|
129 TBool CBtracePubSub::TPubSubNotif::Matches(TUint aCategory, TUint aKey, const TDesC8& aDataValue) const |
|
130 { |
|
131 if ((iCategory == NULL) || (*iCategory == aCategory)) |
|
132 { |
|
133 if ((iKey == NULL) || (*iKey == aKey)) |
|
134 { |
|
135 if (((iIntegerValue == NULL) && (iDataValue == NULL)) || (*iDataValue == aDataValue)) |
|
136 { |
|
137 return ETrue; |
|
138 } |
|
139 } |
|
140 } |
|
141 return EFalse; |
|
142 } |