networking.h
1 #pragma once
2 
3 #include <iostream>
4 #include <string>
5 #include <cstdint>
6 #include <boost/system/error_code.hpp>
7 #include "enum.h"
8 
9 #include "dpyError.h"
10 
11 #ifdef TESTING
12 #include "gtest/gtest.h"
13 #endif
14 
15 namespace dpyNetworking {
16 BETTER_ENUM(Statistics, uint8_t, rx_packets, rx_errors, rx_dropped, tx_packets, tx_errors, tx_dropped)
17 };
18 
23 {
24 public:
25  Networking();
26  virtual ~Networking();
27 
28  static bool isIPFormatValid(const std::string &ip);
29  static bool isInterfaceActive(const std::string &iface);
30  static bool getIPv4Address(const std::string &iface, std::string &address);
31  static uint32_t getInterfaceStatistics(boost::system::error_code &ec, const std::string &iface, const dpyNetworking::Statistics &type);
32  static float getDailyTraffic(boost::system::error_code &ec, const std::string &iface, const struct tm date);
33 private:
34  static float getDailyMegabytes(boost::system::error_code &ec, const std::string &vnstat_response,const std::string& date_string);
35 
36 
37 #ifdef TESTING
38 public:
39  friend class Networking_Daily_Megabytes_test;
40  FRIEND_TEST(Networking_Daily_Megabytes_test,Invalid_response_does_not_match_expression);
41  FRIEND_TEST(Networking_Daily_Megabytes_test,Incomplete_response_full_match_not_found);
42  FRIEND_TEST(Networking_Daily_Megabytes_test,Invalid_date_does_not_match_query);
43  FRIEND_TEST(Networking_Daily_Megabytes_test,Invalid_traffic_value);
44  FRIEND_TEST(Networking_Daily_Megabytes_test,Invalid_value_output_bad_units);
45  FRIEND_TEST(Networking_Daily_Megabytes_test,Valid_value_output_kilobytes);
46  FRIEND_TEST(Networking_Daily_Megabytes_test,Valid_value_output_megabytes);
47  FRIEND_TEST(Networking_Daily_Megabytes_test,Valid_value_output_gigabytes);
48 
49 #endif
50 };
Class meant to facilitate the use of networking functionalities.
Definition: networking.h:22
Definition: networking.h:15