~morphis/aethercast/enable-arm64-builds

« back to all changes in this revision

Viewing changes to src/w11tng/networkdevice.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
 
 
20
#include "networkdevice.h"
 
21
 
 
22
namespace w11tng {
 
23
 
 
24
NetworkDevice::Ptr NetworkDevice::Create(const std::string &object_path) {
 
25
    return std::shared_ptr<NetworkDevice>(new NetworkDevice(object_path))->FinalizeConstruction();
 
26
}
 
27
 
 
28
NetworkDevice::Ptr NetworkDevice::FinalizeConstruction() {
 
29
    auto sp = shared_from_this();
 
30
 
 
31
    peer_->SetDelegate(sp);
 
32
 
 
33
    return sp;
 
34
}
 
35
 
 
36
NetworkDevice::NetworkDevice(const std::string &object_path) :
 
37
    object_path_(object_path),
 
38
    peer_(PeerStub::Create(object_path)),
 
39
    state_(mcs::kIdle) {
 
40
}
 
41
 
 
42
NetworkDevice::~NetworkDevice() {
 
43
}
 
44
 
 
45
void NetworkDevice::SetDelegate(const std::weak_ptr<Delegate> delegate) {
 
46
    delegate_ = delegate;
 
47
}
 
48
 
 
49
void NetworkDevice::ResetDelegate() {
 
50
    delegate_.reset();
 
51
}
 
52
 
 
53
void NetworkDevice::SyncWithPeer()
 
54
{
 
55
    address_ = peer_->Address();
 
56
    name_ = peer_->Name();
 
57
}
 
58
 
 
59
void NetworkDevice::OnPeerChanged() {
 
60
    MCS_DEBUG("Peer properties changed");
 
61
    SyncWithPeer();
 
62
 
 
63
    if (auto sp = delegate_.lock())
 
64
        sp->OnDeviceChanged(shared_from_this());
 
65
}
 
66
 
 
67
void NetworkDevice::OnPeerReady() {
 
68
    SyncWithPeer();
 
69
 
 
70
    if (auto sp = delegate_.lock())
 
71
        sp->OnDeviceReady(shared_from_this());
 
72
}
 
73
 
 
74
void NetworkDevice::SetAddress(const mcs::MacAddress &address) {
 
75
    address_ = address;
 
76
}
 
77
 
 
78
void NetworkDevice::SetIpV4Address(const mcs::IpV4Address &address) {
 
79
    ip_address_ = address;
 
80
}
 
81
 
 
82
void NetworkDevice::SetName(const std::string &name) {
 
83
    name_ = name;
 
84
}
 
85
 
 
86
void NetworkDevice::SetState(mcs::NetworkDeviceState state) {
 
87
    state_ = state;
 
88
}
 
89
 
 
90
void NetworkDevice::SetSupportedRoles(const std::vector<mcs::NetworkDeviceRole> roles) {
 
91
    supported_roles_ = roles;
 
92
}
 
93
 
 
94
void NetworkDevice::SetRole(const std::string &role) {
 
95
    role_ = role;
 
96
}
 
97
 
 
98
mcs::MacAddress NetworkDevice::Address() const {
 
99
    return address_;
 
100
}
 
101
 
 
102
mcs::IpV4Address NetworkDevice::IPv4Address() const {
 
103
    return ip_address_;
 
104
}
 
105
 
 
106
std::string NetworkDevice::Name() const {
 
107
    return name_;
 
108
}
 
109
 
 
110
mcs::NetworkDeviceState NetworkDevice::State() const {
 
111
    return state_;
 
112
}
 
113
 
 
114
std::vector<mcs::NetworkDeviceRole> NetworkDevice::SupportedRoles() const {
 
115
    return supported_roles_;
 
116
}
 
117
 
 
118
std::string NetworkDevice::ObjectPath() const {
 
119
    return object_path_;
 
120
}
 
121
 
 
122
std::string NetworkDevice::Role() const {
 
123
    return role_;
 
124
}
 
125
 
 
126
} // namespace w11tng