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 void UpdateProgressId(uint64_t inProgressId); 30 uint64_t GetProgressId() const; 31 bool CheckProgress(); 32 33 void SetFragmentLen(uint32_t inFragLen); 34 void SetLastFragmentLen(uint32_t inLastFragLen); 35 uint32_t GetThisFragmentLength(uint16_t inFragNo) const; 36 uint32_t GetThisFragmentOffset(uint16_t inFragNo) const; 37 38 void SetFragmentCount(uint16_t inFragCount); 39 bool IsFragNoAlreadyExist(uint16_t inFragNo) const; 40 void CheckInFragmentNo(uint16_t inFragNo); 41 bool IsCombineDone() const; 42 43 private: 44 uint64_t progressId_ = 0; 45 bool hasProgressFlag_ = true; 46 47 uint32_t fragmentLen_ = 0; // Indicate the length of fragment that is split from a frame except the last one 48 uint32_t lastFragmentLen_ = 0; // Indicate the length of the last fragment that is split from a frame 49 50 uint16_t fragmentCount_ = 0; 51 std::set<uint16_t> combinedFragmentNo_; 52 }; 53 } // namespace DistributedDB 54 55 #endif // COMBINE_STATUS_H 56