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>
20
#include "networkdevice.h"
24
NetworkDevice::Ptr NetworkDevice::Create(const std::string &object_path) {
25
return std::shared_ptr<NetworkDevice>(new NetworkDevice(object_path))->FinalizeConstruction();
28
NetworkDevice::Ptr NetworkDevice::FinalizeConstruction() {
29
auto sp = shared_from_this();
31
peer_->SetDelegate(sp);
36
NetworkDevice::NetworkDevice(const std::string &object_path) :
37
object_path_(object_path),
38
peer_(PeerStub::Create(object_path)),
42
NetworkDevice::~NetworkDevice() {
45
void NetworkDevice::SetDelegate(const std::weak_ptr<Delegate> delegate) {
49
void NetworkDevice::ResetDelegate() {
53
void NetworkDevice::SyncWithPeer()
55
address_ = peer_->Address();
56
name_ = peer_->Name();
59
void NetworkDevice::OnPeerChanged() {
60
MCS_DEBUG("Peer properties changed");
63
if (auto sp = delegate_.lock())
64
sp->OnDeviceChanged(shared_from_this());
67
void NetworkDevice::OnPeerReady() {
70
if (auto sp = delegate_.lock())
71
sp->OnDeviceReady(shared_from_this());
74
void NetworkDevice::SetAddress(const mcs::MacAddress &address) {
78
void NetworkDevice::SetIpV4Address(const mcs::IpV4Address &address) {
79
ip_address_ = address;
82
void NetworkDevice::SetName(const std::string &name) {
86
void NetworkDevice::SetState(mcs::NetworkDeviceState state) {
90
void NetworkDevice::SetSupportedRoles(const std::vector<mcs::NetworkDeviceRole> roles) {
91
supported_roles_ = roles;
94
void NetworkDevice::SetRole(const std::string &role) {
98
mcs::MacAddress NetworkDevice::Address() const {
102
mcs::IpV4Address NetworkDevice::IPv4Address() const {
106
std::string NetworkDevice::Name() const {
110
mcs::NetworkDeviceState NetworkDevice::State() const {
114
std::vector<mcs::NetworkDeviceRole> NetworkDevice::SupportedRoles() const {
115
return supported_roles_;
118
std::string NetworkDevice::ObjectPath() const {
122
std::string NetworkDevice::Role() const {
126
} // namespace w11tng