reactor: auto-initialization hooks
This commit is contained in:
parent
6fd18236eb
commit
daa09aff86
4 changed files with 41 additions and 21 deletions
|
|
@ -61,6 +61,9 @@ namespace xo {
|
|||
*/
|
||||
void run() { this->run_n(-1); }
|
||||
|
||||
protected:
|
||||
Reactor();
|
||||
|
||||
private:
|
||||
/* control logging verbosity */
|
||||
log_level loglevel_;
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
#include "xo/subsys/Subsystem.hpp"
|
||||
|
||||
namespace xo {
|
||||
enum S_reactor_tag {};
|
||||
enum S_reactor_tag {};
|
||||
|
||||
template<>
|
||||
struct InitSubsys<S_reactor_tag> {
|
||||
static void init();
|
||||
static InitEvidence require();
|
||||
};
|
||||
template<>
|
||||
struct InitSubsys<S_reactor_tag> {
|
||||
static void init();
|
||||
static InitEvidence require();
|
||||
};
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end init_reactor.hpp */
|
||||
|
|
|
|||
|
|
@ -4,23 +4,33 @@
|
|||
*/
|
||||
|
||||
#include "Reactor.hpp"
|
||||
#include "init_reactor.hpp"
|
||||
#include "xo/subsys/Subsystem.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace reactor {
|
||||
void
|
||||
Reactor::run_n(int32_t n)
|
||||
{
|
||||
if (n == -1) {
|
||||
for (;;) {
|
||||
this->run_one();
|
||||
}
|
||||
} else {
|
||||
for (int32_t i=0; i<n; ++i) {
|
||||
this->run_one();
|
||||
}
|
||||
}
|
||||
} /*run_n*/
|
||||
} /*namespace reactor*/
|
||||
namespace reactor {
|
||||
Reactor::Reactor() {
|
||||
/* ensure reactor subsystem + deps initialized */
|
||||
|
||||
InitSubsys<S_reactor_tag>::require();
|
||||
|
||||
Subsystem::initialize_all();
|
||||
}
|
||||
|
||||
void
|
||||
Reactor::run_n(int32_t n)
|
||||
{
|
||||
if (n == -1) {
|
||||
for (;;) {
|
||||
this->run_one();
|
||||
}
|
||||
} else {
|
||||
for (int32_t i=0; i<n; ++i) {
|
||||
this->run_one();
|
||||
}
|
||||
}
|
||||
} /*run_n*/
|
||||
} /*namespace reactor*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Reactor.cpp */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/* @file PollingReactor.test.cpp */
|
||||
|
||||
#include "xo/reactor/init_reactor.hpp"
|
||||
#include "xo/reactor/PollingReactor.hpp"
|
||||
#include "xo/reactor/FifoQueue.hpp"
|
||||
#include "xo/reactor/Sink.hpp"
|
||||
|
|
@ -57,8 +58,12 @@ namespace xo {
|
|||
}
|
||||
} /*namespace*/
|
||||
|
||||
static InitEvidence s_evidence = InitSubsys<S_reactor_tag>::require();
|
||||
|
||||
namespace ut {
|
||||
TEST_CASE("polling0", "[reactor]") {
|
||||
Subsystem::initialize_all();
|
||||
|
||||
rp<PollingReactor> reactor = PollingReactor::make();
|
||||
|
||||
REQUIRE(reactor.get());
|
||||
|
|
@ -193,6 +198,8 @@ namespace xo {
|
|||
} /*run_polling1_test*/
|
||||
|
||||
TEST_CASE("polling1", "[reactor]") {
|
||||
Subsystem::initialize_all();
|
||||
|
||||
//log_config::style = function_style::streamlined;
|
||||
log_config::location_tab = 100;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue