SObjectizer 5.8
Loading...
Searching...
No Matches
so_5/deadletter_handler/main.cpp
#include <so_5/all.hpp>
// Demo agent which shows deadletter handler.
class demo final : public so_5::agent_t {
// We need two signals. One will be handler by ordinary handler...
struct first_signal final : public so_5::signal_t {};
// ...and second by deadletter handler.
struct second_signal final : public so_5::signal_t {};
public:
demo(context_t ctx) : so_5::agent_t(std::move(ctx)) {
// Create subscriptions.
// The first signal will be handled as usual.
so_subscribe_self().event([](mhood_t<first_signal>) {
std::cout << "first_signal: ordinary handler" << std::endl;
});
// A deadletter handler will be used for the second.
[](mhood_t<second_signal>) {
std::cout << "second_signal: deadletter handler" << std::endl;
});
}
void so_evt_start() override {
// Send two different signal.
// Agent is no more needed.
}
};
int main() {
// Launch the SObjectizer with just one agent inside.
});
}
A helper header file for including all public SObjectizer stuff.
A base class for agents.
Definition agent.hpp:673
void so_subscribe_deadletter_handler(const so_5::mbox_t &mbox, Event_Handler &&handler, thread_safety_t thread_safety=thread_safety_t::unsafe)
Create a subscription for deadletter handler for a specific message from a specific mbox.
Definition agent.hpp:2080
subscription_bind_t so_subscribe_self()
Initiate subscription to agent's direct mbox.
Definition agent.hpp:1416
void so_deregister_agent_coop_normally()
A helper method for deregistering agent's coop in case of normal deregistration.
Definition agent.cpp:982
const mbox_t & so_direct_mbox() const
Get the agent's direct mbox.
Definition agent.cpp:762
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
Definition agent.cpp:701
SObjectizer Environment.
coop_handle_t register_agent_as_coop(std::unique_ptr< A > agent)
Register single agent as a cooperation.
std::unique_ptr< Agent > make_agent(Args &&... args)
Helper method for simplification of agents creation.
A base class for agent signals.
Definition message.hpp:275
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, subscription_bind_t & >::type event(Method_Pointer pfn, thread_safety_t thread_safety=not_thread_safe)
Make subscription to the message.
Definition agent.hpp:3490
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
Definition api.hpp:142
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.