Type of smart handle for a cooperation.
Type coop_handle_t is used for references to registered coops. Before v.5.6 coops in SObjectizer-5 were identified via strings. Every coop had its own name.
Since v.5.6.0 names are no more used for identificators of coops. SObjectizer's environment_t returns instances of coop_handle_t for every registered coop. This handle can be used for deregistration of the coop at the appropriate time. For example:
std::map<request_id_t, so_5::coop_handle_t> active_requests_;
...
void on_new_request(mhood_t<request_t> cmd) {
...;
active_requests_[cmd->request_id()] = so_environment().register_coop(std::move(coop));
}
...
void on_cancel_request(mhood_t<cancel_request_t> cmd) {
auto it = active_requests_.find(cmd->request_id());
if(it != active_requests_.end())
so_environment().deregister_coop(it->second);
}
};
Note that coop_handle_t is somewhat like (smart)pointer. It can be empty, e.g. do not point to any coop. Or it can be not-empty. In that case coop_handle_t is very similar to std::weak_ptr.
- Since
- v.5.6.0
- Examples:
- so_5/coop_listener/main.cpp, so_5/exception_logger/main.cpp, and so_5/ping_pong_with_owner/main.cpp.