Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
13095ce9
Unverified
Commit
13095ce9
authored
Feb 09, 2019
by
Joseph Noir
Committed by
GitHub
Feb 09, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #817
Fix handling of CLI/INI options and fail early on misconfiguration
parents
e9946674
0410a0e7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
26 deletions
+43
-26
examples/hello_world.cpp
examples/hello_world.cpp
+4
-4
libcaf_core/caf/actor_system_config.hpp
libcaf_core/caf/actor_system_config.hpp
+10
-6
libcaf_core/caf/exec_main.hpp
libcaf_core/caf/exec_main.hpp
+12
-10
libcaf_core/src/actor_system_config.cpp
libcaf_core/src/actor_system_config.cpp
+17
-5
libcaf_core/test/config_option_set.cpp
libcaf_core/test/config_option_set.cpp
+0
-1
No files found.
examples/hello_world.cpp
View file @
13095ce9
...
...
@@ -33,13 +33,13 @@ void hello_world(event_based_actor* self, const actor& buddy) {
);
}
int
main
()
{
// our CAF environment
actor_system_config
cfg
;
actor_system
system
{
cfg
};
void
caf_main
(
actor_system
&
system
)
{
// create a new actor that calls 'mirror()'
auto
mirror_actor
=
system
.
spawn
(
mirror
);
// create another actor that calls 'hello_world(mirror_actor)';
system
.
spawn
(
hello_world
,
mirror_actor
);
// system will wait until both actors are destroyed before leaving main
}
// creates a main function for us that calls our caf_main
CAF_MAIN
()
libcaf_core/caf/actor_system_config.hpp
View file @
13095ce9
...
...
@@ -316,6 +316,16 @@ public:
int
(
*
slave_mode_fun
)(
actor_system
&
,
const
actor_system_config
&
);
// -- default error rendering functions --------------------------------------
static
std
::
string
render
(
const
error
&
err
);
static
std
::
string
render_sec
(
uint8_t
,
atom_value
,
const
message
&
);
static
std
::
string
render_exit_reason
(
uint8_t
,
atom_value
,
const
message
&
);
static
std
::
string
render_pec
(
uint8_t
,
atom_value
,
const
message
&
);
protected:
virtual
std
::
string
make_help_text
(
const
std
::
vector
<
message
::
cli_arg
>&
);
...
...
@@ -332,12 +342,6 @@ private:
actor_system_config
&
set_impl
(
string_view
name
,
config_value
value
);
static
std
::
string
render_sec
(
uint8_t
,
atom_value
,
const
message
&
);
static
std
::
string
render_exit_reason
(
uint8_t
,
atom_value
,
const
message
&
);
static
std
::
string
render_pec
(
uint8_t
,
atom_value
,
const
message
&
);
void
extract_config_file_path
(
string_list
&
args
);
/// Adjusts the content of the configuration, e.g., for ensuring backwards
...
...
libcaf_core/caf/exec_main.hpp
View file @
13095ce9
...
...
@@ -20,7 +20,6 @@
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/type_traits.hpp"
...
...
@@ -70,27 +69,31 @@ int exec_main(F fun, int argc, char** argv,
"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
//
Pass CLI options to config.
typename
helper
::
config
cfg
;
cfg
.
parse
(
argc
,
argv
,
config_file_name
);
// return immediately if a help text was printed
if
(
auto
err
=
cfg
.
parse
(
argc
,
argv
,
config_file_name
))
{
std
::
cerr
<<
"error while parsing CLI and file options: "
<<
actor_system_config
::
render
(
err
)
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
// Return immediately if a help text was printed.
if
(
cfg
.
cli_helptext_printed
)
return
0
;
//
load modules
return
EXIT_SUCCESS
;
//
Load modules.
std
::
initializer_list
<
unit_t
>
unused
{
unit_t
{
cfg
.
template
load
<
Ts
>()}...};
CAF_IGNORE_UNUSED
(
unused
);
//
pass config to the actor system
//
Initialize 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
EXIT_FAILURE
;
}
return
cfg
.
slave_mode_fun
(
system
,
cfg
);
}
helper
f
;
f
(
fun
,
system
,
cfg
);
return
0
;
return
EXIT_SUCCESS
;
}
}
// namespace caf
...
...
@@ -99,4 +102,3 @@ int exec_main(F fun, int argc, char** argv,
int main(int argc, char** argv) { \
return ::caf::exec_main<__VA_ARGS__>(caf_main, argc, argv); \
}
libcaf_core/src/actor_system_config.cpp
View file @
13095ce9
...
...
@@ -256,16 +256,16 @@ error actor_system_config::parse(string_list args, std::istream& ini) {
remainder
.
insert
(
remainder
.
end
(),
make_move_iterator
(
first
),
make_move_iterator
(
args
.
end
()));
}
else
{
cli_helptext_printed
=
get_or
(
content
,
"
global.
help"
,
false
)
||
get_or
(
content
,
"
global.
long-help"
,
false
);
cli_helptext_printed
=
get_or
(
content
,
"help"
,
false
)
||
get_or
(
content
,
"long-help"
,
false
);
}
// Generate help text if needed.
if
(
cli_helptext_printed
)
{
bool
long_help
=
get_or
(
content
,
"
global.
long-help"
,
false
);
bool
long_help
=
get_or
(
content
,
"long-help"
,
false
);
std
::
cout
<<
custom_options_
.
help_text
(
!
long_help
)
<<
std
::
endl
;
}
// Generate INI dump if needed.
if
(
!
cli_helptext_printed
&&
get_or
(
content
,
"
global.
dump-config"
,
false
))
{
if
(
!
cli_helptext_printed
&&
get_or
(
content
,
"dump-config"
,
false
))
{
for
(
auto
&
category
:
content
)
{
if
(
auto
dict
=
get_if
<
config_value
::
dictionary
>
(
&
category
.
second
))
{
std
::
cout
<<
'['
<<
category
.
first
<<
"]
\n
"
;
...
...
@@ -325,6 +325,18 @@ timespan actor_system_config::stream_tick_duration() const noexcept {
stream_max_batch_delay
.
count
());
return
timespan
{
ns_count
};
}
std
::
string
actor_system_config
::
render
(
const
error
&
err
)
{
std
::
string
msg
;
switch
(
static_cast
<
uint64_t
>
(
err
.
category
()))
{
case
atom_uint
(
"system"
):
return
render_sec
(
err
.
code
(),
err
.
category
(),
err
.
context
());
case
atom_uint
(
"exit"
):
return
render_exit_reason
(
err
.
code
(),
err
.
category
(),
err
.
context
());
case
atom_uint
(
"parser"
):
return
render_pec
(
err
.
code
(),
err
.
category
(),
err
.
context
());
}
return
"unknown-error"
;
}
std
::
string
actor_system_config
::
render_sec
(
uint8_t
x
,
atom_value
,
const
message
&
xs
)
{
...
...
@@ -342,7 +354,7 @@ std::string actor_system_config::render_exit_reason(uint8_t x, atom_value,
std
::
string
actor_system_config
::
render_pec
(
uint8_t
x
,
atom_value
,
const
message
&
xs
)
{
auto
tmp
=
static_cast
<
exit_reason
>
(
x
);
auto
tmp
=
static_cast
<
pec
>
(
x
);
return
deep_to_string
(
meta
::
type_name
(
"parser_error"
),
tmp
,
meta
::
omittable_if_empty
(),
xs
);
}
...
...
libcaf_core/test/config_option_set.cpp
View file @
13095ce9
...
...
@@ -62,7 +62,6 @@ CAF_TEST(lookup) {
CAF_CHECK_EQUAL
(
opts
.
size
(),
3u
);
CAF_MESSAGE
(
"lookup by long name"
);
CAF_CHECK_NOT_EQUAL
(
opts
.
cli_long_name_lookup
(
"opt1"
),
nullptr
);
CAF_CHECK_NOT_EQUAL
(
opts
.
cli_long_name_lookup
(
"global.opt1"
),
nullptr
);
CAF_CHECK_NOT_EQUAL
(
opts
.
cli_long_name_lookup
(
"test.opt2"
),
nullptr
);
CAF_CHECK_NOT_EQUAL
(
opts
.
cli_long_name_lookup
(
"test.flag"
),
nullptr
);
CAF_MESSAGE
(
"lookup by short name"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment