Exemplo n.º 1
0
static void prv_lost_media_server(const gchar *path, void *user_data)
{
	(void) g_context.connector->notify(g_context.connection,
					   DLEYNA_SERVER_OBJECT,
					   DLEYNA_SERVER_INTERFACE_MANAGER,
					   DLS_INTERFACE_LOST_SERVER,
					   g_variant_new("(o)", path),
					   NULL);

	dleyna_task_processor_remove_queues_for_sink(g_context.processor, path);
}
Exemplo n.º 2
0
static void prv_lost_diagnostics_device(const gchar *path)
{
	DLEYNA_LOG_INFO("Lost: %s", path);

	(void) g_context.connector->notify(g_context.connection,
					   DLEYNA_DIAGNOSTICS_OBJECT,
					   DLEYNA_DIAGNOSTICS_INTERFACE_MANAGER,
					   DLD_INTERFACE_LOST_DEVICE,
					   g_variant_new("(o)", path),
					   NULL);

	dleyna_task_processor_remove_queues_for_sink(g_context.processor, path);
}
Exemplo n.º 3
0
static void prv_device_unavailable_cb(GUPnPControlPoint *cp,
				      GUPnPDeviceProxy *proxy,
				      gpointer user_data)
{
	dls_upnp_t *upnp = user_data;
	const char *udn;
	dls_device_t *device;
	const gchar *ip_address;
	unsigned int i;
	dls_device_context_t *context;
	gboolean subscribed;
	gboolean construction_ctx = FALSE;
	gboolean under_construction = FALSE;
	prv_device_new_ct_t *priv_t;
	const dleyna_task_queue_key_t *queue_id;
	dls_device_context_t *lost_context;
	gpointer key;
	gpointer val;

	DLEYNA_LOG_DEBUG("Enter");

	udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy);

	ip_address = gupnp_context_get_host_ip(
		gupnp_control_point_get_context(cp));

	if (!udn || !ip_address)
		goto on_error;

	DLEYNA_LOG_DEBUG("UDN %s", udn);
	DLEYNA_LOG_DEBUG("IP Address %s", ip_address);

	device = g_hash_table_lookup(upnp->device_udn_map, udn);

	if (!device) {
		priv_t = g_hash_table_lookup(upnp->device_uc_map, udn);

		if (priv_t) {
			device = priv_t->device;
			under_construction = TRUE;
		}
	}

	if (!device) {
		DLEYNA_LOG_WARNING("Device not found. Ignoring");
		goto on_error;
	}

	for (i = 0; i < device->contexts->len; ++i) {
		context = g_ptr_array_index(device->contexts, i);
		if (!strcmp(context->ip_address, ip_address))
			break;
	}

	if (i >= device->contexts->len)
		goto on_error;

	subscribed = (context->cds.subscribed || context->ems.subscribed);
	if (under_construction)
		construction_ctx = !strcmp(context->ip_address,
					   priv_t->ip_address);

	g_ptr_array_set_free_func(device->contexts, NULL);

	lost_context = g_ptr_array_remove_index(device->contexts, i);

	g_ptr_array_set_free_func(device->contexts,
				  (GDestroyNotify)dls_device_delete_context);

	if (device->contexts->len == 0) {
		if (!under_construction) {
			DLEYNA_LOG_DEBUG("Last Context lost.");

			if (!device->sleeping) {
				DLEYNA_LOG_DEBUG("Delete device.");

				upnp->lost_server(device->path,
						  upnp->user_data);

				g_hash_table_remove(upnp->device_udn_map, udn);
			} else {
				DLEYNA_LOG_DEBUG("Persist sleeping device.");

				dleyna_task_processor_remove_queues_for_sink(
						dls_server_get_task_processor(),
						device->path);

				g_hash_table_insert(
						upnp->sleeping_device_udn_map,
						g_strdup(udn),
						device);

				if (g_hash_table_lookup_extended(
							  upnp->device_udn_map,
							  udn,
							  &key,
							  &val)) {
					g_hash_table_steal(upnp->device_udn_map,
							   udn);

					g_free(key);
				}

				device->sleeping_context = lost_context;

				lost_context = NULL;
			}
		} else {
			DLEYNA_LOG_WARNING(
				"Device under construction. Cancelling");

			dleyna_task_processor_cancel_queue(priv_t->queue_id);
		}
	} else if (under_construction && construction_ctx) {
		DLEYNA_LOG_WARNING(
			"Device under construction. Switching context");

		/* Cancel previous contruction task chain */
		g_hash_table_remove(priv_t->upnp->device_uc_map, priv_t->udn);
		dleyna_task_queue_set_finally(priv_t->queue_id,
					      prv_device_context_switch_end);
		dleyna_task_processor_cancel_queue(priv_t->queue_id);

		/* Create a new construction task chain */
		context = dls_device_get_context(device, NULL);
		queue_id = prv_create_device_queue(&priv_t);
		prv_update_device_context(priv_t, upnp, udn, device,
					  context->ip_address, queue_id);

		/* Start tasks from current construction step */
		dls_device_construct(device,
				     context,
				     upnp->connection,
				     upnp->interface_info,
				     upnp->property_map,
				     queue_id);

	} else if (subscribed && !device->timeout_id) {
		DLEYNA_LOG_DEBUG("Subscribe on new context");

		device->timeout_id = g_timeout_add_seconds(1,
				prv_subscribe_to_service_changes,
				device);
	}

	if (lost_context != NULL)
		dls_device_delete_context(lost_context);

on_error:

	DLEYNA_LOG_DEBUG("Exit");
	DLEYNA_LOG_DEBUG_NL();

	return;
}