cmSystemTools: MessageCallback and Message() accept std::string argument

This commit is contained in:
Vitaly Stakhovsky 2019-02-06 15:00:00 -05:00
parent 062cfd991f
commit 82edd98300
12 changed files with 35 additions and 34 deletions

View File

@ -118,7 +118,7 @@ public:
: CM(cm)
{
cmSystemTools::SetMessageCallback(
[&s](const char* msg, const char* /*unused*/) {
[&s](const std::string& msg, const char* /*unused*/) {
s += msg;
s += "\n";
});

View File

@ -150,7 +150,7 @@ int main(int argc, char const* const* argv)
}
cmSystemTools::SetMessageCallback(
[myform](const char* message, const char* title) {
[myform](const std::string& message, const char* title) {
myform->AddError(message, title);
});

View File

@ -9,6 +9,8 @@
#include "cmsys/FStream.hxx"
#include <string>
class cmCursesForm
{
public:
@ -34,7 +36,7 @@ public:
// Description:
// During a CMake run, an error handle should add errors
// to be displayed afterwards.
virtual void AddError(const char*, const char*) {}
virtual void AddError(const std::string&, const char*) {}
// Description:
// Turn debugging on. This will create ccmakelog.txt.

View File

@ -647,7 +647,8 @@ int cmCursesMainForm::Generate()
return 0;
}
void cmCursesMainForm::AddError(const char* message, const char* /*unused*/)
void cmCursesMainForm::AddError(const std::string& message,
const char* /*unused*/)
{
this->Errors.emplace_back(message);
}

View File

@ -81,7 +81,7 @@ public:
* During a CMake run, an error handle should add errors
* to be displayed afterwards.
*/
void AddError(const char* message, const char* title) override;
void AddError(const std::string& message, const char* title) override;
/**
* Used to do a configure. If argument is specified, it does only the check

View File

@ -25,7 +25,7 @@ QCMake::QCMake(QObject* p)
cmSystemTools::SetRunCommandHideConsole(true);
cmSystemTools::SetMessageCallback(
[this](const char* msg, const char* title) {
[this](std::string const& msg, const char* title) {
this->messageCallback(msg, title);
});
cmSystemTools::SetStdoutCallback(
@ -359,9 +359,9 @@ void QCMake::progressCallback(const char* msg, float percent)
QCoreApplication::processEvents();
}
void QCMake::messageCallback(const char* msg, const char* /*title*/)
void QCMake::messageCallback(std::string const& msg, const char* /*title*/)
{
emit this->errorMessage(QString::fromLocal8Bit(msg));
emit this->errorMessage(QString::fromStdString(msg));
QCoreApplication::processEvents();
}

View File

@ -169,7 +169,7 @@ protected:
bool interruptCallback();
void progressCallback(const char* msg, float percent);
void messageCallback(const char* msg, const char* title);
void messageCallback(std::string const& msg, const char* title);
void stdoutCallback(std::string const& msg);
void stderrCallback(std::string const& msg);

View File

@ -97,7 +97,7 @@ void cmServer::ProcessRequest(cmConnection* connection,
}
cmSystemTools::SetMessageCallback(
[&request](const char* msg, const char* title) {
[&request](const std::string& msg, const char* title) {
reportMessage(msg, title, request);
});
@ -165,15 +165,14 @@ void cmServer::reportProgress(const char* msg, float progress,
}
}
void cmServer::reportMessage(const char* msg, const char* title,
void cmServer::reportMessage(const std::string& msg, const char* title,
const cmServerRequest& request)
{
assert(msg);
std::string titleString;
if (title) {
titleString = title;
}
request.ReportMessage(std::string(msg), titleString);
request.ReportMessage(msg, titleString);
}
cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)

View File

@ -121,7 +121,7 @@ public:
private:
static void reportProgress(const char* msg, float progress,
const cmServerRequest& request);
static void reportMessage(const char* msg, const char* title,
static void reportMessage(const std::string& msg, const char* title,
const cmServerRequest& request);
// Handle requests:

View File

@ -323,16 +323,16 @@ void cmSystemTools::Stdout(const std::string& s)
}
}
void cmSystemTools::Message(const char* m1, const char* title)
void cmSystemTools::Message(const std::string& m, const char* title)
{
if (s_DisableMessages) {
return;
}
if (s_MessageCallback) {
s_MessageCallback(m1, title);
s_MessageCallback(m, title);
return;
}
std::cerr << m1 << std::endl << std::flush;
std::cerr << m << std::endl << std::flush;
}
void cmSystemTools::ReportLastSystemError(const char* msg)

View File

@ -56,7 +56,7 @@ public:
*/
static std::string TrimWhitespace(const std::string& s);
using MessageCallback = std::function<void(const char*, const char*)>;
using MessageCallback = std::function<void(const std::string&, const char*)>;
/**
* Set the function used by GUIs to display error messages
* Function gets passed: message as a const char*,
@ -74,11 +74,7 @@ public:
/**
* Display a message.
*/
static void Message(const char* m, const char* title = nullptr);
static void Message(const std::string& m, const char* title = nullptr)
{
Message(m.c_str(), title);
}
static void Message(const std::string& m, const char* title = nullptr);
using OutputCallback = std::function<void(std::string const&)>;

View File

@ -142,8 +142,8 @@ static std::string cmakemainGetStack(cmake* cm)
return msg;
}
static void cmakemainMessageCallback(const char* m, const char* /*unused*/,
cmake* cm)
static void cmakemainMessageCallback(const std::string& m,
const char* /*unused*/, cmake* cm)
{
std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush;
}
@ -319,9 +319,10 @@ int do_cmake(int ac, char const* const* av)
cmake cm(role, mode);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cmSystemTools::SetMessageCallback(
[&cm](const std::string& msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cm.SetProgressCallback([&cm](const char* msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
});
@ -499,9 +500,10 @@ static int do_build(int ac, char const* const* av)
}
cmake cm(cmake::RoleInternal, cmState::Unknown);
cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cmSystemTools::SetMessageCallback(
[&cm](const std::string& msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cm.SetProgressCallback([&cm](const char* msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
});
@ -541,9 +543,10 @@ static int do_open(int ac, char const* const* av)
}
cmake cm(cmake::RoleInternal, cmState::Unknown);
cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cmSystemTools::SetMessageCallback(
[&cm](const std::string& msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cm.SetProgressCallback([&cm](const char* msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
});