📄 gupnp-service-introspection.c
字号:
}/* * * Creates a #GUPnPServiceStateVariableInfo, constructed from the stateVariable * node @variable_node in the SCPD document * */static GUPnPServiceStateVariableInfo *get_state_variable (xmlNodePtr variable_node){ GUPnPServiceStateVariableInfo *variable; xmlChar *send_events; char *data_type; gboolean success; data_type = xml_util_get_child_element_content_glib (variable_node, "dataType"); if (!data_type) { /* We can't report much about a state variable whose dataType * is not specified so better not report anything at all */ return NULL; } variable = g_slice_new0 (GUPnPServiceStateVariableInfo); success = set_variable_type (variable, data_type); g_free (data_type); if (!success) return NULL; set_variable_limits (variable_node, variable); set_default_value (variable_node, variable); send_events = xml_util_get_child_element_content (variable_node, "sendEventsAttribute"); if (send_events == NULL) { /* Some documents put it as attribute of the tag */ send_events = xml_util_get_attribute_contents (variable_node, "sendEvents"); } if (send_events) { if (strcmp ("yes", (char *) send_events) == 0) variable->send_events = TRUE; xmlFree (send_events); } return variable;}/* * * Creates a #GUPnPServiceActionArgInfo, constructed from the argument node * @argument_node in the SCPD document * */static GUPnPServiceActionArgInfo *get_action_argument (xmlNodePtr argument_node){ GUPnPServiceActionArgInfo *argument; char *name, *state_var; xmlChar *direction; name = xml_util_get_child_element_content_glib (argument_node, "name"); state_var = xml_util_get_child_element_content_glib (argument_node, "relatedStateVariable"); direction = xml_util_get_child_element_content (argument_node, "direction"); if (!name || !state_var || !direction) { g_free (name); g_free (state_var); xmlFree (direction); return NULL; } argument = g_slice_new0 (GUPnPServiceActionArgInfo); argument->name = name; argument->related_state_variable = state_var; if (strcmp ("in", (char *) direction) == 0) argument->direction = GUPNP_SERVICE_ACTION_ARG_DIRECTION_IN; else argument->direction = GUPNP_SERVICE_ACTION_ARG_DIRECTION_OUT; xmlFree (direction); if (xml_util_get_element (argument_node, "retval", NULL) != NULL) argument->retval = TRUE; return argument;}/* * * Creates a #GList of all the arguments (of type #GUPnPServiceActionArgInfo) * from the action node @action_node in the SCPD document * */static GList *get_action_arguments (xmlNodePtr action_node){ GList *argument_list = NULL; xmlNodePtr arglist_node; xmlNodePtr argument_node; arglist_node = xml_util_get_element ((xmlNode *) action_node, "argumentList", NULL); if (!arglist_node) return NULL; /* Iterate over all the arguments */ for (argument_node = arglist_node->children; argument_node; argument_node = argument_node->next) { GUPnPServiceActionArgInfo *argument; if (strcmp ("argument", (char *) argument_node->name) != 0) continue; argument = get_action_argument (argument_node); if (argument) { argument_list = g_list_append (argument_list, argument); } } return argument_list;}/* * * Creates a #GList of all the actions (of type #GUPnPServiceActionInfo) from * the SCPD document. * */static GList *get_actions (xmlNode *list_element){ GList *actions = NULL; xmlNodePtr action_node; /* Iterate over all action elements */ for (action_node = list_element->children; action_node; action_node = action_node->next) { GUPnPServiceActionInfo *action_info; GList *arguments; char *name; if (strcmp ("action", (char *) action_node->name) != 0) continue; name = xml_util_get_child_element_content_glib (action_node, "name"); if (!name) continue; arguments = get_action_arguments (action_node); if (!arguments) { g_free (name); continue; } action_info = g_slice_new0 (GUPnPServiceActionInfo); action_info->name = name; action_info->arguments = arguments; actions = g_list_append (actions, action_info); } return actions;}/* * * Creates a #GList of all the state variables (of type * #GUPnPServiceStateVariableInfo) from the SCPD document. * */static GList *get_state_variables (xmlNode *list_element){ GList *variables = NULL; xmlNodePtr variable_node; /* Iterate over all variable elements */ for (variable_node = list_element->children; variable_node; variable_node = variable_node->next) { char *name; GUPnPServiceStateVariableInfo *variable; if (strcmp ("stateVariable", (char *) variable_node->name) != 0) continue; name = xml_util_get_child_element_content_glib (variable_node, "name"); if (!name) continue; variable = get_state_variable (variable_node); if (!variable) { g_free (name); continue; } variable->name = name; variables = g_list_append (variables, variable); } return variables;}/* * Creates the #GHashTable's of action and state variable information * * */static voidconstruct_introspection_info (GUPnPServiceIntrospection *introspection, xmlDoc *scpd){ xmlNode *element; g_return_if_fail (scpd != NULL); /* Get actionList element */ element = xml_util_get_element ((xmlNode *) scpd, "scpd", "actionList", NULL); if (element) introspection->priv->actions = get_actions (element); /* Get serviceStateTable element */ element = xml_util_get_element ((xmlNode *) scpd, "scpd", "serviceStateTable", NULL); if (element) introspection->priv->variables = get_state_variables (element);}static voidcollect_action_names (gpointer data, gpointer user_data){ GList **action_names = (GList **) user_data; GUPnPServiceActionInfo *action_info = (GUPnPServiceActionInfo *) data; *action_names = g_list_append (*action_names, action_info->name);}static voidcollect_variable_names (gpointer data, gpointer user_data){ GList **variable_names = (GList **) user_data; GUPnPServiceStateVariableInfo *variable = (GUPnPServiceStateVariableInfo *) data; *variable_names = g_list_append (*variable_names, variable->name);}/** * gupnp_service_introspection_new * @scpd: Pointer to the SCPD of the service to create a introspection for * * Create a new #GUPnPServiceIntrospection for the service created from the * SCPD @scpd or %NULL. * * Return value: A new #GUPnPServiceIntrospection. **/GUPnPServiceIntrospection *gupnp_service_introspection_new (xmlDoc *scpd){ GUPnPServiceIntrospection *introspection; g_return_val_if_fail (scpd != NULL, NULL); introspection = g_object_new (GUPNP_TYPE_SERVICE_INTROSPECTION, "scpd", scpd, NULL); if (introspection->priv->actions == NULL && introspection->priv->variables == NULL) { g_object_unref (introspection); introspection = NULL; } return introspection;}/** * gupnp_service_introspection_list_action_names * @introspection: A #GUPnPServiceIntrospection * * Returns a GList of names of all the actions in this service. * * Return value: A GList of names of all the actions or %NULL. Do not modify * or free it or its contents. **/const GList *gupnp_service_introspection_list_action_names (GUPnPServiceIntrospection *introspection){ if (introspection->priv->actions == NULL) return NULL; if (introspection->priv->action_names == NULL) { g_list_foreach (introspection->priv->actions, collect_action_names, &introspection->priv->action_names); } return introspection->priv->action_names;}/** * gupnp_service_introspection_list_actions * @introspection: A #GUPnPServiceIntrospection * * Returns a #GList of all the actions (of type #GUPnPServiceActionInfo) in * this service. * * Return value: A #GList of all the actions or %NULL. Do not modify or free it * or its contents. * **/const GList *gupnp_service_introspection_list_actions (GUPnPServiceIntrospection *introspection){ return introspection->priv->actions;}/** * gupnp_service_introspection_list_state_variables * @introspection: A #GUPnPServiceIntrospection * * Returns a GList of all the state variables (of type * #GUPnPServiceStateVariableInfo) in this service. * * Return value: A #GList of all the state variables or %NULL. Do not modify or * free it or its contents. * **/const GList *gupnp_service_introspection_list_state_variables (GUPnPServiceIntrospection *introspection){ return introspection->priv->variables;}/** * gupnp_service_introspection_list_state_variable_names * @introspection: A #GUPnPServiceIntrospection * * Returns a #GList of names of all the state variables in this service. * * Return value: A #GList of names of all the state variables or %NULL. Do not * modify or free it or its contents. **/const GList *gupnp_service_introspection_list_state_variable_names (GUPnPServiceIntrospection *introspection){ if (introspection->priv->variables == NULL) return NULL; if (introspection->priv->variable_names == NULL) { g_list_foreach (introspection->priv->variables, collect_variable_names, &introspection->priv->variable_names); } return introspection->priv->variable_names;}static gintstate_variable_search_func (GUPnPServiceStateVariableInfo *variable, const gchar *variable_name){ return strcmp (variable->name, variable_name);}/** * gupnp_service_introspection_get_state_variable * @introspection: A #GUPnPServiceIntrospection * @variable_name: The name of the variable to retreive * * Returns the state variable by the name @variable_name in this service. * * Return value: the state variable or %NULL. Do not modify or free it. **/const GUPnPServiceStateVariableInfo *gupnp_service_introspection_get_state_variable (GUPnPServiceIntrospection *introspection, const gchar *variable_name){ GList *variable_node; if (introspection->priv->variables == NULL) return NULL; variable_node = g_list_find_custom ( introspection->priv->variables, (gpointer) variable_name, (GCompareFunc) state_variable_search_func); return (GUPnPServiceStateVariableInfo *) variable_node->data;}static gintaction_search_func (GUPnPServiceActionInfo *action, const gchar *action_name){ return strcmp (action->name, action_name);}/** * gupnp_service_introspection_get_action * @introspection: A #GUPnPServiceIntrospection * @action_name: The name of the action to retreive * * Returns the action by the name @action_name in this service. * * Return value: the action or %NULL. Do not modify or free it. **/const GUPnPServiceActionInfo *gupnp_service_introspection_get_action (GUPnPServiceIntrospection *introspection, const gchar *action_name){ GList *action_node; if (introspection->priv->variables == NULL) return NULL; action_node = g_list_find_custom ( introspection->priv->actions, (gpointer) action_name, (GCompareFunc) action_search_func); return (GUPnPServiceActionInfo *) action_node->data;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -