| Left: | ||
| Right: |
| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 #ifndef _PLUGIN_DEBUG_H_ | 18 #ifndef _PLUGIN_DEBUG_H_ |
| 19 #define _PLUGIN_DEBUG_H_ | 19 #define _PLUGIN_DEBUG_H_ |
| 20 | 20 |
| 21 #include <memory> | |
| 22 #include <mutex> | |
| 23 | |
| 24 namespace Trace | |
| 25 { | |
| 26 /** | |
| 27 */ | |
| 28 struct Location | |
| 29 { | |
| 30 std::string prefixText; | |
| 31 std::string postfixText; | |
| 32 | |
| 33 Location() // = default | |
| 34 : prefixText(), postfixText() | |
| 35 {}; | |
| 36 | |
| 37 Location(int id, int subId); | |
| 38 | |
| 39 Location(std::string postfixText) | |
| 40 : prefixText(), postfixText(postfixText) | |
| 41 {} | |
| 42 | |
| 43 Location(std::string prefixText, std::string postfixText) | |
| 44 : prefixText(prefixText), postfixText(postfixText) | |
| 45 {} | |
| 46 }; | |
| 47 | |
| 48 void TextFixed(const std::string& description, Trace::Location location); | |
| 49 void ErrorCode(DWORD errorCode, const std::string& description, Trace::Locatio n location); | |
| 50 void SystemException(const std::system_error& ex, const std::string& descripti on, Trace::Location location); | |
| 51 } | |
| 52 | |
| 53 // Cope with insufficient support on old toolsets | |
| 54 #if !defined(__func__) && defined(_MSC_VER) | |
| 55 #define __func__ __FUNCTION__ | |
| 56 #endif | |
| 57 | |
| 58 // __LINE__ expands to an integer literal, not a string literal | |
| 59 // The stringify operator "#" applies only to arguments, not macro definitions | |
| 60 #define STRING_EXPAND(x) STRINGIFY(x) | |
| 61 #define STRINGIFY(x) #x | |
| 62 #define __LINE_STRING__ STRING_EXPAND(__LINE__) | |
| 63 #define HERE Trace::Location(__FILE__ ":" __LINE_STRING__) | |
| 64 #define HERE_F Trace::Location(__func__, __FILE__ ":" __LINE_STRING__) | |
| 65 | |
| 66 #ifdef _DEBUG | |
| 67 #define TRACE(description, location) Trace::TextFixed(description, location) | |
| 68 #else | |
| 69 #define TRACE(a,b) | |
| 70 #endif | |
| 71 | |
| 21 class CPluginDebug | 72 class CPluginDebug |
| 22 { | 73 { |
| 23 | |
| 24 public: | 74 public: |
| 25 static void DebugSystemException(const std::system_error& ex, int errorId, int errorSubid, const std::string& description); | |
| 26 | |
| 27 #if (defined ENABLE_DEBUG_INFO) | 75 #if (defined ENABLE_DEBUG_INFO) |
| 28 static void Debug(const std::string& text); | 76 static void Debug(const std::string& text); |
| 29 static void Debug(const std::wstring& text); | 77 static void Debug(const std::wstring& text); |
| 30 static void DebugException(const std::exception& ex); | 78 static void DebugException(const std::exception& ex, Trace::Location location) ; |
| 31 static void DebugErrorCode(DWORD errorCode, const std::string& error, DWORD pr ocessId=0, DWORD threadId=0); | 79 static void DebugErrorCode(DWORD errorCode, const std::string& error, Trace::L ocation location); |
| 32 #endif | 80 #endif |
| 33 | 81 |
| 34 #if (defined ENABLE_DEBUG_RESULT) | 82 #if (defined ENABLE_DEBUG_RESULT) |
| 35 static void DebugResult(const std::wstring& text); | 83 static void DebugResult(const std::wstring& text); |
| 36 static void DebugResultDomain(const std::wstring& domain); | 84 static void DebugResultDomain(const std::wstring& domain); |
| 37 static void DebugResultBlocking(const std::wstring& type, const std::wstring& src, const std::wstring& domain); | 85 static void DebugResultBlocking(const std::wstring& type, const std::wstring& src, const std::wstring& domain); |
| 38 static void DebugResultHiding(const std::wstring& tag, const std::wstring& id, const std::wstring& filter); | 86 static void DebugResultHiding(const std::wstring& tag, const std::wstring& id, const std::wstring& filter); |
| 39 #endif | 87 #endif |
| 40 | 88 |
| 41 #if (defined ENABLE_DEBUG_RESULT_IGNORED) | 89 #if (defined ENABLE_DEBUG_RESULT_IGNORED) |
| 42 static void DebugResultIgnoring(const std::wstring& type, const std::wstring& src, const std::wstring& domain); | 90 static void DebugResultIgnoring(const std::wstring& type, const std::wstring& src, const std::wstring& domain); |
| 43 #endif | 91 #endif |
| 44 }; | 92 }; |
| 45 | 93 |
| 94 /* | |
| 95 * Forward declaration. | |
| 96 */ | |
| 97 class LogQueue; | |
| 98 | |
| 99 /** | |
| 100 * This class maintains a singleton LogQueue in existence. | |
| 101 * | |
| 102 * This class exists because it's not possible to use a static declaration for | |
| 103 * 'std::thread' or any class that contains one, such as 'ActiveQueue'. | |
| 104 * To appreciate of the origin of restriction, see | |
| 105 * http://stackoverflow.com/questions/28746016/thread-join-does-not-return-whe n-called-in-global-var-destructor | |
| 106 * In addition, we have no main() function to use for initialization, | |
| 107 * since we're packaged as a COM class provider. | |
| 108 * | |
| 109 * As a substitute, we maintain a reference to the queue in each instance of | |
| 110 * 'CPluginClass', the sole visible COM class, the one that implements the | |
| 111 * BHO interface. | |
| 112 * This class has the responsibility for managing the life cycle of the queue, | |
| 113 * ensuring it exists whenever there's a reference to it. | |
| 114 * The lifespan of instances of 'CPluginClass' encompasses the lifespans of any | |
| 115 * other objects that the BHO uses, so it's sufficient to maintain a LogQueue | |
| 116 * in existence with a reference in that class. | |
| 117 * | |
| 118 * The queue itself is accessible only to the logging functions; | |
| 119 * it need not be visible externally. | |
| 120 * Hence all this class requires is an opaque, forward declaration. | |
| 121 * Mere instantiation of this class is sufficient to ensure we have a log queue. | |
| 122 */ | |
| 123 class LogQueueReference | |
| 124 { | |
| 125 friend LogQueue; | |
| 126 | |
| 127 typedef std::shared_ptr<LogQueue> pointer; | |
| 128 | |
| 129 /** | |
| 130 * The class-wide reference to the debug queue. | |
| 131 */ | |
| 132 static pointer queueMasterReference; | |
|
sergei
2015/10/01 15:50:07
Why do we need more static stuff? We have already
Eric
2015/10/08 21:05:41
In the present case, we want a single log facility
| |
| 133 | |
| 134 /** | |
| 135 * The instance reference to the debug queue. | |
| 136 */ | |
| 137 pointer queueReference; | |
| 138 | |
| 139 /** | |
| 140 * Mutex to allow joint serialization of constructor/destructor calls. | |
| 141 */ | |
| 142 static std::mutex mutex; | |
| 143 | |
| 144 public: | |
| 145 LogQueueReference(); | |
| 146 ~LogQueueReference(); | |
| 147 }; | |
| 46 | 148 |
| 47 #endif // _PLUGIN_DEBUG_H_ | 149 #endif // _PLUGIN_DEBUG_H_ |
| OLD | NEW |