void DeviceBuildTask::run() { HLOG2(H_AT, H_FUN, m_owner->m_loggingIdentifier); QString err; QScopedPointer<HDefaultClientDevice> device; device.reset( m_owner->buildDevice(m_locations[0], m_cacheControlMaxAge, &err)); // the returned device is a fully built root device containing every // embedded device and service advertised in the device and service descriptions // otherwise, the creation failed if (!device.data()) { HLOG_WARN(QString("Couldn't create a device: %1").arg(err)); m_completionValue = -1; m_errorString = err; } else { device->moveToThread(m_owner->thread()); m_completionValue = 0; m_createdDevice.swap(device); } emit done(m_udn); }
void HControlPointPrivate::deviceModelBuildDone(const Herqq::Upnp::HUdn& udn) { HLOG2(H_AT, H_FUN, m_loggingIdentifier); DeviceBuildTask* build = m_deviceBuildTasks.get(udn); Q_ASSERT(build); if (m_state == Initialized) { // The check is done because it is possible that a user has called // HControlPoint::quit() before this event is delivered. if (build->completionValue() == 0) { HLOG_INFO(QString("Device model for [%1] built successfully.").arg( udn.toString())); HDefaultClientDevice* device = build->createdDevice(); Q_ASSERT(device); for (qint32 i = 0; i < build->m_locations.size(); ++i) { device->addLocation(build->m_locations[i]); } processDeviceOnline(device, true); } else { HLOG_WARN(QString("Device model for [%1] could not be built: %2.").arg( udn.toString(), build->errorString())); } } m_deviceBuildTasks.remove(udn); }
void HDataRetriever::timerEvent(QTimerEvent* event) { HLOG2(H_AT, H_FUN, m_loggingIdentifier); HLOG_WARN(QString("Request timed out.")); quit(); killTimer(event->timerId()); m_success = false; }
bool HControlPointPrivate::addRootDevice(HDefaultClientDevice* newRootDevice) { HLOG2(H_AT, H_FUN, m_loggingIdentifier); Q_ASSERT(thread() == QThread::currentThread()); HDefaultClientDevice* existingDevice = static_cast<HDefaultClientDevice*>( m_deviceStorage.searchDeviceByUdn( newRootDevice->info().udn(), AllDevices)); if (existingDevice) { // it seems that the device we've built has already been added // (it is possible, although unlikely, we begin multiple device build // processes of the same device tree) // in this case we only make sure that the device's location list is // updated if necessary existingDevice = static_cast<HDefaultClientDevice*>(existingDevice->rootDevice()); existingDevice->addLocations(newRootDevice->locations()); return false; } if (q_ptr->acceptRootDevice(newRootDevice) == HControlPoint::IgnoreDevice) { HLOG_DBG(QString("Device [%1] rejected").arg( newRootDevice->info().udn().toString())); return false; } newRootDevice->setParent(this); newRootDevice->startStatusNotifier(HDefaultClientDevice::All); bool ok = connect( newRootDevice, SIGNAL(statusTimeout(HDefaultClientDevice*)), this, SLOT(deviceExpired(HDefaultClientDevice*))); Q_ASSERT(ok); Q_UNUSED(ok) if (!m_deviceStorage.addRootDevice(newRootDevice)) { HLOG_WARN(QString( "Failed to add root device [UDN: %1]: %2").arg( newRootDevice->info().udn().toSimpleUuid(), m_deviceStorage.lastError())); return false; } emit q_ptr->rootDeviceOnline(newRootDevice); return true; }
bool HDeviceInfoPrivate::setSerialNumber(const QString& serialNumber) { HLOG(H_AT, H_FUN); if (serialNumber.size() > 64) { HLOG_WARN(QString( "serialNumber [%1] longer than 64 characters: [%1]").arg(serialNumber)); } m_serialNumber = serialNumber; return true; }
bool HDeviceInfoPrivate::setModelNumber(const QString& modelNumber) { HLOG(H_AT, H_FUN); if (modelNumber.size() > 32) { HLOG_WARN(QString( "modelNumber [%1] longer than 32 characters: [%1]").arg(modelNumber)); } m_modelNumber = modelNumber; return true; }
bool HDeviceInfoPrivate::setModelDescription(const QString& modelDescription) { HLOG(H_AT, H_FUN); if (modelDescription.size() > 128) { HLOG_WARN(QString( "modelDescription [%1] longer than 64 characters").arg(modelDescription)); } m_modelDescription = modelDescription; return true; }
bool HDeviceInfoPrivate::setManufacturer(const QString& manufacturer) { HLOG(H_AT, H_FUN); if (manufacturer.isEmpty()) { return false; } if (manufacturer.size() > 64) { HLOG_WARN(QString( "manufacturer [%1] longer than 64 characters").arg(manufacturer)); } m_manufacturer = manufacturer; return true; }
bool HDeviceInfoPrivate::setFriendlyName(const QString& friendlyName) { HLOG(H_AT, H_FUN); if (friendlyName.isEmpty()) { return false; } if (friendlyName.size() > 64) { HLOG_WARN(QString( "friendlyName [%1] longer than 64 characters").arg(friendlyName)); } m_friendlyName = friendlyName; return true; }
bool HDeviceInfoPrivate::setModelName(const QString& modelName) { HLOG(H_AT, H_FUN); if (modelName.isEmpty()) { return false; } if (modelName.size() > 32) { HLOG_WARN(QString( "modelName [%1] longer than 32 characters: [%1]").arg(modelName)); } m_modelName = modelName; return true; }
HCdsObjectData* HCdsFileSystemReaderPrivate::indexFile( const QFileInfo& file, const QString& parentId) { HLOG(H_AT, H_FUN); QString sufx = file.suffix().toLower(); MimeAndItemCreator creator = creatorFunctions[sufx]; if (!creator.second) { HLOG_WARN(QString("File type [%1] is not supported.").arg(sufx)); return 0; } HItem* item = creator.second(file, parentId); Q_ASSERT(item); item->setContentFormat(creator.first); return new HCdsObjectData(item, file.absoluteFilePath()); }
void HDeviceHostHttpServer::incomingControlRequest( HMessagingInfo* mi, const HInvokeActionRequest& invokeActionRequest) { HLOG2(H_AT, H_FUN, m_loggingIdentifier); HLOG_DBG(QString("Control message to [%1] received.").arg( invokeActionRequest.soapAction())); QUuid udn = extractUdn(invokeActionRequest.serviceUrl()); HServerDevice* device = !udn.isNull() ? m_deviceStorage.searchDeviceByUdn(HUdn(udn), AllDevices) : 0; HServerService* service = 0; if (!device) { // the request did not have the UDN prefix, which means that either // 1) the request was for a ControlURL that was defined as an absolute URL // in the device description or // 2) the request is invalid service = m_deviceStorage.searchServiceByControlUrl( invokeActionRequest.serviceUrl()); if (!service) { HLOG_WARN(QString( "Ignoring invalid action invocation to: [%1].").arg( invokeActionRequest.serviceUrl().toString())); mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse( BadRequest, *mi)); return; } } else if (!service) { service = m_deviceStorage.searchServiceByControlUrl( device, extractRequestExludingUdn(invokeActionRequest.serviceUrl())); } if (!service) { HLOG_WARN(QString("Ignoring invalid action invocation to: [%1].").arg( invokeActionRequest.serviceUrl().toString())); mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse( BadRequest, *mi)); return; } const QtSoapMessage* soapMsg = invokeActionRequest.soapMsg(); const QtSoapType& method = soapMsg->method(); if (!method.isValid()) { HLOG_WARN("Invalid control method."); mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse( BadRequest, *mi)); return; } HServerAction* action = service->actions().value(method.name().name()); if (!action) { HLOG_WARN(QString("The service has no action named [%1].").arg( method.name().name())); mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse( *mi, UpnpInvalidArgs, soapMsg->toXmlString())); return; } HActionArguments iargs = action->info().inputArguments(); HActionArguments::iterator it = iargs.begin(); for(; it != iargs.end(); ++it) { HActionArgument iarg = *it; const QtSoapType& arg = method[iarg.name()]; if (!arg.isValid()) { mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse( *mi, UpnpInvalidArgs, soapMsg->toXmlString())); return; } if (!iarg.setValue( HUpnpDataTypes::convertToRightVariantType( arg.value().toString(), iarg.dataType()))) { mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse( *mi, UpnpInvalidArgs, soapMsg->toXmlString())); return; } } HActionArguments outArgs = action->info().outputArguments(); qint32 retVal = action->invoke(iargs, &outArgs); if (retVal != UpnpSuccess) { mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse( *mi, retVal, soapMsg->toXmlString())); return; } QtSoapNamespaces::instance().registerNamespace( "u", service->info().serviceType().toString()); QtSoapMessage soapResponse; soapResponse.setMethod(QtSoapQName( QString("%1%2").arg(action->info().name(), "Response"), service->info().serviceType().toString())); foreach(const HActionArgument& oarg, outArgs) { QtSoapType* soapArg = new SoapType(oarg.name(), oarg.dataType(), oarg.value()); soapResponse.addMethodArgument(soapArg); }
void HDeviceHostHttpServer::incomingSubscriptionRequest( HMessagingInfo* mi, const HSubscribeRequest& sreq) { HLOG2(H_AT, H_FUN, m_loggingIdentifier); HLOG_DBG("Subscription received."); QUuid udn = extractUdn(sreq.eventUrl()); HServerDevice* device = !udn.isNull() ? m_deviceStorage.searchDeviceByUdn(HUdn(udn), AllDevices) : 0; HServerService* service = 0; if (!device) { // the request did not have the UDN prefix, which means that either // 1) the request was for a EventUrl that was defined as an absolute URL // in the device description or // 2) the request is invalid service = m_deviceStorage.searchServiceByEventUrl(sreq.eventUrl()); if (!service) { HLOG_WARN(QString( "Ignoring invalid event subscription to: [%1].").arg( sreq.eventUrl().toString())); mi->setKeepAlive(false); m_httpHandler->send( mi, HHttpMessageCreator::createResponse(BadRequest, *mi)); return; } } else if (!service) { service = m_deviceStorage.searchServiceByEventUrl( device, extractRequestExludingUdn(sreq.eventUrl())); } if (!service) { HLOG_WARN(QString("Subscription defined as [%1] is invalid.").arg( sreq.eventUrl().path())); mi->setKeepAlive(false); m_httpHandler->send( mi, HHttpMessageCreator::createResponse(BadRequest, *mi)); return; } // The UDA v1.1 does not specify what to do when a subscription is received // to a service that is not evented. A "safe" route was taken here and // all subscriptions are accepted rather than returning some error. However, // in such a case the timeout is adjusted to a day and no events are ever sent. HSid sid; StatusCode sc; if (sreq.isRenewal()) { sc = m_eventNotifier.renewSubscription(sreq, &sid); } else { sc = m_eventNotifier.addSubscriber(service, sreq, &sid); } if (sc != Ok) { mi->setKeepAlive(false); m_httpHandler->send(mi, HHttpMessageCreator::createResponse(sc, *mi)); return; } HServiceEventSubscriber* subscriber = m_eventNotifier.remoteClient(sid); HSubscribeResponse response( subscriber->sid(), HSysInfo::instance().herqqProductTokens(), subscriber->timeout()); HHttpAsyncOperation* op = m_httpHandler->send(mi, HHttpMessageCreator::create(response, *mi)); if (op) { HOpInfo opInfo(service, sreq, subscriber); m_ops.append(qMakePair(QPointer<HHttpAsyncOperation>(op), opInfo)); } }
qint32 HTransportSinkService::getStateVariables( quint32 instanceId, const QSet<QString>& stateVariableNames, QString* stateVariableValuePairs) { HLOG2(H_AT, H_FUN, h_ptr->m_loggingIdentifier); Q_ASSERT(stateVariableValuePairs); HRendererConnection* mediaConnection = m_owner->findConnectionByAvTransportId(instanceId); if (!mediaConnection) { return HAvTransportInfo::InvalidInstanceId; } QString retVal; QXmlStreamWriter writer(&retVal); writer.setCodec("UTF-8"); writer.writeStartDocument(); writer.writeStartElement("stateVariableValuePairs"); writer.writeDefaultNamespace("urn:schemas-upnp-org:av:avs"); writer.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.writeAttribute("xsi:schemaLocation", "urn:schemas-upnp-org:av:avs " \ "http://www.upnp.org/schemas/av/avs.xsd"); QSet<QString> stateVarNames; if (stateVariableNames.contains("*")) { stateVarNames = HAvTransportInfo::stateVariablesSetupData().names(); QSet<QString>::iterator it = stateVarNames.begin(); for(; it != stateVarNames.end();) { if (it->startsWith("A_ARG") || *it == "LastChange") { it = stateVarNames.erase(it); } else { ++it; } } } else { stateVarNames = stateVariableNames; } foreach(QString svName, stateVarNames) { svName = svName.trimmed(); if (svName.compare("LastChange", Qt::CaseInsensitive) == 0 || svName.startsWith("A_ARG", Qt::CaseInsensitive)) { return HAvTransportInfo::InvalidStateVariableList; } bool ok = false; QString value = mediaConnection->info()->value(svName, &ok); if (ok) { writer.writeStartElement("stateVariable"); writer.writeAttribute("variableName", svName); writer.writeCharacters(value); writer.writeEndElement(); } else { HLOG_WARN(QString("Could not get the value of state variable [%1]").arg(svName)); return HAvTransportInfo::InvalidStateVariableList; } }
int flush_work(gpointer data){ int ret = 0; CACHE_CTRL *cctrl = (CACHE_CTRL*)data; GTimeVal expired; char *tmp_buf = (char *)g_malloc0(cctrl->block_size \ *cctrl->flush_once_size); g_assert(tmp_buf); while (!cctrl->flush_worker_should_exit) { HLOG_DEBUG("-- flush worker doing --"); g_get_current_time(&expired); g_time_val_add(&expired, cctrl->flush_interval * 1000 * 1000); g_mutex_lock(cctrl->cache_mutex); gboolean res = g_cond_timed_wait(cctrl->flush_waken_cond, \ cctrl->cache_mutex, &expired); g_mutex_unlock(cctrl->cache_mutex); HLOG_DEBUG(" time wait res for cond is :%d !",res); if (cctrl->flush_worker_should_exit) { HLOG_INFO("-- flush worker should exit --"); break; } do { GSList *continue_blocks = NULL; ret = get_continues_blocks(cctrl, &continue_blocks); g_assert(ret==0); uint32_t blocks_count = g_slist_length(continue_blocks); uint32_t buff_len = blocks_count *cctrl->block_size; HLOG_DEBUG("--blocks_count:%d, buff_len:%d--", \ blocks_count, buff_len); if (res == TRUE && buff_len == 0) { HLOG_ERROR("Never reach here"); g_assert(0); } if (buff_len == 0) { HLOG_DEBUG("do not need flush now"); break; } if (NULL == cctrl->write_callback_func) { HLOG_WARN("--not given flush callback func--"); break; } //char* tmp_buf = g_malloc0(buff_len); //g_assert(tmp_buf!=NULL); uint32_t start_no; uint32_t end_no; int i = 0; for (i = 0; i < blocks_count; i++) { block_t *block = g_slist_nth_data(continue_blocks, i); if (i == 0) { start_no = block->block_no; } if (i == blocks_count-1) { end_no = block->block_no; } memcpy(tmp_buf + i * cctrl->block_size, \ block->block, cctrl->block_size); } //HLOG_DEBUG("--tmp_buf:%p",tmp_buf); ret = cctrl->write_callback_func(cctrl->write_callback_user_param, \ tmp_buf, start_no,end_no); g_assert(ret >= 0); //g_free(tmp_buf); if (ret >= 0 ) { HLOG_DEBUG("--signal write thread--"); g_mutex_lock(cctrl->cache_mutex); __free_from_cache(cctrl, continue_blocks); //g_cond_broadcast(cctrl->writer_waken_cond); g_cond_signal(cctrl->writer_waken_cond); g_mutex_unlock(cctrl->cache_mutex); g_slist_free(continue_blocks); //HLOG_DEBUG("--return blocks to cache over--"); } } while (get_cache_free_size(cctrl) < cctrl->flush_trigger_level \ *cctrl->cache_size / 100 || (res == 0 && get_cache_free_size(cctrl) != 0)); } g_free(tmp_buf); HLOG_INFO("--flush worker exit--"); return 0; }
bool parse(const QString& arg, HValidityCheckLevel checkLevel) { HLOG(H_AT, H_FUN); QString tmp(arg.simplified()); HUdn udn; qint32 indx = tmp.indexOf("::"); if (indx == 41) // the length of "uuid:UUID" is 41 { udn = HUdn(tmp.left(41)); if (!udn.isValid(checkLevel)) { return false; } if (tmp.size() > 43) { tmp = tmp.mid(43); } else { m_udn = udn; m_type = HDiscoveryType::SpecificDevice; m_contents = udn.toString(); return true; } } QStringList parsed = tmp.split(':'); if (parsed.size() < 2) { HLOG_WARN(QString("Invalid resource identifier: %1").arg(arg)); return false; } if (!udn.isValid(checkLevel)) { if (parsed[0] == "ssdp" && parsed[1] == "all") { m_type = HDiscoveryType::All; m_contents = "ssdp:all"; return true; } } if (parsed[0] == "upnp" && parsed[1] == "rootdevice") { m_udn = udn; if (m_udn.isValid(checkLevel)) { m_type = HDiscoveryType::SpecificRootDevice; m_contents = QString("%1::upnp:rootdevice").arg(udn.toString()); } else { m_type = HDiscoveryType::RootDevices; m_contents = "upnp:rootdevice"; } return true; } else if (parsed[0] == "uuid") { udn = HUdn(parsed[1]); if (udn.isValid(checkLevel)) { m_udn = udn; m_type = HDiscoveryType::SpecificDevice; m_contents = udn.toString(); return true; } } HResourceType resourceType(tmp); if (parse(resourceType)) { m_udn = udn; if (m_udn.isValid(checkLevel)) { m_type = resourceType.isDeviceType() ? HDiscoveryType::SpecificDeviceWithType : HDiscoveryType::SpecificServiceWithType; m_contents = QString("%1::%2").arg( udn.toString(), resourceType.toString()); } else { m_type = resourceType.isDeviceType() ? HDiscoveryType::DeviceType : HDiscoveryType::ServiceType; m_contents = QString("%1").arg(resourceType.toString()); } return true; } HLOG_WARN(QString("Invalid resource identifier: %1").arg(arg)); return false; }