2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __BEYOND_PRIVATE_EVENT_LOOP_H__
18 #define __BEYOND_PRIVATE_EVENT_LOOP_H__
21 #include <sys/epoll.h>
23 #include "beyond/common.h"
24 #include "beyond/private/event_object_interface_private.h"
28 class API EventLoop : public EventObjectBaseInterface {
30 struct HandlerObject {
31 EventObjectBaseInterface *eventObject;
35 std::function<beyond_handler_return(EventObjectBaseInterface *, int, void *)> eventHandler;
36 std::function<void(EventObjectBaseInterface *, void *)> cancelHandler;
40 static EventLoop *Create(bool thread = false, bool signal = false);
42 virtual void Destroy(void) = 0;
44 virtual HandlerObject *AddEventHandler(EventObjectBaseInterface *eventObject, int type, const std::function<beyond_handler_return(EventObjectBaseInterface *, int, void *)> &eventHandler, void *callbackData = nullptr) = 0;
45 virtual HandlerObject *AddEventHandler(EventObjectBaseInterface *eventObject, int type, const std::function<beyond_handler_return(EventObjectBaseInterface *, int, void *)> &eventHandler, const std::function<void(EventObjectBaseInterface *, void *)> &cancelHandler, void *callbackData = nullptr) = 0;
47 virtual int RemoveEventHandler(HandlerObject *handlerObject) = 0;
49 virtual int Run(int eventQueueSize = 10, int loop_count = -1, int timeout_in_ms = -1) = 0;
50 virtual int Stop(void) = 0;
52 virtual int SetStopHandler(const std::function<void(EventLoop *, void *)> &stopHandler, void *callbackData = nullptr) = 0;
55 EventLoop(void) = default;
56 virtual ~EventLoop(void) = default;
64 #endif // __BEYOND_PRIVATE_EVENT_LOOP_H__