document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //============================================================================
  2. // Name        : UPnPClient2.cpp
  3. // Author      : Majik
  4. //============================================================================
  5.  
  6. #include <libgupnp/gupnp-control-point.h>
  7.  
  8. static GMainLoop *main_loop;
  9.  
  10. /* This is our callback method to terminate the main loop
  11.  * after the timeout has expired
  12.  */
  13. static gboolean main_loop_timeout(void *data)
  14. {
  15.         g_main_loop_quit (main_loop);
  16.         return 0;
  17. }
  18.  
  19. /* This is our callback method to handle new devices
  20.  * which have been discovered. It simply prints the
  21.  * device model and friendly name to to console
  22.  */
  23. static void device_proxy_available_cb(GUPnPControlPoint *cp,
  24.                             GUPnPDeviceProxy *proxy)
  25. {
  26.   GUPnPDeviceInfo* gupnp_device_info  = GUPNP_DEVICE_INFO(proxy);
  27.   g_print("Device model: %s", gupnp_device_info_get_model_name(gupnp_device_info));
  28.   g_print("\\tFriendly name: %s\\n", gupnp_device_info_get_friendly_name(gupnp_device_info));
  29. }
  30.  
  31. /*
  32.  * This is the main prorgram
  33.  */
  34. int main (int argc, char **argv)
  35. {
  36.   GUPnPContext *context;
  37.   GUPnPControlPoint *cp;
  38.  
  39.   /* Required initialisation */
  40.   g_thread_init (NULL);
  41.   g_type_init ();
  42.  
  43.   /* Create a new GUPnP Context.  By here we are using the default GLib main
  44.      context, and connecting to the current machine\'s default IP on an
  45.      automatically generated port. */
  46.   context = gupnp_context_new (NULL, NULL, 0, NULL);
  47.  
  48.   /* Create a Control Point targeting UPnP AV MediaRenderer devices */
  49.   cp = gupnp_control_point_new(context, "urn:schemas-upnp-org:device:MediaRenderer:1");
  50.  
  51.   /* The device-proxy-available signal is emitted when any devices which match
  52.      our target are found, so connect to it */
  53.   g_signal_connect (cp,
  54.                     "device-proxy-available",
  55.                     G_CALLBACK (device_proxy_available_cb),
  56.                     NULL);
  57.  
  58.   /* Tell the Control Point to start searching */
  59.   gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
  60.  
  61.   /* Set a timeout of 2 seconds to finish processing */
  62.   g_timeout_add_seconds (2, main_loop_timeout, NULL);
  63.  
  64.   /* Enter the main loop. This will start the search and result in callbacks to
  65.      device_proxy_available_cb. */
  66.   main_loop = g_main_loop_new (NULL, FALSE);
  67.   g_main_loop_run (main_loop);
  68.  
  69.   /* Clean up */
  70.   g_main_loop_unref (main_loop);
  71.   g_object_unref (cp);
  72.   g_object_unref (context);
  73.  
  74.   return 0;
  75. }
');