4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef __EVENT_LOOP_H__
21 #define __EVENT_LOOP_H__
28 #include "event_handler.h"
32 enum event_condition_e {
36 EVENT_NVAL = G_IO_NVAL,
41 virtual ~idle_handler();
49 handler_info(int64_t _id, int _fd, GIOChannel *_ch, GSource *_src, event_handler *_handler, event_loop *_loop)
62 event_handler *handler;
68 typedef unsigned int event_condition;
69 typedef bool (*idle_cb)(void *);
72 event_loop(GMainLoop *mainloop);
75 uint64_t add_event(const int fd, const event_condition cond, event_handler *handler);
76 uint64_t add_idle_event(unsigned int priority, idle_handler *handler);
78 bool remove_event(uint64_t id, bool close_channel = false);
79 void remove_all_events(void);
81 void release_info(handler_info *info);
83 bool run(int timeout = 0);
87 bool is_running(void);
88 bool is_terminator(int fd);
91 GMainLoop *m_mainloop;
92 std::atomic<bool> m_running;
93 std::atomic<bool> m_terminating;
94 std::atomic<uint64_t> m_sequence;
95 std::map<uint64_t, handler_info *> m_handlers;
102 #endif /* __EVENT_LOOP_H__ */