OLD | NEW |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "library.h" | 23 #include "library.h" |
24 #include "String.h" | 24 #include "String.h" |
25 | 25 |
26 ABP_NS_BEGIN | 26 ABP_NS_BEGIN |
27 | 27 |
28 class Filter; | 28 class Filter; |
29 class Subscription; | 29 class Subscription; |
30 | 30 |
31 namespace FilterNotifier | 31 namespace FilterNotifier |
32 { | 32 { |
33 enum class Topic | 33 enum class Topic : int32_t |
34 { | 34 { |
35 NONE, | 35 NONE, |
36 FILTER_ADDED, | 36 FILTER_ADDED, |
37 FILTER_REMOVED, | 37 FILTER_REMOVED, |
38 FILTER_DISABLED, | 38 FILTER_DISABLED, |
39 FILTER_HITCOUNT, | 39 FILTER_HITCOUNT, |
40 FILTER_LASTHIT, | 40 FILTER_LASTHIT, |
41 SUBSCRIPTION_ADDED, | 41 SUBSCRIPTION_ADDED, |
42 SUBSCRIPTION_REMOVED, | 42 SUBSCRIPTION_REMOVED, |
43 SUBSCRIPTION_MOVED, | 43 SUBSCRIPTION_MOVED, |
44 SUBSCRIPTION_TITLE, | 44 SUBSCRIPTION_TITLE, |
45 SUBSCRIPTION_DISABLED, | 45 SUBSCRIPTION_DISABLED, |
46 SUBSCRIPTION_FIXEDTITLE, | 46 SUBSCRIPTION_FIXEDTITLE, |
47 SUBSCRIPTION_HOMEPAGE, | 47 SUBSCRIPTION_HOMEPAGE, |
48 SUBSCRIPTION_LASTCHECK, | 48 SUBSCRIPTION_LASTCHECK, |
49 SUBSCRIPTION_LASTDOWNLOAD, | 49 SUBSCRIPTION_LASTDOWNLOAD, |
50 SUBSCRIPTION_DOWNLOADSTATUS, | 50 SUBSCRIPTION_DOWNLOADSTATUS, |
51 SUBSCRIPTION_ERRORS, | 51 SUBSCRIPTION_ERRORS, |
52 }; | 52 }; |
53 | 53 |
54 inline void GenerateCustomBindings() | 54 template<typename T> |
| 55 inline T lexical_cast(Topic); |
| 56 |
| 57 template<> |
| 58 inline int32_t lexical_cast<int32_t>(Topic value) |
55 { | 59 { |
56 printf("var FilterNotifier = require('filterNotifier').FilterNotifier;\n"); | 60 return static_cast<int32_t>(value); |
57 printf("var notifierTopics = new Map([\n"); | 61 } |
58 printf(" [%i, 'filter.added'],\n", Topic::FILTER_ADDED); | 62 |
59 printf(" [%i, 'filter.removed'],\n", Topic::FILTER_REMOVED); | 63 namespace GenerateCustomBindings |
60 printf(" [%i, 'filter.disabled'],\n", Topic::FILTER_DISABLED); | 64 { |
61 printf(" [%i, 'filter.hitCount'],\n", Topic::FILTER_HITCOUNT); | 65 inline void printfTopic(const char* format, Topic topic) |
62 printf(" [%i, 'filter.lastHit'],\n", Topic::FILTER_LASTHIT); | 66 { |
63 printf(" [%i, 'subscription.added'],\n", Topic::SUBSCRIPTION_ADDED); | 67 ::printf(format, lexical_cast<int32_t>(topic)); |
64 printf(" [%i, 'subscription.removed'],\n", Topic::SUBSCRIPTION_REMOVED); | 68 } |
65 printf(" [%i, 'subscription.moved'],\n", Topic::SUBSCRIPTION_MOVED); | 69 |
66 printf(" [%i, 'subscription.title'],\n", Topic::SUBSCRIPTION_TITLE); | 70 inline void Generate() |
67 printf(" [%i, 'subscription.disabled'],\n", Topic::SUBSCRIPTION_DISABLED); | 71 { |
68 printf(" [%i, 'subscription.fixedTitle'],\n", Topic::SUBSCRIPTION_FIXEDTITL
E); | 72 printf("var FilterNotifier = require('filterNotifier').FilterNotifier;\n")
; |
69 printf(" [%i, 'subscription.homepage'],\n", Topic::SUBSCRIPTION_HOMEPAGE); | 73 printf("var notifierTopics = new Map([\n"); |
70 printf(" [%i, 'subscription.lastCheck'],\n", Topic::SUBSCRIPTION_LASTCHECK)
; | 74 printfTopic(" [%i, 'filter.added'],\n", Topic::FILTER_ADDED); |
71 printf(" [%i, 'subscription.lastDownload'],\n", Topic::SUBSCRIPTION_LASTDOW
NLOAD); | 75 printfTopic(" [%i, 'filter.removed'],\n", Topic::FILTER_REMOVED); |
72 printf(" [%i, 'subscription.downloadStatus'],\n", Topic::SUBSCRIPTION_DOWNL
OADSTATUS); | 76 printfTopic(" [%i, 'filter.disabled'],\n", Topic::FILTER_DISABLED); |
73 printf(" [%i, 'subscription.errors'],\n", Topic::SUBSCRIPTION_ERRORS); | 77 printfTopic(" [%i, 'filter.hitCount'],\n", Topic::FILTER_HITCOUNT); |
74 printf("]);"); | 78 printfTopic(" [%i, 'filter.lastHit'],\n", Topic::FILTER_LASTHIT); |
| 79 printfTopic(" [%i, 'subscription.added'],\n", Topic::SUBSCRIPTION_ADDED); |
| 80 printfTopic(" [%i, 'subscription.removed'],\n", Topic::SUBSCRIPTION_REMOV
ED); |
| 81 printfTopic(" [%i, 'subscription.moved'],\n", Topic::SUBSCRIPTION_MOVED); |
| 82 printfTopic(" [%i, 'subscription.title'],\n", Topic::SUBSCRIPTION_TITLE); |
| 83 printfTopic(" [%i, 'subscription.disabled'],\n", Topic::SUBSCRIPTION_DISA
BLED); |
| 84 printfTopic(" [%i, 'subscription.fixedTitle'],\n", Topic::SUBSCRIPTION_FI
XEDTITLE); |
| 85 printfTopic(" [%i, 'subscription.homepage'],\n", Topic::SUBSCRIPTION_HOME
PAGE); |
| 86 printfTopic(" [%i, 'subscription.lastCheck'],\n", Topic::SUBSCRIPTION_LAS
TCHECK); |
| 87 printfTopic(" [%i, 'subscription.lastDownload'],\n", Topic::SUBSCRIPTION_
LASTDOWNLOAD); |
| 88 printfTopic(" [%i, 'subscription.downloadStatus'],\n", Topic::SUBSCRIPTIO
N_DOWNLOADSTATUS); |
| 89 printfTopic(" [%i, 'subscription.errors'],\n", Topic::SUBSCRIPTION_ERRORS
); |
| 90 printf("]);"); |
| 91 } |
75 } | 92 } |
76 | 93 |
77 inline void FilterChange(Topic topic, Filter& filter, | 94 inline void FilterChange(Topic topic, Filter& filter, |
78 Subscription* subscription = nullptr, unsigned int position = 0) | 95 Subscription* subscription = nullptr, unsigned int position = 0) |
79 { | 96 { |
80 JSNotifyFilterChange(topic, filter, subscription, position); | 97 JSNotifyFilterChange(topic, filter, subscription, position); |
81 } | 98 } |
82 | 99 |
83 inline void SubscriptionChange(Topic topic, Subscription& subscription) | 100 inline void SubscriptionChange(Topic topic, Subscription& subscription) |
84 { | 101 { |
85 JSNotifySubscriptionChange(topic, subscription); | 102 JSNotifySubscriptionChange(topic, subscription); |
86 } | 103 } |
87 } | 104 } |
88 | 105 |
89 ABP_NS_END | 106 ABP_NS_END |
OLD | NEW |