1 /** @file
2  *
3  *  A brief file description
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #include "QUICFrameGenerator.h"
25 
26 // QUICFrameGenerator
27 void
_records_frame(QUICFrameId id,QUICFrameInformationUPtr info)28 QUICFrameGenerator::_records_frame(QUICFrameId id, QUICFrameInformationUPtr info)
29 {
30   this->_info.insert(std::make_pair(id, std::move(info)));
31 }
32 
33 bool
_is_level_matched(QUICEncryptionLevel level)34 QUICFrameGenerator::_is_level_matched(QUICEncryptionLevel level)
35 {
36   if (level == this->_encryption_level_filter) {
37     return true;
38   } else {
39     return false;
40   }
41 }
42 
43 void
on_frame_acked(QUICFrameId id)44 QUICFrameGenerator::on_frame_acked(QUICFrameId id)
45 {
46   auto it = this->_info.find(id);
47   if (it != this->_info.end()) {
48     this->_on_frame_acked(it->second);
49     this->_info.erase(it);
50   }
51 }
52 
53 void
on_frame_lost(QUICFrameId id)54 QUICFrameGenerator::on_frame_lost(QUICFrameId id)
55 {
56   auto it = this->_info.find(id);
57   if (it != this->_info.end()) {
58     this->_on_frame_lost(it->second);
59     this->_info.erase(it);
60   }
61 }
62 
63 void
add_generator(QUICFrameGenerator & generator,int weight)64 QUICFrameGeneratorManager::add_generator(QUICFrameGenerator &generator, int weight)
65 {
66   auto it = this->_inline_vector.begin();
67   for (; it != this->_inline_vector.end(); ++it) {
68     if (it->first >= weight) {
69       break;
70     }
71   }
72   this->_inline_vector.emplace(it, weight, &generator);
73 }
74 
75 const std::vector<QUICFrameGenerator *> &
generators()76 QUICFrameGeneratorManager::generators()
77 {
78   // Because we don't remove generators. So The size changed means new generators is coming
79   if (!this->_generators.empty() && this->_generators.size() == this->_inline_vector.size()) {
80     return this->_generators;
81   }
82 
83   this->_generators.clear();
84   for (auto it : this->_inline_vector) {
85     this->_generators.emplace_back(it.second);
86   }
87 
88   return this->_generators;
89 }
90