int32_t STDCALL DvProviderAvOpenhomeOrgRadio1SetPropertyIdArray(THandle aProvider, const char* aValue, uint32_t aValueLen, uint32_t* aChanged) { Brh buf; buf.Set((const TByte*)aValue, aValueLen); *aChanged = (reinterpret_cast<DvProviderAvOpenhomeOrgRadio1C*>(aProvider)->SetPropertyIdArray(buf)? 1 : 0); return 0; }
void DeviceListTI::GetProtocolInfoComplete(IAsync& aAsync) { if (Os::TimeInMs(iEnv.OsCtx()) > iStopTimeMs) { return; } FunctorAsync callback = MakeFunctorAsync(*this, &DeviceListTI::GetProtocolInfoComplete); iConnMgr->BeginGetProtocolInfo(callback); Brh source; Brh sink; iConnMgr->EndGetProtocolInfo(aAsync, source, sink); // throws if invocation failed iLock.Wait(); gActionCount++; if (sink.Bytes() == 0) { ASSERT(iExpectedSink.Bytes() == 0); } else { if (iExpectedSink.Bytes() == 0) { sink.TransferTo(iExpectedSink); } else { //ASSERT(sink == iExpectedSink); // can't use the above assertion. aVia Media Renderer sometimes responds with two copies of its supported protocols } } iLock.Signal(); }
void DvProviderAvOpenhomeOrgRadio1C::DoIdArray(IDviInvocation& aInvocation) { DvInvocationCPrivate invocationWrapper(aInvocation); IDvInvocationC* invocationC; void* invocationCPtr; invocationWrapper.GetInvocationC(&invocationC, &invocationCPtr); aInvocation.InvocationReadStart(); aInvocation.InvocationReadEnd(); DviInvocation invocation(aInvocation); uint32_t Token; char* Array; uint32_t ArrayLen; ASSERT(iCallbackIdArray != NULL); if (0 != iCallbackIdArray(iPtrIdArray, invocationC, invocationCPtr, &Token, &Array, &ArrayLen)) { invocation.Error(502, Brn("Action failed")); return; } DviInvocationResponseUint respToken(aInvocation, "Token"); DviInvocationResponseBinary respArray(aInvocation, "Array"); invocation.StartResponse(); respToken.Write(Token); Brh bufArray; bufArray.Set((const TByte*)Array, ArrayLen); OhNetFreeExternal(Array); respArray.Write(bufArray); respArray.WriteFlush(); invocation.EndResponse(); }
void STDCALL DvProviderAvOpenhomeOrgRadio1GetPropertyIdArray(THandle aProvider, char** aValue, uint32_t* aValueLen) { Brh buf; reinterpret_cast<DvProviderAvOpenhomeOrgRadio1C*>(aProvider)->GetPropertyIdArray(buf); *aValueLen = buf.Bytes(); *aValue = (char*)buf.Extract(); }
void DeviceListTI::GetProtocolInfoComplete(IAsync& aAsync) { if (Os::TimeInMs() > iStopTimeMs) { return; } FunctorAsync callback = MakeFunctorAsync(*this, &DeviceListTI::GetProtocolInfoComplete); iConnMgr->BeginGetProtocolInfo(callback); Brh source; Brh sink; iConnMgr->EndGetProtocolInfo(aAsync, source, sink); // throws if invocation failed iLock.Wait(); gActionCount++; if (sink.Bytes() == 0) { ASSERT(iExpectedSink.Bytes() == 0); } else { if (iExpectedSink.Bytes() == 0) { sink.TransferTo(iExpectedSink); } else { ASSERT(sink == iExpectedSink); } } iLock.Signal(); }
static void TestInvocation(CpDevice& aDevice) { static const TUint kTestIterations = 10; Print(" Actions\n"); CpProxyOpenhomeOrgTestBasic1* proxy = new CpProxyOpenhomeOrgTestBasic1(aDevice); TUint i; Print(" Unsigned integer arguments...\n"); TUint valUint = 15; for (i=0; i<kTestIterations; i++) { TUint result; proxy->SyncIncrement(valUint, result); ASSERT(result == valUint+1); valUint = result; } Print(" Integer arguments...\n"); TInt valInt = 3; for (i=0; i<kTestIterations; i++) { TInt result; proxy->SyncDecrement(valInt, result); ASSERT(result == valInt-1); valInt = result; } Print(" Boolean arguments...\n"); TBool valBool = true; for (i=0; i<kTestIterations; i++) { TBool result; proxy->SyncToggle(valBool, result); ASSERT(result == !valBool); valBool = result; } Print(" String arguments...\n"); Brn valStr("<&'tag\">"); for (i=0; i<kTestIterations; i++) { Brh result; proxy->SyncEchoString(valStr, result); ASSERT(result == valStr); } Print(" Binary arguments...\n"); char bin[256]; for (i=0; i<256; i++) { bin[i] = (char)i; } Brn valBin((const TByte*)&bin[0], 256); for (i=0; i<kTestIterations; i++) { Brh result; proxy->SyncEchoBinary(valBin, result); ASSERT(result == valBin); ASSERT(result.Bytes() == 256); } delete proxy; }
void CpiSubscription::DoSubscribe() { CpStack& cpStack = iDevice.GetCpStack(); Bws<Uri::kMaxUriBytes> uri; uri.Append(Http::kSchemeHttp); NetworkAdapter* nif = cpStack.Env().NetworkAdapterList().CurrentAdapter("CpiSubscription::DoSubscribe"); if (nif == NULL) { THROW(NetworkError); } TIpAddress nifAddr = nif->Address(); nif->RemoveRef("CpiSubscription::DoSubscribe"); Endpoint endpt(cpStack.SubscriptionManager().EventServerPort(), nifAddr); Endpoint::EndpointBuf buf; endpt.AppendEndpoint(buf); uri.Append(buf); uri.Append('/'); Uri subscriber(uri); LOG(kEvent, "Subscribing - service = "); LOG(kEvent, iServiceType.FullName()); LOG(kEvent, "\n subscriber = "); LOG(kEvent, subscriber.AbsoluteUri()); LOG(kEvent, "\n"); iNextSequenceNumber = 0; TUint renewSecs; try { renewSecs = iDevice.Subscribe(*this, subscriber); } catch (XmlError&) { // we don't expect to ever get here. Its worth capturing some debug info if we do. Brh deviceXml; if (!iDevice.GetAttribute("Upnp.DeviceXml", deviceXml)) { deviceXml.Set("[missing]"); } const Brx& udn = iDevice.Udn(); cpStack.Env().Mutex().Wait(); Log::Print("XmlError attempting to subscribe to device "); Log::Print(udn); Log::Print(", with xml\n\n"); Log::Print(deviceXml); Log::Print("\n\n"); cpStack.Env().Mutex().Signal(); THROW(XmlError); } cpStack.SubscriptionManager().Add(*this); LOG(kEvent, "Subscription for "); LOG(kEvent, iServiceType.FullName()); LOG(kEvent, " completed\n Sid is "); LOG(kEvent, iSid); LOG(kEvent, "\n Renew in %u secs\n", renewSecs); SetRenewTimer(renewSecs); }
void DviProtocolUpnpServiceXmlWriter::Write(const DviService& aService, const DviProtocolUpnp& aDevice, IResourceWriter& aResourceWriter) { WriterBwh writer(1024); WriteServiceXml(writer, aService, aDevice); Brh xml; writer.TransferTo(xml); aResourceWriter.WriteResourceBegin(xml.Bytes(), kOhNetMimeTypeXml); aResourceWriter.WriteResource(xml.Ptr(), xml.Bytes()); aResourceWriter.WriteResourceEnd(); }
TBool CpDeviceCpp::GetAttribute(const char* aKey, std::string& aValue) const { Brh val; aValue.erase(aValue.begin(), aValue.end()); if (iDevice.GetAttribute(aKey, val)) { aValue.append((const char*)val.Ptr(), val.Bytes()); return true; } return false; }
uint32_t STDCALL ServicePropertySetValueBinary(ServiceProperty aProperty, uint8_t* aValue, uint32_t aLen) { PropertyBinary* prop = reinterpret_cast<PropertyBinary*>(aProperty); ASSERT(prop != NULL); Brh data; data.Set(aValue, aLen); if (prop->SetValue(data)) { return 1; } return 0; }
char* STDCALL DvDeviceStandardResourceManagerUri(DvDeviceC aDevice, THandle aAdapter) { Brh uri; NetworkAdapter* nif = (NetworkAdapter*)aAdapter; ASSERT(nif != NULL); reinterpret_cast<DvDeviceStandard*>(DviDeviceC::DeviceFromHandle(aDevice))->GetResourceManagerUri(*nif, uri); if (uri.Bytes() == 0) { return NULL; } else { Brhz uriz(uri); return (char*)uriz.Transfer(); } }
TBool CpiDeviceUpnp::GetAttribute(const char* aKey, Brh& aValue) const { Brn key(aKey); Parser parser(key); if (parser.Next('.') == Brn("Upnp")) { Brn property = parser.Remaining(); if (property == Brn("Location")) { aValue.Set(iLocation); return (true); } if (property == Brn("DeviceXml")) { aValue.Set(iXml); return (true); } const DeviceXml* device = iDeviceXml; if (parser.Next('.') == Brn("Root")) { device = &iDeviceXmlDocument->Root(); property.Set(parser.Remaining()); } try { if (property == Brn("FriendlyName")) { device->GetFriendlyName(aValue); return (true); } if (property == Brn("PresentationUrl")) { device->GetPresentationUrl(aValue); return (true); } Parser parser(property); Brn token = parser.Next('.'); if (token == Brn("Service")) { aValue.Set(device->ServiceVersion(parser.Remaining())); return (true); } } catch (XmlError&) { } } return (false); }
int32_t DvInvocationReadBinary(DvInvocationC aInvocation, const char* aName, uint8_t** aData, uint32_t* aLen) { IDviInvocation* invocation = InvocationFromHandle(aInvocation); try { Brh value; invocation->InvocationReadBinary(aName, value); *aLen = value.Bytes(); *aData = (uint8_t*)value.Extract(); } catch (InvocationError&) { return -1; } return 0; }
void STDCALL DvDeviceStandardGetResourceManagerUri(DvDeviceC aDevice, THandle aAdapter, char** aUri, uint32_t* aLen) { Brh uri; NetworkAdapter* nif = (NetworkAdapter*)aAdapter; ASSERT(nif != NULL); reinterpret_cast<DvDeviceStandard*>(DviDeviceC::DeviceFromHandle(aDevice))->GetResourceManagerUri(*nif, uri); if (uri.Bytes() == 0) { *aUri = NULL; *aLen = 0; } else { *aLen = uri.Bytes(); *aUri = (char*)uri.Extract(); } }
void CpDevices::WaitForDeviceDiscovery() { (void)iAddedSem.Clear(); iAddedSem.Wait(30*1000); // allow up to 30 seconds to issue the msearch and receive a response // check that we not only have a device but that its at a different location from previously ASSERT(iDevices.size() == 1); CpDevice* device = iDevices[0]; Brh locationBuf; ASSERT(device->GetAttribute("Upnp.Location", locationBuf)); const TChar* location = locationBuf.Extract(); if (iLocation != NULL) { ASSERT(strcmp(location, iLocation) != 0); } iLocation = location; }
void DvProviderAvOpenhomeOrgCredentials1C::DoGet(IDviInvocation& aInvocation) { DvInvocationCPrivate invocationWrapper(aInvocation); IDvInvocationC* invocationC; void* invocationCPtr; invocationWrapper.GetInvocationC(&invocationC, &invocationCPtr); aInvocation.InvocationReadStart(); Brhz Id; aInvocation.InvocationReadString("Id", Id); aInvocation.InvocationReadEnd(); DviInvocation invocation(aInvocation); char* UserName; char* Password; uint32_t PasswordLen; uint32_t Enabled; char* Status; char* Data; ASSERT(iCallbackGet != NULL); if (0 != iCallbackGet(iPtrGet, invocationC, invocationCPtr, (const char*)Id.Ptr(), &UserName, &Password, &PasswordLen, &Enabled, &Status, &Data)) { invocation.Error(502, Brn("Action failed")); return; } DviInvocationResponseString respUserName(aInvocation, "UserName"); DviInvocationResponseBinary respPassword(aInvocation, "Password"); DviInvocationResponseBool respEnabled(aInvocation, "Enabled"); DviInvocationResponseString respStatus(aInvocation, "Status"); DviInvocationResponseString respData(aInvocation, "Data"); invocation.StartResponse(); Brhz bufUserName((const TChar*)UserName); OhNetFreeExternal(UserName); respUserName.Write(bufUserName); respUserName.WriteFlush(); Brh bufPassword; bufPassword.Set((const TByte*)Password, PasswordLen); OhNetFreeExternal(Password); respPassword.Write(bufPassword); respPassword.WriteFlush(); respEnabled.Write((Enabled!=0)); Brhz bufStatus((const TChar*)Status); OhNetFreeExternal(Status); respStatus.Write(bufStatus); respStatus.WriteFlush(); Brhz bufData((const TChar*)Data); OhNetFreeExternal(Data); respData.Write(bufData); respData.WriteFlush(); invocation.EndResponse(); }
void CpiSubscription::SetSid(Brh& aSid) { Mutex& lock = iDevice.GetCpStack().Env().Mutex(); lock.Wait(); aSid.TransferTo(iSid); lock.Signal(); }
void CpProxyAvOpenhomeOrgRadio1::PropertyIdArray(Brh& aIdArray) const { PropertyReadLock(); ASSERT(iCpSubscriptionStatus == CpProxy::eSubscribed); aIdArray.Set(iIdArray->Value()); PropertyReadUnlock(); }
void OutputProcessorDv::ProcessBinary(const Brx& aBuffer, Brh& aVal) { Bwh tmp(aVal.Bytes() + aBuffer.Bytes()); tmp.Append(aVal); tmp.Append(aBuffer); tmp.TransferTo(aVal); }
void CpProxyOpenhomeOrgTestBasic1::PropertyVarBin(Brh& aVarBin) const { AutoMutex a(iCpProxy.PropertyReadLock()); if (iCpProxy.GetSubscriptionStatus() != CpProxy::eSubscribed) { THROW(ProxyNotSubscribed); } aVarBin.Set(iVarBin->Value()); }
void ControlPointProxy::CPUpnpAv::upnpAvPause() { Brh state; Brh dummy; if (iIsActive) { iUpnpAvProxy->SyncGetTransportInfo(0, state, dummy, dummy); string stateStr(state.Extract()); if (canPause(stateStr)) { iUpnpAvProxy->SyncPause(0); } } }
TBool CpiDeviceDv::GetAttribute(const char* aKey, Brh& aValue) const { const TChar* value = NULL; iDeviceDv.GetAttribute(aKey, &value); if (value != NULL) { aValue.Set(value); } return false; }
void ControlPointProxy::CPUpnpAv::pipelineChangedEvent() { Brh state; Brh dummy; TUint mediaOptions = 0; // Ignore this notification if we are not the active source. if (! iIsActive) { return; } // Read the new transport state. try { iUpnpAvProxy->SyncGetTransportInfo(0, state, dummy, dummy); } catch (ProxyError& /*aPe*/) { return; } // Figure out the available playback options from the transport state. string stateStr(state.Extract()); if (canPlay(stateStr)) { mediaOptions |= MEDIAPLAYER_PLAY_OPTION; } if (canStop(stateStr)) { mediaOptions |= MEDIAPLAYER_STOP_OPTION; } if (canPause(stateStr)) { mediaOptions |= MEDIAPLAYER_PAUSE_OPTION; } // Adjust the UI accordingly. PostMessage(iHwnd, WM_APP_PLAYBACK_OPTIONS, NULL, (LPARAM)mediaOptions); }
void DviProviderSubscriptionLongPoll::GetPropertyUpdates(IDvInvocation& aInvocation, const Brx& aClientId, IDvInvocationResponseString& aUpdates) { StartGetPropertyUpdates(aInvocation); AutoGetPropertyUpdatesComplete a(*this); Semaphore sem("PSLP", 0); UpdateReadySignal* updateReadySignal = NULL; Brh response; try { iPropertyUpdateCollection.SetClientSignal(aClientId, &sem); iLock.Wait(); for (TUint i=0; i<iMaxClientCount; i++) { if (iUpdateReady[i].IsFree()) { updateReadySignal = &iUpdateReady[i]; updateReadySignal->Set(sem); break; } } ASSERT(updateReadySignal != NULL); iLock.Signal(); sem.Wait(kGetUpdatesMaxDelay); iPropertyUpdateCollection.SetClientSignal(aClientId, NULL); if (!iExit) { WriterBwh writer(1024); iPropertyUpdateCollection.WriteUpdates(aClientId, writer); writer.TransferTo(response); } } catch (Timeout&) { iPropertyUpdateCollection.SetClientSignal(aClientId, NULL); } iLock.Wait(); updateReadySignal->Clear(); iLock.Signal(); aInvocation.StartResponse(); if (response.Bytes() > 0) { aUpdates.Write(response); } aUpdates.WriteFlush(); aInvocation.EndResponse(); }
void DvProviderLinnCoUkCloud1C::DoSetAssociated(IDviInvocation& aInvocation) { DvInvocationCPrivate invocationWrapper(aInvocation); IDvInvocationC* invocationC; void* invocationCPtr; invocationWrapper.GetInvocationC(&invocationC, &invocationCPtr); aInvocation.InvocationReadStart(); Brh AesKeyRsaEncrypted; aInvocation.InvocationReadBinary("AesKeyRsaEncrypted", AesKeyRsaEncrypted); Brh InitVectorRsaEncrypted; aInvocation.InvocationReadBinary("InitVectorRsaEncrypted", InitVectorRsaEncrypted); Brh TokenAesEncrypted; aInvocation.InvocationReadBinary("TokenAesEncrypted", TokenAesEncrypted); TBool Associated = aInvocation.InvocationReadBool("Associated"); aInvocation.InvocationReadEnd(); DviInvocation invocation(aInvocation); ASSERT(iCallbackSetAssociated != NULL); if (0 != iCallbackSetAssociated(iPtrSetAssociated, invocationC, invocationCPtr, (const char*)AesKeyRsaEncrypted.Ptr(), AesKeyRsaEncrypted.Bytes(), (const char*)InitVectorRsaEncrypted.Ptr(), InitVectorRsaEncrypted.Bytes(), (const char*)TokenAesEncrypted.Ptr(), TokenAesEncrypted.Bytes(), Associated)) { invocation.Error(502, Brn("Action failed")); return; } invocation.StartResponse(); invocation.EndResponse(); }
DviSubscription::DviSubscription(DvStack& aDvStack, DviDevice& aDevice, IPropertyWriterFactory& aWriterFactory, IDviSubscriptionUserData* aUserData, Brh& aSid, TUint& aDurationSecs) : iDvStack(aDvStack) , iLock("MDSB") , iRefCount(1) , iDevice(aDevice) , iWriterFactory(aWriterFactory) , iUserData(aUserData) , iService(NULL) , iSequenceNumber(0) { iDevice.AddWeakRef(); aSid.TransferTo(iSid); iWriterFactory.NotifySubscriptionCreated(iSid); Functor functor = MakeFunctor(*this, &DviSubscription::Expired); iTimer = new Timer(iDvStack.Env(), functor); DoRenew(aDurationSecs); iDvStack.Env().AddObject(this); }
void DvProviderAvOpenhomeOrgCredentials1C::DoSet(IDviInvocation& aInvocation) { DvInvocationCPrivate invocationWrapper(aInvocation); IDvInvocationC* invocationC; void* invocationCPtr; invocationWrapper.GetInvocationC(&invocationC, &invocationCPtr); aInvocation.InvocationReadStart(); Brhz Id; aInvocation.InvocationReadString("Id", Id); Brhz UserName; aInvocation.InvocationReadString("UserName", UserName); Brh Password; aInvocation.InvocationReadBinary("Password", Password); aInvocation.InvocationReadEnd(); DviInvocation invocation(aInvocation); ASSERT(iCallbackSet != NULL); if (0 != iCallbackSet(iPtrSet, invocationC, invocationCPtr, (const char*)Id.Ptr(), (const char*)UserName.Ptr(), (const char*)Password.Ptr(), Password.Bytes())) { invocation.Error(502, Brn("Action failed")); return; } invocation.StartResponse(); invocation.EndResponse(); }
void DeviceListTI::Poll() { Timer timer(iEnv, MakeFunctor(*this, &DeviceListTI::TimerExpired)); FunctorAsync callback = MakeFunctorAsync(*this, &DeviceListTI::GetProtocolInfoComplete); Brh tmp; const TUint count = (TUint)iList.size(); for (TUint i=0; i<count; i++) { CpDevice* device = iList[i]; TUint countBefore = gActionCount; Print("Device "); Print(device->Udn()); iConnMgr = new CpProxyUpnpOrgConnectionManager1(*device); iStopTimeMs = Os::TimeInMs(iEnv.OsCtx()) + kDevicePollMs; timer.FireIn(kDevicePollMs); for (TUint j=0; j<iEnv.InitParams()->NumActionInvokerThreads(); j++) { iConnMgr->BeginGetProtocolInfo(callback); } iPollStop.Wait(); Print(" %u\n", gActionCount - countBefore); delete iConnMgr; iExpectedSink.TransferTo(tmp); } }
void DvProviderAvOpenhomeOrgRadio1C::GetPropertyIdArray(Brh& aValue) { ASSERT(iPropertyIdArray != NULL); aValue.Set(iPropertyIdArray->Value()); }
void InvocationDv::InvocationReadBinary(const TChar* aName, Brh& aData) { ArgumentBinary* arg = static_cast<ArgumentBinary*>(InputArgument(aName)); aData.Set(arg->Value()); }