-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender.h
69 lines (53 loc) · 1.47 KB
/
sender.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef SENDER_H
#define SENDER_H
#include <vector>
#include <string>
#include <mainwindow.h>
#include <string>
#include <iostream>
#include <arpa/inet.h>
#include <errno.h>
#include <getopt.h>
#include <iostream>
#include <stdexcept>
#include <string>
#include <sys/socket.h>
#include <unistd.h>
#include <QObject>
#include <config_parser.h>
class Sender : public QObject{
Q_OBJECT
public:
//Methods
Sender(MainWindow&, Config *);
Config *myo_config;
public slots:
void receive_todo(std::vector<unsigned long>&, bool&);
private:
//Methods
void send_wol(std::vector<unsigned long> &);
std::string get_ether(const std::string &hardware_addr);
unsigned get_hex_from_string(const std::string &);
void send_shutdown(std::vector<unsigned long> &);
//Constants
const unsigned port{60000};
const unsigned long bcast{0xFFFFFFFF};
class socket_handle{
public:
explicit socket_handle(int descriptor) : _descriptor(descriptor) {
if (_descriptor < 0)
throw std::runtime_error("Failed to open socket");
}
socket_handle(const socket_handle&) = delete;
socket_handle& operator=(const socket_handle&) = delete;
int get() const {
return _descriptor;
}
~socket_handle() {
close(_descriptor);
}
private:
const int _descriptor;
};
};
#endif // SENDER_H