void upnp_device_detach(UPNP_CONTEXT *context, UPNP_DEVICE *device) { UPNP_INTERFACE *ifp = context->focus_ifp; upnp_syslog(LOG_INFO, "%s: detach %s", ifp->ifname, device->root_device_xml); if (!ifp->device || ifp->device != device) return; /* Do device specific stop function */ if (device->close) (*device->close)(context); /* Clear event variables and subscribers */ gena_shutdown(context); /* Send byebye */ ssdp_byebye(context); /* Free per interface advertise list */ upnp_device_advlist_deinit(context); /* detach it */ ifp->device = 0; return; }
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; }
void upnp_device_detach(UPNP_CONTEXT *context, UPNP_DEVICE *device) { UPNP_INTERFACE *ifp = context->focus_ifp; UPNP_DEVCHAIN *chain, *prev; upnp_syslog(LOG_INFO, "%s: detach %s", ifp->ifname, device->root_device_xml); /* Locate the device chain */ for (prev = 0, chain = ifp->device_chain; chain; prev = chain, chain = chain->next) { if (chain->device == device) break; } if (chain == 0) return; ifp->focus_devchain = chain; /* Do device specific stop function */ (*device->close)(context); /* Clear event variables and subscribers */ gena_shutdown(context); /* Send byebye */ ssdp_byebye(context); /* detach it */ if (prev == 0) ifp->device_chain = chain->next; else prev->next = chain->next; /* Free this chain */ free(chain); return; }