Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
509f52a0
Commit
509f52a0
authored
6 years ago
by
Éloïs
Browse files
Options
Downloads
Plain Diff
Merge branch '100-create-macro-durs_core_server' into 'dev'
Resolve "create macro durs_core_server!" Closes
#100
See merge request
!86
parents
c8d207f9
b6885129
No related branches found
No related tags found
1 merge request
!86
Resolve "create macro durs_core_server!"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib.rs
+91
-7
91 additions, 7 deletions
core/lib.rs
src/main.rs
+11
-73
11 additions, 73 deletions
src/main.rs
with
102 additions
and
80 deletions
core/lib.rs
+
91
−
7
View file @
509f52a0
...
@@ -69,6 +69,91 @@ use threadpool::ThreadPool;
...
@@ -69,6 +69,91 @@ use threadpool::ThreadPool;
/// Number of thread in plugins ThreadPool
/// Number of thread in plugins ThreadPool
pub
static
THREAD_POOL_SIZE
:
&
'static
usize
=
&
2
;
pub
static
THREAD_POOL_SIZE
:
&
'static
usize
=
&
2
;
#[macro_export]
macro_rules!
durs_core_server
{
(
$closure_inject_cli:expr
,
$closure_plug:expr
)
=>
{{
duniter_core
::
main
(
env!
(
"CARGO_PKG_NAME"
),
env!
(
"CARGO_PKG_VERSION"
),
&
DursOpt
::
clap
(),
$closure_inject_cli
,
$closure_plug
,
);
}};
}
#[macro_export]
macro_rules!
durs_inject_cli
{
(
$
(
$Module:ty
),
*
)
=>
{
{
|
core
|
{
$
(
core
.inject_cli_subcommand
::
<
$Module
>
();)
*
}
}
};
}
#[macro_export]
macro_rules!
durs_plug
{
(
[
$
(
$NetworkModule:ty
),
*
],
[
$
(
$Module:ty
),
*
]
)
=>
{
{
|
core
|
{
$
(
core
.plug
::
<
$Module
>
();)
*
$
(
core
.plug_network
::
<
$NetworkModule
>
();)
*
}
}
};
}
/*
macro_rules! o_O {
(
$(
$x:expr; [ $( $y:expr ),* ]
);*
) => {
&[ $($( $x + $y ),*),* ]
}
}
macro_rules! vec {
( $( $x:expr ),* ) => {
{
let mut temp_vec = Vec::new();
$(
temp_vec.push($x);
)*
temp_vec
}
};
}*/
/// Durs main function
pub
fn
main
<
'b
,
'a
:
'b
,
CliFunc
,
PlugFunc
>
(
soft_name
:
&
'static
str
,
soft_version
:
&
'static
str
,
clap_app
:
&
'a
App
<
'b
,
'a
>
,
mut
inject_modules_subcommands
:
CliFunc
,
mut
plug_modules
:
PlugFunc
,
)
where
'b
:
'a
,
CliFunc
:
FnMut
(
&
mut
DuniterCore
<
'a
,
'b
,
DuRsConf
>
)
->
(),
PlugFunc
:
FnMut
(
&
mut
DuniterCore
<
'a
,
'b
,
DuRsConf
>
)
->
(),
{
// Instantiate duniter core
let
mut
duniter_core
=
DuniterCore
::
<
DuRsConf
>
::
new
(
soft_name
,
soft_version
,
clap_app
,
0
);
// Inject modules subcommands
inject_modules_subcommands
(
&
mut
duniter_core
);
// Match user command
if
duniter_core
.match_user_command
()
{
// Plug all plugins
plug_modules
(
&
mut
duniter_core
);
duniter_core
.start_core
();
}
}
#[derive(Debug,
Clone)]
#[derive(Debug,
Clone)]
/// User command
/// User command
pub
enum
UserCommand
{
pub
enum
UserCommand
{
...
@@ -149,6 +234,11 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> {
...
@@ -149,6 +234,11 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> {
thread_pool
:
ThreadPool
::
new
(
*
THREAD_POOL_SIZE
),
thread_pool
:
ThreadPool
::
new
(
*
THREAD_POOL_SIZE
),
}
}
}
}
/// Inject cli subcommand
pub
fn
inject_cli_subcommand
<
M
:
DuniterModule
<
DuRsConf
,
DursMsg
>>
(
&
mut
self
)
{
//self.cli_conf = TupleApp(&self.cli_conf.0.clone().subcommand(M::ModuleOpt::clap()));
self
.plugins_cli_conf
.push
(
M
::
ModuleOpt
::
clap
());
}
/// Execute user command
/// Execute user command
pub
fn
match_user_command
(
&
mut
self
)
->
bool
{
pub
fn
match_user_command
(
&
mut
self
)
->
bool
{
self
.match_specialize_user_command
(
vec!
[],
None
,
vec!
[])
self
.match_specialize_user_command
(
vec!
[],
None
,
vec!
[])
...
@@ -446,19 +536,13 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> {
...
@@ -446,19 +536,13 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> {
}
}
}
}
/// Inject cli subcommand
pub
fn
inject_cli_subcommand
<
M
:
DuniterModule
<
DuRsConf
,
DursMsg
>>
(
&
mut
self
)
{
//self.cli_conf = TupleApp(&self.cli_conf.0.clone().subcommand(M::ModuleOpt::clap()));
self
.plugins_cli_conf
.push
(
M
::
ModuleOpt
::
clap
());
}
/// Plug a module
/// Plug a module
pub
fn
plug
<
M
:
DuniterModule
<
DuRsConf
,
DursMsg
>>
(
&
mut
self
)
{
pub
fn
plug
<
M
:
DuniterModule
<
DuRsConf
,
DursMsg
>>
(
&
mut
self
)
{
self
.plug_
::
<
M
>
(
false
);
self
.plug_
::
<
M
>
(
false
);
}
}
/// Plug a module
/// Plug a module
fn
plug_
<
M
:
DuniterModule
<
DuRsConf
,
DursMsg
>>
(
&
mut
self
,
is_network_module
:
bool
)
{
pub
fn
plug_
<
M
:
DuniterModule
<
DuRsConf
,
DursMsg
>>
(
&
mut
self
,
is_network_module
:
bool
)
{
let
enabled
=
enabled
::
<
DuRsConf
,
DursMsg
,
M
>
(
&
self
.soft_meta_datas.conf
);
let
enabled
=
enabled
::
<
DuRsConf
,
DursMsg
,
M
>
(
&
self
.soft_meta_datas.conf
);
if
enabled
{
if
enabled
{
if
let
Some
(
UserCommand
::
Start
())
=
self
.user_command
{
if
let
Some
(
UserCommand
::
Start
())
=
self
.user_command
{
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
11
−
73
View file @
509f52a0
...
@@ -28,7 +28,9 @@
...
@@ -28,7 +28,9 @@
unused_qualifications
unused_qualifications
)]
)]
#[macro_use]
extern
crate
duniter_core
;
extern
crate
duniter_core
;
#[cfg(unix)]
#[cfg(unix)]
extern
crate
duniter_tui
;
extern
crate
duniter_tui
;
extern
crate
durs_ws2p_v1_legacy
;
extern
crate
durs_ws2p_v1_legacy
;
...
@@ -46,84 +48,20 @@ use structopt::StructOpt;
...
@@ -46,84 +48,20 @@ use structopt::StructOpt;
#[cfg(unix)]
#[cfg(unix)]
#[cfg(not(target_arch
=
"arm"
))]
#[cfg(not(target_arch
=
"arm"
))]
fn
main
()
{
fn
main
()
{
// Get software name and version
durs_core_server!
(
let
soft_name
=
env!
(
"CARGO_PKG_NAME"
);
durs_inject_cli!
[
WS2PModule
,
TuiModule
/*,DasaModule*/
],
let
soft_version
=
env!
(
"CARGO_PKG_VERSION"
);
durs_plug!
([
WS2PModule
],
[
TuiModule
/*,DasaModule*/
])
);
// Instantiate duniter core
let
clap_app
=
DursOpt
::
clap
();
let
mut
duniter_core
=
DuniterCore
::
<
DuRsConf
>
::
new
(
soft_name
,
soft_version
,
&
clap_app
,
0
);
// Inject plugins subcommands
//duniter_core.inject_cli_subcommand::<GvaModule>();
duniter_core
.inject_cli_subcommand
::
<
TuiModule
>
();
duniter_core
.inject_cli_subcommand
::
<
WS2PModule
>
();
// Match user command
if
duniter_core
.match_user_command
()
{
// Plug all plugins
//duniter_core.plug::<GuiModule>();
//duniter_core.plug::<GvaModule>();
//duniter_core.plug::<PoolModule>();
//duniter_core.plug::<PowModule>();
duniter_core
.plug
::
<
TuiModule
>
();
duniter_core
.plug_network
::
<
WS2PModule
>
();
duniter_core
.start_core
();
}
}
}
#[cfg(unix)]
#[cfg(unix)]
#[cfg(target_arch
=
"arm"
)]
#[cfg(target_arch
=
"arm"
)]
fn
main
()
{
fn
main
()
{
// Get software name and version
durs_core_server!
(
let
soft_name
=
env!
(
"CARGO_PKG_NAME"
);
durs_inject_cli!
[
WS2PModule
,
TuiModule
],
let
soft_version
=
env!
(
"CARGO_PKG_VERSION"
);
durs_plug!
([
WS2PModule
],
[
TuiModule
])
);
// Instantiate duniter core
let
clap_app
=
DursOpt
::
clap
();
let
mut
duniter_core
=
DuniterCore
::
<
DuRsConf
>
::
new
(
soft_name
,
soft_version
,
&
clap_app
,
0
);
// Inject plugins subcommands
//duniter_core.inject_cli_subcommand::<DasaModule>();
//duniter_core.inject_cli_subcommand::<GvaModule>();
duniter_core
.inject_cli_subcommand
::
<
TuiModule
>
();
duniter_core
.inject_cli_subcommand
::
<
WS2PModule
>
();
// Match user command
if
duniter_core
.match_user_command
()
{
// Plug all plugins
//duniter_core.plug::<DasaModule>();
//duniter_core.plug::<GuiModule>();
//duniter_core.plug::<GvaModule>();
//duniter_core.plug::<PoolModule>();
//duniter_core.plug::<PowModule>();
duniter_core
.plug
::
<
TuiModule
>
();
duniter_core
.plug_network
::
<
WS2PModule
>
();
duniter_core
.start_core
();
}
}
}
#[cfg(windows)]
#[cfg(windows)]
fn
main
()
{
fn
main
()
{
// Get software name and version
durs_core_server!
(
durs_inject_cli!
[
WS2PModule
],
durs_plug!
([
WS2PModule
],
[]));
let
soft_name
=
env!
(
"CARGO_PKG_NAME"
);
let
soft_version
=
env!
(
"CARGO_PKG_VERSION"
);
// Instantiate duniter core
let
clap_app
=
DursOpt
::
clap
();
let
mut
duniter_core
=
DuniterCore
::
<
DuRsConf
>
::
new
(
soft_name
,
soft_version
,
&
clap_app
,
0
);
// Inject plugins subcommands
//duniter_core.inject_cli_subcommand::<GvaModule>();
duniter_core
.inject_cli_subcommand
::
<
WS2PModule
>
();
// Match user command
if
duniter_core
.match_user_command
()
{
// Plug all plugins
//duniter_core.plug::<DasaModule>();
//duniter_core.plug::<GuiModule>();
//duniter_core.plug::<GvaModule>();
//duniter_core.plug::<PoolModule>();
//duniter_core.plug::<PowModule>();
duniter_core
.plug_network
::
<
WS2PModule
>
();
duniter_core
.start_core
();
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment