1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/base/nsConsoleService.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * nsConsoleService class declaration. 1.11 + */ 1.12 + 1.13 +#ifndef __nsconsoleservice_h__ 1.14 +#define __nsconsoleservice_h__ 1.15 + 1.16 +#include "mozilla/Attributes.h" 1.17 +#include "mozilla/Mutex.h" 1.18 + 1.19 +#include "nsInterfaceHashtable.h" 1.20 +#include "nsHashKeys.h" 1.21 + 1.22 +#include "nsIConsoleService.h" 1.23 + 1.24 +class nsConsoleService MOZ_FINAL : public nsIConsoleService 1.25 +{ 1.26 +public: 1.27 + nsConsoleService(); 1.28 + nsresult Init(); 1.29 + 1.30 + NS_DECL_THREADSAFE_ISUPPORTS 1.31 + NS_DECL_NSICONSOLESERVICE 1.32 + 1.33 + void SetIsDelivering() { 1.34 + MOZ_ASSERT(NS_IsMainThread()); 1.35 + MOZ_ASSERT(!mDeliveringMessage); 1.36 + mDeliveringMessage = true; 1.37 + } 1.38 + 1.39 + void SetDoneDelivering() { 1.40 + MOZ_ASSERT(NS_IsMainThread()); 1.41 + MOZ_ASSERT(mDeliveringMessage); 1.42 + mDeliveringMessage = false; 1.43 + } 1.44 + 1.45 + // This is a variant of LogMessage which allows the caller to determine 1.46 + // if the message should be output to an OS-specific log. This is used on 1.47 + // B2G to control whether the message is logged to the android log or not. 1.48 + 1.49 + enum OutputMode { 1.50 + SuppressLog, 1.51 + OutputToLog 1.52 + }; 1.53 + virtual nsresult LogMessageWithMode(nsIConsoleMessage *message, OutputMode outputMode); 1.54 + 1.55 + typedef nsInterfaceHashtable<nsISupportsHashKey, nsIConsoleListener> ListenerHash; 1.56 + void EnumerateListeners(ListenerHash::EnumReadFunction aFunction, void* aClosure); 1.57 + 1.58 +private: 1.59 + ~nsConsoleService(); 1.60 + 1.61 + // Circular buffer of saved messages 1.62 + nsIConsoleMessage **mMessages; 1.63 + 1.64 + // How big? 1.65 + uint32_t mBufferSize; 1.66 + 1.67 + // Index of slot in mMessages that'll be filled by *next* log message 1.68 + uint32_t mCurrent; 1.69 + 1.70 + // Is the buffer full? (Has mCurrent wrapped around at least once?) 1.71 + bool mFull; 1.72 + 1.73 + // Are we currently delivering a console message on the main thread? If 1.74 + // so, we suppress incoming messages on the main thread only, to avoid 1.75 + // infinite repitition. 1.76 + bool mDeliveringMessage; 1.77 + 1.78 + // Listeners to notify whenever a new message is logged. 1.79 + ListenerHash mListeners; 1.80 + 1.81 + // To serialize interesting methods. 1.82 + mozilla::Mutex mLock; 1.83 +}; 1.84 + 1.85 +#endif /* __nsconsoleservice_h__ */