Integrate ble_discovered_cb with discovered_cb 99/261799/4
authorCheoleun Moon <chleun.moon@samsung.com>
Mon, 26 Jul 2021 12:09:13 +0000 (21:09 +0900)
committercheoleun moon <chleun.moon@samsung.com>
Mon, 30 Aug 2021 07:50:56 +0000 (07:50 +0000)
To identify peer device, host name or MAC address may be used.
DNS-SD uses host name while BLE and NAN use MAC address.

Change-Id: I4ac6deaea26ed4551c3b7dd1de65a3d5719d0a8f
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
plugins/ble/ble-plugin.cpp
plugins/dns-sd/dns-sd-plugin.cpp
plugins/nan/nan-plugin.cpp
src/include/vine-disc-plugin.h
src/include/vine-disc.h
src/vine-disc.cpp
src/vine-dp.cpp
src/vine-session.cpp
tests/unittest/mocks/vine-mock-dns-sd.cpp [changed mode: 0644->0755]

index 4388042..3896483 100755 (executable)
@@ -149,7 +149,7 @@ static vine_disc_error __convert_ble_error_to_vine_disc_error(int error)
 
 vine_disc_error ble_resolve_ip(void *plugin_handle,
                                const char *service_type, const char *service_name,
-                               const char *host_name, const char *iface_name, int family)
+                               const char *host_name, const char *mac, const char *iface_name, int family)
 {
        VINE_LOGE("Not supported function");
        return VINE_DISC_ERROR_NOT_SUPPORTED;
@@ -348,10 +348,12 @@ static void __le_scan_result_cb(int result, bt_adapter_le_device_scan_result_inf
                char mac[VINE_MAC_LEN + 1] = {0, };
                strncpy(mac, info->remote_address, VINE_MAC_LEN);
 
-               if (event_callbacks.ble_discovered_cb) {
+               if (event_callbacks.discovered_cb) {
                        std::map<string, string> empty_map;
-                               event_callbacks.ble_discovered_cb(ble_handle, true,
-                                       ble_handle->service_type, service_name, mac, ble_handle->disc_handle);
+                               event_callbacks.discovered_cb(ble_handle, true,
+                                       ble_handle->service_type, service_name,
+                                       nullptr, mac, -1, empty_map,
+                                       nullptr, 0, ble_handle->disc_handle);
                }
        }
 
@@ -423,11 +425,10 @@ vine_disc_error ble_process_event(void *plugin_handle, int fd)
 void ble_register_callbacks(vine_disc_plugin_callbacks callbacks)
 {
        event_callbacks.published_cb = callbacks.published_cb;
-       event_callbacks.discovered_cb = NULL;
+       event_callbacks.discovered_cb = callbacks.discovered_cb;
        event_callbacks.ip_resolved_cb = NULL;
        event_callbacks.fd_added_cb = NULL;
        event_callbacks.fd_removed_cb = NULL;
-       event_callbacks.ble_discovered_cb = callbacks.ble_discovered_cb;
 }
 
 void vine_disc_plugin_init(vine_disc_plugin_fn *fn)
index f741843..7637bb5 100755 (executable)
@@ -325,7 +325,7 @@ static DNSServiceProtocol get_protocol(int family)
 
 vine_disc_error dns_sd_resolve_ip(void *plugin_handle,
                                const char *service_type, const char *service_name,
-                               const char *host_name, const char *iface_name, int family)
+                               const char *host_name, const char *mac, const char *iface_name, int family)
 {
        RET_VAL_IF(!plugin_handle, VINE_DISC_ERROR_INVALID_PARAMETER, "plugin_handle is NULL");
        RET_VAL_IF(!service_type, VINE_DISC_ERROR_INVALID_PARAMETER, "service_type is NULL");
@@ -400,7 +400,7 @@ static void __resolve_reply(DNSServiceRef sdRef, unsigned int flags,
        char iface_name[IF_NAMESIZE + 1] = {0, };
        if (if_indextoname(if_index, iface_name))
                event_callbacks.discovered_cb(dns_sd_handle, true,
-                       service->service_type, service->service_name, host_name,
+                       service->service_type, service->service_name, host_name, nullptr,
                        service->port, service->attributes, iface_name,
                        flags & kDNSServiceFlagsMoreComing, dns_sd_handle->user_data);
        else
@@ -472,7 +472,7 @@ static void __browse_reply(DNSServiceRef sdRef, unsigned int flags,
                map<string, string> empty_map;
                if (event_callbacks.discovered_cb)
                        event_callbacks.discovered_cb(dns_sd_handle, false,
-                               dns_sd_handle->service_type, service_name, NULL,
+                               dns_sd_handle->service_type, service_name, nullptr, nullptr,
                                0, empty_map, iface_name,
                                flags & kDNSServiceFlagsMoreComing,
                                dns_sd_handle->user_data);
index 9f2f9a6..3bcadb8 100755 (executable)
@@ -52,7 +52,7 @@ static vine_disc_error __convert_nan_error_to_vine_disc_error(int error)
 
 vine_disc_error nan_resolve_ip(void *plugin_handle,
                                const char *service_type, const char *service_name,
-                               const char *host_name, const char *iface_name, int family)
+                               const char *host_name, const char *mac, const char *iface_name, int family)
 {
        RET_VAL_IF(!plugin_handle, VINE_DISC_ERROR_INVALID_PARAMETER, "plugin_handle is NULL");
        RET_VAL_IF(!service_type, VINE_DISC_ERROR_INVALID_PARAMETER, "service_type is NULL");
@@ -195,7 +195,7 @@ static void __subscribed_cb(wifi_aware_session_h session,
        if (event_callbacks.discovered_cb) {
                std::map<string, string> empty_map;
                event_callbacks.discovered_cb(nan_handle, false,
-                       nullptr, nullptr, nullptr, -1, empty_map, nullptr, 0, nan_handle->disc_handle);
+                       nullptr, nullptr, nullptr, nullptr, -1, empty_map, nullptr, 0, nan_handle->disc_handle);
        }
 }
 
@@ -416,7 +416,6 @@ void nan_register_callbacks(vine_disc_plugin_callbacks callbacks)
        event_callbacks.ip_resolved_cb = callbacks.ip_resolved_cb;
        event_callbacks.fd_added_cb = nullptr;
        event_callbacks.fd_removed_cb = nullptr;
-       event_callbacks.ble_discovered_cb = nullptr;
 }
 
 vine_disc_error nan_process_event(void *plugin_handle, int fd)
index cf36d20..60eac58 100755 (executable)
@@ -54,16 +54,13 @@ typedef struct {
                const char *service_name, vine_disc_error error, void *disc_handle);
        void (*discovered_cb)(void *plugin_handle, bool available,
                const char *service_type, const char *service_name,
-               const char *host_name, int port, const map<string, string> &attr,
+               const char *host_name, const char *mac, int port, const map<string, string> &attr,
                const char *iface_name, int more_coming, void *disc_handle);
        void (*ip_resolved_cb)(void *plugin_handle, bool add,
                const char *ip, sa_family_t address_family, void *disc_handle);
        void (*fd_added_cb)(int fd, void *disc_handle);
        void (*fd_removed_cb)(int fd, void *disc_handle);
 
-       void (*ble_discovered_cb)(void *plugin_handle, bool available,
-               const char *service_type, const char *service_name, const char *mac,
-               void *disc_handle);
 } vine_disc_plugin_callbacks;
 
 typedef struct {
@@ -79,7 +76,7 @@ typedef struct {
        vine_disc_error (*stop_subscribe)(void *plugin_handle);
        vine_disc_error (*resolve_ip)(void *plugin_handle,
                                const char *service_type, const char *service_name,
-                               const char *host_name, const char *iface_name, int family);
+                               const char *host_name, const char *mac, const char *iface_name, int family);
        vine_disc_error (*cancel_resolve_ip)(void *plugin_handle);
        vine_disc_error (*process_event)(void *plugin_handle, int fd);
 
index 42faa43..820a9c9 100755 (executable)
@@ -31,8 +31,8 @@ typedef void (*vine_disc_published_cb)(vine_disc_h disc,
                                const char *service_name, vine_error_e error, void *user_data);
 typedef void (*vine_disc_discovered_cb)(vine_disc_h disc, bool available,
                                const char *service_type, const char *service_name,
-                               const char *host_name, int port, const map<string, string> &attr,
-                               const char *iface_name, int more_coming, const char *mac, void *user_data);
+                               const char *host_name, const char *mac, int port, const map<string, string> &attr,
+                               const char *iface_name, int more_coming, void *user_data);
 typedef void (*vine_disc_ip_resolved_cb)(vine_disc_h disc, vine_service_h service, bool add,
                                const char *ip, vine_address_family_e address_family, void *user_data);
 
index 77083a2..084172d 100755 (executable)
@@ -146,11 +146,11 @@ static void __invoke_discovered_user_cb(void *event, void *user_data)
                        discovered_event->service_type,
                        discovered_event->service_name,
                        discovered_event->host_name,
+                       discovered_event->mac,
                        discovered_event->port,
                        discovered_event->attributes,
                        discovered_event->iface_name,
                        discovered_event->more_coming,
-                       discovered_event->mac,
                        disc_handle->discovered_cb_data);
 }
 
@@ -217,15 +217,15 @@ static void __published_cb(void *plugin_handle,
 
 static void __discovered_cb(void *plugin_handle, bool available,
                const char *service_type, const char *service_name,
-               const char *host_name, int port, const map<string, string> &attr,
+               const char *host_name, const char *mac, int port, const map<string, string> &attr,
                const char *iface_name, int more_coming, void *user_data)
 {
        RET_IF(service_type == NULL, "service type is NULL");
        RET_IF(service_name == NULL, "service_name type is NULL");
 
        VINE_LOGD("Discovered callback from plugin available[%d]", available);
-       VINE_LOGD("service type[%s] service_name[%s] host_name[%s] port[%d] iface[%s] user_data[%p]",
-                       service_type, service_name, host_name, port, iface_name, user_data);
+       VINE_LOGD("service type[%s] service_name[%s] host_name[%s] mac[%s] port[%d] iface[%s] user_data[%p]",
+                       service_type, service_name, host_name, mac, port, iface_name, user_data);
 
        vine_discovered_event *discovered_event = new vine_discovered_event;
 
@@ -235,6 +235,12 @@ static void __discovered_cb(void *plugin_handle, bool available,
        strncpy(discovered_event->iface_name, iface_name, IF_NAMESIZE);
        if (host_name != NULL)
                strncpy(discovered_event->host_name, host_name, VINE_MAX_HOST_NAME_LEN);
+       else
+               memset(discovered_event->host_name, 0, VINE_MAX_HOST_NAME_LEN + 1);
+       if (mac != NULL)
+               strncpy(discovered_event->mac, mac, VINE_MAC_LEN);
+       else
+               memset(discovered_event->mac, 0, VINE_MAC_LEN + 1);
 
        discovered_event->port = port;
        discovered_event->attributes = attr;
@@ -251,37 +257,6 @@ static void __discovered_cb(void *plugin_handle, bool available,
        __free_discovered_event(discovered_event);
 }
 
-static void __ble_discovered_cb(void *plugin_handle, bool available,
-               const char *service_type, const char *service_name, const char *mac,
-               void *user_data)
-{
-       RET_IF(service_type == NULL, "service type is NULL");
-       RET_IF(service_name == NULL, "service_name type is NULL");
-       RET_IF(mac == NULL, "service mac is NULL");
-
-       VINE_LOGD("Discovered callback from plugin available[%d]", available);
-       VINE_LOGD("service type[%s] service_name[%s] mac[%s] user_data[%p]",
-                       service_type, service_name, mac, user_data);
-
-       vine_discovered_event *discovered_event = new vine_discovered_event;
-
-       discovered_event->available = available;
-       strncpy(discovered_event->service_type, service_type, VINE_MAX_SERVICE_TYPE_LEN);
-       strncpy(discovered_event->service_name, service_name, VINE_MAX_SERVICE_NAME_LEN);
-       strncpy(discovered_event->mac, mac, VINE_MAC_LEN);
-       discovered_event->port = -1;
-
-       VINE_LOGD("Create a discovered_event[%p]", discovered_event);
-
-       vine_disc_s *disc_handle = (vine_disc_s *)user_data;
-       if (disc_handle) {
-               if (vine_event_loop_add_event(disc_handle->event_queue, discovered_event,
-                       __invoke_discovered_user_cb, __free_discovered_event, user_data) == VINE_ERROR_NONE)
-                       return;
-       }
-       __free_discovered_event(discovered_event);
-}
-
 static void __ip_resolved_cb(void *plugin_handle, bool add,
                const char *ip, sa_family_t address_family, void *user_data)
 {
@@ -375,7 +350,6 @@ static void __init_plugins()
                __vine_disc_plugins[i].callbacks.ip_resolved_cb = __ip_resolved_cb;
                __vine_disc_plugins[i].callbacks.fd_added_cb = __fd_added_cb;
                __vine_disc_plugins[i].callbacks.fd_removed_cb = __fd_removed_cb;
-               __vine_disc_plugins[i].callbacks.ble_discovered_cb = __ble_discovered_cb;
                __vine_disc_plugins[i].fn.register_callbacks(__vine_disc_plugins[i].callbacks);
        }
 }
@@ -683,7 +657,7 @@ vine_error_e __vine_disc_plugin_resolve_ip(vine_disc_h disc, vine_service_h serv
        }
        error = disc_handle->plugin_fn->resolve_ip(plugin_handle,
                _vine_service_get_type(service), _vine_service_get_name(service),
-               _vine_service_get_host_name(service), _vine_service_get_iface_name(service),
+               _vine_service_get_host_name(service), nullptr, _vine_service_get_iface_name(service),
                (int)_vine_service_get_address_family(service));
        if (error != VINE_DISC_ERROR_NONE) {
                VINE_LOGE("Fail to resolve ip %d", error);
index e66715f..94a94d0 100755 (executable)
@@ -327,8 +327,8 @@ static std::string __get_full_topic(const map<string, string> &attr)
 
 static void _service_discovered_cb(vine_disc_h disc, bool available,
                const char *service_type, const char *service_name,
-               const char *host_name, int port, const map<string, string> &attr,
-               const char *iface_name, int more_coming, const char *mac, void *user_data)
+               const char *host_name, const char *mac, int port, const map<string, string> &attr,
+               const char *iface_name, int more_coming, void *user_data)
 {
        VINE_LOGD("%s is discovered. %s",
                        service_name, available ? "available" : "not available");
index 8652e96..4415aef 100755 (executable)
@@ -262,8 +262,8 @@ int _vine_session_unregister(vine_session_h session)
 
 static int __vine_set_discovered_service(vine_service_h service,
                const char *service_type, const char *service_name,
-               const char *host_name, int port, const map<string, string> &attr,
-               const char *iface_name, const char *mac)
+               const char *host_name, const char *mac, int port, const map<string, string> &attr,
+               const char *iface_name)
 {
        int ret = VINE_ERROR_NONE;
        ret = _vine_service_set_type(service, service_type);
@@ -272,6 +272,8 @@ static int __vine_set_discovered_service(vine_service_h service,
        RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to set service name");
        ret = _vine_service_set_host_name(service, host_name);
        RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to set host name");
+       ret = _vine_service_set_mac(service, mac);
+       RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to set mac");
 
        if (port >= 0) {
                ret = _vine_service_set_port(service, port);
@@ -284,15 +286,13 @@ static int __vine_set_discovered_service(vine_service_h service,
        ret = _vine_service_set_iface_name(service, iface_name);
        RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to set iface_name");
 
-       ret = _vine_service_set_mac(service, mac);
-       RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to set mac");
        return VINE_ERROR_NONE;
 }
 
 static void __discovered_cb(vine_disc_h disc, bool available,
                const char *service_type, const char *service_name,
-               const char *host_name, int port, const map<string, string> &attr,
-               const char *iface_name, int more_coming, const char *mac, void *user_data)
+               const char *host_name, const char *mac, int port, const map<string, string> &attr,
+               const char *iface_name, int more_coming, void *user_data)
 {
        VINE_LOGD("Service is discovered. Available[%d]", available);
        int ret = VINE_ERROR_NONE;
@@ -306,7 +306,7 @@ static void __discovered_cb(vine_disc_h disc, bool available,
        RET_IF(ret != VINE_ERROR_NONE, "Fail to create a service");
 
        ret = __vine_set_discovered_service(discovered_service,
-                       service_type, service_name, host_name, port, attr, iface_name, mac);
+                       service_type, service_name, host_name, mac, port, attr, iface_name);
        if (ret != VINE_ERROR_NONE) {
                VINE_LOGE("Fail to set a service. error(%d)", ret);
                _vine_service_destroy(discovered_service);
old mode 100644 (file)
new mode 100755 (executable)
index c574d79..a51c9dd
@@ -74,7 +74,7 @@ vine_disc_error __mock_disc_plugin_stop_subscribe(void *plugin_handle)
 
 vine_disc_error __mock_disc_plugin_resolve_ip(void *plugin_handle,
                                const char *service_type, const char *service_name,
-                               const char *host_name, const char *iface_name, int family)
+                               const char *host_name, const char *mac, const char *iface_name, int family)
 {
        return VINE_DISC_ERROR_NONE;
 }