• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef LE_EVENT_LOOP_H
17 #define LE_EVENT_LOOP_H
18 #include <unistd.h>
19 
20 #include "le_task.h"
21 #include "le_utils.h"
22 #include "init_hashmap.h"
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif
28 #endif
29 
30 typedef struct EventLoop_ {
31     LE_STATUS (*close)(const struct EventLoop_ *loop);
32     LE_STATUS (*runLoop)(const struct EventLoop_ *loop);
33     LE_STATUS (*addEvent)(const struct EventLoop_ *loop, const BaseTask *task, int op);
34     LE_STATUS (*modEvent)(const struct EventLoop_ *loop, const BaseTask *task, int op);
35     LE_STATUS (*delEvent)(const struct EventLoop_ *loop, int fd, int op);
36 
37     uint32_t maxevents;
38     uint32_t timeout;
39     uint32_t stop;
40 #ifdef LOOP_EVENT_USE_MUTEX
41     LoopMutex mutex;
42 #else
43     char mutex;
44 #endif
45     HashMapHandle taskMap;
46 } EventLoop;
47 
48 LE_STATUS CloseLoop(EventLoop *loop);
49 LE_STATUS AddTask(EventLoop *loop, BaseTask *task);
50 BaseTask *GetTaskByFd(EventLoop *loop, int fd);
51 void DelTask(EventLoop *loop, BaseTask *task);
52 LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper);
53 
54 #ifdef __cplusplus
55 #if __cplusplus
56 }
57 #endif
58 #endif
59 
60 #endif