OGLplus  (0.59.0) a C++ wrapper for rendering APIs

eagine/message_bus/014_tracker.cpp

Copyright Matus Chochlik. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt

namespace eagine {
namespace msgbus {
//------------------------------------------------------------------------------
using tracker_base = service_composition<node_tracker<shutdown_invoker<>>>;
class tracker_example
: public main_ctx_object
, public tracker_base {
using base = tracker_base;
public:
tracker_example(endpoint& bus)
: main_ctx_object{EAGINE_ID(TrkrExampl), bus}
, base{bus} {
object_description("Node tracker", "Node tracker example");
}
void on_node_change(remote_node& node, remote_node_changes changes) final {
log_info("node change ${nodeId}")
.arg(EAGINE_ID(changes), changes)
.arg(EAGINE_ID(nodeId), extract(node.id()));
}
auto is_done() const noexcept -> bool {
return true;
}
auto update() -> bool {
some_true something_done{};
something_done(base::update());
if(_checkup_needed) {
this->for_each_node([&](auto, auto& node) {
this->log_info("node ${nodeId} status")
.arg(EAGINE_ID(nodeId), node)
.arg(EAGINE_ID(host), node.host());
});
}
return something_done;
}
void shutdown() {
this->for_each_node(
[&](auto node_id, auto&) { this->shutdown_one(node_id); });
}
private:
resetting_timeout _checkup_needed{std::chrono::seconds(5)};
};
//------------------------------------------------------------------------------
} // namespace msgbus
auto main(main_ctx& ctx) -> int {
ctx.preinitialize();
msgbus::router_address address{ctx};
msgbus::connection_setup conn_setup(ctx);
msgbus::endpoint bus{EAGINE_ID(TrckrEndpt), ctx};
msgbus::tracker_example the_tracker{bus};
conn_setup.setup_connectors(the_tracker, address);
timeout keep_going{std::chrono::minutes(5)};
while(!keep_going) {
the_tracker.process_all();
if(!the_tracker.update()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
the_tracker.shutdown();
return 0;
}
//------------------------------------------------------------------------------
} // namespace eagine
auto main(int argc, const char** argv) -> int {
options.app_id = EAGINE_ID(PingExe);
return eagine::main_impl(argc, argv, options);
}
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
auto update() const noexcept -> bool
Updates the internal endpoint state (should be called repeatedly).
Definition: subscriber.hpp:51
@ endpoint
Message bus client endpoint.
main_ctx_object(identifier obj_id, main_ctx_parent parent) noexcept
Initialization from object id and parent.
Definition: main_ctx_object.hpp:77
auto log_info(string_view format) noexcept
Create a log message entry for information, with specified format.
Definition: logger.hpp:329
basic_address< false > address
Type alias for non-const memory address values.
Definition: address.hpp:203
void object_description(string_view display_name, string_view description) noexcept
Sets the human-readable name and description of this object.
Definition: logger.hpp:303
auto bus() noexcept -> auto &
Returns a reference to the associated endpoint.
Definition: subscriber.hpp:38
identifier app_id
The application root logger identifier.
Definition: main_ctx.hpp:30
Structure storing customization options for main context.
Definition: main_ctx.hpp:24

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).