13f4cbf05Sopenharmony_ci/* 23f4cbf05Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 33f4cbf05Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43f4cbf05Sopenharmony_ci * you may not use this file except in compliance with the License. 53f4cbf05Sopenharmony_ci * You may obtain a copy of the License at 63f4cbf05Sopenharmony_ci * 73f4cbf05Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83f4cbf05Sopenharmony_ci * 93f4cbf05Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103f4cbf05Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113f4cbf05Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123f4cbf05Sopenharmony_ci * See the License for the specific language governing permissions and 133f4cbf05Sopenharmony_ci * limitations under the License. 143f4cbf05Sopenharmony_ci */ 153f4cbf05Sopenharmony_ci 163f4cbf05Sopenharmony_ci#include "event_handler.h" 173f4cbf05Sopenharmony_ci#include "event_reactor.h" 183f4cbf05Sopenharmony_ci#include <sys/epoll.h> 193f4cbf05Sopenharmony_ci 203f4cbf05Sopenharmony_cinamespace OHOS { 213f4cbf05Sopenharmony_cinamespace Utils { 223f4cbf05Sopenharmony_ci 233f4cbf05Sopenharmony_ciEventHandler::EventHandler(int fd, EventReactor* r) 243f4cbf05Sopenharmony_ci :fd_(fd), events_(EventReactor::NONE_EVENT), reactor_(r) 253f4cbf05Sopenharmony_ci{ 263f4cbf05Sopenharmony_ci} 273f4cbf05Sopenharmony_ci 283f4cbf05Sopenharmony_civoid EventHandler::EnableRead() 293f4cbf05Sopenharmony_ci{ 303f4cbf05Sopenharmony_ci events_ |= EventReactor::READ_EVENT; 313f4cbf05Sopenharmony_ci Update(); 323f4cbf05Sopenharmony_ci} 333f4cbf05Sopenharmony_ci 343f4cbf05Sopenharmony_civoid EventHandler::DisableAll() 353f4cbf05Sopenharmony_ci{ 363f4cbf05Sopenharmony_ci events_ = EventReactor::NONE_EVENT; 373f4cbf05Sopenharmony_ci Update(); 383f4cbf05Sopenharmony_ci} 393f4cbf05Sopenharmony_ci 403f4cbf05Sopenharmony_civoid EventHandler::HandleEvents(uint32_t events) 413f4cbf05Sopenharmony_ci{ 423f4cbf05Sopenharmony_ci if (events & (EventReactor::READ_EVENT)) { 433f4cbf05Sopenharmony_ci if (readCallback_) { 443f4cbf05Sopenharmony_ci readCallback_(); 453f4cbf05Sopenharmony_ci } 463f4cbf05Sopenharmony_ci } 473f4cbf05Sopenharmony_ci} 483f4cbf05Sopenharmony_ci 493f4cbf05Sopenharmony_civoid EventHandler::Update() 503f4cbf05Sopenharmony_ci{ 513f4cbf05Sopenharmony_ci if (reactor_ != nullptr) { 523f4cbf05Sopenharmony_ci reactor_->UpdateEventHandler(this); 533f4cbf05Sopenharmony_ci } 543f4cbf05Sopenharmony_ci} 553f4cbf05Sopenharmony_ci 563f4cbf05Sopenharmony_ci} // Utils 573f4cbf05Sopenharmony_ci} // OHOS 58