Exemplo n.º 1
0
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();
}
Exemplo n.º 2
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();
}
Exemplo n.º 3
0
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();
}
Exemplo n.º 4
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();
    }
}
Exemplo n.º 5
0
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();
}
Exemplo n.º 6
0
void OutputProcessorDv::ProcessBinary(const Brx& aBuffer, Brh& aVal)
{
    Bwh tmp(aVal.Bytes() + aBuffer.Bytes());
    tmp.Append(aVal);
    tmp.Append(aBuffer);
    tmp.TransferTo(aVal);
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
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();
    }
}
Exemplo n.º 10
0
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 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();
}
Exemplo n.º 12
0
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();
}
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();
}
Exemplo n.º 14
0
static void TestSubscription(CpDevice& aDevice)
{
    Semaphore sem("TSEM", 0);
    Print("  Subscriptions\n");
    CpProxyOpenhomeOrgTestBasic1* proxy = new CpProxyOpenhomeOrgTestBasic1(aDevice);
    Functor functor = MakeFunctor(&sem, updatesComplete);
    proxy->SetPropertyChanged(functor);
    proxy->Subscribe();
    sem.Wait(); // wait for initial event

    /* For each property,
         call the setter action it
         wait on a property being updated
         check that the property matches the value set
         check that the getter action matches the property
    */

    Print("    Uint...\n");
    proxy->SyncSetUint(1);
    sem.Wait();
    TUint propUint;
    proxy->PropertyVarUint(propUint);
    ASSERT(propUint == 1);
    TUint valUint;
    proxy->SyncGetUint(valUint);
    ASSERT(propUint == valUint);

    Print("    Int...\n");
    proxy->SyncSetInt(-99);
    sem.Wait();
    TInt propInt;
    proxy->PropertyVarInt(propInt);
    ASSERT(propInt == -99);
    TInt valInt;
    proxy->SyncGetInt(valInt);
    ASSERT(propInt == valInt);

    Print("    Bool...\n");
    proxy->SyncSetBool(true);
    sem.Wait();
    TBool propBool;
    proxy->PropertyVarBool(propBool);
    ASSERT(propBool);
    TBool valBool;
    proxy->SyncGetBool(valBool);
    ASSERT(valBool);

    Print("    String...\n");
    Brn str("<&'tag\">");
    proxy->SyncSetString(str);
    sem.Wait();
    Brhz propStr;
    proxy->PropertyVarStr(propStr);
    ASSERT(propStr == str);
    // test again to check that PropertyVarStr didn't TransferTo the property
    proxy->PropertyVarStr(propStr);
    ASSERT(propStr == str);
    Brh valStr;
    proxy->SyncGetString(valStr);
    ASSERT(propStr == valStr);
    // change str, check evented update doesn't aggregate previous and new values
    Brn str2(str.Ptr(), str.Bytes()/2);
    proxy->SyncSetString(str2);
    sem.Wait();
    Brhz propStr2;
    proxy->PropertyVarStr(propStr2);
    ASSERT(propStr2 == str2);
    ASSERT(propStr2.Bytes() == propStr.Bytes()/2);

    Print("    Binary...\n");
    char bin[256];
    for (TUint i=0; i<256; i++) {
        bin[i] = (char)i;
    }
    Brn bufBin((const TByte*)&bin[0], 256);
    proxy->SyncSetBinary(bufBin);
    sem.Wait();
    Brh propBin;
    proxy->PropertyVarBin(propBin);
    ASSERT(propBin == bufBin);
    // test again to check that PropertyVarBin didn't TransferTo the property
    proxy->PropertyVarBin(propBin);
    ASSERT(propBin == bufBin);
    Brh valBin;
    proxy->SyncGetBinary(valBin);
    ASSERT(propBin == valBin);
    // change bufBin, check evented update doesn't aggregate previous and new values
    Brn bufBin2(bufBin.Ptr(), bufBin.Bytes()/2);
    proxy->SyncSetBinary(bufBin2);
    sem.Wait();
    Brh propBin2;
    proxy->PropertyVarBin(propBin2);
    ASSERT(propBin2 == bufBin2);
    ASSERT(propBin2.Bytes() == propBin.Bytes()/2);

    Print("    Multiple...\n");
    proxy->SyncSetMultiple(15, 658, false);
    sem.Wait();
    proxy->PropertyVarUint(propUint);
    ASSERT(propUint == 15);
    proxy->SyncGetUint(valUint);
    ASSERT(propUint == valUint);
    proxy->PropertyVarInt(propInt);
    ASSERT(propInt == 658);
    proxy->SyncGetInt(valInt);
    ASSERT(propInt == valInt);
    proxy->PropertyVarBool(propBool);
    ASSERT(!propBool);
    proxy->SyncGetBool(valBool);
    ASSERT(!valBool);

    delete proxy; // automatically unsubscribes
}