~morphis/aethercast/enable-arm64-builds

« back to all changes in this revision

Viewing changes to src/w11tng/interfacestub.cpp

  • Committer: Tarmac
  • Author(s): Simon Fels
  • Date: 2016-02-04 06:38:31 UTC
  • mfrom: (119.1.65 trunk)
  • Revision ID: tarmac-20160204063831-b6q9o8ktznevvd8x
Add a network manager implementation to use the DBus interface of wpa-supplicant.

Approved by PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 */
 
17
 
 
18
#include <mcs/logger.h>
 
19
#include <mcs/keep_alive.h>
 
20
 
 
21
#include "interfacestub.h"
 
22
 
 
23
namespace w11tng {
 
24
 
 
25
InterfaceStub::Ptr InterfaceStub::Create(const std::string &object_path) {
 
26
    return std::shared_ptr<InterfaceStub>(new InterfaceStub)->FinalizeConstruction(object_path);
 
27
}
 
28
 
 
29
InterfaceStub::Ptr InterfaceStub::FinalizeConstruction(const std::string &object_path) {
 
30
    auto sp = shared_from_this();
 
31
 
 
32
    GError *error = nullptr;
 
33
    connection_.reset(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error));
 
34
    if (!connection_) {
 
35
        MCS_ERROR("Failed to connect to system bus: %s", error->message);
 
36
        g_error_free(error);
 
37
        return sp;
 
38
    }
 
39
 
 
40
    wpa_supplicant_interface_proxy_new(connection_.get(),
 
41
                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
 
42
                                       kBusName,
 
43
                                       object_path.c_str(),
 
44
                                       nullptr,
 
45
                                       [](GObject *source, GAsyncResult *res, gpointer user_data) {
 
46
 
 
47
        auto inst = static_cast<mcs::SharedKeepAlive<InterfaceStub>*>(user_data)->ShouldDie();
 
48
 
 
49
        GError *error = nullptr;
 
50
        inst->proxy_.reset(wpa_supplicant_interface_proxy_new_finish(res, &error));
 
51
        if (!inst->proxy_) {
 
52
            MCS_ERROR("Failed to connect with Interface proxy: %s", error->message);
 
53
            g_error_free(error);
 
54
            return;
 
55
        }
 
56
 
 
57
        if (auto sp = inst->delegate_.lock())
 
58
            sp->OnInterfaceReady();
 
59
 
 
60
    }, new mcs::SharedKeepAlive<InterfaceStub>{shared_from_this()});
 
61
 
 
62
    return sp;
 
63
}
 
64
 
 
65
InterfaceStub::InterfaceStub() {
 
66
}
 
67
 
 
68
InterfaceStub::~InterfaceStub() {
 
69
}
 
70
 
 
71
void InterfaceStub::SetDelegate(const std::weak_ptr<Delegate> &delegate) {
 
72
    delegate_ = delegate;
 
73
}
 
74
 
 
75
void InterfaceStub::ResetDelegate() {
 
76
    delegate_.reset();
 
77
}
 
78
 
 
79
std::vector<std::string> InterfaceStub::Capabilities() const {
 
80
    std::vector<std::string> capabilities;
 
81
    return capabilities;
 
82
}
 
83
std::string InterfaceStub::Driver() const {
 
84
    return wpa_supplicant_interface_get_driver(proxy_.get());
 
85
}
 
86
 
 
87
std::string InterfaceStub::Ifname() const {
 
88
    return wpa_supplicant_interface_get_ifname(proxy_.get());
 
89
}
 
90
 
 
91
std::string InterfaceStub::ObjectPath() const {
 
92
    return g_dbus_proxy_get_object_path(G_DBUS_PROXY(proxy_.get()));
 
93
}
 
94
 
 
95
} // namespace w11tng