• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2016 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include "src/core/handshaker/handshaker_registry.h"
20 
21 #include <grpc/support/port_platform.h>
22 #include <stddef.h>
23 
24 #include <algorithm>
25 #include <utility>
26 
27 namespace grpc_core {
28 
RegisterHandshakerFactory(HandshakerType handshaker_type,std::unique_ptr<HandshakerFactory> factory)29 void HandshakerRegistry::Builder::RegisterHandshakerFactory(
30     HandshakerType handshaker_type,
31     std::unique_ptr<HandshakerFactory> factory) {
32   auto& vec = factories_[handshaker_type];
33   auto where = vec.empty() ? vec.begin() : vec.end();
34   for (auto iter = vec.begin(); iter != vec.end(); ++iter) {
35     if (factory->Priority() < iter->get()->Priority()) {
36       where = iter;
37       break;
38     }
39   }
40   vec.insert(where, std::move(factory));
41 }
42 
Build()43 HandshakerRegistry HandshakerRegistry::Builder::Build() {
44   HandshakerRegistry out;
45   for (size_t i = 0; i < NUM_HANDSHAKER_TYPES; i++) {
46     out.factories_[i] = std::move(factories_[i]);
47   }
48   return out;
49 }
50 
AddHandshakers(HandshakerType handshaker_type,const ChannelArgs & args,grpc_pollset_set * interested_parties,HandshakeManager * handshake_mgr) const51 void HandshakerRegistry::AddHandshakers(HandshakerType handshaker_type,
52                                         const ChannelArgs& args,
53                                         grpc_pollset_set* interested_parties,
54                                         HandshakeManager* handshake_mgr) const {
55   for (const auto& factory : factories_[handshaker_type]) {
56     factory->AddHandshakers(args, interested_parties, handshake_mgr);
57   }
58 }
59 
60 }  // namespace grpc_core
61