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