GObject * start_upnp_server (void) { GUPnPContext *context; GUPnPRootDevice *dev; GUPnPServiceInfo *service; GUPnPDeviceInfo *subdev1; GUPnPDeviceInfo *subdev2; context = gupnp_context_new (NULL, NULL, 0, NULL); ts_fail_if (context == NULL, "Can't get gupnp context"); if (g_getenv ("UPNP_XML_PATH")) { gchar **paths = g_strsplit (g_getenv ("UPNP_XML_PATH"), ":", 0); gint i; for (i=0; paths[i]; i++) { gupnp_context_host_path (context, paths[i], ""); } g_strfreev (paths); } else { gupnp_context_host_path (context, "upnp/InternetGatewayDevice.xml", "/InternetGatewayDevice.xml"); gupnp_context_host_path (context, "upnp/WANIPConnection.xml", "/WANIPConnection.xml"); } dev = gupnp_root_device_new (context, "/InternetGatewayDevice.xml"); ts_fail_if (dev == NULL, "could not get root dev"); subdev1 = gupnp_device_info_get_device (GUPNP_DEVICE_INFO (dev), "urn:schemas-upnp-org:device:WANDevice:1"); ts_fail_if (subdev1 == NULL, "Could not get WANDevice"); subdev2 = gupnp_device_info_get_device (subdev1, "urn:schemas-upnp-org:device:WANConnectionDevice:1"); ts_fail_if (subdev2 == NULL, "Could not get WANConnectionDevice"); g_object_unref (subdev1); service = gupnp_device_info_get_service (subdev2, "urn:schemas-upnp-org:service:WANIPConnection:1"); ts_fail_if (service == NULL, "Could not get WANIPConnection"); g_object_unref (subdev2); g_signal_connect (service, "action-invoked::GetExternalIPAddress", G_CALLBACK (get_external_ip_address_cb), NULL); g_signal_connect (service, "action-invoked::AddPortMapping", G_CALLBACK (add_port_mapping_cb), NULL); g_signal_connect (service, "action-invoked::DeletePortMapping", G_CALLBACK (delete_port_mapping_cb), NULL); gupnp_root_device_set_available (dev, TRUE); return G_OBJECT (context); }
GUPnPControlPoint *yasc_get_control_point() { static GUPnPControlPoint *control_point = NULL; if (G_UNLIKELY(control_point == NULL)) { GUPnPContext *context = NULL; GUPnPResourceFactory *factory = NULL; GError *error = NULL; context = gupnp_context_new(NULL, interface, port, &error); if (context == NULL) { g_printerr("Error creating the GUPnP context: %s\n", error->message); return NULL; } factory = gupnp_resource_factory_new(); gupnp_resource_factory_register_resource_proxy_type(factory, YASC_ZONE_PLAYER_UPNP_TYPE, YASC_TYPE_ZONE_PLAYER); gupnp_resource_factory_register_resource_proxy_type(factory, YASC_MEDIA_RENDERER_UPNP_TYPE, YASC_TYPE_MEDIA_RENDERER); gupnp_resource_factory_register_resource_proxy_type(factory, YASC_MEDIA_SERVER_UPNP_TYPE, YASC_TYPE_MEDIA_SERVER); control_point = gupnp_control_point_new_full(context, factory, YASC_ZONE_PLAYER_UPNP_TYPE); g_signal_connect(control_point, "device-proxy-available", G_CALLBACK(on_zone_player_available), NULL); g_signal_connect(control_point, "device-proxy-unavailable", G_CALLBACK(on_zone_player_unavailable), NULL); g_object_unref(factory); g_object_unref(context); } return control_point; }
UpnpControlPointService::UpnpControlPointService() { // TODO Auto-generated constructor stub pthread_attr_t attri; pthread_attr_init(&attri); pthread_attr_setdetachstate(&attri, PTHREAD_CREATE_JOINABLE); pthread_mutex_init(&m_lck, NULL); pthread_cond_init(&m_cond, NULL); pthread_attr_destroy(&attri); m_context = gupnp_context_new (NULL, NULL, 0, NULL); m_controlPoint = gupnp_control_point_new(m_context, "ssdp:all"); // m_discoverer = gupnp_dlna_discoverer_new(180, TRUE, FALSE); }
gint main (gint argc, gchar *argv[]) { GError *error = NULL; gint i; GOptionContext *context; #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init (); #endif context = g_option_context_new ("- Upload files to UPnP MediaServer"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); return -1; } if (argc < 3) { char *help = NULL; help = g_option_context_get_help (context, TRUE, NULL); g_print ("%s\n", help); g_free (help); return -4; } /* Get the list of files to upload */ for (i = 1; i < argc; i++) { if (!g_file_test (argv[i], G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { g_printerr ("File %s does not exist\n", argv[i]); } else { files = g_list_append (files, argv[i]); } } if (files == NULL) { return -5; } error = NULL; upnp_context = gupnp_context_new (NULL, interface, 0, &error); if (error) { g_printerr ("Error creating the GUPnP context: %s\n", error->message); g_error_free (error); return -6; } g_print ("UPnP context created for interface %s (%s)\n", gssdp_client_get_interface (GSSDP_CLIENT (upnp_context)), gssdp_client_get_host_ip (GSSDP_CLIENT (upnp_context))); if (!init_control_point (upnp_context, udn, search_timeout)) { return -3; } main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); /* Clean-up */ g_clear_pointer (&main_loop, g_main_loop_unref); deinit_control_point (); g_object_unref (upnp_context); g_option_context_free (context); g_free (dest_container); g_free (interface); return 0; }
int main (int argc, char **argv) { GError *error = NULL; GUPnPContext *context; GUPnPControlPoint *cp; #if !GLIB_CHECK_VERSION(2,35,0) g_type_init (); #endif /* Check and parse command line arguments */ if (argc != 2) { usage (); return EXIT_FAILURE; } if (g_str_equal (argv[1], "on")) { mode = ON; } else if (g_str_equal (argv[1], "off")) { mode = OFF; } else if (g_str_equal (argv[1], "toggle")) { mode = TOGGLE; } else { usage (); return EXIT_FAILURE; } /* Create the UPnP context */ context = gupnp_context_new (NULL, NULL, 0, &error); if (error) { g_printerr ("Error creating the GUPnP context: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } /* Create the control point, searching for SwitchPower services */ cp = gupnp_control_point_new (context, "urn:schemas-upnp-org:service:SwitchPower:1"); /* Connect to the service-found callback */ g_signal_connect (cp, "service-proxy-available", G_CALLBACK (service_proxy_available_cb), NULL); /* Start searching when the main loop runs */ gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE); /* Run the main loop */ main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); /* Cleanup */ g_main_loop_unref (main_loop); g_object_unref (cp); g_object_unref (context); return EXIT_SUCCESS; }
static void run_gupnp_simple_igd_test (GMainContext *mainctx, GUPnPSimpleIgd *igd, guint requested_port) { GUPnPContext *context; GUPnPRootDevice *dev; GUPnPDeviceInfo *subdev1; GUPnPDeviceInfo *subdev2; const gchar *xml_path = "."; if (mainctx) g_main_context_push_thread_default (mainctx); context = gupnp_context_new (NULL, NULL, 0, NULL); g_assert (context); if (g_getenv ("XML_PATH")) xml_path = g_getenv ("XML_PATH"); gupnp_context_host_path (context, xml_path, ""); /* gupnp_context_host_path (context, "InternetGatewayDevice.xml", "/InternetGatewayDevice.xml"); gupnp_context_host_path (context, "WANIPConnection.xml", "/WANIPConnection.xml"); gupnp_context_host_path (context, "WANPPPConnection.xml", "/WANPPPConnection.xml"); */ dev = gupnp_root_device_new (context, "InternetGatewayDevice.xml", xml_path); g_assert (dev); subdev1 = gupnp_device_info_get_device (GUPNP_DEVICE_INFO (dev), "urn:schemas-upnp-org:device:WANDevice:1"); g_assert (subdev1); subdev2 = gupnp_device_info_get_device (subdev1, "urn:schemas-upnp-org:device:WANConnectionDevice:1"); g_assert (subdev2); g_object_unref (subdev1); ipservice = gupnp_device_info_get_service (subdev2, "urn:schemas-upnp-org:service:WANIPConnection:1"); g_assert (ipservice); pppservice = gupnp_device_info_get_service (subdev2, "urn:schemas-upnp-org:service:WANPPPConnection:1"); g_assert (pppservice); g_object_unref (subdev2); g_signal_connect (ipservice, "action-invoked::GetExternalIPAddress", G_CALLBACK (get_external_ip_address_cb), GINT_TO_POINTER (CONNECTION_IP)); g_signal_connect (ipservice, "action-invoked::AddPortMapping", G_CALLBACK (add_port_mapping_cb), GUINT_TO_POINTER (requested_port));; g_signal_connect (ipservice, "action-invoked::DeletePortMapping", G_CALLBACK (delete_port_mapping_cb), GUINT_TO_POINTER (requested_port)); g_signal_connect (pppservice, "action-invoked::GetExternalIPAddress", G_CALLBACK (get_external_ip_address_cb), GINT_TO_POINTER (CONNECTION_PPP)); g_signal_connect (pppservice, "action-invoked::AddPortMapping", G_CALLBACK (add_port_mapping_cb), GUINT_TO_POINTER (requested_port)); g_signal_connect (pppservice, "action-invoked::DeletePortMapping", G_CALLBACK (delete_port_mapping_cb), GUINT_TO_POINTER (requested_port)); gupnp_root_device_set_available (dev, TRUE); g_signal_connect (igd, "mapped-external-port", G_CALLBACK (mapped_external_port_cb), GUINT_TO_POINTER (requested_port)); g_signal_connect (igd, "error-mapping-port", G_CALLBACK (error_mapping_port_cb), NULL); gupnp_simple_igd_add_port (igd, "UDP", requested_port, "192.168.4.22", INTERNAL_PORT, 10, "GUPnP Simple IGD test"); loop = g_main_loop_new (mainctx, FALSE); g_main_loop_run (loop); g_main_loop_unref (loop); gupnp_root_device_set_available (dev, FALSE); g_object_unref (dev); if (mainctx) g_main_context_pop_thread_default (mainctx); g_object_unref (context); }
int main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) { GOptionContext *optionContext; GMainLoop *main_loop; GError *error = NULL; GUPnPContext *context; GUPnPRootDevice *dev; GUPnPServiceInfo *service; #if !GLIB_CHECK_VERSION(2,35,0) g_type_init (); #endif optionContext = g_option_context_new (NULL); g_option_context_add_main_entries (optionContext, entries, NULL); if (!g_option_context_parse (optionContext, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } /* By default the light is off */ status = FALSE; if (!quiet) { g_print ("The light is now %s.\n", status ? "on" : "off"); } /* Create the UPnP context */ context = gupnp_context_new (NULL, NULL, 0, &error); if (error) { g_printerr ("Error creating the GUPnP context: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } /* Create root device */ dev = gupnp_root_device_new (context, "BinaryLight1.xml", "."); gupnp_root_device_set_available (dev, TRUE); /* Get the switch service from the root device */ service = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (dev), "urn:schemas-upnp-org:service:SwitchPower:1"); if (!service) { g_printerr ("Cannot get SwitchPower1 service\n"); return EXIT_FAILURE; } /* Autoconnect the action and state variable handlers. This connects query_target_cb and query_status_cb to the Target and Status state variables query callbacks, and set_target_cb, get_target_cb and get_status_cb to SetTarget, GetTarget and GetStatus actions respectively. */ gupnp_service_signals_autoconnect (GUPNP_SERVICE (service), NULL, &error); if (error) { g_printerr ("Failed to autoconnect signals: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } /* Run the main loop */ main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); /* Cleanup */ g_main_loop_unref (main_loop); g_object_unref (service); g_object_unref (dev); g_object_unref (context); return EXIT_SUCCESS; }