diff --git a/Tizen.web/ImageClassificationOffloadingService/src/main.c b/Tizen.web/ImageClassificationOffloadingService/src/main.c index 05bf4278..8f4d19ef 100644 --- a/Tizen.web/ImageClassificationOffloadingService/src/main.c +++ b/Tizen.web/ImageClassificationOffloadingService/src/main.c @@ -8,14 +8,16 @@ #include "main.h" #include +#include #include #include +#include #include /** * @brief Service app create callback */ -static bool _create_cb(void* user_data){ +static bool _create_cb(void *user_data) { dlog_print(DLOG_INFO, LOG_TAG, "Callback create\n"); return true; } @@ -23,38 +25,127 @@ static bool _create_cb(void* user_data){ /** * @brief Service app terminate callback */ -static void _terminate_cb(void* user_data){ +static void _terminate_cb(void *user_data) { dlog_print(DLOG_INFO, LOG_TAG, "Callback terminate\n"); } /** * @brief Service app app control callback */ -static void _app_control_cb(app_control_h app_control, void* user_data){ +static void _app_control_cb(app_control_h app_control, void *user_data) { dlog_print(DLOG_INFO, LOG_TAG, "Callback app_control\n"); } +/** + * @brief print dnssd remote service information + */ +void _dnssd_print_found(dnssd_service_h dnssd_remote_service) { + /* Handling the found service */ + char *service_name = NULL; + char *service_type = NULL; + char *ip_v4_address = NULL; + char *ip_v6_address = NULL; + int port = 0; + int error_code = dnssd_service_get_name(dnssd_remote_service, &service_name); + if (error_code == DNSSD_ERROR_NONE && service_name != NULL) + dlog_print(DLOG_DEBUG, LOG_TAG, "Service name [%s]", service_name); + + error_code = dnssd_service_get_type(dnssd_remote_service, &service_type); + if (error_code == DNSSD_ERROR_NONE && service_type != NULL) + dlog_print(DLOG_DEBUG, LOG_TAG, "Service type [%s]", service_type); + + error_code = dnssd_service_get_ip(dnssd_remote_service, &ip_v4_address, + &ip_v6_address); + if (error_code == DNSSD_ERROR_NONE) { + if (ip_v4_address) + dlog_print(DLOG_DEBUG, LOG_TAG, "IPV4 address [%s]", ip_v4_address); + if (ip_v6_address) + dlog_print(DLOG_DEBUG, LOG_TAG, "IPV6 address [%s]", ip_v6_address); + } + + error_code = dnssd_service_get_port(dnssd_remote_service, &port); + if (error_code == DNSSD_ERROR_NONE) + dlog_print(DLOG_DEBUG, LOG_TAG, "Service port [%d]", port); + + if (service_name) + free(service_name); + if (service_type) + free(service_type); + if (ip_v4_address) + free(ip_v4_address); + if (ip_v6_address) + free(ip_v6_address); +} + +/** + * @brief dnssd found callback + */ +void _found_cb(dnssd_service_state_e state, + dnssd_service_h dnssd_remote_service, void *user_data) { + dlog_print(DLOG_DEBUG, LOG_TAG, "Browse Service Callback\n"); + dlog_print(DLOG_DEBUG, LOG_TAG, "Handler: %u\n", dnssd_remote_service); + dlog_print(DLOG_DEBUG, LOG_TAG, "State: "); + switch (state) { + case DNSSD_SERVICE_STATE_AVAILABLE: + /* DNS-SD service found */ + dlog_print(DLOG_DEBUG, LOG_TAG, "Available\n"); + _dnssd_print_found(dnssd_remote_service); + break; + case DNSSD_SERVICE_STATE_UNAVAILABLE: + /* DNS-SD service becomes unavailable */ + dlog_print(DLOG_DEBUG, LOG_TAG, "Un-Available\n"); + break; + case DNSSD_SERVICE_STATE_NAME_LOOKUP_FAILED: + /* Browsing failed */ + dlog_print(DLOG_DEBUG, LOG_TAG, "Browse Failure\n"); + break; + case DNSSD_SERVICE_STATE_HOST_NAME_LOOKUP_FAILED: + /* Resolving service name failed */ + dlog_print(DLOG_DEBUG, LOG_TAG, "Resolve Service Name Failure\n"); + break; + case DNSSD_SERVICE_STATE_ADDRESS_LOOKUP_FAILED: + /* Resolving service address failed */ + dlog_print(DLOG_DEBUG, LOG_TAG, "Resolve Service Address\n"); + break; + default: + dlog_print(DLOG_DEBUG, LOG_TAG, "Unknown Browse State\n"); + break; + } +} + /** * @brief Main function. */ int main(int argc, char *argv[]) { - service_app_lifecycle_callback_s event_callback = { - .create = _create_cb, - .terminate = _terminate_cb, - .app_control = _app_control_cb - }; + dnssd_browser_h browser_handle; + char *target = "_nsd_offloading._tcp"; + int ret; + bool found; + + service_app_lifecycle_callback_s event_callback = {.create = _create_cb, + .terminate = _terminate_cb, + .app_control = + _app_control_cb}; dlog_print(DLOG_ERROR, LOG_TAG, "Image classification offloading service start"); - bool found; - int ret = message_port_check_remote_port(REMOTE_APP_ID, PORT_NAME, &found); + ret = dnssd_initialize(); + if (ret != DNSSD_ERROR_NONE) + dlog_print(DLOG_ERROR, LOG_TAG, "Dnssd initialize failed"); + + ret = dnssd_start_browsing_service(target, &browser_handle, _found_cb, NULL); + if (ret == DNSSD_ERROR_NONE) + dlog_print(DLOG_DEBUG, LOG_TAG, "Start browsing"); + ret = message_port_check_remote_port(REMOTE_APP_ID, PORT_NAME, &found); if (ret != MESSAGE_PORT_ERROR_NONE || !found) { dlog_print(DLOG_ERROR, LOG_TAG, "Failed to check remote port"); } - /* Todo: Send network information to ui application */ + /** Todo: Change Uni-directional to Bi-directional + It takes time to find a remote service + Do not send network information when starting service */ bundle *b = bundle_create(); bundle_add_str(b, "command", "connected"); ret = message_port_send_message(REMOTE_APP_ID, PORT_NAME, b); diff --git a/Tizen.web/ImageClassificationOffloadingService/tizen-manifest.xml b/Tizen.web/ImageClassificationOffloadingService/tizen-manifest.xml index a95c8a21..0400d280 100644 --- a/Tizen.web/ImageClassificationOffloadingService/tizen-manifest.xml +++ b/Tizen.web/ImageClassificationOffloadingService/tizen-manifest.xml @@ -5,4 +5,7 @@ imageclassificationoffloadingservice.png + + http://tizen.org/privilege/internet +