1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 OHOS_SHARING_EVENT_DESCRIPTOR_LISTENER_H 17 #define OHOS_SHARING_EVENT_DESCRIPTOR_LISTENER_H 18 19 #include "common/const_def.h" 20 #include "file_descriptor_listener.h" 21 22 namespace OHOS { 23 namespace Sharing { 24 25 class DataBuffer; 26 class EventDescriptorListener : public OHOS::AppExecFwk::FileDescriptorListener { 27 public: 28 EventDescriptorListener(); 29 explicit EventDescriptorListener(int32_t fd); 30 virtual ~EventDescriptorListener(); 31 32 virtual void OnClose(int32_t fd); 33 void OnReadable(int32_t fd) override; 34 void OnWritable(int32_t fd) override; 35 void OnShutdown(int32_t fd) override; 36 void OnException(int32_t fd) override; 37 38 void RemoveFdListener(int32_t fd, const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &handler = nullptr); 39 bool AddFdListener(int32_t fd, const std::shared_ptr<FileDescriptorListener> &listener, 40 const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &handler = nullptr, 41 const std::string &taskName = DUMMY_EMPTY); 42 43 virtual int32_t GetSocketFd(); 44 45 protected: 46 virtual void OnReadData(int32_t fd, std::shared_ptr<DataBuffer> &buf); 47 48 protected: 49 int32_t socketLocalFd_ = -1; 50 }; 51 } // namespace Sharing 52 } // namespace OHOS 53 #endif 54