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_CONN_COMMON_H 17 #define SOFTBUS_CONN_COMMON_H 18 19 #include "common_list.h" 20 #include "message_handler.h" 21 #include "softbus_queue.h" 22 #include "softbus_adapter_thread.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define COMPARE_SUCCESS 0 29 #define COMPARE_FAILED 1 30 #define MAX_DATA_LEN (40 * 1000) 31 #define WAIT_QUEUE_BUFFER_PERIOD_LEN 2 32 #define QUEUE_NUM_PER_PID 3 33 34 #define WAIT_TIMEOUT_OCCUPY (3 * 1000) 35 #define WAIT_TIMEOUT_TRY_AGAIN (1 * 1000) 36 #define WAIT_DISCONNECT_TIME_MS 200 37 38 // provide remove event compare function field 39 typedef struct { 40 SoftBusHandler handler; 41 int (*eventCompareFunc)(const SoftBusMessage *, void *); 42 } SoftBusHandlerWrapper; 43 44 typedef struct { 45 uint8_t *buffer; 46 uint32_t capacity; 47 uint32_t length; 48 } LimitedBuffer; 49 50 typedef struct { 51 ListNode node; 52 int32_t pid; 53 LockFreeQueue *queue[QUEUE_NUM_PER_PID]; 54 } ConnectionQueue; 55 56 typedef enum { 57 HIGH_PRIORITY = 0, 58 MIDDLE_PRIORITY, 59 LOW_PRIORITY, 60 PRIORITY_BOUNDARY, 61 } QueuePriority; 62 63 int32_t ConnStartActionAsync(void *arg, void *(*runnable)(void *), const char *taskName); 64 void ConvertAnonymizeMacAddress(char *outAnomize, uint32_t anomizeLen, const char *mac, uint32_t macLen); 65 void ConvertAnonymizeSensitiveString(char *outAnomize, uint32_t anomizeLen, const char *origin); 66 void ConvertAnonymizeIpAddress(char *outAnomize, uint32_t anomizeLen, const char *ip, uint32_t ipLen); 67 68 int32_t ConnPostMsgToLooper( 69 SoftBusHandlerWrapper *wrapper, int32_t what, uint64_t arg1, uint64_t arg2, void *obj, uint64_t delayMillis); 70 void ConnRemoveMsgFromLooper( 71 const SoftBusHandlerWrapper *wrapper, int32_t what, uint64_t arg1, uint64_t arg2, void *obj); 72 73 int32_t ConnNewLimitedBuffer(LimitedBuffer **outLimiteBuffer, uint32_t capacity); 74 void ConnDeleteLimitedBuffer(LimitedBuffer **limiteBuffer); 75 76 int32_t WaitQueueLength(const LockFreeQueue *lockFreeQueue, uint32_t maxLen, uint32_t diffLen, SoftBusCond *cond, 77 SoftBusMutex *mutex); 78 int32_t GetMsg(ConnectionQueue *queue, void **msg, bool *isFull, QueuePriority leastPriority); 79 uint32_t GetQueueLimit(int32_t index); 80 81 #ifdef __cplusplus 82 } 83 #endif /* __cplusplus */ 84 #endif /* SOFTBUS_CONN_COMMON_H */