michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * nsConsoleService class declaration. michael@0: */ michael@0: michael@0: #ifndef __nsconsoleservice_h__ michael@0: #define __nsconsoleservice_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/Mutex.h" michael@0: michael@0: #include "nsInterfaceHashtable.h" michael@0: #include "nsHashKeys.h" michael@0: michael@0: #include "nsIConsoleService.h" michael@0: michael@0: class nsConsoleService MOZ_FINAL : public nsIConsoleService michael@0: { michael@0: public: michael@0: nsConsoleService(); michael@0: nsresult Init(); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSICONSOLESERVICE michael@0: michael@0: void SetIsDelivering() { michael@0: MOZ_ASSERT(NS_IsMainThread()); michael@0: MOZ_ASSERT(!mDeliveringMessage); michael@0: mDeliveringMessage = true; michael@0: } michael@0: michael@0: void SetDoneDelivering() { michael@0: MOZ_ASSERT(NS_IsMainThread()); michael@0: MOZ_ASSERT(mDeliveringMessage); michael@0: mDeliveringMessage = false; michael@0: } michael@0: michael@0: // This is a variant of LogMessage which allows the caller to determine michael@0: // if the message should be output to an OS-specific log. This is used on michael@0: // B2G to control whether the message is logged to the android log or not. michael@0: michael@0: enum OutputMode { michael@0: SuppressLog, michael@0: OutputToLog michael@0: }; michael@0: virtual nsresult LogMessageWithMode(nsIConsoleMessage *message, OutputMode outputMode); michael@0: michael@0: typedef nsInterfaceHashtable ListenerHash; michael@0: void EnumerateListeners(ListenerHash::EnumReadFunction aFunction, void* aClosure); michael@0: michael@0: private: michael@0: ~nsConsoleService(); michael@0: michael@0: // Circular buffer of saved messages michael@0: nsIConsoleMessage **mMessages; michael@0: michael@0: // How big? michael@0: uint32_t mBufferSize; michael@0: michael@0: // Index of slot in mMessages that'll be filled by *next* log message michael@0: uint32_t mCurrent; michael@0: michael@0: // Is the buffer full? (Has mCurrent wrapped around at least once?) michael@0: bool mFull; michael@0: michael@0: // Are we currently delivering a console message on the main thread? If michael@0: // so, we suppress incoming messages on the main thread only, to avoid michael@0: // infinite repitition. michael@0: bool mDeliveringMessage; michael@0: michael@0: // Listeners to notify whenever a new message is logged. michael@0: ListenerHash mListeners; michael@0: michael@0: // To serialize interesting methods. michael@0: mozilla::Mutex mLock; michael@0: }; michael@0: michael@0: #endif /* __nsconsoleservice_h__ */