void BackendSelection::Init(void) { EntryMap::Iterator it; EntryMap ourMap; DeviceLocation *pDevLoc; SSDPCacheEntries *pEntries = SSDPCache::Instance()->Find( gBackendURI ); if (!pEntries) { VERBOSE(VB_GENERAL, "Found zero backends, bailing"); return; } pEntries->AddRef(); pEntries->Lock(); EntryMap *pMap = pEntries->GetEntryMap(); for (it = pMap->begin(); it != pMap->end(); ++it) { pDevLoc = (DeviceLocation *)*it; if (!pDevLoc) continue; pDevLoc->AddRef(); ourMap.insert(pDevLoc->m_sUSN, pDevLoc); } pEntries->Unlock(); pEntries->Release(); for (it = ourMap.begin(); it != ourMap.end(); ++it) { pDevLoc = (DeviceLocation *)*it; AddItem(pDevLoc); // this does a Release() } }
void BackendSelection::Init(void) { SSDPCacheEntries *pEntries = SSDPCache::Instance()->Find(gBackendURI); if (pEntries) { EntryMap ourMap; pEntries->GetEntryMap(ourMap); pEntries->Release(); EntryMap::const_iterator it; for (it = ourMap.begin(); it != ourMap.end(); ++it) AddItem(*it); // this does an (*it)->Release() } }
/** Reimplementation. */ void CLexiconKeyChooser::refreshContent() { if (m_modules.count() == 1) { m_widget->reset(&m_modules.first()->entries(), 0, true); // qWarning("resetted"); } else { using EntryMap = std::multimap<unsigned int, QStringList const *>; EntryMap entryMap; QListIterator<const CSwordLexiconModuleInfo*> mit(m_modules); while (mit.hasNext()) { const QStringList &entries = mit.next()->entries(); entryMap.insert( std::make_pair(entries.count(), &entries) ); } QStringList goodEntries; //The string list which contains the entries which are available in all modules EntryMap::iterator it = entryMap.begin(); //iterator to go thoigh all selected modules QStringList refEntries = *(it->second); //copy the items for the first time const QStringList *cmpEntries = (++it)->second; //list for comparision, starts with the second module in the map // Testing for refEntries being empty is not needed for the set union // of all keys, but is a good idea since it is being updated in the // loop. It is necessary for set intersection and prevents a crash. while (it != entryMap.end() && (refEntries.begin() != refEntries.end())) { std::set_union( refEntries.begin(), --(refEntries.end()), //--end() is the last valid entry cmpEntries->begin(), --(cmpEntries->end()), std::back_inserter(goodEntries), //append valid entries to the end of goodEntries my_cmpEntries //ci_cmpEntries is the comparision function ); cmpEntries = ( ++it )->second; //this is a pointer to the string list of a new module /* * use the good entries for next comparision, * because the final list can only have the entries of goodEntries as maxiumum */ refEntries = goodEntries; }; m_widget->reset(goodEntries, 0, true); //write down the entries } //end of ELSE }
/** * This method is used to save element properties that are stored in plugins * @param element The element being saved * @param doc The XML document * @param elProperties The xml properties of the element */ void CMapFileFilterXML::savePluginPropertiesForElement(CMapElement *element,QDomDocument *doc,QDomElement *elProperties) { typedef QMap<QString, QString> EntryMap; QDomElement pluginsNode = doc->createElement ("plugins"); for (CMapPluginBase *plugin = m_mapManager->getPluginList()->first(); plugin!=0; plugin = m_mapManager->getPluginList()->next()) { QDomElement pNode = doc->createElement(plugin->name()); KMemConfig pluginProperties; plugin->saveElementProperties(element,&pluginProperties); EntryMap entries = pluginProperties.entryMap("Properties"); for (EntryMap::ConstIterator it = entries.begin(); it != entries.end(); ++it) { pNode.setAttribute(it.key(),it.data()); } pluginsNode.appendChild(pNode); } elProperties->appendChild(pluginsNode); }
void SSDPCache::Dump() { int nCount = 0; if (VERBOSE_LEVEL_CHECK(VB_UPNP)) { Lock(); // ---------------------------------------------------------------------- // Build List of items to be removed // ---------------------------------------------------------------------- VERBOSE( VB_UPNP, "===============================================================================" ); VERBOSE( VB_UPNP, QString( " URI (type) - Found: %1 Entries - %2 have been Allocated. " ) .arg( m_cache.count() ) .arg( SSDPCacheEntries::g_nAllocated )); VERBOSE( VB_UPNP, " \t\tUSN (unique id)\t\t | Expires\t | Location" ); VERBOSE( VB_UPNP, "-------------------------------------------------------------------------------" ); for (SSDPCacheEntriesMap::Iterator it = m_cache.begin(); it != m_cache.end(); ++it ) { SSDPCacheEntries *pEntries = *it; if (pEntries != NULL) { VERBOSE( VB_UPNP, it.key() ); pEntries->Lock(); EntryMap *pMap = pEntries->GetEntryMap(); for (EntryMap::Iterator itEntry = pMap->begin(); itEntry != pMap->end(); ++itEntry ) { DeviceLocation *pEntry = *itEntry; if (pEntry != NULL) { nCount++; pEntry->AddRef(); VERBOSE( VB_UPNP, QString( " * \t\t%1\t | %2\t | %3 " ) .arg( pEntry->m_sUSN ) .arg( pEntry->ExpiresInSecs() ) .arg( pEntry->m_sLocation )); pEntry->Release(); } } VERBOSE( VB_UPNP, " "); pEntries->Unlock(); } } VERBOSE( VB_UPNP, "-------------------------------------------------------------------------------" ); VERBOSE( VB_UPNP, QString( " Found: %1 Entries - %2 have been Allocated. " ) .arg( nCount ) .arg( DeviceLocation::g_nAllocated )); VERBOSE( VB_UPNP, "===============================================================================" ); Unlock(); } }
/** * Creates a complete set of positioned label nodes from a feature list. */ osg::Node* createNode( const FeatureList& input, const Style& style, const FilterContext& context ) { const TextSymbol* text = style.get<TextSymbol>(); if ( !text ) return 0L; osg::Group* group = new osg::Group(); Decluttering::setEnabled( group->getOrCreateStateSet(), true ); if ( text->priority().isSet() ) { DeclutteringOptions dco = Decluttering::getOptions(); dco.sortByPriority() = text->priority().isSet(); Decluttering::setOptions( dco ); } StringExpression contentExpr ( *text->content() ); NumericExpression priorityExpr( *text->priority() ); if ( text->removeDuplicateLabels() == true ) { // in remove-duplicates mode, make a list of unique features, selecting // the one with the largest area as the one we'll use for labeling. typedef std::pair<double, osg::ref_ptr<const Feature> > Entry; typedef std::map<std::string, Entry> EntryMap; EntryMap used; for( FeatureList::const_iterator i = input.begin(); i != input.end(); ++i ) { Feature* feature = i->get(); if ( feature && feature->getGeometry() ) { const std::string& value = feature->eval( contentExpr ); if ( !value.empty() ) { double area = feature->getGeometry()->getBounds().area2d(); if ( used.find(value) == used.end() ) { used[value] = Entry(area, feature); } else { Entry& biggest = used[value]; if ( area > biggest.first ) { biggest.first = area; biggest.second = feature; } } } } } for( EntryMap::iterator i = used.begin(); i != used.end(); ++i ) { const std::string& value = i->first; const Feature* feature = i->second.second.get(); group->addChild( makeLabelNode(context, feature, value, text, priorityExpr) ); } } else { for( FeatureList::const_iterator i = input.begin(); i != input.end(); ++i ) { const Feature* feature = i->get(); if ( !feature ) continue; const Geometry* geom = feature->getGeometry(); if ( !geom ) continue; const std::string& value = feature->eval( contentExpr, &context ); if ( value.empty() ) continue; group->addChild( makeLabelNode(context, feature, value, text, priorityExpr) ); } } #if 0 // good idea but needs work. DepthOffsetGroup* dog = new DepthOffsetGroup(); dog->setMinimumOffset( 500.0 ); dog->addChild( group ); return dog; #endif return group; }
void SSDPExtension::GetDeviceList( HTTPRequest *pRequest ) { SSDPCache* pCache = SSDPCache::Instance(); int nCount = 0; NameValues list; VERBOSE( VB_UPNP, "SSDPExtension::GetDeviceList" ); pCache->Lock(); QString sXML = ""; QTextStream os( &sXML, QIODevice::WriteOnly ); for (SSDPCacheEntriesMap::Iterator it = pCache->Begin(); it != pCache->End(); ++it ) { SSDPCacheEntries *pEntries = *it; if (pEntries != NULL) { os << "<Device uri='" << it.key() << "'>" << endl; pEntries->Lock(); EntryMap *pMap = pEntries->GetEntryMap(); for (EntryMap::Iterator itEntry = pMap->begin(); itEntry != pMap->end(); ++itEntry ) { DeviceLocation *pEntry = *itEntry; if (pEntry != NULL) { nCount++; pEntry->AddRef(); os << "<Service usn='" << pEntry->m_sUSN << "' expiresInSecs='" << pEntry->ExpiresInSecs() << "' url='" << pEntry->m_sLocation << "' />" << endl; pEntry->Release(); } } os << "</Device>" << endl; pEntries->Unlock(); } } os << flush; list.push_back( NameValue("DeviceCount" , pCache->Count() )); list.push_back( NameValue("DevicesAllocated" , SSDPCacheEntries::g_nAllocated)); list.push_back( NameValue("CacheEntriesFound" , nCount )); list.push_back( NameValue("CacheEntriesAllocated", DeviceLocation::g_nAllocated )); list.push_back( NameValue("DeviceList" , sXML )); pCache->Unlock(); pRequest->FormatActionResponse( list ); pRequest->m_eResponseType = ResponseTypeXML; pRequest->m_nResponseStatus = 200; }
virtual bool ProcessRequest(HTTPRequest *pRequest) { if (!pRequest) return false; if (pRequest->m_sBaseUrl != "/") return false; if (pRequest->m_sMethod == "getDeviceDesc") return false; pRequest->m_eResponseType = ResponseTypeHTML; pRequest->m_mapRespHeaders["Cache-Control"] = "no-cache=\"Ext\", max-age = 5000"; SSDPCacheEntries* cache = NULL; QString ipaddress = QString(); /* QStringList::const_iterator sit = UPnp::g_IPAddrList.begin(); for (; sit != UPnp::g_IPAddrList.end(); ++sit) { if (QHostAddress(*sit).protocol() == QAbstractSocket::IPv4Protocol) { ipaddress = *sit; break; } }*/ if (!UPnp::g_IPAddrList.isEmpty()) ipaddress = UPnp::g_IPAddrList.at(0); QString hostname = gCoreContext->GetHostName(); QDateTime qdtNow = MythDate::current(); QString masterhost = gCoreContext->GetMasterHostName(); QString masterip = gCoreContext->GetSetting("MasterServerIP"); QString masterport = gCoreContext->GetSettingOnHost("BackendStatusPort", masterhost, "6544"); QTextStream stream ( &pRequest->m_response ); stream.setCodec("UTF-8"); stream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n" << "<html xmlns=\"http://www.w3.org/1999/xhtml\"" << " xml:lang=\"en\" lang=\"en\">\r\n" << "<head>\r\n" << " <meta http-equiv=\"Content-Type\"" << "content=\"text/html; charset=UTF-8\" />\r\n" << " <title>MythFrontend Status - " << MythDate::toString(qdtNow, MythDate::kDateTimeShort) << " - " << MYTH_BINARY_VERSION << "</title>\r\n" << " <link rel=\"stylesheet\" href=\"/css/site.css\" type=\"text/css\">\r\n" << " <link rel=\"stylesheet\" href=\"/css/Status.css\" type=\"text/css\">\r\n" << "</head>\r\n" << "<body>\r\n\r\n" << " <h1 class=\"status\">MythFrontend Status</h1>\r\n"; // This frontend stream << " <div class=\"content\">\r\n" << " <h2 class=\"status\">This Frontend</h2>\r\n" << "Name : " << hostname << "<br />\r\n" << "Version : " << MYTH_BINARY_VERSION << "\r\n" << " </div>\r\n"; // Other frontends // This will not work with multiple frontends on the same machine (upnp // setup will fail on a second frontend anyway) and the ip address // filtering of the current frontend may not work in all situations cache = SSDP::Find("urn:schemas-mythtv-org:service:MythFrontend:1"); if (cache) { stream << " <div class=\"content\">\r\n" << " <h2 class=\"status\">Other Frontends</h2>\r\n"; EntryMap map; cache->GetEntryMap(map); cache->DecrRef(); cache = NULL; for (EntryMap::iterator it = map.begin(); it != map.end(); ++it) { QUrl url((*it)->m_sLocation); if (url.host() != ipaddress) { stream << "<br />" << url.host() << " (<a href=\"" << url.toString(QUrl::RemovePath) << "\">Status page</a>)\r\n"; } (*it)->DecrRef(); } stream << " </div>\r\n"; } // Master backend stream << " <div class=\"content\">\r\n" << " <h2 class=\"status\">MythTV Backends</h2>\r\n" << "Master: " << masterhost << " (<a href=\"http://" << masterip << ":" << masterport << "\">Status page</a>)\r\n"; // Slave backends cache = SSDP::Find("urn:schemas-mythtv-org:device:SlaveMediaServer:1"); if (cache) { EntryMap map; cache->GetEntryMap(map); cache->DecrRef(); cache = NULL; for (EntryMap::iterator it = map.begin(); it != map.end(); ++it) { QUrl url((*it)->m_sLocation); stream << "<br />" << "Slave: " << url.host() << " (<a href=\"" << url.toString(QUrl::RemovePath) << "\">Status page</a>)\r\n"; (*it)->DecrRef(); } } stream << " </div>\r\n"; stream << " <div class=\"content\">\r\n" << " <h2 class=\"status\">Services</h2>\r\n" << " <a href=\"MythFE/GetRemote\">Remote Control</a>\r\n" << " </div>\r\n"; double load[3]; if (getloadavg(load, 3) != -1) { stream << " <div class=\"content\">\r\n" << " <h2 class=\"status\">Machine Information</h2>\r\n" << " <div class=\"loadstatus\">\r\n" << " This machine's load average:" << "\r\n <ul>\r\n <li>" << "1 Minute: " << QString::number(load[0]) << "</li>\r\n" << " <li>5 Minutes: " << QString::number(load[1]) << "</li>\r\n" << " <li>15 Minutes: " << QString::number(load[2]) << "</li>\r\n </ul>\r\n" << " </div>\r\n" << " </div>\r\n"; } stream << "</body>\r\n</html>\r\n"; stream.flush(); return true; }