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 "MIUtilString.h"
17 #include "MICmnBase.h"
18 #include "MIUtilSingletonBase.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 // Authors: Illya Rudkin 01/02/2012.
33 class CMICmnLog : public MI::ISingleton<CMICmnLog>
35 friend MI::ISingleton<CMICmnLog>;
40 // Description: Data given to the Logger can be of several types. The Logger can be
41 // set at levels of verbosity. Can determine how data is sent to one or
45 { // Descriptions of what 'may' occur, depends ultimately on the medium itself. See the medium.
46 eLogVerbosity_FnTrace = 0x00000004, // Debug function stack call tracing
47 eLogVerbosity_DbgOp = 0x00000008, // Send a string to the debugger for display (not implemented)
48 eLogVerbosity_ClientMsg = 0x00000010, // A client using MI can insert messages into the log (not implemented)
49 eLogVerbosity_Log = 0x00000020 // Send to only the Log file.
55 // Description: Register a medium derived from this interface which will be
56 // called writing log trace data i.e. a file or a console.
57 // Medium objects registered are not owned by *this logger.
62 virtual bool Initialize(void) = 0;
63 virtual const CMIUtilString &GetName(void) const = 0;
64 virtual bool Write(const CMIUtilString &vData, const ELogVerbosity veType) = 0;
65 virtual const CMIUtilString &GetError(void) const = 0;
66 virtual bool Shutdown(void) = 0;
68 // Not part of the interface, ignore
69 // AD: This virtual destructor seems to hit a bug in the stdlib
70 // where vector delete is incorrectly called. Workaround is
71 // to comment this out while I investigate.
72 /* dtor */ virtual ~IMedium(void) {}
77 static bool WriteLog(const CMIUtilString &vData);
81 bool RegisterMedium(const IMedium &vrMedium);
82 bool UnregisterMedium(const IMedium &vrMedium);
83 bool Write(const CMIUtilString &vData, const ELogVerbosity veType);
84 bool SetEnabled(const bool vbYes);
85 bool GetEnabled(void) const;
87 // MI common object handling - duplicate of CMICmnBase functions, necessary for LINUX build
88 // Done to stop locking on object construction init circular dependency.
89 const CMIUtilString &GetErrorDescription(void) const;
90 void SetErrorDescription(const CMIUtilString &vrTxt) const;
91 void ClrErrorDescription(void) const;
95 // From MI::ISingleton
96 bool Initialize(void) override;
97 bool Shutdown(void) override;
101 /* ctor */ CMICmnLog(void);
102 /* ctor */ CMICmnLog(const CMICmnLog &);
103 void operator=(const CMICmnLog &);
108 /* dtor */ ~CMICmnLog(void) override;
112 typedef std::map<IMedium *, CMIUtilString> MapMediumToName_t;
113 typedef std::pair<IMedium *, CMIUtilString> MapPairMediumToName_t;
117 bool HaveMediumAlready(const IMedium &vrMedium) const;
118 bool UnregisterMediumAll(void);
122 bool m_bRecursiveDive; // True = yes recursive, false = no
123 MapMediumToName_t m_mapMediumToName;
124 bool m_bEnabled; // True = Logger enabled for writing to mediums, false = medium not written to
125 bool m_bInitializingATM; // True = Yes in process of initing *this logger, false = not initing
127 // MI common object handling - duplicate of CMICmnBase functions, necessary for LINUX build
128 bool m_bInitialized; // True = yes successfully initialized, false = no yet or failed
129 mutable CMIUtilString m_strMILastErrorDescription;
130 MIint m_clientUsageRefCnt; // Count of client using *this object so not shutdown() object to early