Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::BufferedMessageCallback Class Reference

#include <message_callback_data.h>

Public Member Functions

 BufferedMessageCallback (SolverInterface::MessageCallback user_message_callback)
 
bool has_user_message_callback () const
 
void OnMessage (absl::string_view message)
 
void Flush ()
 

Detailed Description

Buffers callback data into lines using MessageCallbackData and invokes the callback as new lines are ready.

In MathOpt, typically used for solvers that provide a callback with the solver logs where the logs contain \n characters and messages may be both less than a complete line or multiple lines. Recommended use:

  • Register a callback with the underlying solver to get its logs. In the callback, when given a log string, call OnMessage() on it.
  • Run the solver's Solve() function.
  • Unregister the callback with the underlying solver.
  • Call Flush() to ensure any final incomplete lines are sent.

If initialized with a nullptr for the user callback, all functions on this class have no effect.

This class is threadsafe if the input callback is also threadsafe.

Definition at line 81 of file message_callback_data.h.

Constructor & Destructor Documentation

◆ BufferedMessageCallback()

operations_research::math_opt::BufferedMessageCallback::BufferedMessageCallback ( SolverInterface::MessageCallback user_message_callback)
explicit

Definition at line 65 of file message_callback_data.cc.

Member Function Documentation

◆ Flush()

void operations_research::math_opt::BufferedMessageCallback::Flush ( )

If the buffer has any pending message, sends it to the callback. This function has no effect if called when the buffer is empty. Calling this function when the buffer is non-empty before the stream of logs is complete will result in the user getting extra line breaks.

Do not hold lock during callback to user code.

Definition at line 84 of file message_callback_data.cc.

◆ has_user_message_callback()

bool operations_research::math_opt::BufferedMessageCallback::has_user_message_callback ( ) const
inline

If false, incoming messages are ignored and OnMessage() and Flush() have no effect.

Definition at line 88 of file message_callback_data.h.

◆ OnMessage()

void operations_research::math_opt::BufferedMessageCallback::OnMessage ( absl::string_view message)

Appends message to the buffer, then invokes the callback once on all newly complete lines and removes those lines from the buffer. In particular, the callback is not invoked if message does not contain any \n.

Do not hold lock during callback to user code.

Definition at line 69 of file message_callback_data.cc.


The documentation for this class was generated from the following files: