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_conn_interface.h" 21 #include "softbus_def.h" 22 #include "softbus_utils.h" 23 24 #ifdef __cplusplus 25 #if __cplusplus 26 extern "C" { 27 #endif 28 #endif 29 30 // NOTICE: all element MUST be bitmap mode 31 typedef enum { 32 READ_TRIGGER = 1, 33 WRITE_TRIGGER = 2, 34 EXCEPT_TRIGGER = 4, 35 RW_TRIGGER = READ_TRIGGER | WRITE_TRIGGER, 36 } TriggerType; 37 38 typedef enum { 39 UNSET_MODE, 40 CLIENT_MODE, 41 SERVER_MODE, 42 } ModeType; 43 44 typedef struct { 45 int32_t (*onConnectEvent)(ListenerModule module, int32_t cfd, const ConnectOption *clientAddr); 46 int32_t (*onDataEvent)(ListenerModule module, int32_t events, int32_t fd); 47 } SoftbusBaseListener; 48 49 int32_t InitBaseListener(void); 50 void DeinitBaseListener(void); 51 52 // dynamic module management, mean while static module is already registered in InitBaseListener 53 uint32_t CreateListenerModule(void); 54 void DestroyBaseListener(ListenerModule module); 55 56 int32_t StartBaseClient(ListenerModule module, const SoftbusBaseListener *listener); 57 int32_t StartBaseListener(const LocalListenerInfo *info, const SoftbusBaseListener *listener); 58 int32_t StopBaseListener(ListenerModule module); 59 60 bool IsListenerNodeExist(ListenerModule module); 61 int32_t AddTrigger(ListenerModule module, int32_t fd, TriggerType trigger); 62 int32_t DelTrigger(ListenerModule module, int32_t fd, TriggerType trigger); 63 64 #ifdef __cplusplus 65 #if __cplusplus 66 } 67 #endif /* __cplusplus */ 68 #endif /* __cplusplus */ 69 70 #endif /* SOFTBUS_BASE_LISTENER_H */