//============================================================================
// Name : UPnPClient2.cpp
// Author : Majik
//============================================================================
#include <libgupnp/gupnp-control-point.h>
static GMainLoop *main_loop;
/* This is our callback method to terminate the main loop
* after the timeout has expired
*/
static gboolean main_loop_timeout(void *data)
{
g_main_loop_quit (main_loop);
return 0;
}
/* This is our callback method to handle new devices
* which have been discovered. It simply prints the
* device model and friendly name to to console
*/
static void device_proxy_available_cb(GUPnPControlPoint *cp,
GUPnPDeviceProxy *proxy)
{
GUPnPDeviceInfo* gupnp_device_info = GUPNP_DEVICE_INFO(proxy);
g_print("Device model: %s", gupnp_device_info_get_model_name(gupnp_device_info));
g_print("\\tFriendly name: %s\\n", gupnp_device_info_get_friendly_name(gupnp_device_info));
}
/*
* This is the main prorgram
*/
int main (int argc, char **argv)
{
GUPnPContext *context;
GUPnPControlPoint *cp;
/* Required initialisation */
g_thread_init (NULL);
g_type_init ();
/* Create a new GUPnP Context. By here we are using the default GLib main
context, and connecting to the current machine\'s default IP on an
automatically generated port. */
context = gupnp_context_new (NULL, NULL, 0, NULL);
/* Create a Control Point targeting UPnP AV MediaRenderer devices */
cp = gupnp_control_point_new(context, "urn:schemas-upnp-org:device:MediaRenderer:1");
/* The device-proxy-available signal is emitted when any devices which match
our target are found, so connect to it */
g_signal_connect (cp,
"device-proxy-available",
G_CALLBACK (device_proxy_available_cb),
NULL);
/* Tell the Control Point to start searching */
gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
/* Set a timeout of 2 seconds to finish processing */
g_timeout_add_seconds (2, main_loop_timeout, NULL);
/* Enter the main loop. This will start the search and result in callbacks to
device_proxy_available_cb. */
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
/* Clean up */
g_main_loop_unref (main_loop);
g_object_unref (cp);
g_object_unref (context);
return 0;
}