📄 gupnp-service-info.c
字号:
/* * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd. * * Author: Jorn Baayen <jorn@openedhand.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//** * SECTION:gupnp-service-info * @short_description: Base abstract class for querying service information. * * The #GUPnPDeviceInfo base abstract class provides methods for querying * service information. */#include <libsoup/soup.h>#include <string.h>#include "gupnp-service-info.h"#include "gupnp-service-introspection-private.h"#include "gupnp-context-private.h"#include "gupnp-error.h"#include "gupnp-error-private.h"#include "http-headers.h"#include "xml-util.h"G_DEFINE_ABSTRACT_TYPE (GUPnPServiceInfo, gupnp_service_info, G_TYPE_OBJECT);struct _GUPnPServiceInfoPrivate { GUPnPContext *context; char *location; char *udn; char *service_type; SoupURI *url_base; XmlDocWrapper *doc; xmlNode *element; /* For async downloads */ GList *pending_gets;};enum { PROP_0, PROP_CONTEXT, PROP_LOCATION, PROP_UDN, PROP_SERVICE_TYPE, PROP_URL_BASE, PROP_DOCUMENT, PROP_ELEMENT};typedef struct { GUPnPServiceInfo *info; GUPnPServiceIntrospectionCallback callback; gpointer user_data; SoupMessage *message;} GetSCPDURLData;static voidget_scpd_url_data_free (GetSCPDURLData *data){ g_slice_free (GetSCPDURLData, data);}static voidgupnp_service_info_init (GUPnPServiceInfo *info){ info->priv = G_TYPE_INSTANCE_GET_PRIVATE (info, GUPNP_TYPE_SERVICE_INFO, GUPnPServiceInfoPrivate);}static voidgupnp_service_info_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec){ GUPnPServiceInfo *info; info = GUPNP_SERVICE_INFO (object); switch (property_id) { 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_SERVICE_TYPE: info->priv->service_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_get_object (value); if (info->priv->doc) g_object_ref_sink (info->priv->doc); 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; }}static voidgupnp_service_info_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec){ GUPnPServiceInfo *info; info = GUPNP_SERVICE_INFO (object); switch (property_id) { 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, info->priv->udn); break; case PROP_SERVICE_TYPE: g_value_set_string (value, gupnp_service_info_get_service_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; }}static voidgupnp_service_info_dispose (GObject *object){ GUPnPServiceInfo *info; info = GUPNP_SERVICE_INFO (object); /* Cancel any pending SCPD GETs */ if (info->priv->context) { SoupSession *session; session = _gupnp_context_get_session (info->priv->context); while (info->priv->pending_gets) { GetSCPDURLData *data; data = info->priv->pending_gets->data; soup_session_cancel_message (session, data->message, SOUP_STATUS_CANCELLED); get_scpd_url_data_free (data); info->priv->pending_gets = g_list_delete_link (info->priv->pending_gets, info->priv->pending_gets); } /* Unref 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; }}static voidgupnp_service_info_finalize (GObject *object){ GUPnPServiceInfo *info; info = GUPNP_SERVICE_INFO (object); g_free (info->priv->location); g_free (info->priv->udn); g_free (info->priv->service_type); soup_uri_free (info->priv->url_base);}static voidgupnp_service_info_class_init (GUPnPServiceInfoClass *klass){ GObjectClass *object_class; object_class = G_OBJECT_CLASS (klass); object_class->set_property = gupnp_service_info_set_property; object_class->get_property = gupnp_service_info_get_property; object_class->dispose = gupnp_service_info_dispose; object_class->finalize = gupnp_service_info_finalize; g_type_class_add_private (klass, sizeof (GUPnPServiceInfoPrivate)); /** * GUPnPServiceInfo:context * * The #GUPnPContext to use. **/ g_object_class_install_property (object_class, PROP_CONTEXT, g_param_spec_object ("context", "Context", "The GUPnPContext.", GUPNP_TYPE_CONTEXT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPServiceInfo:location * * The location of the device description file. **/ g_object_class_install_property (object_class, PROP_LOCATION, g_param_spec_string ("location", "Location", "The location of the device description " "file", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPServiceInfo:udn * * The UDN of the containing device. **/ g_object_class_install_property (object_class, PROP_UDN, g_param_spec_string ("udn", "UDN", "The UDN of the containing device", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPServiceInfo:service-type * * The service type. **/ g_object_class_install_property (object_class, PROP_SERVICE_TYPE, g_param_spec_string ("service-type", "Service type", "The service type", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPServiceInfo:url-base * * The URL base (#SoupURI). **/ g_object_class_install_property (object_class, PROP_URL_BASE, g_param_spec_pointer ("url-base", "URL base", "The URL base", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPServiceInfo:document * * Private property. * * Stability: Private **/ g_object_class_install_property (object_class, PROP_DOCUMENT, g_param_spec_object ("document", "Document", "The XML document related to this " "service", TYPE_XML_DOC_WRAPPER, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); /** * GUPnPServiceInfo:element * * Private property. * * Stability: Private **/ g_object_class_install_property (object_class, PROP_ELEMENT, g_param_spec_pointer ("element", "Element",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -