blob: 2261b8ed8b3109be85fcbc8a294ca447ee995378 [file] [log] [blame]
Peter Qiu326b6cf2015-09-02 11:11:42 -07001//
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//
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080016
Peter Qiu2a6fb332015-09-17 22:19:17 -070017#include "apmanager/shill_manager.h"
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080018
Peter Qiu267fff32014-12-10 14:01:58 -080019#include <base/bind.h>
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070020#include <brillo/errors/error.h>
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080021
Peter Qiube128822015-10-13 13:55:03 -070022#include "apmanager/control_interface.h"
Peter Qiu37328b82015-09-18 09:28:18 -070023
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080024using std::string;
25
26namespace apmanager {
27
Peter Qiu2a6fb332015-09-17 22:19:17 -070028ShillManager::ShillManager() {}
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080029
Peter Qiu2a6fb332015-09-17 22:19:17 -070030ShillManager::~ShillManager() {}
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080031
Peter Qiube128822015-10-13 13:55:03 -070032void ShillManager::Init(ControlInterface* control_interface) {
Peter Qiu37328b82015-09-18 09:28:18 -070033 CHECK(!shill_proxy_) << "Already init";
Peter Qiube128822015-10-13 13:55:03 -070034 shill_proxy_ =
35 control_interface->CreateShillProxy(
Peter Qiu37328b82015-09-18 09:28:18 -070036 base::Bind(&ShillManager::OnShillServiceAppeared,
37 weak_factory_.GetWeakPtr()),
38 base::Bind(&ShillManager::OnShillServiceVanished,
Peter Qiube128822015-10-13 13:55:03 -070039 weak_factory_.GetWeakPtr()));
Peter Qiuc9ce1f12014-12-05 11:14:29 -080040}
41
Peter Qiu2a6fb332015-09-17 22:19:17 -070042void ShillManager::ClaimInterface(const string& interface_name) {
Peter Qiu37328b82015-09-18 09:28:18 -070043 CHECK(shill_proxy_) << "Proxy not initialize yet";
44 shill_proxy_->ClaimInterface(interface_name);
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080045 claimed_interfaces_.insert(interface_name);
46}
47
Peter Qiu2a6fb332015-09-17 22:19:17 -070048void ShillManager::ReleaseInterface(const string& interface_name) {
Peter Qiu37328b82015-09-18 09:28:18 -070049 CHECK(shill_proxy_) << "Proxy not initialize yet";
50 shill_proxy_->ReleaseInterface(interface_name);
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080051 claimed_interfaces_.erase(interface_name);
52}
53
Peter Qiuc7717b62015-10-22 15:21:27 -070054#if defined(__BRILLO__)
55bool ShillManager::SetupApModeInterface(string* interface_name) {
56 CHECK(shill_proxy_) << "Proxy not initialized yet";
57 return shill_proxy_->SetupApModeInterface(interface_name);
58}
59
60bool ShillManager::SetupStationModeInterface(string* interface_name) {
61 CHECK(shill_proxy_) << "Proxy not initialized yet";
62 return shill_proxy_->SetupStationModeInterface(interface_name);
63}
64#endif // __BRILLO__
65
Peter Qiu37328b82015-09-18 09:28:18 -070066void ShillManager::OnShillServiceAppeared() {
67 LOG(INFO) << __func__;
68 // Claim all interfaces from shill service in case this is a new instance.
Peter Qiu267fff32014-12-10 14:01:58 -080069 for (const auto& interface : claimed_interfaces_) {
Peter Qiu37328b82015-09-18 09:28:18 -070070 shill_proxy_->ClaimInterface(interface);
Peter Qiu267fff32014-12-10 14:01:58 -080071 }
72}
73
Peter Qiu37328b82015-09-18 09:28:18 -070074void ShillManager::OnShillServiceVanished() {
75 LOG(INFO) << __func__;
Peter Qiu267fff32014-12-10 14:01:58 -080076}
77
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080078} // namespace apmanager