Skip to content

Commit

Permalink
refactor(server): addRecord using avahi
Browse files Browse the repository at this point in the history
WIP

Signed-off-by: Vasilij Strassheim <[email protected]>
  • Loading branch information
V-Strassheim committed Nov 6, 2024
1 parent 94fc571 commit d99998a
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 410 deletions.
5 changes: 3 additions & 2 deletions examples/discovery/server_multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ int main(int argc, char **argv) {
// NOTE: UaExpert does not show LDS-only servers in the list.
// See also: https://forum.unified-automation.com/topic1987.html

config->mdnsConfig.serverCapabilitiesSize = 1;
UA_String *caps = (UA_String *) UA_Array_new(1, &UA_TYPES[UA_TYPES_STRING]);
config->mdnsConfig.serverCapabilitiesSize = 2;
UA_String *caps = (UA_String *) UA_Array_new(2, &UA_TYPES[UA_TYPES_STRING]);
caps[0] = UA_String_fromChars("LDS");
caps[1] = UA_String_fromChars("DA");
config->mdnsConfig.serverCapabilities = caps;

// Start the server and call iterate to wait for the multicast discovery of the LDS
Expand Down
2 changes: 2 additions & 0 deletions src/server/ua_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ UA_DiscoveryManager_clear(struct UA_ServerComponent *sc) {
currHash = nextHash;
}
}
/* Clean up mdns daemon */
//TODO UA_DiscoveryManager_clearMulticast(&dm);

# endif /* UA_ENABLE_DISCOVERY_MULTICAST */

Expand Down
17 changes: 14 additions & 3 deletions src/server/ua_discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
#define UA_DISCOVERY_MANAGER_H_

#include "ua_server_internal.h"
#include <avahi-client/client.h>
#include <avahi-client/lookup.h>
#include <avahi-client/publish.h>
#include <avahi-common/error.h>
#include <avahi-common/malloc.h>
#include <avahi-common/simple-watch.h>
#include <avahi-common/strlst.h>
#include <avahi-common/address.h>

_UA_BEGIN_DECLS

Expand Down Expand Up @@ -62,6 +70,7 @@ typedef struct {
typedef struct serverOnNetwork {
LIST_ENTRY(serverOnNetwork) pointers;
UA_ServerOnNetwork serverOnNetwork;
AvahiEntryGroup *group;
UA_DateTime created;
UA_DateTime lastSeen;
UA_Boolean txtSet;
Expand Down Expand Up @@ -91,7 +100,6 @@ struct UA_DiscoveryManager {
void* registerServerCallbackData;

# ifdef UA_ENABLE_DISCOVERY_MULTICAST
// mdns_daemon_t *mdnsDaemon;
UA_Boolean mdnsMainSrvAdded;

/* Full Domain Name of server itself. Used to detect if received mDNS
Expand All @@ -110,6 +118,9 @@ struct UA_DiscoveryManager {
void *serverOnNetworkCallbackData;

UA_UInt64 mdnsCallbackId;
AvahiClient *client;
AvahiSimplePoll *simple_poll;
AvahiServiceBrowser *browser;
# endif /* UA_ENABLE_DISCOVERY_MULTICAST */
};

Expand Down Expand Up @@ -152,8 +163,8 @@ void mdns_create_txt(UA_DiscoveryManager *dm, const char *fullServiceDomain,
const size_t capabilitiesSize,
void (*conflict)(char *host, int type, void *arg));

void mdns_set_address_record(UA_DiscoveryManager *dm, const char *fullServiceDomain,
const char *localDomain);
void mdns_set_address_record(UA_DiscoveryManager *dm, AvahiEntryGroup *group, const char *fullServiceDomain,
const char *localDomain);

#endif /* UA_ENABLE_DISCOVERY_MULTICAST */

Expand Down
Loading

0 comments on commit d99998a

Please sign in to comment.