void UPnpSearchTask::Execute( TaskQueue * /*pQueue*/ ) { MSocketDevice *pSocket = new MSocketDevice( MSocketDevice::Datagram ); // ---------------------------------------------------------------------- // Refresh IP Address List in case of changes // ---------------------------------------------------------------------- m_addressList = UPnp::g_IPAddrList; // ---------------------------------------------------------------------- // Check to see if this is a rootdevice or all request. // ---------------------------------------------------------------------- UPnpDevice &device = UPnp::g_UPnpDeviceDesc.m_rootDevice; if ((m_sST == "upnp:rootdevice") || (m_sST == "ssdp:all" )) { SendMsg( pSocket, "upnp:rootdevice", device.GetUDN() ); if (m_sST == "ssdp:all") ProcessDevice( pSocket, &device ); } else { // ------------------------------------------------------------------ // Send Device/Service specific response. // ------------------------------------------------------------------ SendMsg( pSocket, m_sST, m_sUDN ); } delete pSocket; pSocket = NULL; }
void UPnpSearchTask::ProcessDevice( MSocketDevice *pSocket, UPnpDevice *pDevice) { // ---------------------------------------------------------------------- // Loop for each device and send the 2 required messages // // -=>TODO: We need to add support to only notify // Version 1 of a service. // ---------------------------------------------------------------------- SendMsg( pSocket, pDevice->GetUDN(), "" ); SendMsg( pSocket, pDevice->m_sDeviceType, pDevice->GetUDN() ); // ------------------------------------------------------------------ // Loop for each service in this device and send the 1 required message // ------------------------------------------------------------------ UPnpServiceList::const_iterator sit = pDevice->m_listServices.begin(); for (; sit != pDevice->m_listServices.end(); ++sit) SendMsg(pSocket, (*sit)->m_sServiceType, pDevice->GetUDN()); // ---------------------------------------------------------------------- // Process any Embedded Devices // ---------------------------------------------------------------------- UPnpDeviceList::const_iterator dit = pDevice->m_listDevices.begin(); for (; dit != pDevice->m_listDevices.end(); ++dit) ProcessDevice( pSocket, *dit); }
void UPnpNotifyTask::Execute( TaskQueue *pQueue ) { MSocketDevice *pMulticast = new MMulticastSocketDevice( SSDP_GROUP, SSDP_PORT); // ---------------------------------------------------------------------- // Must send rootdevice Notification for first device. // ---------------------------------------------------------------------- UPnpDevice &device = UPnp::g_UPnpDeviceDesc.m_rootDevice; SendNotifyMsg( pMulticast, "upnp:rootdevice", device.GetUDN() ); // ---------------------------------------------------------------------- // Process rest of notifications // ---------------------------------------------------------------------- ProcessDevice( pMulticast, &device ); // ---------------------------------------------------------------------- // Clean up and reshedule task if needed (timeout = m_nMaxAge / 2). // ---------------------------------------------------------------------- delete pMulticast; pMulticast = nullptr; m_mutex.lock(); if (m_eNTS == NTS_alive) pQueue->AddTask( (m_nMaxAge / 2) * 1000, (Task *)this ); m_mutex.unlock(); }