polybar-dwm/include/interfaces/net.hpp

84 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
2016-05-19 14:41:06 +00:00
#include <string>
#include <memory>
#include <net/if.h>
#include <iwlib.h>
#include <limits.h>
#include <linux/ethtool.h>
#include <linux/sockios.h>
#include "exception.hpp"
#include "services/command.hpp"
namespace net
{
2016-06-21 01:59:43 +00:00
bool is_wireless_interface(std::string ifname);
2016-05-19 14:41:06 +00:00
// Network
2016-05-19 14:41:06 +00:00
class NetworkException : public Exception
{
public:
2016-06-21 01:59:43 +00:00
explicit NetworkException(std::string msg)
2016-05-19 14:41:06 +00:00
: Exception("[Network] "+ msg){}
};
class Network
{
protected:
std::unique_ptr<Command> ping;
std::string interface;
struct ifreq data;
int fd;
bool test_interface();
bool test_connection();
2016-05-19 14:41:06 +00:00
public:
2016-06-21 01:59:43 +00:00
explicit Network(std::string interface);
2016-05-19 14:41:06 +00:00
~Network();
virtual bool connected();
virtual bool test();
std::string get_ip();
2016-05-19 14:41:06 +00:00
};
// WiredNetwork
2016-05-19 14:41:06 +00:00
class WiredNetworkException : public NetworkException {
using NetworkException::NetworkException;
};
class WiredNetwork : public Network
{
int linkspeed = 0;
public:
2016-06-21 01:59:43 +00:00
explicit WiredNetwork(std::string interface);
2016-05-19 14:41:06 +00:00
std::string get_link_speed();
2016-05-19 14:41:06 +00:00
};
// WirelessNetwork
2016-05-19 14:41:06 +00:00
class WirelessNetworkException : public NetworkException {
using NetworkException::NetworkException;
};
class WirelessNetwork : public Network
{
struct iwreq iw;
public:
2016-06-21 01:59:43 +00:00
explicit WirelessNetwork(std::string interface);
2016-05-19 14:41:06 +00:00
std::string get_essid();
float get_signal_dbm();
2016-05-19 14:41:06 +00:00
float get_signal_quality();
};
}