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 "list.h" 23#include "init_hashmap.h" 24 25#ifdef __cplusplus 26#if __cplusplus 27extern "C" { 28#endif 29#endif 30 31typedef struct EventLoop_ { 32 LE_STATUS (*close)(const struct EventLoop_ *loop); 33 LE_STATUS (*runLoop)(const struct EventLoop_ *loop); 34 LE_STATUS (*addEvent)(const struct EventLoop_ *loop, const BaseTask *task, int op); 35 LE_STATUS (*modEvent)(const struct EventLoop_ *loop, const BaseTask *task, int op); 36 LE_STATUS (*delEvent)(const struct EventLoop_ *loop, int fd, int op); 37 38 uint32_t maxevents; 39 uint32_t timeout; 40 uint32_t stop; 41#ifdef LOOP_EVENT_USE_MUTEX 42 LoopMutex mutex; 43#else 44 char mutex; 45#endif 46 HashMapHandle taskMap; 47 48 ListNode idleList; 49 ListNode timerList; 50} EventLoop; 51 52LE_STATUS CloseLoop(EventLoop *loop); 53LE_STATUS AddTask(EventLoop *loop, BaseTask *task); 54BaseTask *GetTaskByFd(EventLoop *loop, int fd); 55void DelTask(EventLoop *loop, BaseTask *task); 56LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper); 57 58#ifdef __cplusplus 59#if __cplusplus 60} 61#endif 62#endif 63 64#endif