Commit c6756f4e authored by Zeeshan Ali (Khattak)'s avatar Zeeshan Ali (Khattak) Committed by Ross Burton
Browse files

Refactor emit_notification function

parent 6066ec3f
......@@ -1581,55 +1581,61 @@ gupnp_service_proxy_remove_notify (GUPnPServiceProxy *proxy,
return found;
}
static void emit_notification (GUPnPServiceProxy *proxy,
xmlDoc *doc)
static void
emit_notification (GUPnPServiceProxy *proxy,
xmlNode *var_node)
{
xmlNode *node;
NotifyData *data;
GValue value = {0, };
GList *l;
node = xmlDocGetRootElement (doc);
data = g_hash_table_lookup (proxy->priv->notify_hash, var_node->name);
if (data == NULL)
return;
/* Iterate over all provided properties */
for (node = node->children; node; node = node->next) {
xmlNode *var_node;
NotifyData *data;
GValue value = {0, };
GList *l;
/* Make a GValue of the desired type */
g_value_init (&value, data->type);
/* variableName node */
var_node = node->children;
if (!gvalue_util_set_value_from_xml_node (&value, var_node)) {
g_value_unset (&value);
return;
}
if (var_node == NULL ||
strcmp ((char *) node->name, "property") != 0)
continue;
/* Call callbacks */
for (l = data->callbacks; l; l = l->next) {
CallbackData *callback_data;
data = g_hash_table_lookup (proxy->priv->notify_hash,
var_node->name);
if (data == NULL)
continue;
callback_data = l->data;
/* Make a GValue of the desired type */
g_value_init (&value, data->type);
callback_data->callback (proxy,
(const char *) var_node->name,
&value,
callback_data->user_data);
}
if (!gvalue_util_set_value_from_xml_node (&value, var_node)) {
g_value_unset (&value);
/* Cleanup */
g_value_unset (&value);
}
continue;
}
static void
emit_notifications_for_doc (GUPnPServiceProxy *proxy,
xmlDoc *doc)
{
xmlNode *node;
/* Call callbacks */
for (l = data->callbacks; l; l = l->next) {
CallbackData *callback_data;
node = xmlDocGetRootElement (doc);
callback_data = l->data;
/* Iterate over all provided properties */
for (node = node->children; node; node = node->next) {
xmlNode *var_node;
callback_data->callback (proxy,
(const char *) var_node->name,
&value,
callback_data->user_data);
}
/* variableName node */
var_node = node->children;
/* Cleanup */
g_value_unset (&value);
if (var_node != NULL &&
strcmp ((char *) node->name, "property") == 0)
emit_notification (proxy, var_node);
}
}
......@@ -1673,7 +1679,8 @@ emit_notifications (gpointer user_data)
strcmp (emit_notify_data->sid,
proxy->priv->sid) == 0))
/* Our SID, entertain! */
emit_notification (proxy, emit_notify_data->doc);
emit_notifications_for_doc (proxy,
emit_notify_data->doc);
}
/* Cleanup */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment