Network.cpp revision f4f6c8de3f091be4b91a5a9d7f14e8882ec6d502
1/*
2 * Copyright (C) 2014 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 "Network.h"
18
19#define LOG_TAG "Netd"
20#include "log/log.h"
21
22Network::Network(unsigned netId) : mNetId(netId) {
23}
24
25Network::~Network() {
26    if (!mInterfaces.empty()) {
27        ALOGE("deleting network with netId %u without clearing its interfaces", mNetId);
28    }
29}
30
31bool Network::hasInterface(const std::string& interface) const {
32    return mInterfaces.find(interface) != mInterfaces.end();
33}
34
35int Network::clearInterfaces() {
36    while (!mInterfaces.empty()) {
37        // Make a copy of the string, so removeInterface() doesn't lose its parameter when it
38        // removes the string from the set.
39        std::string interface = *mInterfaces.begin();
40        if (int ret = removeInterface(interface)) {
41            return ret;
42        }
43    }
44    return 0;
45}
46