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 "apmanager/shill_manager.h"
18 
19 #include <base/bind.h>
20 #include <brillo/errors/error.h>
21 
22 #include "apmanager/control_interface.h"
23 
24 using std::string;
25 
26 namespace apmanager {
27 
ShillManager()28 ShillManager::ShillManager() {}
29 
~ShillManager()30 ShillManager::~ShillManager() {}
31 
Init(ControlInterface * control_interface)32 void ShillManager::Init(ControlInterface* control_interface) {
33   CHECK(!shill_proxy_) << "Already init";
34   shill_proxy_ =
35       control_interface->CreateShillProxy(
36           base::Bind(&ShillManager::OnShillServiceAppeared,
37                      weak_factory_.GetWeakPtr()),
38           base::Bind(&ShillManager::OnShillServiceVanished,
39                      weak_factory_.GetWeakPtr()));
40 }
41 
ClaimInterface(const string & interface_name)42 void ShillManager::ClaimInterface(const string& interface_name) {
43   CHECK(shill_proxy_) << "Proxy not initialize yet";
44   shill_proxy_->ClaimInterface(interface_name);
45   claimed_interfaces_.insert(interface_name);
46 }
47 
ReleaseInterface(const string & interface_name)48 void ShillManager::ReleaseInterface(const string& interface_name) {
49   CHECK(shill_proxy_) << "Proxy not initialize yet";
50   shill_proxy_->ReleaseInterface(interface_name);
51   claimed_interfaces_.erase(interface_name);
52 }
53 
54 #if defined(__BRILLO__)
SetupApModeInterface(string * interface_name)55 bool ShillManager::SetupApModeInterface(string* interface_name) {
56   CHECK(shill_proxy_) << "Proxy not initialized yet";
57   return shill_proxy_->SetupApModeInterface(interface_name);
58 }
59 
SetupStationModeInterface(string * interface_name)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 
OnShillServiceAppeared()66 void ShillManager::OnShillServiceAppeared() {
67   LOG(INFO) << __func__;
68   // Claim all interfaces from shill service in case this is a new instance.
69   for (const auto& interface : claimed_interfaces_) {
70     shill_proxy_->ClaimInterface(interface);
71   }
72 }
73 
OnShillServiceVanished()74 void ShillManager::OnShillServiceVanished() {
75   LOG(INFO) << __func__;
76 }
77 
78 }  // namespace apmanager
79