Пример #1
0
InvocationManager::InvocationManager(CpStack& aCpStack)
    : Thread("InvocationManager")
    , iCpStack(aCpStack)
    , iLock("INVM")
    , iFreeInvocations(aCpStack.Env().InitParams()->NumInvocations())
    , iWaitingInvocations(aCpStack.Env().InitParams()->NumInvocations())
    , iFreeInvokers(aCpStack.Env().InitParams()->NumActionInvokerThreads())
{
    TUint i;
    iInvokers = (Invoker**)malloc(sizeof(*iInvokers) * iCpStack.Env().InitParams()->NumActionInvokerThreads());
    for (i=0; i<iCpStack.Env().InitParams()->NumActionInvokerThreads(); i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("ActionInvoker %d", i);
        thName.PtrZ();
        iInvokers[i] = new Invoker((const TChar*)thName.Ptr(), iFreeInvokers);
        iFreeInvokers.Write(iInvokers[i]);
        iInvokers[i]->Start();
    }

    for (i=0; i<iCpStack.Env().InitParams()->NumInvocations(); i++) {
        iFreeInvocations.Write(new OpenHome::Net::Invocation(iCpStack, iFreeInvocations));
    }
    iActive = true;
    Start();
}
Пример #2
0
CpiDeviceListUpnp::CpiDeviceListUpnp(CpStack& aCpStack, FunctorCpiDevice aAdded, FunctorCpiDevice aRemoved)
    : CpiDeviceList(aCpStack, aAdded, aRemoved)
    , iSsdpLock("DLSM")
    , iEnv(aCpStack.Env())
    , iStarted(false)
    , iNoRemovalsFromRefresh(false)
{
    NetworkAdapterList& ifList = aCpStack.Env().NetworkAdapterList();
    AutoNetworkAdapterRef ref(iEnv, "CpiDeviceListUpnp ctor");
    const NetworkAdapter* current = ref.Adapter();
    iRefreshTimer = new Timer(iEnv, MakeFunctor(*this, &CpiDeviceListUpnp::RefreshTimerComplete), "DeviceListRefresh");
    iResumedTimer = new Timer(iEnv, MakeFunctor(*this, &CpiDeviceListUpnp::ResumedTimerComplete), "DeviceListResume");
    iRefreshRepeatCount = 0;
    iInterfaceChangeListenerId = ifList.AddCurrentChangeListener(MakeFunctor(*this, &CpiDeviceListUpnp::CurrentNetworkAdapterChanged));
    iSubnetListChangeListenerId = ifList.AddSubnetListChangeListener(MakeFunctor(*this, &CpiDeviceListUpnp::SubnetListChanged));
    iSsdpLock.Wait();
    if (current == NULL) {
        iInterface = 0;
        iUnicastListener = NULL;
        iMulticastListener = NULL;
        iNotifyHandlerId = 0;
    }
    else {
        iInterface = current->Address();
        iUnicastListener = new SsdpListenerUnicast(iCpStack.Env(), *this, iInterface);
        iMulticastListener = &(iCpStack.Env().MulticastListenerClaim(iInterface));
        iNotifyHandlerId = iMulticastListener->AddNotifyHandler(this);
    }
    iSsdpLock.Signal();
    iCpStack.Env().AddResumeObserver(*this);
}
Пример #3
0
EventServerUpnp::EventServerUpnp(CpStack& aCpStack, TIpAddress aInterface)
    : iTcpServer(aCpStack.Env(), "EventServer", aCpStack.Env().InitParams()->CpUpnpEventServerPort(), aInterface)
{
    const TUint numThread = aCpStack.Env().InitParams()->NumEventSessionThreads();
    for (TUint i=0; i<numThread; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("EventSession %d", i);
        thName.PtrZ();
        iTcpServer.Add((const TChar*)thName.Ptr(), new EventSessionUpnp(aCpStack));
    }
}
Пример #4
0
EventServerUpnp::EventServerUpnp(CpStack& aCpStack, TIpAddress aInterface)
    : iTcpServer(aCpStack.Env(), "EventServer", aCpStack.Env().InitParams()->CpUpnpEventServerPort(), aInterface)
{
    const TUint numThread = aCpStack.Env().InitParams()->NumEventSessionThreads();
#ifndef _WIN32
    // nothing terribly bad would happen if this assertion failed so its not worth a separate Windows implementation
    ASSERT(numThread < 10);
#endif
    for (TUint i=0; i<numThread; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("EventSession %d", i);
        thName.PtrZ();
        iTcpServer.Add((const TChar*)thName.Ptr(), new EventSessionUpnp(aCpStack));
    }
}
Пример #5
0
InvocationUpnp::InvocationUpnp(CpStack& aCpStack, Invocation& aInvocation)
    : iCpStack(aCpStack)
    , iInvocation(aInvocation)
    , iReadBuffer(iSocket)
    , iReaderResponse(aCpStack.Env(), iReadBuffer)
{
}
Пример #6
0
void TestSubscription(CpStack& aCpStack)
{
    gSubscriptionCount = 0; // reset this here in case we're run multiple times via TestShell
    Debug::SetLevel(Debug::kNone);
    Environment& env = aCpStack.Env();
    DeviceList* deviceList = new DeviceList(env);
    FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &DeviceList::Added);
    FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &DeviceList::Removed);
    const Brn domainName("upnp.org");
    const Brn serviceType("ConnectionManager");
#if 1
    const TUint ver = 1;
    CpDeviceListUpnpServiceType* list =
                new CpDeviceListUpnpServiceType(aCpStack, domainName, serviceType, ver, added, removed);
#else
    const Brn uuid("896659847466-a4badbeaacbc-737837");
    CpDeviceListUpnpUuid* list = new CpDeviceListUpnpUuid(aCpStack, uuid, added, removed);
#endif
    Blocker* blocker = new Blocker(env);
    blocker->Wait(env.InitParams().MsearchTimeSecs());
    delete blocker;
    deviceList->Stop();

    TUint startTime = Os::TimeInMs(env.OsCtx());
    deviceList->Poll();

    const TUint count = deviceList->Count();
    Print("\n%u subscriptions on %u devices (avg %u) in %u seconds\n",
                        gSubscriptionCount, count, (count==0? 0 : gSubscriptionCount/count), (Os::TimeInMs(env.OsCtx())-startTime+500)/1000);

    delete list;
    delete deviceList;
}
Пример #7
0
void OpenHome::TestFramework::Runner::Main(TInt /*aArgc*/, TChar* /*aArgv*/[], Net::InitialisationParams* aInitParams)
{
    Library* lib = new Library(aInitParams);
    std::vector<NetworkAdapter*>* subnetList = lib->CreateSubnetList();
    TIpAddress subnet = (*subnetList)[0]->Subnet();
    TIpAddress addr = (*subnetList)[0]->Address();
    Endpoint endpt(0, addr);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("Connect to %s:%u then 'help' for options\n\n", buf.Ptr(), Shell::kServerPortDefault);
    Library::DestroySubnetList(subnetList);
    CpStack* cpStack = NULL;
    DvStack* dvStack = NULL;
    lib->StartCombined(subnet, cpStack, dvStack);

    Shell* shell = new Shell(cpStack->Env());
    Semaphore* blocker = new Semaphore("BLCK", 0);

    std::vector<ShellTest> shellTests;
    shellTests.push_back(ShellTest("TestBuffer", RunTestBuffer));
    shellTests.push_back(ShellTest("TestThread", RunTestThread));
    shellTests.push_back(ShellTest("TestFifo", RunTestFifo));
    shellTests.push_back(ShellTest("TestQueue", RunTestQueue));
    shellTests.push_back(ShellTest("TestTextUtils", RunTestTextUtils));
    shellTests.push_back(ShellTest("TestNetwork", RunTestNetwork, true));
    shellTests.push_back(ShellTest("TestTimer", RunTestTimer));
    shellTests.push_back(ShellTest("TestSsdpMListen", RunTestSsdpMListen, true));
    shellTests.push_back(ShellTest("TestSsdpUListen", RunTestSsdpUListen, true));
    shellTests.push_back(ShellTest("TestDeviceList", RunTestDeviceList, true));
    shellTests.push_back(ShellTest("TestInvocation", RunTestInvocation));
    shellTests.push_back(ShellTest("TestSubscription", RunTestSubscription));
    shellTests.push_back(ShellTest("TestCpDeviceDv", RunTestCpDeviceDv));
    shellTests.push_back(ShellTest("TestDviDiscovery", RunTestDviDiscovery));
    shellTests.push_back(ShellTest("TestDviDeviceList", RunTestDviDeviceList));
    shellTests.push_back(ShellTest("TestDvInvocation", RunTestDvInvocation));
    shellTests.push_back(ShellTest("TestDvSubscription", RunTestDvSubscription));
    shellTests.push_back(ShellTest("TestDvLpec", RunTestDvLpec));
    shellTests.push_back(ShellTest("TestException", RunTestException));
    shellTests.push_back(ShellTest("TestFunctorGeneric", RunTestFunctorGeneric));
    shellTests.push_back(ShellTest("TestXmlParser", RunTestXmlParser));

    ShellCommandRun* cmdRun = new ShellCommandRun(*cpStack, *dvStack, *shell, shellTests);
    ShellCommandDebug* cmdDebug = new ShellCommandDebug(*shell);
    ShellCommandQuit* cmdQuit = new ShellCommandQuit(*shell, *blocker);
    ShellCommandWatchDog* cmdWatchDog = new ShellCommandWatchDog(*shell, 60); // default to 60s watchdog. This can be changed at runtime by client.
    blocker->Wait();
    // control never reaches here
    delete blocker;
    delete cmdWatchDog;
    delete cmdQuit;
    delete cmdDebug;
    delete cmdRun;
    delete shell;
    delete lib;
}
Пример #8
0
CpiSubscriptionManager::CpiSubscriptionManager(CpStack& aCpStack)
    : Thread("SBSM")
    , iCpStack(aCpStack)
    , iLock("SBSL")
    , iFree(aCpStack.Env().InitParams().NumSubscriberThreads())
    , iWaiter("SBSS", 0)
    , iWaiters(0)
    , iShutdownSem("SBMS", 0)
{
    NetworkAdapterList& ifList = iCpStack.Env().NetworkAdapterList();
    AutoNetworkAdapterRef ref(aCpStack.Env(), "CpiSubscriptionManager ctor");
    const NetworkAdapter* currentInterface = ref.Adapter();
    Functor functor = MakeFunctor(*this, &CpiSubscriptionManager::CurrentNetworkAdapterChanged);
    iInterfaceListListenerId = ifList.AddCurrentChangeListener(functor);
    functor = MakeFunctor(*this, &CpiSubscriptionManager::SubnetListChanged);
    iSubnetListenerId = ifList.AddSubnetListChangeListener(functor);
    if (currentInterface == NULL) {
        iEventServer = NULL;
    }
    else {
        iLock.Wait();
        iEventServer = new EventServerUpnp(iCpStack, currentInterface->Address());
        iLock.Signal();
    }

    TChar thName[5] = "SBS ";
#ifndef _WIN32
    ASSERT(iCpStack.Env().InitParams().NumSubscriberThreads() <= 9);
#endif
    const TUint numThreads = iCpStack.Env().InitParams().NumSubscriberThreads();
    iSubscribers = (Subscriber**)malloc(sizeof(*iSubscribers) * numThreads);
    for (TUint i=0; i<numThreads; i++) {
        thName[3] = (TChar)('0'+i);
        iSubscribers[i] = new Subscriber(&thName[0], iFree);
        iFree.Write(iSubscribers[i]);
        iSubscribers[i]->Start();
    }

    iActive = true;
    Start();
}
Пример #9
0
InvocationManager::InvocationManager(CpStack& aCpStack)
    : Thread("INVM")
    , iCpStack(aCpStack)
    , iLock("INVM")
    , iFreeInvocations(aCpStack.Env().InitParams()->NumInvocations())
    , iWaitingInvocations(aCpStack.Env().InitParams()->NumInvocations())
    , iFreeInvokers(aCpStack.Env().InitParams()->NumActionInvokerThreads())
{
    TUint i;
    TChar thName[5] = "IN  ";
    iInvokers = (Invoker**)malloc(sizeof(*iInvokers) * iCpStack.Env().InitParams()->NumActionInvokerThreads());
    for (i=0; i<iCpStack.Env().InitParams()->NumActionInvokerThreads(); i++) {
        thName[3] = (TChar)('0'+i);
        iInvokers[i] = new Invoker(&thName[0], iFreeInvokers);
        iFreeInvokers.Write(iInvokers[i]);
        iInvokers[i]->Start();
    }

    for (i=0; i<iCpStack.Env().InitParams()->NumInvocations(); i++) {
        iFreeInvocations.Write(new OpenHome::Net::Invocation(iCpStack, iFreeInvocations));
    }
    iActive = true;
    Start();
}
Пример #10
0
EventSessionUpnp::EventSessionUpnp(CpStack& aCpStack)
    : iCpStack(aCpStack)
    , iShutdownSem("EVSD", 1)
{
    iReadBuffer = new Srs<1024>(*this);
    iReaderUntil = new ReaderUntilS<1024>(*iReadBuffer);
    iDechunker = new ReaderHttpChunked(*iReaderUntil);
    iReaderRequest = new ReaderHttpRequest(aCpStack.Env(), *iReaderUntil);

    iReaderRequest->AddMethod(kMethodNotify);
    iReaderRequest->AddHeader(iHeaderNt);
    iReaderRequest->AddHeader(iHeaderNts);
    iReaderRequest->AddHeader(iHeaderSid);
    iReaderRequest->AddHeader(iHeaderSeq);
    iReaderRequest->AddHeader(iHeaderContentLength);
    iReaderRequest->AddHeader(iHeaderTransferEncoding);
}
Пример #11
0
CpiDeviceUpnp::CpiDeviceUpnp(CpStack& aCpStack, const Brx& aUdn, const Brx& aLocation, TUint aMaxAgeSecs, IDeviceRemover& aDeviceList, CpiDeviceListUpnp& aList)
    : iLock("CDUP")
    , iLocation(aLocation)
    , iXmlFetch(NULL)
    , iDeviceXmlDocument(NULL)
    , iDeviceXml(NULL)
    , iExpiryTime(0)
    , iDeviceList(aDeviceList)
    , iList(&aList)
    , iSemReady("CDUS", 0)
    , iRemoved(false)
{
    iDevice = new CpiDevice(aCpStack, aUdn, *this, *this, this);
    iTimer = new Timer(aCpStack.Env(), MakeFunctor(*this, &CpiDeviceUpnp::TimerExpired));
    UpdateMaxAge(aMaxAgeSecs);
    iInvocable = new Invocable(*this);
}
Пример #12
0
CpiDeviceUpnp::CpiDeviceUpnp(CpStack& aCpStack, const Brx& aUdn, const Brx& aLocation, TUint aMaxAgeSecs, IDeviceRemover& aDeviceList, CpiDeviceListUpnp& aList)
    : iLock("CDUP")
    , iLocation(aLocation)
    , iXmlFetch(NULL)
    , iDeviceXmlDocument(NULL)
    , iDeviceXml(NULL)
    , iExpiryTime(0)
    , iDeviceList(aDeviceList)
    , iList(&aList)
    , iSemReady("CDUS", 0)
    , iRemoved(false)
    , iNewLocation(NULL)
    , iXmlCheck(NULL)
{
    Environment& env = aCpStack.Env();
    iHostUdpIsLowQuality = env.InitParams()->IsHostUdpLowQuality();
    iDevice = new CpiDevice(aCpStack, aUdn, *this, *this, this);
    iTimer = new Timer(env, MakeFunctor(*this, &CpiDeviceUpnp::TimerExpired), "CpiDeviceUpnp");
    UpdateMaxAge(aMaxAgeSecs);
    iInvocable = new Invocable(*this);
}
Пример #13
0
void TestInvocation(CpStack& aCpStack)
{
    gActionCount = 0; // reset this here in case we're run multiple times via TestShell
    Environment& env = aCpStack.Env();
    FunctorAsync dummy;
    /* Set an empty handler for errors to avoid test output being swamped by expected
       errors from invocations we interrupt at the end of each device's 1s timeslice */
    env.InitParams()->SetAsyncErrorHandler(dummy);

    Debug::SetLevel(Debug::kNone);
    DeviceListTI* deviceList = new DeviceListTI(env);
    FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &DeviceListTI::Added);
    FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &DeviceListTI::Removed);
    const Brn domainName("upnp.org");
    const Brn serviceType("ConnectionManager");
#if 1
    const TUint ver = 1;
    CpDeviceListUpnpServiceType* list =
                new CpDeviceListUpnpServiceType(aCpStack, domainName, serviceType, ver, added, removed);
#else
    const Brn uuid("7076436f-6e65-1063-8074-000da201f542");
    CpDeviceListUpnpUuid* list = new CpDeviceListUpnpUuid(aCpStack, uuid, added, removed);
#endif
    Blocker* blocker = new Blocker(env);
    blocker->Wait(env.InitParams()->MsearchTimeSecs());
    delete blocker;
    deviceList->Stop();

    TUint startTime = Os::TimeInMs(env.OsCtx());
    //deviceList->TestSync();
    deviceList->Poll();

    const TUint count = deviceList->Count();
    Print("\n%u actions invoked on %u devices (avg %u) in %u seconds\n",
                        gActionCount, count, (count==0? 0 : gActionCount/count), (Os::TimeInMs(env.OsCtx())-startTime+500)/1000);

    delete list;
    delete deviceList;
}
Пример #14
0
static void RunTestSsdpUListen(CpStack& aCpStack, DvStack& /*aDvStack*/, const std::vector<Brn>& aArgs) { TestSsdpUListen(aCpStack.Env(), aArgs); }
Пример #15
0
static void RunTestTimer(CpStack& aCpStack, DvStack& /*aDvStack*/, const std::vector<Brn>& /*aArgs*/) { TestTimer(aCpStack.Env()); }
Пример #16
0
void TestDeviceList(CpStack& aCpStack, const std::vector<Brn>& aArgs)
{
    OptionParser parser;
    OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over");
    parser.AddOption(&mx);
    OptionBool all("-a", "--all", "Search for all devices and services");
    parser.AddOption(&all);
    OptionBool root("-r", "--root", "Search for root devices only");
    parser.AddOption(&root);
    Brn emptyString("");
    OptionString uuid("-u", "--uuid", emptyString, "[uuid string] search for a particular device");
    parser.AddOption(&uuid);
    OptionString urn("-t", "--urn", emptyString, "Search for a device or service of the form [domain:[device|service]:type:ver]");
    parser.AddOption(&urn);
    OptionBool refresh("-f", "--refresh", "Wait mx secs then refresh list");
    parser.AddOption(&refresh);
    if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
        return;
    }
//    Debug::SetLevel(Debug::kDevice);
    DeviceListLogger logger;
    CpDeviceList* deviceList = NULL;
    FunctorCpDevice added = MakeFunctorCpDevice(logger, &DeviceListLogger::Added);
    FunctorCpDevice removed = MakeFunctorCpDevice(logger, &DeviceListLogger::Removed);
    if (all.Value()) {
        deviceList = new CpDeviceListUpnpAll(aCpStack, added, removed);
    }
    else if (root.Value()) {
        Print("Search root...\n");
        deviceList = new CpDeviceListUpnpRoot(aCpStack, added, removed);
    }
    else if (uuid.Value().Bytes() > 0) {
        Print("Search uuid...\n");
        deviceList = new CpDeviceListUpnpUuid(aCpStack, uuid.Value(), added, removed);
    }
    else if (urn.Value().Bytes() > 0) {
        Print("Search device/service...\n");
        Brn domainName;
        Brn type;
        TUint ver;
        if (OpenHome::Net::Ssdp::ParseUrnDevice(urn.Value(), domainName, type, ver)) {
            deviceList = new CpDeviceListUpnpDeviceType(aCpStack, domainName, type, ver, added, removed);
        }
        else if (OpenHome::Net::Ssdp::ParseUrnService(urn.Value(), domainName, type, ver)) {
            deviceList = new CpDeviceListUpnpServiceType(aCpStack, domainName, type, ver, added, removed);
        }
        else {
            parser.DisplayHelp();
        }
    }
    else {
        parser.DisplayHelp();
    }

    Environment& env = aCpStack.Env();
    Blocker* blocker = new Blocker(env);
    if (deviceList != NULL) {
        blocker->Wait(env.InitParams()->MsearchTimeSecs());
    }
    if (refresh.Value()) {
        Print("\nRefreshing...\n\n");
        deviceList->Refresh();
        blocker->Wait(env.InitParams()->MsearchTimeSecs());
    }
    delete blocker;
    delete deviceList;
}