1 //===-- MICmnBase.cpp -------------------------------------------*- 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 //===----------------------------------------------------------------------===//
13 #include "MICmnBase.h"
15 #include "MICmnStreamStderr.h"
18 // Details: CMICmnBase constructor.
24 CMICmnBase::CMICmnBase()
25 : m_strMILastErrorDescription(CMIUtilString()), m_bInitialized(false),
26 m_pLog(&CMICmnLog::Instance()), m_clientUsageRefCnt(0) {}
29 // Details: CMICmnBase destructor.
30 // Type: Overrideable.
35 CMICmnBase::~CMICmnBase() { m_pLog = nullptr; }
38 // Details: Retrieve whether *this object has an error description set.
41 // Return: bool - True = Yes already defined, false = empty description.
44 bool CMICmnBase::HaveErrorDescription() const {
45 return m_strMILastErrorDescription.empty();
49 // Details: Retrieve MI's last error condition.
52 // Return: CMIUtilString & - Text description.
55 const CMIUtilString &CMICmnBase::GetErrorDescription() const {
56 return m_strMILastErrorDescription;
60 // Details: Set MI's error condition description. This may be accessed by
62 // seen by users. Message is available to the client using the server
66 // Args: vrTxt - (R) Text description.
70 void CMICmnBase::SetErrorDescription(const CMIUtilString &vrTxt) const {
71 m_strMILastErrorDescription = vrTxt;
73 const CMIUtilString txt(CMIUtilString::Format("Error: %s", vrTxt.c_str()));
74 CMICmnStreamStderr::Instance().Write(txt);
79 // Details: Set MI's error condition description. This may be accessed by
81 // seen by users. Message is available to the client using the server
85 // Args: vrTxt - (R) Text description.
89 void CMICmnBase::SetErrorDescriptionNoLog(const CMIUtilString &vrTxt) const {
90 m_strMILastErrorDescription = vrTxt;
94 // Details: Clear MI's error condition description.
100 void CMICmnBase::ClrErrorDescription() const {
101 m_strMILastErrorDescription.clear();
105 // Details: Set MI's error condition description. This may be accessed by
107 // seen by users. Message is available to the client using the server
111 // Args: vFormat - (R) Format string.
112 // ... - (R) Variable number of CMIUtilString type objects.
116 void CMICmnBase::SetErrorDescriptionn(const char *vFormat, ...) const {
118 va_start(args, vFormat);
119 CMIUtilString strResult = CMIUtilString::FormatValist(vFormat, args);
122 SetErrorDescription(strResult);