1 //
2 // Copyright (C) 2015 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 "shill/dbus/chromeos_dhcpcd_proxy.h"
18
19 #include "shill/logging.h"
20
21 using std::string;
22 namespace shill {
23
24 namespace Logging {
25 static auto kModuleLogScope = ScopeLogger::kDHCP;
ObjectID(ChromeosDHCPCDProxy * d)26 static string ObjectID(ChromeosDHCPCDProxy* d) { return "(dhcpcd_proxy)"; }
27 }
28
ChromeosDHCPCDProxy(const scoped_refptr<dbus::Bus> & bus,const std::string & service_name)29 ChromeosDHCPCDProxy::ChromeosDHCPCDProxy(const scoped_refptr<dbus::Bus>& bus,
30 const std::string& service_name)
31 : dhcpcd_proxy_(
32 new org::chromium::dhcpcdProxy(bus, service_name)) {
33 SLOG(this, 2) << "DHCPCDProxy(service=" << service_name << ").";
34 // Do not register signal handlers, signals are processed by
35 // ChromeosDHCPCDListener.
36 }
37
~ChromeosDHCPCDProxy()38 ChromeosDHCPCDProxy::~ChromeosDHCPCDProxy() {
39 dhcpcd_proxy_->ReleaseObjectProxy(base::Bind(&base::DoNothing));
40 }
41
Rebind(const string & interface)42 void ChromeosDHCPCDProxy::Rebind(const string& interface) {
43 SLOG(DBus, nullptr, 2) << __func__;
44 brillo::ErrorPtr error;
45 if (!dhcpcd_proxy_->Rebind(interface, &error)) {
46 LogDBusError(error, __func__, interface);
47 }
48 }
49
Release(const string & interface)50 void ChromeosDHCPCDProxy::Release(const string& interface) {
51 SLOG(DBus, nullptr, 2) << __func__;
52 brillo::ErrorPtr error;
53 if (!dhcpcd_proxy_->Release(interface, &error)) {
54 LogDBusError(error, __func__, interface);
55 }
56 }
57
LogDBusError(const brillo::ErrorPtr & error,const string & method,const string & interface)58 void ChromeosDHCPCDProxy::LogDBusError(const brillo::ErrorPtr& error,
59 const string& method,
60 const string& interface) {
61 if (error->GetCode() == DBUS_ERROR_SERVICE_UNKNOWN ||
62 error->GetCode() == DBUS_ERROR_NO_REPLY) {
63 LOG(INFO) << method << ": dhcpcd daemon appears to have exited.";
64 } else {
65 LOG(FATAL) << "DBus error: " << method << " " << interface << ": "
66 << error->GetCode() << ": " << error->GetMessage();
67 }
68 }
69
70 } // namespace shill
71