void addEventSource(const int fd, const Event events, Callback&& callback);
void removeEventSource(const int fd);
bool dispatch(const int timeout);
- void run(bool useGMainloop = false);
+ void run();
void stop();
private:
Service(const Service&) = delete;
Service& operator=(const Service&) = delete;
- void start(bool useGMainloop = false);
+ void start();
void stop();
void setAuditTrail(const AuditTrail& trail);
namespace runtime {
-namespace {
-
-gboolean GIOCallback(GIOChannel* channel, GIOCondition condition, void *data)
-{
- Mainloop* mainloop = reinterpret_cast<Mainloop*>(data);
- mainloop->dispatch(-1);
- return TRUE;
-}
-
-} // namespace
-
Mainloop::Mainloop() :
pollFd(::epoll_create1(EPOLL_CLOEXEC)),
stopped(false)
addEventSource(wakeupSignal.getFd(), EPOLLIN, wakeupMainloop);
}
-void Mainloop::run(bool useGMainloop)
+void Mainloop::run()
{
prepare();
- if (useGMainloop) {
- GIOChannel* channel;
- channel = g_io_channel_unix_new(pollFd);
- if (channel == NULL) {
- std::cout << "GMAINLOOP CHANNEL ALLOC FAILED" << std::endl;
- return;
- }
- g_io_add_watch(channel, (GIOCondition)(G_IO_IN|G_IO_HUP), GIOCallback, this);
- g_io_channel_unref(channel);
-
- while (!stopped) {
- g_main_iteration(TRUE);
- }
- } else {
- while (!stopped) {
- dispatch(-1);
- }
+ while (!stopped) {
+ dispatch(-1);
}
}
{
}
-void Service::start(bool useGMainloop)
+void Service::start()
{
Socket socket(Socket::create(address));
EPOLLIN | EPOLLHUP | EPOLLRDHUP,
accept);
- mainloop.run(useGMainloop);
+ mainloop.run();
}
void Service::stop()