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 typedef struct EventLoop_ { 25 LE_STATUS (*close)(const struct EventLoop_ *loop); 26 LE_STATUS (*runLoop)(const struct EventLoop_ *loop); 27 LE_STATUS (*addEvent)(const struct EventLoop_ *loop, const BaseTask *task, int op); 28 LE_STATUS (*modEvent)(const struct EventLoop_ *loop, const BaseTask *task, int op); 29 LE_STATUS (*delEvent)(const struct EventLoop_ *loop, int fd, int op); 30 31 uint32_t maxevents; 32 uint32_t timeout; 33 uint32_t stop; 34 LoopMutex mutex; 35 HashMapHandle taskMap; 36 } EventLoop; 37 38 LE_STATUS CloseLoop(EventLoop *loop); 39 LE_STATUS AddTask(EventLoop *loop, BaseTask *task); 40 BaseTask *GetTaskByFd(EventLoop *loop, int fd); 41 void DelTask(EventLoop *loop, BaseTask *task); 42 LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper); 43 44 #endif