1 //===-- MICmnLog.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Third party headers:
16 #include "MICmnBase.h"
17 #include "MIUtilSingletonBase.h"
18 #include "MIUtilString.h"
21 //============================================================================
22 // Details: MI common code implementation class. Handle application trace
23 // activity logging. Medium objects derived from the Medium abstract
24 /// class are registered with this logger. The function Write is called
25 // by a client callee to log information. That information is given to
26 // registered relevant mediums. The medium file is registered during
27 // *this logs initialization so it will always have a file log for the
31 class CMICmnLog : public MI::ISingleton<CMICmnLog> {
32 friend MI::ISingleton<CMICmnLog>;
37 // Description: Data given to the Logger can be of several types. The Logger
39 // set at levels of verbosity. Can determine how data is sent to
43 enum ELogVerbosity { // Descriptions of what 'may' occur, depends ultimately
44 // on the medium itself. See the medium.
45 eLogVerbosity_FnTrace = 0x00000004, // Debug function stack call tracing
46 eLogVerbosity_DbgOp = 0x00000008, // Send a string to the debugger for
47 // display (not implemented)
48 eLogVerbosity_ClientMsg = 0x00000010, // A client using MI can insert
49 // messages into the log (not
51 eLogVerbosity_Log = 0x00000020 // Send to only the Log file.
57 // Description: Register a medium derived from this interface which will be
58 // called writing log trace data i.e. a file or a console.
59 // Medium objects registered are not owned by *this logger.
63 virtual bool Initialize() = 0;
64 virtual const CMIUtilString &GetName() const = 0;
65 virtual bool Write(const CMIUtilString &vData,
66 const ELogVerbosity veType) = 0;
67 virtual const CMIUtilString &GetError() const = 0;
68 virtual bool Shutdown() = 0;
70 // Not part of the interface, ignore
71 // AD: This virtual destructor seems to hit a bug in the stdlib
72 // where vector delete is incorrectly called. Workaround is
73 // to comment this out while I investigate.
74 /* dtor */ virtual ~IMedium() {}
79 static bool WriteLog(const CMIUtilString &vData);
83 bool RegisterMedium(const IMedium &vrMedium);
84 bool UnregisterMedium(const IMedium &vrMedium);
85 bool Write(const CMIUtilString &vData, const ELogVerbosity veType);
86 bool SetEnabled(const bool vbYes);
87 bool GetEnabled() const;
89 // MI common object handling - duplicate of CMICmnBase functions, necessary
91 // Done to stop locking on object construction init circular dependency.
92 const CMIUtilString &GetErrorDescription() const;
93 void SetErrorDescription(const CMIUtilString &vrTxt) const;
94 void ClrErrorDescription() const;
98 // From MI::ISingleton
99 bool Initialize() override;
100 bool Shutdown() override;
104 /* ctor */ CMICmnLog();
105 /* ctor */ CMICmnLog(const CMICmnLog &);
106 void operator=(const CMICmnLog &);
111 /* dtor */ ~CMICmnLog() override;
115 typedef std::map<IMedium *, CMIUtilString> MapMediumToName_t;
116 typedef std::pair<IMedium *, CMIUtilString> MapPairMediumToName_t;
120 bool HaveMediumAlready(const IMedium &vrMedium) const;
121 bool UnregisterMediumAll();
125 bool m_bRecursiveDive; // True = yes recursive, false = no
126 MapMediumToName_t m_mapMediumToName;
127 bool m_bEnabled; // True = Logger enabled for writing to mediums, false =
128 // medium not written to
129 bool m_bInitializingATM; // True = Yes in process of initing *this logger,
130 // false = not initing
132 // MI common object handling - duplicate of CMICmnBase functions, necessary
134 bool m_bInitialized; // True = yes successfully initialized, false = no yet or
136 mutable CMIUtilString m_strMILastErrorDescription;
137 MIint m_clientUsageRefCnt; // Count of client using *this object so not
138 // shutdown() object to early