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
22 #include "../stdafx.h"
28 #include <boost/thread.hpp>
30 #include <tbb/spin_mutex.h>
34 namespace caspar { namespace diagnostics {
36 int color(float r, float g, float b, float a)
39 code |= static_cast<int>(r*255.0f+0.5f) << 24;
40 code |= static_cast<int>(g*255.0f+0.5f) << 16;
41 code |= static_cast<int>(b*255.0f+0.5f) << 8;
42 code |= static_cast<int>(a*255.0f+0.5f) << 0;
46 std::tuple<float, float, float, float> color(int code)
48 float r = static_cast<float>((code >> 24) & 255)/255.0f;
49 float g = static_cast<float>((code >> 16) & 255)/255.0f;
50 float b = static_cast<float>((code >> 8) & 255)/255.0f;
51 float a = static_cast<float>((code >> 0) & 255)/255.0f;
52 return std::make_tuple(r, g, b, a);
55 typedef std::vector<spi::sink_factory_t> sink_factories_t;
56 static boost::mutex g_sink_factories_mutex;
57 static sink_factories_t g_sink_factories;
59 std::vector<spl::shared_ptr<spi::graph_sink>> create_sinks()
61 boost::lock_guard<boost::mutex> lock(g_sink_factories_mutex);
63 return cpplinq::from(g_sink_factories)
64 .select([](const spi::sink_factory_t& s){ return s(); })
70 std::vector<spl::shared_ptr<spi::graph_sink>> sinks_ = create_sinks();
78 for (auto& sink : sinks_)
82 void set_text(const std::wstring& value)
84 for (auto& sink : sinks_)
85 sink->set_text(value);
88 void set_value(const std::string& name, double value)
90 for (auto& sink : sinks_)
91 sink->set_value(name, value);
94 void set_tag(tag_severity severity, const std::string& name)
96 for (auto& sink : sinks_)
97 sink->set_tag(severity, name);
100 void set_color(const std::string& name, int color)
102 for (auto& sink : sinks_)
103 sink->set_color(name, color);
108 for (auto& sink : sinks_)
114 impl& operator=(impl&);
117 graph::graph() : impl_(new impl)
121 void graph::set_text(const std::wstring& value) { impl_->set_text(value); }
122 void graph::set_value(const std::string& name, double value) { impl_->set_value(name, value); }
123 void graph::set_color(const std::string& name, int color) { impl_->set_color(name, color); }
124 void graph::set_tag(tag_severity severity, const std::string& name) { impl_->set_tag(severity, name); }
125 void graph::auto_reset() { impl_->auto_reset(); }
127 void register_graph(const spl::shared_ptr<graph>& graph)
129 graph->impl_->activate();
134 void register_sink_factory(sink_factory_t factory)
136 boost::lock_guard<boost::mutex> lock(g_sink_factories_mutex);
138 g_sink_factories.push_back(std::move(factory));