Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 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 | // |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 16 | |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 17 | #include "apmanager/shill_manager.h" |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 18 | |
Peter Qiu | 267fff3 | 2014-12-10 14:01:58 -0800 | [diff] [blame] | 19 | #include <base/bind.h> |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 20 | #include <brillo/errors/error.h> |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 21 | |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 22 | #include "apmanager/control_interface.h" |
Peter Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 23 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 24 | using std::string; |
| 25 | |
| 26 | namespace apmanager { |
| 27 | |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 28 | ShillManager::ShillManager() {} |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 29 | |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 30 | ShillManager::~ShillManager() {} |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 31 | |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 32 | void ShillManager::Init(ControlInterface* control_interface) { |
Peter Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 33 | CHECK(!shill_proxy_) << "Already init"; |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 34 | shill_proxy_ = |
| 35 | control_interface->CreateShillProxy( |
Peter Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 36 | base::Bind(&ShillManager::OnShillServiceAppeared, |
| 37 | weak_factory_.GetWeakPtr()), |
| 38 | base::Bind(&ShillManager::OnShillServiceVanished, |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 39 | weak_factory_.GetWeakPtr())); |
Peter Qiu | c9ce1f1 | 2014-12-05 11:14:29 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 42 | void ShillManager::ClaimInterface(const string& interface_name) { |
Peter Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 43 | CHECK(shill_proxy_) << "Proxy not initialize yet"; |
| 44 | shill_proxy_->ClaimInterface(interface_name); |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 45 | claimed_interfaces_.insert(interface_name); |
| 46 | } |
| 47 | |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 48 | void ShillManager::ReleaseInterface(const string& interface_name) { |
Peter Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 49 | CHECK(shill_proxy_) << "Proxy not initialize yet"; |
| 50 | shill_proxy_->ReleaseInterface(interface_name); |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 51 | claimed_interfaces_.erase(interface_name); |
| 52 | } |
| 53 | |
Peter Qiu | c7717b6 | 2015-10-22 15:21:27 -0700 | [diff] [blame] | 54 | #if defined(__BRILLO__) |
| 55 | bool ShillManager::SetupApModeInterface(string* interface_name) { |
| 56 | CHECK(shill_proxy_) << "Proxy not initialized yet"; |
| 57 | return shill_proxy_->SetupApModeInterface(interface_name); |
| 58 | } |
| 59 | |
| 60 | bool 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 Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 66 | void ShillManager::OnShillServiceAppeared() { |
| 67 | LOG(INFO) << __func__; |
| 68 | // Claim all interfaces from shill service in case this is a new instance. |
Peter Qiu | 267fff3 | 2014-12-10 14:01:58 -0800 | [diff] [blame] | 69 | for (const auto& interface : claimed_interfaces_) { |
Peter Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 70 | shill_proxy_->ClaimInterface(interface); |
Peter Qiu | 267fff3 | 2014-12-10 14:01:58 -0800 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
Peter Qiu | 37328b8 | 2015-09-18 09:28:18 -0700 | [diff] [blame] | 74 | void ShillManager::OnShillServiceVanished() { |
| 75 | LOG(INFO) << __func__; |
Peter Qiu | 267fff3 | 2014-12-10 14:01:58 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 78 | } // namespace apmanager |