Skip to content
Snippets Groups Projects
Verified Commit efa2eb9e authored by Benny Baumann's avatar Benny Baumann
Browse files

Split libev interface into separate modules

parent 41be9f66
No related branches found
No related tags found
No related merge requests found
...@@ -3,31 +3,11 @@ ...@@ -3,31 +3,11 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <ev++.h> #include "lib/ev/ev.hpp"
#include "service/daemonctl.hpp" #include "mumta/evloop.hpp"
bool check_version_libev() {
auto ev_major{ev::version_major()};
auto ev_minor{ev::version_minor()};
constexpr auto exp_major{EV_VERSION_MAJOR};
constexpr auto exp_minor{EV_VERSION_MINOR};
std::cout << "Checking dependency: libev: detected " << ev_major << "." << ev_minor << ", compiled " << exp_major << "." << exp_minor << "\n" << std::flush;
if(ev_major != exp_major) {
std::cerr << "Checking dependency: libev: failed version check: Major API version mismatch.\n" << std::flush;
return false;
}
if(ev_minor < exp_minor) { #include "service/daemonctl.hpp"
std::cerr << "Checking dependency: libev: failed version check: Minor API version too old.\n" << std::flush;
return false;
}
return true;
}
int main() { int main() {
dctl_status_msg("Checking environment"); dctl_status_msg("Checking environment");
...@@ -48,10 +28,8 @@ int main() { ...@@ -48,10 +28,8 @@ int main() {
dctl_status_ready(); dctl_status_ready();
dctl_status_msg("Active"); dctl_status_msg("Active");
for(size_t x = 10; x; x--) { dctl_watchdog_refresh();
std::this_thread::sleep_for(std::chrono::seconds(1)); rmrf::ev::loop();
dctl_watchdog_refresh();
}
dctl_status_msg("Preparing for shutdown"); dctl_status_msg("Preparing for shutdown");
dctl_status_shutdown(); dctl_status_shutdown();
......
#include "lib/ev/ev.hpp"
#include <iomanip>
#include <sstream>
#include <string>
#include <ev++.h>
#include "service/daemonctl.hpp"
bool check_version_libev()
{
auto ev_major{ev::version_major()};
auto ev_minor{ev::version_minor()};
constexpr auto exp_major{EV_VERSION_MAJOR};
constexpr auto exp_minor{EV_VERSION_MINOR};
std::stringstream str;
str <<
"Checking dependency: libev: detected " <<
std::dec << ev_major << "." << std::setw(2) << std::setfill('0') << ev_minor <<
", compiled " <<
std::dec << exp_major << "." << std::setw(2) << std::setfill('0') << exp_minor;
dctl_status_msg(str.str().c_str());
if (ev_major != exp_major) {
dctl_status_err("Checking dependency: libev: failed version check: Major API version mismatch.\n");
return false;
}
if (ev_minor < exp_minor) {
dctl_status_err("Checking dependency: libev: failed version check: Minor API version too old.\n");
return false;
}
return true;
}
#pragma once
bool check_version_libev();
#include "mumta/evloop.hpp"
#include <fcntl.h>
#include <functional>
#include <memory>
struct stdin_waiter;
struct stdin_waiter : std::enable_shared_from_this<stdin_waiter>
{
::ev::io e_stdin;
stdin_waiter() : e_stdin{} {
fcntl(0, F_SETFL, fcntl(0, F_GETFL)|O_NONBLOCK);
e_stdin.set<stdin_waiter, &stdin_waiter::cb>(this);
e_stdin.set(0, ::ev::READ);
e_stdin.start();
}
~stdin_waiter() {
e_stdin.stop();
}
void cb(::ev::io &w, int events) {
(void)w;
(void)events;
this->e_stdin.stop();
}
};
void rmrf::ev::loop() {
::ev::default_loop defloop;
auto w = std::make_shared<stdin_waiter>();
defloop.run(0);
}
#pragma once
#include <ev++.h>
#if !EV_MULTIPLICITY
#error We require support for multiple event loops
#endif
namespace rmrf::ev {
bool init_libev();
bool init_watchdog();
void loop();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment