Esempio n. 1
0
static void
on_network_light_available (GUPnPControlPoint *cp,
                            GUPnPDeviceProxy  *light_proxy,
                            gpointer           user_data)
{
        GUPnPServiceProxy *switch_proxy;
        GUPnPServiceProxy *dimming_proxy;
        GUPnPServiceInfo  *info;

        info = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (light_proxy),
                                              SWITCH_SERVICE);
        switch_proxy = GUPNP_SERVICE_PROXY (info);

        if (switch_proxy) {
                switch_proxies = g_list_append (switch_proxies, switch_proxy);
        }

        info = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (light_proxy),
                                              DIMMING_SERVICE);
        dimming_proxy = GUPNP_SERVICE_PROXY (info);

        if (dimming_proxy) {
                dimming_proxies = g_list_append (dimming_proxies,
                                                 dimming_proxy);
        }
}
Esempio n. 2
0
static gboolean
init_server (GUPnPContext *context)
{
        NetworkLight *network_light;
        GUPnPRootDevice *dev;
        GUPnPServiceInfo *switch_power;
        GUPnPServiceInfo *dimming;
        GError *error = NULL;

        /* Create root device */
        dev = gupnp_root_device_new_full (context,
                                          gupnp_resource_factory_get_default (),
                                          doc,
                                          desc_location,
                                          DATA_DIR);

        switch_power = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (dev),
                                                      SWITCH_SERVICE);

        if (switch_power) {
                gupnp_service_signals_autoconnect
                                (GUPNP_SERVICE (switch_power),
                                 NULL,
                                 &error);

                g_signal_connect (switch_power,
                                  "notify-failed",
                                  G_CALLBACK (on_notify_failed),
                                  NULL);
        }

        dimming = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (dev),
                                                 DIMMING_SERVICE);

        if (dimming) {
                gupnp_service_signals_autoconnect (GUPNP_SERVICE (dimming),
                                                   NULL,
                                                   &error);

                g_signal_connect (dimming,
                                  "notify-failed",
                                  G_CALLBACK (on_notify_failed),
                                  NULL);
        }

        network_light = network_light_new (dev, switch_power, dimming);
        g_hash_table_insert (nl_hash, g_object_ref (context), network_light);

        /* Run */
        gupnp_root_device_set_available (dev, TRUE);

        g_print ("Attaching to IP/Host %s on port %d\n",
                 gupnp_context_get_host_ip (context),
                 gupnp_context_get_port (context));

        return TRUE;
}
Esempio n. 3
0
static void on_zone_player_unavailable(GUPnPControlPoint  *control_point,
                                       GUPnPDeviceProxy   *device_proxy,
                                       gpointer            user_data)
{
	g_return_if_fail(YASC_IS_ZONE_PLAYER(device_proxy));

	g_message("Device %s (%s) now unavailable.",
	          gupnp_device_info_get_model_name(GUPNP_DEVICE_INFO(device_proxy)),
	          gupnp_device_info_get_udn(GUPNP_DEVICE_INFO(device_proxy)));
}
Esempio n. 4
0
void UpnpControlPointService::deviceProxyRemoved (GUPnPControlPoint *cp, GUPnPServiceProxy *proxy, gpointer data)
{
	UpnpControlPointService* pThis = static_cast<UpnpControlPointService*>(data);
	const char* type = gupnp_device_info_get_device_type(GUPNP_DEVICE_INFO(proxy));
	const char* location = gupnp_device_info_get_location(GUPNP_DEVICE_INFO(proxy));

	g_print("Device removed: \n");
	g_print("\ttype: %s\n", type);
	g_print("\tlocation: %s\n", location);
	pThis->fireDeviceRemoved(cp, proxy);
}
Esempio n. 5
0
static GUPnPDeviceInfo *
gupnp_device_proxy_get_device (GUPnPDeviceInfo *info,
                               xmlNode         *element)
{
        GUPnPDeviceProxy     *device;
        GUPnPResourceFactory *factory;
        GUPnPContext         *context;
        GUPnPXMLDoc          *doc;
        const char           *location;
        const SoupURI        *url_base;

        factory = gupnp_device_info_get_resource_factory (info);
        context = gupnp_device_info_get_context (info);
        doc = _gupnp_device_info_get_document (info);
        location = gupnp_device_info_get_location (info);
        url_base = gupnp_device_info_get_url_base (info);

        device = gupnp_resource_factory_create_device_proxy (factory,
                                                             context,
                                                             doc,
                                                             element,
                                                             NULL,
                                                             location,
                                                             url_base);

        return GUPNP_DEVICE_INFO (device);
}
void upnpConnectionManagerServiceConnect(UpnpConnectionManagerService *self) {
	UpnpConnectionManagerServicePrivate *priv = UPNP_CONNECTION_MANAGER_SERVICE_GET_PRIVATE(self);
	
	priv->service = gupnp_device_info_get_service(GUPNP_DEVICE_INFO(priv->device), "urn:schemas-upnp-org:service:ConnectionManager:3");
	if(!priv->service) {
//		g_printerr("Cannot get ConnectionManager service\n");
		
		exit(EXIT_FAILURE);
	}


/* ACTION CONNECT */
	g_signal_connect(GUPNP_SERVICE(priv->service), "action-invoked::GetProtocolInfo", G_CALLBACK(getProtocolInfo), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "action-invoked::GetCurrentConnectionIDs", G_CALLBACK(getCurrentConnectionIDs), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "action-invoked::GetCurrentConnectionInfo", G_CALLBACK(getCurrentConnectionInfo), self);

/* QUERY CONNECT */
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::SourceProtocolInfo", G_CALLBACK(querySourceProtocolInfo), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::SinkProtocolInfo", G_CALLBACK(querySinkProtocolInfo), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::CurrentConnectionIDs", G_CALLBACK(queryCurrentConnectionIDs), self);
//	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::FeatureList", G_CALLBACK(queryFeatureList), self);
//	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::ClockUpdateID", G_CALLBACK(queryClockUpdateID), self);
//	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::DeviceClockInfoUpdates", G_CALLBACK(queryDeviceClockInfoUpdates), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ConnectionStatus", G_CALLBACK(queryConnectionStatus), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ConnectionManager", G_CALLBACK(queryConnectionManager), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_Direction", G_CALLBACK(queryDirection), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ProtocolInfo", G_CALLBACK(queryProtocolInfo), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ConnectionID", G_CALLBACK(queryConnectionID), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_AVTransportID", G_CALLBACK(queryAVTransportID), self);
	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_RcsID", G_CALLBACK(queryRcsID), self);
//	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ItemInfoFilter", G_CALLBACK(queryItemInfoFilter), self);
//	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_Result", G_CALLBACK(queryResult), self);
//	g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_RenderingInfoList", G_CALLBACK(queryRenderingInfoList), self);
}
Esempio n. 7
0
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);
}
Esempio n. 8
0
static void
on_network_light_unavailable (GUPnPControlPoint *control_point,
                              GUPnPDeviceProxy  *light_proxy,
                              gpointer           user_data)
{
        GUPnPServiceInfo *info;

        info = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (light_proxy),
                                              SWITCH_SERVICE);
        if (info) {
                remove_service_from_list (info, &switch_proxies);
        }

        info = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (light_proxy),
                                              DIMMING_SERVICE);
        if (info) {
                remove_service_from_list (info, &dimming_proxies);
        }
}
Esempio n. 9
0
static void device_proxy_found(GUPnPControlPoint* cp, GUPnPServiceProxy* proxy, GUPnPContext* context) {
  GUPnPDeviceInfo* info = GUPNP_DEVICE_INFO(proxy);
  
  if(g_strcmp0(gupnp_device_info_get_device_type(info),"urn:schemas-upnp-org:device:InternetGatewayDevice:1") == 0) {
    const char* devname = gupnp_device_info_get_friendly_name(info);
    const char* serialno = gupnp_device_info_get_serial_number(info);
    devname = devname ? devname : "unknown";
    serialno = serialno ? serialno : "unknown";
    routerip = gupnp_context_get_host_ip(context);
    printf("Found device named %s with serial number %s on local interface %s\n",devname,serialno,gupnp_context_get_host_ip(context));
  }
}
Esempio n. 10
0
static void
gupnp_device_info_finalize (GObject *object)
{
        GUPnPDeviceInfo *info;

        info = GUPNP_DEVICE_INFO (object);

        g_free (info->priv->location);
        g_free (info->priv->udn);
        g_free (info->priv->device_type);

        soup_uri_free (info->priv->url_base);

        G_OBJECT_CLASS (gupnp_device_info_parent_class)->finalize (object);
}
Esempio n. 11
0
static void
append_device_tree (GUPnPDeviceInfo *info,
                    GtkTreeModel    *model,
                    GtkTreeIter     *parent_iter)
{
        char *friendly_name;

        friendly_name = gupnp_device_info_get_friendly_name (info);
        if (friendly_name) {
                GtkTreeIter device_iter;
                GList *child;

                gtk_tree_store_insert_with_values
                                (GTK_TREE_STORE (model),
                                 &device_iter, parent_iter, -1,
                                 0, get_icon_by_id (ICON_DEVICE),
                                 1, friendly_name,
                                 2, info,
                                 5, ICON_DEVICE,
                                 -1);
                g_free (friendly_name);

                schedule_icon_update (info, on_device_icon_available);

                /* Append the embedded devices */
                child = gupnp_device_info_list_devices (info);
                while (child) {
                        append_device_tree (GUPNP_DEVICE_INFO (child->data),
                                            model,
                                            &device_iter);
                        g_object_unref (child->data);
                        child = g_list_delete_link (child, child);
                }

                /* Append the services */
                child = gupnp_device_info_list_services (info);
                while (child) {
                        append_service_tree (GUPNP_SERVICE_INFO (child->data),
                                             GTK_TREE_STORE (model),
                                             &device_iter);
                        g_object_unref (child->data);
                        child = g_list_delete_link (child, child);
                }
        }
}
Esempio n. 12
0
static void
gupnp_device_info_set_property (GObject      *object,
                                guint         property_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
        GUPnPDeviceInfo *info;

        info = GUPNP_DEVICE_INFO (object);

        switch (property_id) {
        case PROP_RESOURCE_FACTORY:
                info->priv->factory = 
			GUPNP_RESOURCE_FACTORY (g_value_dup_object (value));
                break;
        case PROP_CONTEXT:
                info->priv->context = g_object_ref (g_value_get_object (value));
                break;
        case PROP_LOCATION:
                info->priv->location = g_value_dup_string (value);
                break;
        case PROP_UDN:
                info->priv->udn = g_value_dup_string (value);
                break;
        case PROP_DEVICE_TYPE:
                info->priv->device_type = g_value_dup_string (value);
                break;
        case PROP_URL_BASE:
                info->priv->url_base = g_value_get_pointer (value);
                if (info->priv->url_base)
                        info->priv->url_base =
                                soup_uri_copy (info->priv->url_base);

                break;
        case PROP_DOCUMENT:
                info->priv->doc = g_value_dup_object (value);
                break;
        case PROP_ELEMENT:
                info->priv->element = g_value_get_pointer (value);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
        }
}
Esempio n. 13
0
static GList *
find_device_node (GUPnPControlPoint *control_point,
                  const char        *udn)
{
        GList *l;

        l = control_point->priv->devices;

        while (l) {
                GUPnPDeviceInfo *info;

                info = GUPNP_DEVICE_INFO (l->data);

                if (strcmp (udn, gupnp_device_info_get_udn (info)) == 0)
                        break;

                l = l->next;
        }

        return l;
}
Esempio n. 14
0
static void
gupnp_device_info_get_property (GObject    *object,
                                guint       property_id,
                                GValue     *value,
                                GParamSpec *pspec)
{
        GUPnPDeviceInfo *info;

        info = GUPNP_DEVICE_INFO (object);

        switch (property_id) {
        case PROP_RESOURCE_FACTORY:
                g_value_set_object (value,
                                    info->priv->factory);
                break;
        case PROP_CONTEXT:
                g_value_set_object (value,
                                    info->priv->context);
                break;
        case PROP_LOCATION:
                g_value_set_string (value,
                                    info->priv->location);
                break;
        case PROP_UDN:
                g_value_set_string (value,
                                    gupnp_device_info_get_udn (info));
                break;
        case PROP_DEVICE_TYPE:
                g_value_set_string (value,
                                    gupnp_device_info_get_device_type (info));
                break;
        case PROP_URL_BASE:
                g_value_set_pointer (value,
                                     info->priv->url_base);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
        }
}
Esempio n. 15
0
static GUPnPDeviceInfo *
gupnp_device_get_device (GUPnPDeviceInfo *info,
                         xmlNode         *element)
{
        GUPnPDevice          *device;
        GUPnPResourceFactory *factory;
        GUPnPContext         *context;
        GUPnPDevice          *root_device;
        const char           *location;
        const SoupURI        *url_base;

        device = GUPNP_DEVICE (info);

        root_device = GUPNP_IS_ROOT_DEVICE (device) ? device :
                      GUPNP_DEVICE (device->priv->root_device);
        if (root_device == NULL) {
                g_warning ("Root device not found.");

                return NULL;
        }

        factory = gupnp_device_info_get_resource_factory (info);
        context = gupnp_device_info_get_context (info);
        location = gupnp_device_info_get_location (info);
        url_base = gupnp_device_info_get_url_base (info);

        device = gupnp_resource_factory_create_device (factory,
                                                       context,
                                                       root_device,
                                                       element,
                                                       NULL,
                                                       location,
                                                       url_base);

        return GUPNP_DEVICE_INFO (device);
}
Esempio n. 16
0
static void
gupnp_device_info_dispose (GObject *object)
{
        GUPnPDeviceInfo *info;

        info = GUPNP_DEVICE_INFO (object);

        if (info->priv->factory) {
                g_object_unref (info->priv->factory);
                info->priv->factory = NULL;
        }

        if (info->priv->context) {
                g_object_unref (info->priv->context);
                info->priv->context = NULL;
        }

        if (info->priv->doc) {
                g_object_unref (info->priv->doc);
                info->priv->doc = NULL;
        }

        G_OBJECT_CLASS (gupnp_device_info_parent_class)->dispose (object);
}
Esempio n. 17
0
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;
}
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);

}