Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/PluginDebug.h

Issue 29323611: Issue #1234, #2058 - Rewrite log facility, improving thread implementation
Patch Set: rebase only Created July 27, 2016, 9:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/PluginClientBase.cpp ('k') | src/plugin/PluginDebug.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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>
21 #include <string> 23 #include <string>
22 24
25 namespace Trace
26 {
27 /**
28 */
29 struct Location
30 {
31 std::string prefixText;
32 std::string postfixText;
33
34 Location() // = default
35 : prefixText(), postfixText()
36 {};
37
38 Location(int id, int subId);
39
40 Location(std::string postfixText)
41 : prefixText(), postfixText(postfixText)
42 {}
43
44 Location(std::string prefixText, std::string postfixText)
45 : prefixText(prefixText), postfixText(postfixText)
46 {}
47 };
48
49 void TextFixed(const std::string& description, Trace::Location location);
50 void ErrorCode(DWORD errorCode, const std::string& description, Trace::Locatio n location);
51 void SystemException(const std::system_error& ex, const std::string& descripti on, Trace::Location location);
52 }
53
54 // Cope with insufficient support on old toolsets
55 #if !defined(__func__) && defined(_MSC_VER)
56 #define __func__ __FUNCTION__
57 #endif
58
59 // __LINE__ expands to an integer literal, not a string literal
60 // The stringify operator "#" applies only to arguments, not macro definitions
61 #define STRING_EXPAND(x) STRINGIFY(x)
62 #define STRINGIFY(x) #x
63 #define __LINE_STRING__ STRING_EXPAND(__LINE__)
64 #define HERE Trace::Location(__FILE__ ":" __LINE_STRING__)
65 #define HERE_F Trace::Location(__func__, __FILE__ ":" __LINE_STRING__)
66
67 #ifdef _DEBUG
68 #define TRACE(description, location) Trace::TextFixed(description, location)
69 #else
70 #define TRACE(a,b)
71 #endif
72
23 class CPluginDebug 73 class CPluginDebug
24 { 74 {
25
26 public: 75 public:
27 static void DebugSystemException(const std::system_error& ex, int errorId, int errorSubid, const std::string& description);
28
29 #if (defined ENABLE_DEBUG_INFO) 76 #if (defined ENABLE_DEBUG_INFO)
30 static void Debug(const std::string& text); 77 static void Debug(const std::string& text);
31 static void Debug(const std::wstring& text); 78 static void Debug(const std::wstring& text);
32 static void DebugException(const std::exception& ex); 79 static void DebugException(const std::exception& ex, Trace::Location location) ;
33 static void DebugErrorCode(DWORD errorCode, const std::string& error, DWORD pr ocessId=0, DWORD threadId=0); 80 static void DebugErrorCode(DWORD errorCode, const std::string& error, Trace::L ocation location);
34 #endif 81 #endif
35 82
36 #if (defined ENABLE_DEBUG_RESULT) 83 #if (defined ENABLE_DEBUG_RESULT)
37 static void DebugResult(const std::wstring& text); 84 static void DebugResult(const std::wstring& text);
38 static void DebugResultDomain(const std::wstring& domain); 85 static void DebugResultDomain(const std::wstring& domain);
39 static void DebugResultBlocking(const std::wstring& type, const std::wstring& src, const std::wstring& domain); 86 static void DebugResultBlocking(const std::wstring& type, const std::wstring& src, const std::wstring& domain);
40 static void DebugResultHiding(const std::wstring& tag, const std::wstring& id, const std::wstring& filter); 87 static void DebugResultHiding(const std::wstring& tag, const std::wstring& id, const std::wstring& filter);
41 #endif 88 #endif
42 89
43 #if (defined ENABLE_DEBUG_RESULT_IGNORED) 90 #if (defined ENABLE_DEBUG_RESULT_IGNORED)
44 static void DebugResultIgnoring(const std::wstring& type, const std::wstring& src, const std::wstring& domain); 91 static void DebugResultIgnoring(const std::wstring& type, const std::wstring& src, const std::wstring& domain);
45 #endif 92 #endif
46 }; 93 };
47 94
48 /** 95 /**
49 * Convert a pointer to a hexadecimal literal (0x...) 96 * Convert a pointer to a hexadecimal literal (0x...)
50 * 97 *
51 * The length of the literal varies with pointer size: 98 * The length of the literal varies with pointer size:
52 * 10 characters for WIN32, and 18 for WIN64. 99 * 10 characters for WIN32, and 18 for WIN64.
53 */ 100 */
54 std::wstring ToHexLiteral(const void*); 101 std::wstring ToHexLiteral(const void*);
55 102
103 /*
104 * Forward declaration.
105 */
106 class LogQueue;
107
108 /**
109 * This class maintains a singleton LogQueue in existence.
110 *
111 * This class exists because it's not possible to use a static declaration for
112 * 'std::thread' or any class that contains one, such as 'ActiveQueue'.
113 * To appreciate of the origin of restriction, see
114 * http://stackoverflow.com/questions/28746016/thread-join-does-not-return-whe n-called-in-global-var-destructor
115 * In addition, we have no main() function to use for initialization,
116 * since we're packaged as a COM class provider.
117 *
118 * As a substitute, we maintain a reference to the queue in each instance of
119 * 'CPluginClass', the sole visible COM class, the one that implements the
120 * BHO interface.
121 * This class has the responsibility for managing the life cycle of the queue,
122 * ensuring it exists whenever there's a reference to it.
123 * The lifespan of instances of 'CPluginClass' encompasses the lifespans of any
124 * other objects that the BHO uses, so it's sufficient to maintain a LogQueue
125 * in existence with a reference in that class.
126 *
127 * The queue itself is accessible only to the logging functions;
128 * it need not be visible externally.
129 * Hence all this class requires is an opaque, forward declaration.
130 * Mere instantiation of this class is sufficient to ensure we have a log queue.
131 */
132 class LogQueueReference
133 {
134 friend LogQueue;
135
136 typedef std::shared_ptr<LogQueue> pointer;
137
138 /**
139 * The class-wide reference to the debug queue.
140 */
141 static pointer queueMasterReference;
142
143 /**
144 * The instance reference to the debug queue.
145 */
146 pointer queueReference;
147
148 /**
149 * Mutex to allow joint serialization of constructor/destructor calls.
150 */
151 static std::mutex mutex;
152
153 public:
154 LogQueueReference();
155 ~LogQueueReference();
156 };
157
56 #endif // _PLUGIN_DEBUG_H_ 158 #endif // _PLUGIN_DEBUG_H_
OLDNEW
« no previous file with comments | « src/plugin/PluginClientBase.cpp ('k') | src/plugin/PluginDebug.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld