📄 gupnp-root-device.c
字号:
GUPnPRootDevice *device; GUPnPContext *context; const char *relative_location, *udn; gboolean own_description_doc; char *location, *usn; int i; xmlDoc *description_doc; xmlNode *root_element, *element; SoupURI *url_base; object = NULL; own_description_doc = FALSE; /* Get 'description-doc', 'context' and 'relative-location' property * values */ description_doc = NULL; context = NULL; relative_location = NULL; for (i = 0; i < n_construct_params; i++) { const char *par_name; par_name = construct_params[i].pspec->name; if (strcmp (par_name, "description-doc") == 0) { description_doc = g_value_get_pointer (construct_params[i].value); continue; } if (strcmp (par_name, "context") == 0) { context = g_value_get_object (construct_params[i].value); continue; } if (strcmp (par_name, "relative-location") == 0) { relative_location = g_value_get_string (construct_params[i].value); continue; } } if (!context) { g_warning ("No context specified."); return NULL; } if (!relative_location) { g_warning ("No relative location specified."); return NULL; } /* Generate full location */ location = g_build_path ("/", _gupnp_context_get_server_url (context), relative_location, NULL); /* Check whether we have a parsed description document */ if (!description_doc) { /* We don't, so download and parse it */ description_doc = download_and_parse (context, location); if (description_doc == NULL) goto DONE; own_description_doc = TRUE; } /* Find correct element */ root_element = xml_util_get_element ((xmlNode *) description_doc, "root", NULL); if (!root_element) { g_warning ("\"/root\" element not found."); goto DONE; } element = xml_util_get_element (root_element, "device", NULL); if (!element) { g_warning ("\"/root/device\" element not found."); goto DONE; } /* Set 'element' and 'description-doc' properties */ for (i = 0; i < n_construct_params; i++) { const char *par_name; par_name = construct_params[i].pspec->name; if (strcmp (par_name, "element") == 0) { g_value_set_pointer (construct_params[i].value, element); continue; } if (strcmp (par_name, "description-doc") == 0) { g_value_set_pointer (construct_params[i].value, description_doc); continue; } } /* Create object */ object_class = G_OBJECT_CLASS (gupnp_root_device_parent_class); object = object_class->constructor (type, n_construct_params, construct_params); device = GUPNP_ROOT_DEVICE (object); /* Save the URL base, if any */ url_base = xml_util_get_child_element_content_uri (root_element, "URLBase", NULL); if (!url_base) url_base = soup_uri_new (location); /* Set additional properties */ g_object_set (object, "location", location, "url-base", url_base, NULL); device->priv->own_description_doc = own_description_doc; /* Create resource group */ device->priv->group = gssdp_resource_group_new (GSSDP_CLIENT (context)); /* Add services and devices to resource group */ udn = gupnp_device_info_get_udn (GUPNP_DEVICE_INFO (device)); usn = g_strdup_printf ("%s::upnp:rootdevice", (const char *) udn); gssdp_resource_group_add_resource_simple (device->priv->group, "upnp:rootdevice", usn, location); g_free (usn); fill_resource_group (element, location, device->priv->group); DONE: /* Cleanup */ g_free (location); return object;}static voidgupnp_root_device_class_init (GUPnPRootDeviceClass *klass){ GObjectClass *object_class; object_class = G_OBJECT_CLASS (klass); object_class->set_property = gupnp_root_device_set_property; object_class->get_property = gupnp_root_device_get_property; object_class->constructor = gupnp_root_device_constructor; object_class->dispose = gupnp_root_device_dispose; object_class->finalize = gupnp_root_device_finalize; g_type_class_add_private (klass, sizeof (GUPnPRootDevicePrivate)); /** * GUPnPRootDevice:description-doc * * Pointer to description document. Constructor property. **/ g_object_class_install_property (object_class, PROP_DESCRIPTION_DOC, g_param_spec_pointer ("description-doc", "Description document", "Pointer to description document", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPRootDevice:relative-location * * Relative location. **/ g_object_class_install_property (object_class, PROP_RELATIVE_LOCATION, g_param_spec_string ("relative-location", "Relative location", "Relative location", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPRootDevice:available * * TRUE if this device is available. **/ g_object_class_install_property (object_class, PROP_AVAILABLE, g_param_spec_boolean ("available", "Available", "Whether this device is available", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));}/** * gupnp_root_device_new * @context: The #GUPnPContext * @relative_location: Location of the description file for this device, * relative to the HTTP root * * Create a new #GUPnPRootDevice object, automatically downloading and * parsing @relative_location. * * Return value: A new @GUPnPRootDevice object. **/GUPnPRootDevice *gupnp_root_device_new (GUPnPContext *context, const char *relative_location){ GUPnPResourceFactory *factory; factory = gupnp_resource_factory_get_default (); return gupnp_root_device_new_full (context, factory, NULL, relative_location);}/** * gupnp_root_device_new_full * @context: A #GUPnPContext * @factory: A #GUPnPResourceFactory * @description_doc: Pointer to the device description document, or %NULL * @relative_location: Location of the description file for this device, * relative to the HTTP root * * Create a new #GUPnPRootDevice, automatically downloading and parsing * @relative_location if @description_doc is %NULL. * * Return value: A new #GUPnPRootDevice object. **/GUPnPRootDevice *gupnp_root_device_new_full (GUPnPContext *context, GUPnPResourceFactory *factory, xmlDoc *description_doc, const char *relative_location){ g_return_val_if_fail (GUPNP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GUPNP_IS_RESOURCE_FACTORY (factory), NULL); return g_object_new (GUPNP_TYPE_ROOT_DEVICE, "context", context, "resource-factory", factory, "root-device", NULL, "description-doc", description_doc, "relative-location", relative_location, NULL);}/** * gupnp_root_device_set_available * @root_device: A #GUPnPRootDevice * @available: %TRUE if @root_device should be available * * Controls whether or not @root_device is available (announcing * its presence). **/voidgupnp_root_device_set_available (GUPnPRootDevice *root_device, gboolean available){ g_return_if_fail (GUPNP_IS_ROOT_DEVICE (root_device)); gssdp_resource_group_set_available (root_device->priv->group, available); g_object_notify (G_OBJECT (root_device), "available");}/** * gupnp_root_device_get_available * @root_device: A #GUPnPRootDevice * * Get whether or not @root_device is available (announcing its presence). * * Return value: %TRUE if @root_device is available, %FALSE otherwise. **/gbooleangupnp_root_device_get_available (GUPnPRootDevice *root_device){ g_return_val_if_fail (GUPNP_IS_ROOT_DEVICE (root_device), FALSE); return gssdp_resource_group_get_available (root_device->priv->group);}/** * gupnp_root_device_get_relative_location * @root_device: A #GUPnPRootDevice * * Get the relative location of @root_device. * * Return value: The relative location of @root_device. **/const char *gupnp_root_device_get_relative_location (GUPnPRootDevice *root_device){ g_return_val_if_fail (GUPNP_IS_ROOT_DEVICE (root_device), NULL); return root_device->priv->relative_location;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -