1 /*
2  * Copyright 2019, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "bridge_builder.h"
18 
19 #include "bridge.h"
20 #include "log.h"
21 #include "result.h"
22 
BridgeBuilder(Bridge & bridge,const char * interfacePrefix)23 BridgeBuilder::BridgeBuilder(Bridge& bridge, const char* interfacePrefix) :
24     mBridge(bridge),
25     mInterfacePrefix(interfacePrefix),
26     mPrefixLength(strlen(interfacePrefix)) {
27 }
28 
onInterfaceState(unsigned int,const char * name,InterfaceState state)29 void BridgeBuilder::onInterfaceState(unsigned int /*index*/,
30                                      const char* name,
31                                      InterfaceState state) {
32     if (strncmp(name, mInterfacePrefix, mPrefixLength) != 0) {
33         // Does not match our prefix, ignore it
34         return;
35     }
36 
37     if (state == InterfaceState::Up) {
38         Result res = mBridge.addInterface(name);
39         if (!res) {
40             LOGE("%s", res.c_str());
41         }
42     }
43 }
44