blob: ab02a280616a07d6dff65cbc1c1641fb069d846d [file] [log] [blame]
Peter Qiu7e0ffcf2014-12-02 12:53:27 -08001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "apmanager/shill_proxy.h"
6
7#include <chromeos/dbus/service_constants.h>
8#include <chromeos/errors/error.h>
9
10using std::string;
11
12namespace apmanager {
13
14// static.
15const char ShillProxy::kManagerPath[] = "/";
16
17ShillProxy::ShillProxy() {
18 dbus::Bus::Options options;
19 options.bus_type = dbus::Bus::SYSTEM;
20 bus_ = new dbus::Bus(options);
21 manager_proxy_.reset(
22 new org::chromium::flimflam::ManagerProxy(
23 bus_, shill::kFlimflamServiceName, dbus::ObjectPath(kManagerPath)));
24}
25
26ShillProxy::~ShillProxy() {}
27
28void ShillProxy::ClaimInterface(const string& interface_name) {
29 chromeos::ErrorPtr error;
30 if (!manager_proxy_->ClaimInterface(kServiceName, interface_name, &error)) {
31 // Ignore unknown object error (when shill is not running). Only report
32 // internal error from shill.
33 if (error->GetCode() != DBUS_ERROR_UNKNOWN_OBJECT) {
34 LOG(ERROR) << "Failed to claim interface from shill: "
35 << error->GetCode() << " " << error->GetMessage();
36 }
37 }
38 claimed_interfaces_.insert(interface_name);
39}
40
41void ShillProxy::ReleaseInterface(const string& interface_name) {
42 chromeos::ErrorPtr error;
43 if (!manager_proxy_->ReleaseInterface(interface_name, &error)) {
44 // Ignore unknown object error (when shill is not running). Only report
45 // internal error from shill.
46 if (error->GetCode() != DBUS_ERROR_UNKNOWN_OBJECT) {
47 LOG(ERROR) << "Failed to release interface from shill: "
48 << error->GetCode() << " " << error->GetMessage();
49 }
50 }
51 claimed_interfaces_.erase(interface_name);
52}
53
54} // namespace apmanager