forked from mhaberler/directoryd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathService.hpp
74 lines (61 loc) · 1.57 KB
/
Service.hpp
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
70
71
72
73
74
#if !defined(_SERVICE_HPP)
#define _SERVICE_HPP
#include <string>
#include <vector>
#include <map>
#include <avahi-common/strlst.h>
using std::string;
using std::vector;
using std::map;
namespace Avahi {
class Service {
unsigned short port_;
map<string, string> txt_;
string hostname_;
string address_;
string type_;
void parse_txt(AvahiStringList *txt)
{
char *key, *value;
while (txt != NULL) {
avahi_string_list_get_pair(txt, &key, &value, NULL);
txt_[string(key)] = string(value);
txt = avahi_string_list_get_next(txt);
avahi_free(key);
avahi_free(value);
}
}
public:
Service(string const &type,
unsigned short port,
map<string, string> const &txt) : port_(port), txt_(txt), type_(type) {}
Service(string const &type,
string const &hostname,
unsigned short port,
AvahiStringList *txt) : port_(port), hostname_(hostname), type_(type)
{
parse_txt(txt);
}
Service(string const &type,
string const &hostname,
const AvahiAddress *address,
unsigned short port,
AvahiStringList *txt)
: port_(port), hostname_(hostname), type_(type)
{
char buf[AVAHI_ADDRESS_STR_MAX];
avahi_address_snprint(buf, AVAHI_ADDRESS_STR_MAX, address);
address_ = string(buf);
parse_txt(txt);
}
friend class ServiceGroup;
const map<string, string> &txt() const { return txt_; }
unsigned short port() const { return port_; }
const string &hostname() const { return hostname_; }
const string &address() const { return address_; }
const string &type() const { return type_; }
Service() {};
~Service() {};
};
}
#endif