NymphCast Client Library
nyansd.h
1 /*
2  nyansd.h - Header file for the NyanSD service discovery library.
3 
4  Notes:
5  -
6 
7  2020/04/23, Maya Posch
8 */
9 
10 
11 #ifndef NYANSD_H
12 #define NYANSD_H
13 
14 
15 #include <vector>
16 #include <atomic>
17 #include <thread>
18 #include <mutex>
19 #include <string>
20 
21 #include "bytebauble.h"
22 
23 
24 enum NYSD_message_type {
25  NYSD_MESSAGE_TYPE_BROADCAST = 0x01,
26  NYSD_MESSAGE_TYPE_RESPONSE = 0x02
27 };
28 
29 
30 enum NYSD_protocol {
31  NYSD_PROTOCOL_ALL = 0x00,
32  NYSD_PROTOCOL_TCP = 0x01,
33  NYSD_PROTOCOL_UDP = 0x02
34 };
35 
36 
37 struct NYSD_service {
38  uint32_t ipv4 = 0;
39  std::string ipv6;
40  uint16_t port = 0;
41  std::string hostname;
42  std::string service;
43  NYSD_protocol protocol = NYSD_PROTOCOL_ALL;
44 };
45 
46 
47 struct NYSD_query {
48  NYSD_protocol protocol;
49  std::string filter;
50 };
51 
52 
53 class NyanSD {
54  static std::vector<NYSD_service> services;
55  static std::mutex servicesMutex;
56  static std::atomic<bool> running;
57  static std::thread handler;
58  static ByteBauble bb;
59 
60  static void clientHandler(uint16_t port);
61 
62 public:
63  static bool sendQuery(uint16_t port, std::vector<NYSD_query> queries,
64  std::vector<NYSD_service> &responses);
65  static bool addService(NYSD_service service);
66  static bool startListener(uint16_t port);
67  static bool stopListener();
68 
69  static std::string ipv4_uintToString(uint32_t ipv4);
70  static uint32_t ipv4_stringToUint(std::string ipv4);
71 };
72 
73 
74 #endif
Definition: bytebauble.h:35
Definition: nyansd.h:53
Definition: nyansd.h:47
Definition: nyansd.h:37