12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "Network.h"
- #define LOG_TAG "Netd"
- #include "log/log.h"
- #include <android-base/strings.h>
- #include <sstream>
- namespace android {
- namespace net {
- Network::~Network() {
- if (!mInterfaces.empty()) {
- ALOGE("deleting network with netId %u without clearing its interfaces", mNetId);
- }
- }
- unsigned Network::getNetId() const {
- return mNetId;
- }
- bool Network::hasInterface(const std::string& interface) const {
- return mInterfaces.find(interface) != mInterfaces.end();
- }
- const std::set<std::string>& Network::getInterfaces() const {
- return mInterfaces;
- }
- int Network::clearInterfaces() {
- while (!mInterfaces.empty()) {
-
-
- std::string interface = *mInterfaces.begin();
- if (int ret = removeInterface(interface)) {
- return ret;
- }
- }
- return 0;
- }
- std::string Network::toString() const {
- const char kSeparator[] = " ";
- std::stringstream repr;
- repr << mNetId;
- repr << kSeparator;
- switch (getType()) {
- case DUMMY:
- repr << "DUMMY";
- break;
- case LOCAL:
- repr << "LOCAL";
- break;
- case PHYSICAL:
- repr << "PHYSICAL";
- break;
- case VIRTUAL:
- repr << "VIRTUAL";
- break;
- default:
- repr << "unknown";
- }
- if (mInterfaces.size() > 0) {
- repr << kSeparator << android::base::Join(mInterfaces, ",");
- }
- return repr.str();
- }
- Network::Network(unsigned netId) : mNetId(netId) {
- }
- }
- }
|