SObjectizer  5.5
Classes | Public Member Functions | Private Attributes | List of all members
so_5::wrapped_env_t Class Reference

A wrapped environment. More...

#include <wrapped_env.hpp>

Classes

struct  details_t
 Implementation details for wrapped_env. More...
 

Public Member Functions

 wrapped_env_t (const wrapped_env_t &)=delete
 
 wrapped_env_t (wrapped_env_t &&)=delete
 
 wrapped_env_t ()
 Default constructor. More...
 
 wrapped_env_t (so_5::api::generic_simple_init_t init_func)
 A constructor which receives only initialization function. More...
 
 wrapped_env_t (so_5::api::generic_simple_init_t init_func, so_5::api::generic_simple_so_env_params_tuner_t params_tuner)
 
 wrapped_env_t (so_5::api::generic_simple_init_t init_func, environment_params_t &&params)
 
 wrapped_env_t (environment_params_t &&params)
 A constructor which receives already prepared environment's params. More...
 
 ~wrapped_env_t ()
 Destructor. More...
 
environment_tenvironment () const
 Access to wrapped environment. More...
 
void stop ()
 Send stop signal to environment. More...
 
void join ()
 Wait for complete finish of environment's work. More...
 
void stop_then_join ()
 Send stop signal and wait for complete finish of environment's work. More...
 

Private Attributes

std::unique_ptr< details_tm_impl
 Implementation details. More...
 

Detailed Description

A wrapped environment.

Since
v.5.5.9
Note
Starts a SObjectizer Environment in the constructor. Automatically stops it in the destructor (via stop_then_join() call). An Environment will be started on the context of new thread. This thread is also created in the constructor of wrapped_env_t.
SObjectizer Environment is started with autoshutdown disabled. It means that the Environment won't be stopped when the last coop will be deregistered. Autoshutdown will be disabled even if a constructor with custom Environment's params will be used.
Usage examples
// Start Environment without initialization function.
int main()
{
... // Some user code.
// Add a cooperation to environment.
env.environment().introduce_coop( []( so_5::coop_t & coop ) {
coop.make_agent< some_agent >(...);
...
} );
... // Some user code.
return 0; // env.stop_then_join() will be called in env destructor.
}
// Start Environment with initialization function but with
// default parameters.
int main()
{
[]( so_5::environment_t & env ) {
... // Some initialization stuff.
}
};
... // Some user code.
return 0; // env.stop_then_join() will be called in env destructor.
}
// Start Environment with initialization function and custom
// parameters.
{
...
return params;
}
int main()
{
[]( so_5::environment_t & env ) {
... // Some initialization stuff.
},
make_params()
};
... // Some user code.
return 0; // env.stop_then_join() will be called in env destructor.
}
// Start Environment with initialization function and custom
// parameters tuner function.
int main()
{
[]( so_5::environment_t & env ) {
... // Some initialization stuff.
},
[]( so_5::environment_params_t & params ) {
...
}
};
... // Some user code.
return 0; // env.stop_then_join() will be called in env destructor.
}
// Explicit stop and join.
int main()
{
so_5::wrapped_env_t env{ ... };
... // Some user code.
// Stopping environment.
env.stop();
... // Some user code.
// Waiting for finish of environment's work.
env.join();
... // Some user code.
}
Attention
Please note that if an init function is passed to the constructor of wrapped_env_t objects then it is possible that this init function will work longer than lifetime of wrapped_env_t object. For example:
int some_func() {
[](so_5::environment_t & env) { ... } // Some long-running code inside.
};
... // Some very fast actions.
return 42; // It is possible that init-function is not finished yet.
}
This can lead to some nasty surprises. For example:
[](so_5::environment & env) {
env.introduce_coop(...); // Creation of one coop.
env.introduce_coop(...); // Creation of another coop.
...
env.introduce_coop(...); // Creation of yet another coop.
}
};
... // Some very fact actions.
env.stop(); // Several coops could not be registered yet.
Examples:
so_5/convert_lib/main.cpp, so_5/intercom_statechart/main.cpp, so_5/mchain_handler_formats/main.cpp, so_5/mchain_multi_consumers/main.cpp, so_5/mchain_select/main.cpp, so_5/mchain_svc_req/main.cpp, so_5/state_deep_history/main.cpp, so_5/wrapped_env_demo/main.cpp, so_5/wrapped_env_demo_2/main.cpp, and so_5/wrapped_env_demo_3/main.cpp.

Constructor & Destructor Documentation

◆ wrapped_env_t() [1/7]

so_5::wrapped_env_t::wrapped_env_t ( const wrapped_env_t )
delete

◆ wrapped_env_t() [2/7]

so_5::wrapped_env_t::wrapped_env_t ( wrapped_env_t &&  )
delete

◆ wrapped_env_t() [3/7]

so_5::wrapped_env_t::wrapped_env_t ( )

Default constructor.

Starts environment without any initialization actions.

◆ wrapped_env_t() [4/7]

so_5::wrapped_env_t::wrapped_env_t ( so_5::api::generic_simple_init_t  init_func)

A constructor which receives only initialization function.

Default environment parameters will be used.

Parameters
init_funcInitialization function.

◆ wrapped_env_t() [5/7]

so_5::wrapped_env_t::wrapped_env_t ( so_5::api::generic_simple_init_t  init_func,
so_5::api::generic_simple_so_env_params_tuner_t  params_tuner 
)

A constructor which receives initialization function and a function for environment's params tuning.

Parameters
init_funcInitialization function.
params_tunerFunction for environment's params tuning.

◆ wrapped_env_t() [6/7]

so_5::wrapped_env_t::wrapped_env_t ( so_5::api::generic_simple_init_t  init_func,
environment_params_t &&  params 
)

A constructor which receives initialization function and already prepared environment's params.

Parameters
init_funcInitialization function.
paramsEnvironment's params.

◆ wrapped_env_t() [7/7]

so_5::wrapped_env_t::wrapped_env_t ( environment_params_t &&  params)

A constructor which receives already prepared environment's params.

Since
v.5.5.13
Parameters
paramsEnvironment's params.

◆ ~wrapped_env_t()

so_5::wrapped_env_t::~wrapped_env_t ( )

Destructor.

Stops the environment and waits it.

Member Function Documentation

◆ environment()

environment_t & so_5::wrapped_env_t::environment ( ) const

◆ join()

void so_5::wrapped_env_t::join ( )

Wait for complete finish of environment's work.

◆ stop()

void so_5::wrapped_env_t::stop ( )

Send stop signal to environment.

◆ stop_then_join()

void so_5::wrapped_env_t::stop_then_join ( )

Send stop signal and wait for complete finish of environment's work.

Member Data Documentation

◆ m_impl

std::unique_ptr< details_t > so_5::wrapped_env_t::m_impl
private

Implementation details.


The documentation for this class was generated from the following files: