Example #1
0
int
upnp_device_attach(UPNP_CONTEXT *context, UPNP_DEVICE *device)
{
	UPNP_INTERFACE *ifp = context->focus_ifp;

	upnp_syslog(LOG_INFO, "%s: attach %s", ifp->ifname, device->root_device_xml);

	/* Check if the device has already attached? */
	if (ifp->device && ifp->device == device)
		return 0;

	ifp->device = device;

	/* Setup per interface UUIDs */
	upnp_device_advlist_init(context);

	/* Remove this chain, if open error */
	if (device->open && (*device->open)(context) != 0) {
		ifp->device = 0;
		return -1;
	}

	/* Initialize gena event variable */
	gena_init(context);

	/* Send alive here */
	ssdp_alive(context);

	return 0;
}
Example #2
0
int
upnp_device_attach(UPNP_CONTEXT *context, UPNP_DEVICE *device)
{
	UPNP_INTERFACE	*ifp = context->focus_ifp;
	UPNP_DEVCHAIN	*chain;

	upnp_syslog(LOG_INFO, "%s: attach %s", ifp->ifname, device->root_device_xml);

	/* Check if the device has already attached? */
	for (chain = ifp->device_chain;
	     chain;
	     chain = chain->next) {
		/* Attached, do nothing */
		if (chain->device == device)
			return 0;
	}

	/* Allocate a new one */
	chain = (UPNP_DEVCHAIN *)malloc(sizeof(*chain));
	if (chain == 0)
		return -1;

	chain->ifp = ifp;
	chain->device = device;

	/* Prepend this chain */
	chain->next = ifp->device_chain;
	ifp->device_chain = chain;

	ifp->focus_devchain = chain;

	/* Remove this chain, if open error */
	if ((*device->open)(context) != 0) {
		ifp->device_chain = chain->next;
		ifp->focus_devchain = chain->next;

		free(chain);
		return -1;
	}

	/* Initialize gena event variable */
	gena_init(context);

	/* Send byby here */
	ssdp_byebye(context);

	upnp_sleep(1);

	/* Send alive here */
	ssdp_alive(context);

	return 0;
}