OR-Tools  9.6
gscip_solver_message_callback_handler.cc
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
15 
16 #include <functional>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 #include "absl/strings/string_view.h"
22 #include "absl/synchronization/mutex.h"
26 
27 namespace operations_research {
28 namespace math_opt {
29 
31  SolverInterface::MessageCallback message_callback)
32  : message_callback_(std::move(message_callback)) {}
33 
35  const absl::MutexLock lock(&message_mutex_);
36  const std::vector<std::string> lines = message_callback_data_.Flush();
37  if (!lines.empty()) {
38  message_callback_(lines);
39  }
40 }
41 
43  return std::bind(&GScipSolverMessageCallbackHandler::MessageCallback, this,
44  std::placeholders::_1, std::placeholders::_2);
45 }
46 
47 void GScipSolverMessageCallbackHandler::MessageCallback(
48  GScipMessageType, const absl::string_view message) {
49  const absl::MutexLock lock(&message_mutex_);
50  const std::vector<std::string> lines = message_callback_data_.Parse(message);
51  if (!lines.empty()) {
52  message_callback_(lines);
53  }
54 }
55 
56 } // namespace math_opt
57 } // namespace operations_research
GScipSolverMessageCallbackHandler(SolverInterface::MessageCallback message_callback)
std::function< void(const std::vector< std::string > &)> MessageCallback
Collection of objects used to extend the Constraint Solver library.
std::function< void(GScipMessageType type, absl::string_view message)> GScipMessageHandler
std::string message
Definition: trace.cc:399