• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // provide remove event compare function field
38 typedef struct {
39     SoftBusHandler handler;
40     int (*eventCompareFunc)(const SoftBusMessage *, void *);
41 } SoftBusHandlerWrapper;
42 
43 typedef struct {
44     uint8_t *buffer;
45     uint32_t capacity;
46     uint32_t length;
47 } LimitedBuffer;
48 
49 typedef struct {
50     ListNode node;
51     int32_t pid;
52     LockFreeQueue *queue[QUEUE_NUM_PER_PID];
53 } ConnectionQueue;
54 
55 typedef enum {
56     HIGH_PRIORITY = 0,
57     MIDDLE_PRIORITY,
58     LOW_PRIORITY,
59     PRIORITY_BOUNDARY,
60 } QueuePriority;
61 
62 int32_t ConnStartActionAsync(void *arg, void *(*runnable)(void *));
63 void ConvertAnonymizeMacAddress(char *outAnomize, uint32_t anomizeLen, const char *mac, uint32_t macLen);
64 void ConvertAnonymizeSensitiveString(char *outAnomize, uint32_t anomizeLen, const char *origin);
65 void ConvertAnonymizeIpAddress(char *outAnomize, uint32_t anomizeLen, const char *ip, uint32_t ipLen);
66 
67 int32_t ConnPostMsgToLooper(
68     SoftBusHandlerWrapper *wrapper, int32_t what, uint64_t arg1, uint64_t arg2, void *obj, uint64_t delayMillis);
69 void ConnRemoveMsgFromLooper(
70     const SoftBusHandlerWrapper *wrapper, int32_t what, uint64_t arg1, uint64_t arg2, void *obj);
71 
72 int32_t ConnNewLimitedBuffer(LimitedBuffer **outLimiteBuffer, uint32_t capacity);
73 void ConnDeleteLimitedBuffer(LimitedBuffer **limiteBuffer);
74 
75 int32_t WaitQueueLength(const LockFreeQueue *lockFreeQueue, uint32_t maxLen, uint32_t diffLen, SoftBusCond *cond,
76     SoftBusMutex *mutex);
77 int32_t GetMsg(ConnectionQueue *queue, void **msg, bool *isFull, QueuePriority leastPriority);
78 uint32_t GetQueueLimit(int32_t index);
79 
80 #ifdef __cplusplus
81 }
82 #endif /* __cplusplus */
83 #endif /* SOFTBUS_CONN_COMMON_H  */