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 SOFTBUS_BASE_LISTENER_H 17 #define SOFTBUS_BASE_LISTENER_H 18 19 #include "common_list.h" 20 #include "softbus_def.h" 21 #include "softbus_utils.h" 22 #include "sys/select.h" 23 24 #ifdef __cplusplus 25 #if __cplusplus 26 extern "C" { 27 #endif 28 #endif 29 30 typedef enum { 31 READ_TRIGGER, 32 WRITE_TRIGGER, 33 EXCEPT_TRIGGER, 34 RW_TRIGGER, 35 } TriggerType; 36 37 typedef enum { 38 UNSET_MODE, 39 CLIENT_MODE, 40 SERVER_MODE, 41 } ModeType; 42 43 typedef enum { 44 PROXY = 0, 45 AUTH, 46 AUTH_P2P, 47 DIRECT_CHANNEL_SERVER_P2P, 48 DIRECT_CHANNEL_CLIENT, 49 DIRECT_CHANNEL_SERVER_WIFI, 50 UNUSE_BUTT, 51 } ListenerModule; 52 53 typedef struct { 54 int32_t (*onConnectEvent)(int32_t events, int32_t cfd, const char *ip); 55 int32_t (*onDataEvent)(int32_t events, int32_t fd); 56 } SoftbusBaseListener; 57 58 int32_t GetSoftbusBaseListener(ListenerModule module, SoftbusBaseListener *listener); 59 int32_t SetSoftbusBaseListener(ListenerModule module, const SoftbusBaseListener *listener); 60 int32_t StartBaseClient(ListenerModule module); 61 int32_t StartBaseListener(ListenerModule module, const char *ip, int32_t port, ModeType modeType); 62 int32_t StopBaseListener(ListenerModule module); 63 void ResetBaseListener(ListenerModule module); 64 void ResetBaseListenerSet(ListenerModule module); 65 void DestroyBaseListener(ListenerModule module); 66 67 int32_t AddTrigger(ListenerModule module, int32_t fd, TriggerType triggerType); 68 int32_t DelTrigger(ListenerModule module, int32_t fd, TriggerType triggerType); 69 70 #ifdef __cplusplus 71 #if __cplusplus 72 } 73 #endif /* __cplusplus */ 74 #endif /* __cplusplus */ 75 76 #endif /* SOFTBUS_BASE_LISTENER_H */