|
SObjectizer
5.5
|
A traditional way of starting SO Environment is to use so_5::launch free function:
This way is useful if all application logic is implemented by SObjectizer’s agents and there is only one SO Environment in the application. But sometimes it is not the case. For example if an application has to have GUI-event handling loop. In that case application’s main() function could look like:
Usage of so_5::launch() in such cases is not as straightforward as intended to be. It could look like:
It is not a simple approach and it could lead to mistakes.
To simplify a development of applications with some GUI-event loops a new class has been added in v.5.5.9: so_5::wrapped_env_t. With that class the example above can be rewritten that way:
Working principle of so_5::wrapped_env_t is very simple:
This way of working guarantees that a reference to actual so_5::rt::environment_t instance will be valid for the whole lifetime of wrapped_env_t object.
There are several constructors for so_5::wrapped_env_t. The simplest one is the default constructor:
New coops could be added later via traditional approaches:
There is also a constructor which receives a lambda-function or a functional object for doing initial actions right after start of SO Environment (just like in the case of so_5::launch):
There are also two constructors which allows to tune SO Environment parameters. One of them receives a rvalue reference to so_5::rt::environment_params_t object:
The second receives parameters' tuner lambda or functional object:
Class wrapped_env_t always adds disable_autoshutdown option to SO Environment parameters. It means that SO Environment will not be stopped after deregistration of the last coop. Only explicit call to wrapped_env_t::stop() or wrapped_ent_t::stop_then_join() stops SO Environment. SO Environment also automatically stopped in the wrapped_env’s destructor.
1.8.14