1 /* 2 * Copyright (c) 2024 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_FLOW_CONTROL_H 17 #define SOFTBUS_FLOW_CONTROL_H 18 19 #include "stdint.h" 20 21 #include "common_list.h" 22 #include "softbus_adapter_thread.h" 23 #include "softbus_error_code.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 // invalid parameters range 30 #define MIN_WINDOW_IN_MILLIS 100 // 100ms 31 #define MAX_WINDOW_IN_MILLIS 2000 // 2s 32 #define MIN_QUOTA_IN_BYTES (10 * 1024) // 10kB 33 #define MAX_QUOTA_IN_BYTES (2 * 1024 * 1024) // 2MB 34 35 struct ConnSlideWindowController { 36 int32_t (*apply)(struct ConnSlideWindowController *self, int32_t expect); 37 int32_t (*enable)(struct ConnSlideWindowController *self, int32_t windowInMillis, int32_t quotaInBytes); 38 int32_t (*disable)(struct ConnSlideWindowController *self); 39 40 // lock protect fields of this section, as they are access by send thread and modification by config thread 41 SoftBusMutex lock; 42 bool active; 43 int32_t windowInMillis; 44 int32_t quotaInBytes; 45 ListNode histories; 46 }; 47 48 int32_t ConnSlideWindowControllerConstructor(struct ConnSlideWindowController *self); 49 void ConnSlideWindowControllerDestructor(struct ConnSlideWindowController *self); 50 struct ConnSlideWindowController *ConnSlideWindowControllerNew(void); 51 void ConnSlideWindowControllerDelete(struct ConnSlideWindowController *self); 52 53 #ifdef __cplusplus 54 } 55 #endif 56 57 #endif // SOFTBUS_FLOW_CONTROL_H 58