예제 #1
0
void SuiteMsearch::Test()
{
    DviDevice* device = new DviDeviceStandard(iDvStack, gNameDevice1);
    iDevices[0] = device;
    device->SetAttribute("Upnp.Domain", "upnp.org");
    device->SetAttribute("Upnp.Type", "test1");
    device->SetAttribute("Upnp.Version", "1");
    AddService(device, new DviService(iDvStack, "upnp.org", "service1", 1));
    AddService(device, new DviService(iDvStack, "openhome.org", "service2", 3));
    AddService(device, new DviService(iDvStack, "upnp.org", "service3", 1));
    DviService* service = new DviService(iDvStack, "upnp.org", "service1", 1);
    TEST_THROWS(device->AddService(service), AssertionFailed);
    service->RemoveRef();
    device->SetEnabled();
    service = new DviService(iDvStack, "upnp.org", "service4", 1);
    TEST_THROWS(device->AddService(service), AssertionFailed);
    service->RemoveRef();

    device = new DviDeviceStandard(iDvStack, gNameDevice2);
    iDevices[1] = device;
    device->SetAttribute("Upnp.Domain", "openhome.org");
    device->SetAttribute("Upnp.Type", "test2");
    device->SetAttribute("Upnp.Version", "2");
    AddService(device, new DviService(iDvStack, "openhome.org", "service4", 2));
    AddService(device, new DviService(iDvStack, "openhome.org", "service5", 1));

    device = new DviDeviceStandard(iDvStack, gNameDevice2Embedded1);
    iDevices[1]->AddDevice(device);
    device->SetAttribute("Upnp.Domain", "openhome.org");
    device->SetAttribute("Upnp.Type", "test3");
    device->SetAttribute("Upnp.Version", "1");
    AddService(device, new DviService(iDvStack, "upnp.org", "service1", 1));
    AddService(device, new DviService(iDvStack, "openhome.org", "service6", 1));
    AddService(device, new DviService(iDvStack, "openhome.org", "service2", 3));
    service = new DviService(iDvStack, "openhome.org", "service5", 1);
    TEST_THROWS(device->AddService(service), AssertionFailed);
    service->RemoveRef();
    iDevices[1]->SetEnabled();
    device->SetEnabled();
    device = new DviDeviceStandard(iDvStack, kNameDummy);
    TEST_THROWS(iDevices[1]->AddDevice(device), AssertionFailed);
    device->Destroy();
    //Wait(); // allow time for initial annoucements to be delivered

    TestMsearchAll();
    TestMsearchRoot();
    TestMsearchUuid();
    TestMsearchDeviceType();
    TestMsearchServiceType();
}
예제 #2
0
TUint CpiDeviceDv::Subscribe(CpiSubscription& aSubscription, const OpenHome::Uri& /*aSubscriber*/)
{
    Brh sid;
    iDeviceDv.CreateSid(sid);
    Brn tmp(sid);
    Brh transfer(tmp);
    aSubscription.SetSid(transfer);
    TUint durationSecs = iDeviceCp->GetCpStack().Env().InitParams()->SubscriptionDurationSecs();
    DviSubscription* subscriptionDv = new DviSubscription(iDeviceDv.GetDvStack(), iDeviceDv, *this, NULL, sid);
    subscriptionDv->AddRef(); // guard against subscription expiring before client tries to renew or unsubscribe
    iDeviceDv.GetDvStack().SubscriptionManager().AddSubscription(*subscriptionDv);
    subscriptionDv->SetDuration(durationSecs);

    iLock.Wait();
    if (iSubscriptions.size() == 0) {
        iShutdownSem.Wait(); // consume shutdown signal now the map is non-empty
    }
    Brn sid2(subscriptionDv->Sid());
    Subscription* subscription = new Subscription(aSubscription, subscriptionDv);
    iSubscriptions.insert(std::pair<Brn,Subscription*>(sid2, subscription));
    iDeviceCp->AddRef();
    iLock.Signal();

    DviService* service = iDeviceDv.ServiceReference(aSubscription.ServiceType());
    ASSERT(service != NULL);
    service->AddSubscription(subscriptionDv);
    service->RemoveRef();

    return durationSecs;
}
예제 #3
0
void DviSubscription::Remove()
{
    iLock.Wait();
    DviService* service = iService;
    if (service != NULL) {
        service->AddRef();
    }
    iLock.Signal();
    if (service != NULL) {
        service->RemoveSubscription(iSid);
        service->RemoveRef();
    }
}
예제 #4
0
void CpiDeviceDv::InvokeAction(Invocation& aInvocation)
{
    const OpenHome::Net::ServiceType& serviceType = aInvocation.ServiceType();
    DviService* service = iDeviceDv.ServiceReference(serviceType);
    if (service == NULL) {
        const HttpStatus& err = HttpStatus::kNotFound;
        aInvocation.SetError(Error::eUpnp, err.Code(), err.Reason());
    }
    else {
        InvocationDv stream(aInvocation, *service);
        stream.Start();
        service->RemoveRef();
    }
    aInvocation.SignalCompleted();
}
예제 #5
0
void CpiDeviceDv::Invocable::InvokeAction(Invocation& aInvocation)
{
    const OpenHome::Net::ServiceType& serviceType = aInvocation.ServiceType();
    DviService* service = iDevice.iDeviceDv.ServiceReference(serviceType);
    if (service == NULL) {
        LOG2(kCpDeviceDv, kError, "CpiDeviceDv::Invocable::InvokeAction failed lookup for service %.*s:%.*s:%u\n",
                                  PBUF(serviceType.Domain()), PBUF(serviceType.Name()), serviceType.Version());
        const HttpStatus& err = HttpStatus::kNotFound;
        aInvocation.SetError(Error::eUpnp, err.Code(), err.Reason());
    }
    else {
        InvocationDv stream(aInvocation, *service);
        stream.Start();
        service->RemoveRef();
    }
}
예제 #6
0
void CpiDeviceDv::Unsubscribe(CpiSubscription& aSubscription, const Brx& aSid)
{
    iLock.Wait();
    Brn sid(aSid);
    SubscriptionMap::iterator it = iSubscriptions.find(sid);
    if (it == iSubscriptions.end()) {
        iLock.Signal();
        return;
    }
    Subscription* subscription = it->second;
    iLock.Signal();
    DviService* service = iDeviceDv.ServiceReference(aSubscription.ServiceType());
    if (service != NULL) {
        service->RemoveSubscription(aSid);
        service->RemoveRef();
    }
    subscription->iCp = NULL;
    subscription->iDv->RemoveRef();
    // can't safely access subscription now - RemoveRef() above may have resulted in it being deleted
}