mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Move some repetitive code into a separate method
This commit is contained in:
parent
ec50b66ff3
commit
f4461d5e95
3 changed files with 25 additions and 80 deletions
|
@ -59,7 +59,7 @@ protected:
|
|||
bool DoUpdate() override;
|
||||
bool DoHeartbeat(double network_time, double current_time) override;
|
||||
|
||||
zeek::detail::Location* GetLocationInfo() const override { return read_location.get(); }
|
||||
const zeek::detail::Location* GetLocationInfo() const override { return read_location.get(); }
|
||||
|
||||
private:
|
||||
bool ReadHeader(bool useCached);
|
||||
|
|
|
@ -89,11 +89,11 @@ public:
|
|||
INTERNAL_ERROR
|
||||
};
|
||||
|
||||
ReporterMessage(Type arg_type, MsgThread* thread, const char* arg_msg)
|
||||
ReporterMessage(Type arg_type, MsgThread* thread, std::string_view arg_msg)
|
||||
: OutputMessage<MsgThread>("ReporterMessage", thread)
|
||||
{
|
||||
type = arg_type;
|
||||
msg = util::copy_string(arg_msg);
|
||||
msg = util::copy_string(arg_msg.data());
|
||||
}
|
||||
|
||||
~ReporterMessage() override { delete[] msg; }
|
||||
|
@ -125,11 +125,11 @@ public:
|
|||
class DebugMessage final : public OutputMessage<MsgThread>
|
||||
{
|
||||
public:
|
||||
DebugMessage(DebugStream arg_stream, MsgThread* thread, const char* arg_msg)
|
||||
DebugMessage(DebugStream arg_stream, MsgThread* thread, std::string_view arg_msg)
|
||||
: OutputMessage<MsgThread>("DebugMessage", thread)
|
||||
{
|
||||
stream = arg_stream;
|
||||
msg = util::copy_string(arg_msg);
|
||||
msg = util::copy_string(arg_msg.data());
|
||||
}
|
||||
|
||||
~DebugMessage() override { delete[] msg; }
|
||||
|
@ -341,7 +341,7 @@ void MsgThread::Finished()
|
|||
SendOut(new detail::FinishedMessage(this));
|
||||
}
|
||||
|
||||
void MsgThread::Info(const char* msg)
|
||||
std::string MsgThread::BuildMsgWithLocation(const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
|
@ -352,96 +352,48 @@ void MsgThread::Info(const char* msg)
|
|||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INFO, this, desc.Description()));
|
||||
return std::string(desc.Description());
|
||||
}
|
||||
|
||||
void MsgThread::Info(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INFO, this,
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::Warning(const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(
|
||||
new detail::ReporterMessage(detail::ReporterMessage::WARNING, this, desc.Description()));
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::WARNING, this,
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::Error(const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::ERROR, this, desc.Description()));
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::ERROR, this,
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::FatalError(const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::FATAL_ERROR, this,
|
||||
desc.Description()));
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::FatalErrorWithCore(const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::FATAL_ERROR_WITH_CORE, this,
|
||||
desc.Description()));
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::InternalWarning(const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INTERNAL_WARNING, this,
|
||||
desc.Description()));
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::InternalError(const char* msg)
|
||||
{
|
||||
// This one aborts immediately.
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
fprintf(stderr, "internal error in thread: %s\n", desc.Description());
|
||||
fprintf(stderr, "internal error in thread: %s\n", BuildMsgWithLocation(msg).c_str());
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -449,16 +401,7 @@ void MsgThread::InternalError(const char* msg)
|
|||
|
||||
void MsgThread::Debug(DebugStream stream, const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::DebugMessage(stream, this, desc.Description()));
|
||||
SendOut(new detail::DebugMessage(stream, this, BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -289,7 +289,7 @@ protected:
|
|||
* @return A Location pointer containing the file location information,
|
||||
* or nullptr if nothing is available.
|
||||
*/
|
||||
virtual zeek::detail::Location* GetLocationInfo() const { return nullptr; }
|
||||
virtual const zeek::detail::Location* GetLocationInfo() const { return nullptr; }
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -353,6 +353,8 @@ private:
|
|||
*/
|
||||
void Finished();
|
||||
|
||||
std::string BuildMsgWithLocation(const char* msg);
|
||||
|
||||
Queue<BasicInputMessage*> queue_in;
|
||||
Queue<BasicOutputMessage*> queue_out;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue