2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
26 #include <boost/thread/tss.hpp>
27 #include <boost/algorithm/string/join.hpp>
31 boost::thread_specific_ptr<std::list<std::string>>& context_stacks_per_thread()
33 static boost::thread_specific_ptr<std::list<std::string>> instances;
42 std::list<std::string>& context_stack_for_thread()
44 auto local = context_stacks_per_thread().get();
48 local = new std::list<std::string>();
49 context_stacks_per_thread().reset(local);
55 std::string get_context()
57 return boost::join(context_stack_for_thread(), "");
60 scoped_context::scoped_context()
61 : scoped_context::scoped_context("")
65 scoped_context::scoped_context(std::string msg)
66 : for_thread_(context_stack_for_thread())
68 for_thread_.push_back(std::move(msg));
69 msg_ = &for_thread_.back();
72 void scoped_context::replace_msg(std::string msg)
74 if (&for_thread_ != &context_stack_for_thread())
75 CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Called from wrong thread"));
77 *msg_ = std::move(msg);
80 void scoped_context::clear_msg()
85 scoped_context::~scoped_context()
87 for_thread_.pop_back();
92 std::string get_message_and_context(const caspar_exception& e)
96 auto msg = boost::get_error_info<msg_info_t>(e);
97 auto ctx = boost::get_error_info<context_info_t>(e);
102 if (ctx && !ctx->empty())
109 if (!result.empty() && result.back() != '.')