2
* Copyright (C) 2015 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include <mcs/logger.h>
19
#include <mcs/keep_alive.h>
21
#include "interfacestub.h"
25
InterfaceStub::Ptr InterfaceStub::Create(const std::string &object_path) {
26
return std::shared_ptr<InterfaceStub>(new InterfaceStub)->FinalizeConstruction(object_path);
29
InterfaceStub::Ptr InterfaceStub::FinalizeConstruction(const std::string &object_path) {
30
auto sp = shared_from_this();
32
GError *error = nullptr;
33
connection_.reset(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error));
35
MCS_ERROR("Failed to connect to system bus: %s", error->message);
40
wpa_supplicant_interface_proxy_new(connection_.get(),
41
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
45
[](GObject *source, GAsyncResult *res, gpointer user_data) {
47
auto inst = static_cast<mcs::SharedKeepAlive<InterfaceStub>*>(user_data)->ShouldDie();
49
GError *error = nullptr;
50
inst->proxy_.reset(wpa_supplicant_interface_proxy_new_finish(res, &error));
52
MCS_ERROR("Failed to connect with Interface proxy: %s", error->message);
57
if (auto sp = inst->delegate_.lock())
58
sp->OnInterfaceReady();
60
}, new mcs::SharedKeepAlive<InterfaceStub>{shared_from_this()});
65
InterfaceStub::InterfaceStub() {
68
InterfaceStub::~InterfaceStub() {
71
void InterfaceStub::SetDelegate(const std::weak_ptr<Delegate> &delegate) {
75
void InterfaceStub::ResetDelegate() {
79
std::vector<std::string> InterfaceStub::Capabilities() const {
80
std::vector<std::string> capabilities;
83
std::string InterfaceStub::Driver() const {
84
return wpa_supplicant_interface_get_driver(proxy_.get());
87
std::string InterfaceStub::Ifname() const {
88
return wpa_supplicant_interface_get_ifname(proxy_.get());
91
std::string InterfaceStub::ObjectPath() const {
92
return g_dbus_proxy_get_object_path(G_DBUS_PROXY(proxy_.get()));