b5644f6e56205ee1811672f7ba9776f299fe3d88
[platform/core/ml/beyond.git] / subprojects / libbeyond / include / beyond / private / event_loop_private.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __BEYOND_PRIVATE_EVENT_LOOP_H__
18 #define __BEYOND_PRIVATE_EVENT_LOOP_H__
19
20 #include <functional>
21 #include <sys/epoll.h>
22
23 #include "beyond/common.h"
24 #include "beyond/private/event_object_interface_private.h"
25
26 namespace beyond {
27
28 class API EventLoop : public EventObjectBaseInterface {
29 public:
30     struct HandlerObject {
31         EventObjectBaseInterface *eventObject;
32         int type;
33         void *data;
34
35         std::function<beyond_handler_return(EventObjectBaseInterface *, int, void *)> eventHandler;
36         std::function<void(EventObjectBaseInterface *, void *)> cancelHandler;
37     };
38
39 public:
40     static EventLoop *Create(bool thread = false, bool signal = false);
41
42     virtual void Destroy(void) = 0;
43
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;
46
47     virtual int RemoveEventHandler(HandlerObject *handlerObject) = 0;
48
49     virtual int Run(int eventQueueSize = 10, int loop_count = -1, int timeout_in_ms = -1) = 0;
50     virtual int Stop(void) = 0;
51
52     virtual int SetStopHandler(const std::function<void(EventLoop *, void *)> &stopHandler, void *callbackData = nullptr) = 0;
53
54 protected:
55     EventLoop(void) = default;
56     virtual ~EventLoop(void) = default;
57
58 private:
59     class impl;
60 };
61
62 } // namespace beyond
63
64 #endif // __BEYOND_PRIVATE_EVENT_LOOP_H__