LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <emscripten.h> | 18 #include <emscripten.h> |
19 | 19 |
20 #include "FilterNotifier.h" | 20 #include "FilterNotifier.h" |
21 | 21 |
22 namespace | 22 void FilterNotifier::FilterChange(Topic topic, Filter* filter) |
23 { | 23 { |
24 enum class ArgType | 24 EM_ASM_ARGS({ |
25 { | 25 FilterNotifier.triggerListeners(notifierTopics.get($0), |
26 BOOL = 0, | 26 exports.Filter.fromPointer($1)); |
27 INT = 1, | 27 }, topic, filter); |
28 INT64 = 2, | |
29 STRING = 3, | |
30 }; | |
31 | |
32 template<typename T> | |
33 void NotifyPropertyChange(FilterNotifier::Topic topic, void* object, | |
34 T newValue, T oldValue, ArgType type) | |
35 { | |
36 EM_ASM_ARGS({ | |
37 var topic = notifierTopics.get($0); | |
38 var object = topic.startsWith("subscription.") ? | |
39 exports.Subscription.fromPointer($1) : | |
40 exports.Filter.fromPointer($1); | |
41 var newValue; | |
42 var oldValue; | |
43 if ($4 == 0) | |
44 { | |
45 newValue = $2 != 0; | |
46 oldValue = $3 != 0; | |
47 } | |
48 else if ($4 == 3) | |
49 { | |
50 newValue = readString($2); | |
51 oldValue = readString($3); | |
52 } | |
53 else | |
54 { | |
55 newValue = $2; | |
56 oldValue = $3; | |
57 } | |
58 FilterNotifier.triggerListeners(topic, object, newValue, oldValue); | |
59 }, topic, object, (sizeof(T) <= 4 ? newValue : (double)newValue), | |
60 (sizeof(T) <= 4 ? oldValue : (double)oldValue), type); | |
61 } | |
62 | |
63 template void NotifyPropertyChange<int>(FilterNotifier::Topic, void*, | |
64 int, int, ArgType); | |
65 | |
66 template void NotifyPropertyChange<double>(FilterNotifier::Topic, void*, | |
67 double, double, ArgType); | |
68 } | 28 } |
69 | 29 |
70 namespace FilterNotifier | 30 void FilterNotifier::SubscriptionChange(Topic topic, Subscription* subscription) |
71 { | 31 { |
72 void PropertyChange(Topic topic, void* object, bool newValue, bool oldValue) | 32 EM_ASM_ARGS({ |
73 { | 33 FilterNotifier.triggerListeners(notifierTopics.get($0), |
74 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::BOOL); | 34 exports.Subscription.fromPointer($1)); |
75 } | 35 }, topic, subscription); |
76 | |
77 void PropertyChange(Topic topic, void* object, int newValue, int oldValue) | |
78 { | |
79 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT); | |
80 } | |
81 | |
82 void PropertyChange(Topic topic, void* object, unsigned int newValue, | |
83 unsigned int oldValue) | |
84 { | |
85 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT); | |
86 } | |
87 | |
88 void PropertyChange(Topic topic, void* object, uint64_t newValue, | |
89 uint64_t oldValue) | |
90 { | |
91 NotifyPropertyChange<uint64_t>(topic, object, newValue, oldValue, | |
92 ArgType::INT64); | |
93 } | |
94 | |
95 void PropertyChange(Topic topic, void* object, const String& newValue, | |
96 const String& oldValue) | |
97 { | |
98 NotifyPropertyChange<int>(topic, object, reinterpret_cast<int>(&newValue), | |
99 reinterpret_cast<int>(&oldValue), ArgType::STRING)
; | |
100 } | |
101 } | 36 } |
LEFT | RIGHT |