• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 constexpr uint32_t g_defaultEvents = AppExecFwk::FILE_DESCRIPTOR_EVENTS_MASK |
25                                      AppExecFwk::FILE_DESCRIPTOR_SHUTDOWN_EVENT |
26                                      AppExecFwk::FILE_DESCRIPTOR_EXCEPTION_EVENT;
27 class DataBuffer;
28 class EventDescriptorListener : public OHOS::AppExecFwk::FileDescriptorListener {
29 public:
30     EventDescriptorListener();
31     explicit EventDescriptorListener(int32_t fd);
32     virtual ~EventDescriptorListener();
33 
34     virtual void OnClose(int32_t fd);
35     void OnReadable(int32_t fd) override;
36     void OnWritable(int32_t fd) override;
37     void OnShutdown(int32_t fd) override;
38     void OnException(int32_t fd) override;
39 
40     void RemoveFdListener(int32_t fd, const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &handler = nullptr);
41     bool AddFdListener(int32_t fd, const std::shared_ptr<FileDescriptorListener> &listener,
42                        const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &handler = nullptr,
43                        const std::string &taskName = DUMMY_EMPTY, uint32_t events = g_defaultEvents);
44 
45     virtual int32_t GetSocketFd();
46 
47 protected:
48     virtual void OnReadData(int32_t fd, std::shared_ptr<DataBuffer> &buf);
49 
50 protected:
51     int32_t socketLocalFd_ = -1;
52 };
53 } // namespace Sharing
54 } // namespace OHOS
55 #endif
56