|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * nsConsoleService class declaration. |
|
8 */ |
|
9 |
|
10 #ifndef __nsconsoleservice_h__ |
|
11 #define __nsconsoleservice_h__ |
|
12 |
|
13 #include "mozilla/Attributes.h" |
|
14 #include "mozilla/Mutex.h" |
|
15 |
|
16 #include "nsInterfaceHashtable.h" |
|
17 #include "nsHashKeys.h" |
|
18 |
|
19 #include "nsIConsoleService.h" |
|
20 |
|
21 class nsConsoleService MOZ_FINAL : public nsIConsoleService |
|
22 { |
|
23 public: |
|
24 nsConsoleService(); |
|
25 nsresult Init(); |
|
26 |
|
27 NS_DECL_THREADSAFE_ISUPPORTS |
|
28 NS_DECL_NSICONSOLESERVICE |
|
29 |
|
30 void SetIsDelivering() { |
|
31 MOZ_ASSERT(NS_IsMainThread()); |
|
32 MOZ_ASSERT(!mDeliveringMessage); |
|
33 mDeliveringMessage = true; |
|
34 } |
|
35 |
|
36 void SetDoneDelivering() { |
|
37 MOZ_ASSERT(NS_IsMainThread()); |
|
38 MOZ_ASSERT(mDeliveringMessage); |
|
39 mDeliveringMessage = false; |
|
40 } |
|
41 |
|
42 // This is a variant of LogMessage which allows the caller to determine |
|
43 // if the message should be output to an OS-specific log. This is used on |
|
44 // B2G to control whether the message is logged to the android log or not. |
|
45 |
|
46 enum OutputMode { |
|
47 SuppressLog, |
|
48 OutputToLog |
|
49 }; |
|
50 virtual nsresult LogMessageWithMode(nsIConsoleMessage *message, OutputMode outputMode); |
|
51 |
|
52 typedef nsInterfaceHashtable<nsISupportsHashKey, nsIConsoleListener> ListenerHash; |
|
53 void EnumerateListeners(ListenerHash::EnumReadFunction aFunction, void* aClosure); |
|
54 |
|
55 private: |
|
56 ~nsConsoleService(); |
|
57 |
|
58 // Circular buffer of saved messages |
|
59 nsIConsoleMessage **mMessages; |
|
60 |
|
61 // How big? |
|
62 uint32_t mBufferSize; |
|
63 |
|
64 // Index of slot in mMessages that'll be filled by *next* log message |
|
65 uint32_t mCurrent; |
|
66 |
|
67 // Is the buffer full? (Has mCurrent wrapped around at least once?) |
|
68 bool mFull; |
|
69 |
|
70 // Are we currently delivering a console message on the main thread? If |
|
71 // so, we suppress incoming messages on the main thread only, to avoid |
|
72 // infinite repitition. |
|
73 bool mDeliveringMessage; |
|
74 |
|
75 // Listeners to notify whenever a new message is logged. |
|
76 ListenerHash mListeners; |
|
77 |
|
78 // To serialize interesting methods. |
|
79 mozilla::Mutex mLock; |
|
80 }; |
|
81 |
|
82 #endif /* __nsconsoleservice_h__ */ |