2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #define LOG_TAG "Netd"
22 #include <android-base/strings.h>
26 if (!mInterfaces.empty()) {
27 ALOGE("deleting network with netId %u without clearing its interfaces", mNetId);
31 unsigned Network::getNetId() const {
35 bool Network::hasInterface(const std::string& interface) const {
36 return mInterfaces.find(interface) != mInterfaces.end();
39 const std::set<std::string>& Network::getInterfaces() const {
43 int Network::clearInterfaces() {
44 while (!mInterfaces.empty()) {
45 // Make a copy of the string, so removeInterface() doesn't lose its parameter when it
46 // removes the string from the set.
47 std::string interface = *mInterfaces.begin();
48 if (int ret = removeInterface(interface)) {
55 std::string Network::toString() const {
56 const char kSeparator[] = " ";
57 std::stringstream repr;
79 if (mInterfaces.size() > 0) {
80 repr << kSeparator << android::base::Join(mInterfaces, ",");
87 Network::Network(unsigned netId) : mNetId(netId) {