Index: compiled/FilterNotifier.cpp |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/compiled/FilterNotifier.cpp |
@@ -0,0 +1,99 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2017 eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+#include <emscripten.h> |
+ |
+#include "FilterNotifier.h" |
+ |
+namespace |
+{ |
+ enum class ArgType |
+ { |
+ BOOL = 0, |
+ INT = 1, |
+ DOUBLE = 2, |
+ STRING = 3, |
+ }; |
+ |
+ template<typename T> |
+ void NotifyPropertyChange(FilterNotifier::Topic topic, void* object, |
+ T newValue, T oldValue, ArgType type) |
+ { |
+ EM_ASM_ARGS({ |
+ var topic = notifierTopics.get($0); |
+ var object = topic.startsWith("subscription.") ? |
+ exports.Subscription.fromPointer($1) : |
+ exports.Filter.fromPointer($1); |
+ var newValue; |
+ var oldValue; |
+ if ($4 == 0) |
+ { |
+ newValue = $2 != 0; |
+ oldValue = $3 != 0; |
+ } |
+ else if ($4 == 3) |
+ { |
+ newValue = readString($2); |
+ oldValue = readString($3); |
+ } |
+ else |
+ { |
+ newValue = $2; |
+ oldValue = $3; |
+ } |
+ FilterNotifier.triggerListeners(topic, object, newValue, oldValue); |
+ }, topic, object, newValue, oldValue, type); |
+ } |
+ |
+ template void NotifyPropertyChange<int>(FilterNotifier::Topic, void*, |
+ int, int, ArgType); |
+ |
+ template void NotifyPropertyChange<double>(FilterNotifier::Topic, void*, |
+ double, double, ArgType); |
+} |
+ |
+namespace FilterNotifier |
+{ |
+ void PropertyChange(Topic topic, void* object, bool newValue, bool oldValue) |
+ { |
+ NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::BOOL); |
+ } |
+ |
+ void PropertyChange(Topic topic, void* object, int newValue, int oldValue) |
+ { |
+ NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT); |
+ } |
+ |
+ void PropertyChange(Topic topic, void* object, unsigned int newValue, |
+ unsigned int oldValue) |
+ { |
+ NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT); |
+ } |
+ |
+ void PropertyChange(Topic topic, void* object, double newValue, double oldValue) |
+ { |
+ NotifyPropertyChange<double>(topic, object, newValue, oldValue, |
+ ArgType::DOUBLE); |
+ } |
+ |
+ void PropertyChange(Topic topic, void* object, const String& newValue, |
+ const String& oldValue) |
+ { |
+ NotifyPropertyChange<int>(topic, object, reinterpret_cast<int>(&newValue), |
+ reinterpret_cast<int>(&oldValue), ArgType::STRING); |
+ } |
+} |