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