/* * Run with "EINA_LOG_LEVELS=upnp_sniffer:4,Eupnp.DeviceInfo:4 ./upnp_sniffer" * for watching all log messages. */ int main(void) { Eupnp_Control_Point *c; int ret = -1; if (!eupnp_init()) { fprintf(stderr, "Failed to initialize eina log module.\n"); return ret; } if ((_log_domain = eina_log_domain_register("upnp_sniffer", EINA_COLOR_BLUE)) < 0) { fprintf(stderr, "Failed to create a logging domain for the application.\n"); goto log_domain_reg_error; } if (!eupnp_ecore_init()) { fprintf(stderr, "Could not initialize eupnp-ecore\n"); goto eupnp_ecore_init_error; } c = eupnp_control_point_new(); if (!c) { fprintf(stderr, "Could not create control point instance\n"); goto eupnp_cp_alloc_error; } /* Subscribe for device events */ eupnp_event_bus_subscribe(EUPNP_EVENT_DEVICE_FOUND, EUPNP_CALLBACK(on_device_found), NULL); eupnp_event_bus_subscribe(EUPNP_EVENT_DEVICE_READY, EUPNP_CALLBACK(on_device_ready), NULL); eupnp_event_bus_subscribe(EUPNP_EVENT_DEVICE_GONE, EUPNP_CALLBACK(on_device_gone), NULL); /* Subscribe for service events */ eupnp_event_bus_subscribe(EUPNP_EVENT_SERVICE_FOUND, EUPNP_CALLBACK(on_service_found), NULL); eupnp_event_bus_subscribe(EUPNP_EVENT_SERVICE_GONE, EUPNP_CALLBACK(on_service_gone), NULL); /* Start control point */ eupnp_control_point_start(c); eupnp_control_point_discovery_request_send(c, 5, "upnp:rootdevice"); ret = 0; INF("Started sniffing on the UPnP network."); ecore_main_loop_begin(); INF("Shutting down application."); /* Shutdown procedure */ eupnp_control_point_stop(c); eupnp_control_point_free(c); eupnp_cp_alloc_error: eupnp_cp_init_error: eupnp_ecore_shutdown(); eupnp_ecore_init_error: eina_log_domain_unregister(_log_domain); log_domain_reg_error: eupnp_shutdown(); return ret; }
EAPI int elm_main(int argc, char **argv) { int ret = -1; Eupnp_Control_Point *c; if (!eupnp_init()) { fprintf(stderr, "Failed to initialize eupnp module."); return -1; } if (!eupnp_ecore_init()) { fprintf(stderr, "Could not initialize eupnp-ecore module"); goto eupnp_ecore_init_err; } if ((_log_domain = eina_log_domain_register("light_status_monitor", EINA_COLOR_BLUE)) < 0) { fprintf(stderr, "Failed to create a logging domain for the application."); goto log_domain_reg_error; } c = eupnp_control_point_new(); if (!c) { fprintf(stderr, "Could not create control point instance"); goto eupnp_cp_alloc_error; } /* Subscribe for device events */ eupnp_event_bus_subscribe(EUPNP_EVENT_DEVICE_READY, EUPNP_CALLBACK(on_device_ready), NULL); eupnp_event_bus_subscribe(EUPNP_EVENT_DEVICE_GONE, EUPNP_CALLBACK(on_device_gone), NULL); /* Start control point */ eupnp_control_point_start(c); igd_client_win_create(); /* Send a test search for all devices*/ if (!eupnp_control_point_discovery_request_send(c, 5, IGD_DEVICE_ST)) { WRN("Failed to perform MSearch."); } else DBG("MSearch sent sucessfully."); elm_run(); /* Shutdown procedure */ ret = 0; elm_shutdown(); eupnp_control_point_stop(c); eupnp_control_point_free(c); eupnp_cp_alloc_error: eina_log_domain_unregister(_log_domain); log_domain_reg_error: eupnp_ecore_shutdown(); eupnp_ecore_init_err: eupnp_shutdown(); return -1; }