1 //===-- MICmnLog.h ----------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // Third party headers:
15 #include "MICmnBase.h"
16 #include "MIUtilSingletonBase.h"
17 #include "MIUtilString.h"
20 //============================================================================
21 // Details: MI common code implementation class. Handle application trace
22 // activity logging. Medium objects derived from the Medium abstract
23 /// class are registered with this logger. The function Write is called
24 // by a client callee to log information. That information is given to
25 // registered relevant mediums. The medium file is registered during
26 // *this logs initialization so it will always have a file log for the
30 class CMICmnLog : public MI::ISingleton<CMICmnLog> {
31 friend MI::ISingleton<CMICmnLog>;
36 // Description: Data given to the Logger can be of several types. The Logger
38 // set at levels of verbosity. Can determine how data is sent to
42 enum ELogVerbosity { // Descriptions of what 'may' occur, depends ultimately
43 // on the medium itself. See the medium.
44 eLogVerbosity_FnTrace = 0x00000004, // Debug function stack call tracing
45 eLogVerbosity_DbgOp = 0x00000008, // Send a string to the debugger for
46 // display (not implemented)
47 eLogVerbosity_ClientMsg = 0x00000010, // A client using MI can insert
48 // messages into the log (not
50 eLogVerbosity_Log = 0x00000020 // Send to only the Log file.
56 // Description: Register a medium derived from this interface which will be
57 // called writing log trace data i.e. a file or a console.
58 // Medium objects registered are not owned by *this logger.
62 virtual bool Initialize() = 0;
63 virtual const CMIUtilString &GetName() const = 0;
64 virtual bool Write(const CMIUtilString &vData,
65 const ELogVerbosity veType) = 0;
66 virtual const CMIUtilString &GetError() const = 0;
67 virtual bool Shutdown() = 0;
69 // Not part of the interface, ignore
70 // AD: This virtual destructor seems to hit a bug in the stdlib
71 // where vector delete is incorrectly called. Workaround is
72 // to comment this out while I investigate.
73 /* dtor */ virtual ~IMedium() {}
78 static bool WriteLog(const CMIUtilString &vData);
82 bool RegisterMedium(const IMedium &vrMedium);
83 bool UnregisterMedium(const IMedium &vrMedium);
84 bool Write(const CMIUtilString &vData, const ELogVerbosity veType);
85 bool SetEnabled(const bool vbYes);
86 bool GetEnabled() const;
88 // MI common object handling - duplicate of CMICmnBase functions, necessary
90 // Done to stop locking on object construction init circular dependency.
91 const CMIUtilString &GetErrorDescription() const;
92 void SetErrorDescription(const CMIUtilString &vrTxt) const;
93 void ClrErrorDescription() const;
97 // From MI::ISingleton
98 bool Initialize() override;
99 bool Shutdown() override;
103 /* ctor */ CMICmnLog();
104 /* ctor */ CMICmnLog(const CMICmnLog &);
105 void operator=(const CMICmnLog &);
110 /* dtor */ ~CMICmnLog() override;
114 typedef std::map<IMedium *, CMIUtilString> MapMediumToName_t;
115 typedef std::pair<IMedium *, CMIUtilString> MapPairMediumToName_t;
119 bool HaveMediumAlready(const IMedium &vrMedium) const;
120 bool UnregisterMediumAll();
124 bool m_bRecursiveDive; // True = yes recursive, false = no
125 MapMediumToName_t m_mapMediumToName;
126 bool m_bEnabled; // True = Logger enabled for writing to mediums, false =
127 // medium not written to
128 bool m_bInitializingATM; // True = Yes in process of initing *this logger,
129 // false = not initing
131 // MI common object handling - duplicate of CMICmnBase functions, necessary
133 bool m_bInitialized; // True = yes successfully initialized, false = no yet or
135 mutable CMIUtilString m_strMILastErrorDescription;
136 MIint m_clientUsageRefCnt; // Count of client using *this object so not
137 // shutdown() object to early