Commit 53feac8d authored by Dominik Charousset's avatar Dominik Charousset

Improve exec_main, make config for caf_main const

parent 8f523243
......@@ -17,10 +17,10 @@
MARKDOWN_SUPPORT = YES
#---------------------------------------------------------------------------
# Project related configuration options
# Project related actor_system& system, const uration options
#---------------------------------------------------------------------------
# This tag specifies the encoding used for all characters in the config file
# This tag specifies the encoding used for all characters in the actor_system& system, const file
# that follow. The default is UTF-8 which is also the encoding used for all
# text before the first occurrence of this tag. Doxygen uses libiconv (or the
# iconv built into libc) for the transcoding. See
......@@ -280,7 +280,7 @@ SUBGROUPING = YES
TYPEDEF_HIDES_STRUCT = NO
#---------------------------------------------------------------------------
# Build related configuration options
# Build related actor_system& system, const uration options
#---------------------------------------------------------------------------
# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
......@@ -490,7 +490,7 @@ FILE_VERSION_FILTER =
LAYOUT_FILE =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
# actor_system& system, const uration options related to warning and progress messages
#---------------------------------------------------------------------------
# The QUIET tag can be used to turn on/off the messages that are generated
......@@ -541,7 +541,7 @@ WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
# actor_system& system, const uration options related to the input files
#---------------------------------------------------------------------------
# The INPUT tag can be used to specify the files and/or directories that contain
......@@ -657,7 +657,7 @@ FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
# actor_system& system, const uration options related to source browsing
#---------------------------------------------------------------------------
# If the SOURCE_BROWSER tag is set to YES then a list of source files will
......@@ -713,7 +713,7 @@ USE_HTAGS = NO
VERBATIM_HEADERS = NO
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
# actor_system& system, const uration options related to the alphabetical class index
#---------------------------------------------------------------------------
# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
......@@ -736,7 +736,7 @@ COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
# actor_system& system, const uration options related to the HTML output
#---------------------------------------------------------------------------
# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
......@@ -947,7 +947,7 @@ TREEVIEW_WIDTH = 250
FORMULA_FONTSIZE = 10
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
# actor_system& system, const uration options related to the LaTeX output
#---------------------------------------------------------------------------
# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
......@@ -1023,7 +1023,7 @@ LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
# actor_system& system, const uration options related to the RTF output
#---------------------------------------------------------------------------
# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
......@@ -1054,18 +1054,18 @@ COMPACT_RTF = NO
RTF_HYPERLINKS = NO
# Load stylesheet definitions from file. Syntax is similar to doxygen's
# config file, i.e. a series of assignments. You only have to provide
# actor_system& system, const file, i.e. a series of assignments. You only have to provide
# replacements, missing definitions are set to their default value.
RTF_STYLESHEET_FILE =
# Set optional variables used in the generation of an rtf document.
# Syntax is similar to doxygen's config file.
# Syntax is similar to doxygen's actor_system& system, const file.
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
# actor_system& system, const uration options related to the man page output
#---------------------------------------------------------------------------
# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
......@@ -1093,7 +1093,7 @@ MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
# actor_system& system, const uration options related to the XML output
#---------------------------------------------------------------------------
# If the GENERATE_XML tag is set to YES Doxygen will
......@@ -1116,7 +1116,7 @@ XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
# actor_system& system, const uration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
......@@ -1128,7 +1128,7 @@ XML_PROGRAMLISTING = YES
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
# actor_system& system, const uration options related to the Perl module output
#---------------------------------------------------------------------------
# If the GENERATE_PERLMOD tag is set to YES Doxygen will
......
......@@ -193,7 +193,7 @@ public:
}
};
void caf_main(actor_system& system, config& cfg) {
void caf_main(actor_system& system, const config& cfg) {
if (cfg.server_mode) {
cout << "run in server mode" << endl;
auto pong_actor = system.spawn(pong);
......
......@@ -74,7 +74,7 @@ public:
}
};
void caf_main(actor_system& system, config& cfg) {
void caf_main(actor_system& system, const config& cfg) {
cout << "*** run in server mode listen on: " << cfg.port << endl;
cout << "*** to quit the program, simply press <enter>" << endl;
auto server_actor = system.middleman().spawn_server(server, cfg.port);
......
......@@ -90,7 +90,7 @@ public:
}
};
void caf_main(actor_system& system, config&) {
void caf_main(actor_system& system, const config&) {
// two variables for testing serialization
foo2 f1;
foo2 f2;
......
......@@ -68,7 +68,7 @@ public:
}
};
void caf_main(actor_system& system, config&) {
void caf_main(actor_system& system, const config&) {
anon_send(system.spawn(testee), foo{1, 2});
}
......
......@@ -82,7 +82,7 @@ public:
}
};
void caf_main(actor_system& system, config&) {
void caf_main(actor_system& system, const config&) {
anon_send(system.spawn(testee), foo{1, 2});
}
......
......@@ -57,7 +57,7 @@ public:
}
};
void caf_main(actor_system& system, config&) {
void caf_main(actor_system& system, const config&) {
double x;
double y;
cout << "x: " << flush;
......
......@@ -263,7 +263,7 @@ public:
}
};
void caf_main(actor_system& system, config& cfg) {
void caf_main(actor_system& system, const config& cfg) {
if (! cfg.server_mode && cfg.port == 0) {
cerr << "*** no port to server specified" << endl;
return;
......
......@@ -73,15 +73,16 @@ public:
}
};
void caf_main(actor_system& system, config& cfg) {
while (cfg.name.empty()) {
void caf_main(actor_system& system, const config& cfg) {
auto name = cfg.name;
while (name.empty()) {
cout << "please enter your name: " << flush;
if (! getline(cin, cfg.name)) {
if (! getline(cin, name)) {
cerr << "*** no name given... terminating" << endl;
return;
}
}
auto client_actor = system.spawn(client, cfg.name);
auto client_actor = system.spawn(client, name);
// evaluate group parameters
if (! cfg.group_id.empty()) {
auto p = cfg.group_id.find(':');
......
......@@ -28,7 +28,7 @@ public:
}
};
void caf_main(actor_system& system, config& cfg) {
void caf_main(actor_system& system, const config& cfg) {
system.middleman().publish_local_groups(cfg.port);
cout << "type 'quit' to shutdown the server" << endl;
string line;
......
......@@ -207,6 +207,8 @@ public:
node_id network_id;
proxy_registry* network_proxies;
int (*slave_mode_fun)(actor_system&, const actor_system_config&);
protected:
virtual void init();
......
......@@ -42,7 +42,7 @@ struct exec_main_helper<detail::type_list<actor_system&>> {
};
template <class T>
struct exec_main_helper<detail::type_list<actor_system&, T&>> {
struct exec_main_helper<detail::type_list<actor_system&, const T&>> {
using config = T;
template <class F>
......@@ -55,6 +55,22 @@ template <class... Ts, class F = void (*)(actor_system&)>
int exec_main(F fun, int argc, char** argv,
const char* config_file_name = "caf-application.ini") {
using trait = typename detail::get_callable_trait<F>::type;
using arg_types = typename trait::arg_types;
static_assert(detail::tl_size<arg_types>::value == 1
|| detail::tl_size<arg_types>::value == 2,
"main function must have one or two arguments");
static_assert(std::is_same<
typename detail::tl_head<arg_types>::type,
actor_system&
>::value,
"main function must take actor_system& as first parameter");
using arg2 = typename detail::tl_at<arg_types, 1>::type;
using decayed_arg2 = typename std::decay<arg2>::type;
static_assert(std::is_same<arg2, unit_t>::value
|| (std::is_base_of<actor_system_config, decayed_arg2>::value
&& std::is_same<arg2, const decayed_arg2&>::value),
"second parameter of main function must take a subtype of "
"actor_system_config as const reference");
using helper = exec_main_helper<typename trait::arg_types>;
// pass CLI options to config
typename helper::config cfg;
......@@ -68,7 +84,11 @@ int exec_main(F fun, int argc, char** argv,
// pass config to the actor system
actor_system system{cfg};
if (cfg.slave_mode) {
if (! cfg.slave_mode_fun) {
std::cerr << "cannot run slave mode, I/O module not loaded" << std::endl;
return 1;
}
return cfg.slave_mode_fun(system, cfg);
}
helper f;
f(fun, system, cfg);
......@@ -79,7 +99,7 @@ int exec_main(F fun, int argc, char** argv,
#define CAF_MAIN(...) \
int main(int argc, char** argv) { \
::caf::exec_main<__VA_ARGS__>(caf_main, argc, argv); \
return ::caf::exec_main<__VA_ARGS__>(caf_main, argc, argv); \
}
#endif // CAF_EXEC_MAIN_HPP
......@@ -89,7 +89,8 @@ actor_system_config::~actor_system_config() {
actor_system_config::actor_system_config()
: cli_helptext_printed(false),
slave_mode(false) {
slave_mode(false),
slave_mode_fun(nullptr) {
// (1) hard-coded defaults
scheduler_policy = atom("stealing");
scheduler_max_threads = std::max(std::thread::hardware_concurrency(),
......
......@@ -308,6 +308,8 @@ private:
strong_actor_ptr remote_actor(std::set<std::string> ifs,
std::string host, uint16_t port);
static int exec_slave_mode(actor_system&, const actor_system_config&);
// environment
actor_system& system_;
// prevents backend from shutting down unless explicitly requested
......
......@@ -339,6 +339,8 @@ void middleman::init(actor_system_config& cfg) {
// set options relevant to BASP
heartbeat_interval_ = cfg.middleman_heartbeat_interval;
enable_automatic_connections_ = cfg.middleman_enable_automatic_connections;
// enable slave mode
cfg.slave_mode_fun = &middleman::exec_slave_mode;
}
actor_system::module::id_t middleman::id() const {
......@@ -357,5 +359,10 @@ middleman_actor middleman::actor_handle() {
return manager_;
}
int middleman::exec_slave_mode(actor_system&, const actor_system_config&) {
// TODO
return 0;
}
} // namespace io
} // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment