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 COMBINE_STATUS_H 17 #define COMBINE_STATUS_H 18 19 #include <set> 20 #include <cstdint> 21 22 namespace DistributedDB { 23 /* 24 * Class CombineStatus does not support multi-thread. 25 * It should be protected by mutex in multi-thread environment 26 */ 27 class CombineStatus { 28 public: 29 CombineStatus() = default; 30 ~CombineStatus() = default; 31 void UpdateProgressId(uint64_t inProgressId); 32 uint64_t GetProgressId() const; 33 bool CheckProgress(); 34 35 void SetFragmentLen(uint32_t inFragLen); 36 void SetLastFragmentLen(uint32_t inLastFragLen); 37 uint32_t GetThisFragmentLength(uint16_t inFragNo) const; 38 uint32_t GetThisFragmentOffset(uint16_t inFragNo) const; 39 40 void SetFragmentCount(uint16_t inFragCount); 41 bool IsFragNoAlreadyExist(uint16_t inFragNo) const; 42 void CheckInFragmentNo(uint16_t inFragNo); 43 bool IsCombineDone() const; 44 45 private: 46 uint64_t progressId_ = 0; 47 bool hasProgressFlag_ = true; 48 49 uint32_t fragmentLen_ = 0; // Indicate the length of fragment that is split from a frame except the last one 50 uint32_t lastFragmentLen_ = 0; // Indicate the length of the last fragment that is split from a frame 51 52 uint16_t fragmentCount_ = 0; 53 std::set<uint16_t> combinedFragmentNo_; 54 }; 55 } // namespace DistributedDB 56 57 #endif // COMBINE_STATUS_H 58