• 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 #include "event_handler.h"
17 #include "event_reactor.h"
18 
19 namespace OHOS {
20 namespace Utils {
21 
EventHandler(int fd,EventReactor * r)22 EventHandler::EventHandler(int fd, EventReactor* r)
23     :fd_(fd), events_(EventReactor::NONE_EVENT), reactor_(r)
24 {
25 }
26 
EnableRead()27 void EventHandler::EnableRead()
28 {
29     events_ |= EventReactor::READ_EVENT;
30     Update();
31 }
32 
DisableAll()33 void EventHandler::DisableAll()
34 {
35     events_ = EventReactor::NONE_EVENT;
36     Update();
37 }
38 
HandleEvents(uint32_t events)39 void EventHandler::HandleEvents(uint32_t events)
40 {
41     if (events & (EventReactor::READ_EVENT)) {
42         if (readCallback_) {
43             readCallback_();
44         }
45     }
46 }
47 
Update()48 void EventHandler::Update()
49 {
50     if (reactor_ != nullptr) {
51         reactor_->UpdateEventHandler(this);
52     }
53 }
54 
55 } // Utils
56 } // OHOS
57