1 //===-- MICmnBase.cpp -------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // Third party headers 11 #include <stdarg.h> 12 13 // In-house headers: 14 #include "MICmnBase.h" 15 #include "MICmnLog.h" 16 #include "MICmnStreamStderr.h" 17 18 //++ 19 //------------------------------------------------------------------------------------ 20 // Details: CMICmnBase constructor. 21 // Type: Method. 22 // Args: None. 23 // Return: None. 24 // Throws: None. 25 //-- CMICmnBase()26CMICmnBase::CMICmnBase() 27 : m_strMILastErrorDescription(CMIUtilString()), m_bInitialized(false), 28 m_pLog(&CMICmnLog::Instance()), m_clientUsageRefCnt(0) {} 29 30 //++ 31 //------------------------------------------------------------------------------------ 32 // Details: CMICmnBase destructor. 33 // Type: Overrideable. 34 // Args: None. 35 // Return: None. 36 // Throws: None. 37 //-- ~CMICmnBase()38CMICmnBase::~CMICmnBase() { m_pLog = NULL; } 39 40 //++ 41 //------------------------------------------------------------------------------------ 42 // Details: Retrieve whether *this object has an error description set. 43 // Type: Method. 44 // Args: None. 45 // Return: bool - True = Yes already defined, false = empty description. 46 // Throws: None. 47 //-- HaveErrorDescription() const48bool CMICmnBase::HaveErrorDescription() const { 49 return m_strMILastErrorDescription.empty(); 50 } 51 52 //++ 53 //------------------------------------------------------------------------------------ 54 // Details: Retrieve MI's last error condition. 55 // Type: Method. 56 // Args: None. 57 // Return: CMIUtilString & - Text description. 58 // Throws: None. 59 //-- GetErrorDescription() const60const CMIUtilString &CMICmnBase::GetErrorDescription() const { 61 return m_strMILastErrorDescription; 62 } 63 64 //++ 65 //------------------------------------------------------------------------------------ 66 // Details: Set MI's error condition description. This may be accessed by 67 // clients and 68 // seen by users. Message is available to the client using the server 69 // and sent 70 // to the Logger. 71 // Type: Method. 72 // Args: vrTxt - (R) Text description. 73 // Return: None. 74 // Throws: None. 75 //-- SetErrorDescription(const CMIUtilString & vrTxt) const76void CMICmnBase::SetErrorDescription(const CMIUtilString &vrTxt) const { 77 m_strMILastErrorDescription = vrTxt; 78 if (!vrTxt.empty()) { 79 const CMIUtilString txt(CMIUtilString::Format("Error: %s", vrTxt.c_str())); 80 CMICmnStreamStderr::Instance().Write(txt); 81 } 82 } 83 84 //++ 85 //------------------------------------------------------------------------------------ 86 // Details: Set MI's error condition description. This may be accessed by 87 // clients and 88 // seen by users. Message is available to the client using the server 89 // and sent 90 // to the Logger. 91 // Type: Method. 92 // Args: vrTxt - (R) Text description. 93 // Return: None. 94 // Throws: None. 95 //-- SetErrorDescriptionNoLog(const CMIUtilString & vrTxt) const96void CMICmnBase::SetErrorDescriptionNoLog(const CMIUtilString &vrTxt) const { 97 m_strMILastErrorDescription = vrTxt; 98 } 99 100 //++ 101 //------------------------------------------------------------------------------------ 102 // Details: Clear MI's error condition description. 103 // Type: Method. 104 // Args: None. 105 // Return: None. 106 // Throws: None. 107 //-- ClrErrorDescription() const108void CMICmnBase::ClrErrorDescription() const { 109 m_strMILastErrorDescription.clear(); 110 } 111 112 //++ 113 //------------------------------------------------------------------------------------ 114 // Details: Set MI's error condition description. This may be accessed by 115 // clients and 116 // seen by users. Message is available to the client using the server 117 // and sent 118 // to the Logger. 119 // Type: Method. 120 // Args: vFormat - (R) Format string. 121 // ... - (R) Variable number of CMIUtilString type objects. 122 // Return: None. 123 // Throws: None. 124 //-- SetErrorDescriptionn(const char * vFormat,...) const125void CMICmnBase::SetErrorDescriptionn(const char *vFormat, ...) const { 126 va_list args; 127 va_start(args, vFormat); 128 CMIUtilString strResult = CMIUtilString::FormatValist(vFormat, args); 129 va_end(args); 130 131 SetErrorDescription(strResult); 132 } 133