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 <grpc/support/port_platform.h>
20
21 #include "src/core/lib/transport/handshaker_registry.h"
22
23 #include <stddef.h>
24
25 #include <algorithm>
26 #include <utility>
27
28 namespace grpc_core {
29
RegisterHandshakerFactory(HandshakerType handshaker_type,std::unique_ptr<HandshakerFactory> factory)30 void HandshakerRegistry::Builder::RegisterHandshakerFactory(
31 HandshakerType handshaker_type,
32 std::unique_ptr<HandshakerFactory> factory) {
33 auto& vec = factories_[handshaker_type];
34 auto where = vec.empty() ? vec.begin() : vec.end();
35 for (auto iter = vec.begin(); iter != vec.end(); ++iter) {
36 if (factory->Priority() < iter->get()->Priority()) {
37 where = iter;
38 break;
39 }
40 }
41 vec.insert(where, std::move(factory));
42 }
43
Build()44 HandshakerRegistry HandshakerRegistry::Builder::Build() {
45 HandshakerRegistry out;
46 for (size_t i = 0; i < NUM_HANDSHAKER_TYPES; i++) {
47 out.factories_[i] = std::move(factories_[i]);
48 }
49 return out;
50 }
51
AddHandshakers(HandshakerType handshaker_type,const ChannelArgs & args,grpc_pollset_set * interested_parties,HandshakeManager * handshake_mgr) const52 void HandshakerRegistry::AddHandshakers(HandshakerType handshaker_type,
53 const ChannelArgs& args,
54 grpc_pollset_set* interested_parties,
55 HandshakeManager* handshake_mgr) const {
56 for (const auto& factory : factories_[handshaker_type]) {
57 factory->AddHandshakers(args, interested_parties, handshake_mgr);
58 }
59 }
60
61 } // namespace grpc_core
62