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
#ifndef W11TNG_DHCPCLIENT_H_
19
#define W11TNG_DHCPCLIENT_H_
23
#include <boost/noncopyable.hpp>
27
#include <mcs/ip_v4_address.h>
28
#include <mcs/non_copyable.h>
30
#include "processexecutor.h"
31
#include "filemonitor.h"
34
class DhcpClient : public std::enable_shared_from_this<DhcpClient>,
35
public w11tng::ProcessExecutor::Delegate,
36
public w11tng::FileMonitor::Delegate {
38
typedef std::shared_ptr<DhcpClient> Ptr;
40
class Delegate : private mcs::NonCopyable {
42
virtual void OnDhcpAddressAssigned(const mcs::IpV4Address &local_address, const mcs::IpV4Address &remote_address) = 0;
43
virtual void OnDhcpTerminated() = 0;
46
static Ptr Create(const std::weak_ptr<Delegate> &delegate, const std::string &interface_name);
50
mcs::IpV4Address RemoteAddress() const;
51
mcs::IpV4Address LocalAddress() const;
53
void OnProcessTerminated() override;
54
void OnFileChanged(const std::string &path) override;
57
DhcpClient(const std::weak_ptr<Delegate> &delegate, const std::string &interface_name);
61
std::weak_ptr<Delegate> delegate_;
62
std::string interface_name_;
63
mcs::IpV4Address local_address_;
64
mcs::IpV4Address remote_address_;
65
std::string lease_file_path_;
66
ProcessExecutor::Ptr executor_;
67
FileMonitor::Ptr monitor_;