2 * Copyright 2013 Sveriges Television AB http://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
23 #include <common/memory.h>
24 #include <common/assert.h>
26 #include <boost/variant.hpp>
27 #include <boost/chrono/duration.hpp>
33 namespace caspar { namespace core { namespace monitor {
35 typedef boost::variant<bool,
42 std::vector<std::int8_t>> data_t;
48 message(std::string path, std::vector<data_t> data = std::vector<data_t>())
49 : path_(std::move(path))
50 , data_ptr_(std::make_shared<std::vector<data_t>>(std::move(data)))
52 CASPAR_ASSERT(path.empty() || path[0] == '/');
55 message(std::string path, spl::shared_ptr<std::vector<data_t>> data_ptr)
56 : path_(std::move(path))
57 , data_ptr_(std::move(data_ptr))
59 CASPAR_ASSERT(path.empty() || path[0] == '/');
62 const std::string& path() const
67 const std::vector<data_t>& data() const
72 message propagate(const std::string& path) const
74 return message(path + path_, data_ptr_);
78 message& operator%(T&& data)
80 data_ptr_->push_back(std::forward<T>(data));
86 spl::shared_ptr<std::vector<data_t>> data_ptr_;
93 virtual void propagate(const message& msg) = 0;
96 class subject : public sink
99 std::weak_ptr<sink> parent_;
100 const std::string path_;
102 subject(std::string path = "")
103 : path_(std::move(path))
105 CASPAR_ASSERT(path.empty() || path[0] == '/');
108 void attach_parent(spl::shared_ptr<sink> parent)
110 parent_ = std::move(parent);
118 subject& operator<<(const message& msg)
125 virtual void propagate(const message& msg) override
127 auto parent = parent_.lock();
130 parent->propagate(msg.propagate(path_));