Ejemplo n.º 1
0
void Http::WriteHeaderRange(WriterHttpHeader& aWriter, TUint64 aFirst, TUint64 aLast)
{
    Bws<6+20+1+20> buf;
    buf.Append(Http::kRangeBytes);
    Ascii::AppendDec(buf, aFirst);
    buf.Append(Http::kRangeSeparator);
    Ascii::AppendDec(buf, aLast);

    aWriter.WriteHeader(Http::kHeaderRange, buf);
}
Ejemplo n.º 2
0
    void SourcesCallback(MockCbData<ITopology2Source*>* aArgs)
    {
        // w("Source " + v.Index + " " + v.Name + " " + v.Type + " " + v.Visible));
        ITopology2Source* src = aArgs->iData;
        FunctorGeneric<const Brx&> f = aArgs->iCallback;

        Bws<100> buf;
        buf.Replace(Brn("Source "));
        Ascii::AppendDec(buf, src->Index());
        buf.Append(Brn(" "));

        Brn name(src->Name());

        buf.Append(src->Name());
        buf.Append(Brn(" "));
        buf.Append(src->Type());
        buf.Append(Brn(" "));
        if (src->Visible())
        {
            buf.Append(Brn("True"));
        }
        else
        {
            buf.Append(Brn("False"));
        }
        f(buf);
        delete aArgs;
    }
Ejemplo n.º 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));
    }
}
Ejemplo n.º 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));
    }
}
Ejemplo n.º 5
0
void OpenHome::UnhandledExceptionHandler(Exception& aException)
{
    Bws<5> thName;
    GetThreadName(thName);
    char buf[1024];
    (void)snprintf(buf, sizeof(buf), "Unhandled exception %s at %s:%lu in thread %s\n", aException.Message(), aException.File(), (unsigned long)aException.Line(), thName.Ptr());

    TInt len = 8*1024;
    char* msg = new char[len];
    if (msg != NULL) {
        (void)strncpy(msg, buf, len);
        len -= (TInt)strlen(buf);
        (void)strncat(msg, "\n", len);
        len -= 2;

        THandle stackTrace = aException.StackTrace();
        TUint count = Os::StackTraceNumEntries(stackTrace);
        for (TUint i=0; i<count; i++) {
            const char* entry = Os::StackTraceEntry(stackTrace, i);
            (void)strncat(msg, entry, len);
            len -= (TInt)strlen(entry) + 2;
            if (len < 0) {
                break;
            }
            (void)strncat(msg, "\n", len);
        }
    }
    if (len > 0) {
        (void)strncat(msg, "\n", len);
    }

    CallFatalErrorHandler((msg!=NULL? msg : buf));
    delete msg;
}
Ejemplo n.º 6
0
SocketTcpServer* DviServerLpec::CreateServer(const NetworkAdapter& aNif)
{
    SocketTcpServer* server = new SocketTcpServer(iDvStack.Env(), "LpecServer", iPort, aNif.Address());
    const TUint numThreads = iDvStack.Env().InitParams()->DvNumLpecThreads();
    AdapterData* ad = new AdapterData(aNif.Address());
    iAdapterData.push_back(ad);
    for (TUint i=0; i<numThreads; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("LpecSession %d", i);
        thName.PtrZ();
        DviSessionLpec* session = new DviSessionLpec(iDvStack, aNif.Address(), iPort);
        server->Add((const TChar*)thName.Ptr(), session);
        ad->iSessions.push_back(session);
    }
    return server;
}
Ejemplo n.º 7
0
void XmlFetch::Output(IAsyncOutput& aConsole)
{
    Mutex& lock = iCpStack.Env().Mutex();
    lock.Wait();
    Bws<Ascii::kMaxUintStringBytes+1> buf;
    (void)Ascii::AppendDec(buf, iSequenceNumber);
    buf.PtrZ();
    aConsole.Output("SequenceNumber", (const TChar*)buf.Ptr());
    Bws<Uri::kMaxUriBytes+1> uri(iUri->AbsoluteUri());
    uri.PtrZ();
    aConsole.Output("XmlFetch", (const TChar*)uri.Ptr());
    if (Error()) {
        iError.Output(aConsole);
    }
    lock.Signal();
}
Ejemplo n.º 8
0
void LogMsg(const char *format, ...)
{
#ifdef DEFINE_TRACE
    va_list args;
    va_start(args, format);
    // not all messages are errors but enough are that its handy to log everything here if we're interested in errors
    if(Debug::TestLevel(Debug::kBonjour) || Debug::TestLevel(Debug::kError)) {
        Bws<kMaxLogMsgBytes> msg;
        TUint written = mDNS_vsnprintf((char*)msg.Ptr(), msg.MaxBytes(), format, args);
        msg.SetBytes(written);
        Log::Print(msg);
        Log::Print("\n");
    }
    va_end(args);
#endif
}
Ejemplo n.º 9
0
void OpenHome::UnhandledExceptionHandler(const TChar* aExceptionMessage, const TChar* aFile, TUint aLine)
{
    Bws<5> thName;
    GetThreadName(thName);
    char buf[1024];
    (void)snprintf(buf, sizeof(buf), "Unhandled exception %s at %s:%lu in thread %s\n", aExceptionMessage, aFile, (unsigned long)aLine, thName.Ptr());
    CallFatalErrorHandler(buf);
}
Ejemplo n.º 10
0
void OpenHome::UnhandledExceptionHandler(std::exception& aException)
{
    Bws<5> thName;
    GetThreadName(thName);
    char buf[1024];
    (void)snprintf(buf, sizeof(buf), "Unhandled exception %s in thread %s\n", aException.what(), thName.Ptr());
    CallFatalErrorHandler(buf);
}
Ejemplo n.º 11
0
 void StandbyCallback(MockCbData<TBool>* aArgs)
 {
     TBool i = aArgs->iData;
     FunctorGeneric<const Brx&> f = aArgs->iCallback;
     Bws<100> buf;
     buf.Replace(Brn("Standby "));
     if (i)
     {
         buf.Append(Brn("True"));
     }
     else
     {
         buf.Append(Brn("False"));
     }
     f(buf);
     delete aArgs;
 }
Ejemplo n.º 12
0
DviSubscriptionManager::DviSubscriptionManager(DvStack& aDvStack)
    : Thread("DvSubscriptionMgr")
    , iDvStack(aDvStack)
    , iLock("DSBM")
    , iFree(aDvStack.Env().InitParams()->DvNumPublisherThreads())
{
    const TUint numPublisherThreads = iDvStack.Env().InitParams()->DvNumPublisherThreads();
    LOG(kDvEvent, "> DviSubscriptionManager: creating %u publisher threads\n", numPublisherThreads);
    iPublishers = (Publisher**)malloc(sizeof(*iPublishers) * numPublisherThreads);
    for (TUint i=0; i<numPublisherThreads; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("Publisher %d", i);
        thName.PtrZ();
        iPublishers[i] = new Publisher((const TChar*)thName.Ptr(), iFree);
        iFree.Write(iPublishers[i]);
        iPublishers[i]->Start();
    }
    Start();
}
Ejemplo n.º 13
0
TChar* CpListenerMsearch::CreateTypeString(const Brx& aDomain, const Brx& aType, TUint aVersion)
{
    TChar* type = (TChar*)malloc(aDomain.Bytes() + aType.Bytes() + 2 + Ascii::kMaxUintStringBytes + 1);
    TChar* ptr = type;
    (void)strncpy(ptr, (const TChar*)aDomain.Ptr(), aDomain.Bytes());
    ptr += aDomain.Bytes();
    *ptr = ':';
    ptr++;
    (void)strncpy(ptr, (const TChar*)aType.Ptr(), aType.Bytes());
    ptr += aType.Bytes();
    *ptr = ':';
    ptr++;
    Bws<Ascii::kMaxUintStringBytes> ver;
    Ascii::AppendDec(ver, aVersion);
    (void)strncpy(ptr, (const TChar*)ver.Ptr(), ver.Bytes());
    ptr += ver.Bytes();
    *ptr = '\0';
    return type;
}
Ejemplo n.º 14
0
TUint Ascii::AppendDec(Bwx& aBuffer, TUint64 aValue)
{
    Bws<20> reversed; // Maximum value requires 20 digits

    if (aValue == 0) {
        aBuffer.Append('0');
        return (1);
    }

    while(aValue > 0) {
        reversed.Append((TChar)('0' + aValue % 10));
        aValue = aValue / 10;
    }

    for (TUint i = reversed.Bytes(); i > 0; i--) {
        aBuffer.Append(reversed[i - 1]);
    }

    return (reversed.Bytes());
}
Ejemplo n.º 15
0
XmlFetchManager::XmlFetchManager(CpStack& aCpStack)
    : Thread("XmlFetchManager")
    , iCpStack(aCpStack)
    , iLock("FETL")
    , iFree(iCpStack.Env().InitParams()->NumXmlFetcherThreads())
{
    const TUint numThreads = iCpStack.Env().InitParams()->NumXmlFetcherThreads();
    iFetchers = (XmlFetcher**)malloc(sizeof(*iFetchers) * numThreads);
    for (TUint i=0; i<numThreads; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("XmlFetcher %d", i);
        thName.PtrZ();
        iFetchers[i] = new XmlFetcher((const TChar*)thName.Ptr(), iFree);
        iFree.Write(iFetchers[i]);
        iFetchers[i]->Start();
    }

    iActive = true;
    Start();
}
Ejemplo n.º 16
0
void CpiDeviceUpnp::GetServiceUri(Uri& aUri, const TChar* aType, const ServiceType& aServiceType)
{
    Brn root = XmlParserBasic::Find("root", iXml);
    Brn device = XmlParserBasic::Find("device", root);
    Brn udn = XmlParserBasic::Find("UDN", device);
    if (!CpiDeviceUpnp::UdnMatches(udn, Udn())) {
        Brn deviceList = XmlParserBasic::Find("deviceList", device);
        do {
            Brn remaining;
            device.Set(XmlParserBasic::Find("device", deviceList, remaining));
            udn.Set(XmlParserBasic::Find("UDN", device));
            deviceList.Set(remaining);
        } while (!CpiDeviceUpnp::UdnMatches(udn, Udn()));
    }
    Brn serviceList = XmlParserBasic::Find("serviceList", device);
    Brn service;
    Brn serviceType;
    const Brx& targServiceType = aServiceType.FullName();
    do {
        Brn remaining;
        service.Set(XmlParserBasic::Find("service", serviceList, remaining));
        serviceType.Set(XmlParserBasic::Find("serviceType", service));
        serviceList.Set(remaining);
    } while (serviceType != targServiceType);
    Brn path = XmlParserBasic::Find(aType, service);
    if (path.Bytes() == 0) {
        // no event url => service doesn't have any evented state variables
        THROW(XmlError);
    }

    // now create a uri using the scheme/host/port of the device xml location
    // plus the path we've just constructed
    Bws<40> base; // just need space for http://xxx.xxx.xxx.xxx:xxxxx
    aUri.Replace(iLocation);
    base.Append(aUri.Scheme());
    base.Append("://");
    base.Append(aUri.Host());
    base.Append(':');
    Ascii::AppendDec(base, aUri.Port());
    aUri.Replace(base, path);
}
Ejemplo n.º 17
0
mStatus mDNSPlatformSendUDP(const mDNS* m, const void* const aMessage, const mDNSu8* const aEnd,
        mDNSInterfaceID aInterface, const mDNSAddr *aAddress, mDNSIPPort aPort)
{
    if (aInterface ==  mDNSInterface_LocalOnly) {
        LOG(kBonjour, "Bonjour             mDNSPlatformSendUDP - local only, ignore\n");
        return 0;
    }
    
    LOG(kBonjour, "Bonjour             mDNSPlatformSendUDP\n");
    
    MdnsPlatform& platform = *(MdnsPlatform*)m->p;
    Brn buffer((const TByte*)aMessage, (TUint)((const TByte*)aEnd - (const TByte*)aMessage));
    ASSERT(aAddress->type == mDNSAddrType_IPv4);
    Bws<16> address;
    address.AppendPrintf("%d.%d.%d.%d",
        aAddress->ip.v4.b[0],
        aAddress->ip.v4.b[1],
        aAddress->ip.v4.b[2],
        aAddress->ip.v4.b[3] );
    
    Endpoint endpoint(Arch::BigEndian2(aPort.NotAnInteger), address);
    return platform.SendUdp(buffer, endpoint);
}
Ejemplo n.º 18
0
void WsProtocol80::Read(Brn& aData, TBool& aClosed)
{
    aData.Set(NULL, 0);
    aClosed = false;

    static const TByte kBitMaskFinalFragment = 1<<7;
    static const TByte kBitMaskRsv123        = 0x70;
    static const TByte kBitMaskOpcode        = 0xf;
    static const TByte kBitMaskPayloadMask   = 1<<7;
    static const TByte kBitMaskPayloadLen    = 0x7f;

    // validate framing
    Bws<2> ctrl;
    ctrl.Append(iReadBuffer.Read(2));
    const TByte& byte0 = ctrl.At(0);
    const TByte& byte1 = ctrl.At(1);
    const TBool fragment = ((byte0 & kBitMaskFinalFragment) == 0);
    if (byte0 & kBitMaskRsv123) {
        LOG2(kDvWebSocket, kError, "WS: RSV bit(s) set - %u - but no extension negotiated\n", (byte0 & kBitMaskRsv123) >> 4);
        Close(kCloseProtocolError);
        aClosed = true;
        return;
    }
Ejemplo n.º 19
0
void SuiteUnicast::Receiver()
{
    TBool first = true;
    iLastVal = 0;
    TUint val;
    Bws<kMsgBytes> recv;
    do {
        recv.SetBytes(0);
        (void)iReceiver->Receive(recv);
        ASSERT(recv.Bytes() >= sizeof(TUint32));
        val = *((TUint32*)recv.Ptr());
        if (val != kQuit) {
            if (first) {
                TEST(val == 0);
                first = false;
            }
            else {
                TEST(val == iLastVal+1);
            }
        }
        //Print("Received %u, last sent %u\n", val, iSendVal);
        iLastVal = val;
    } while (val != kQuit);
}
Ejemplo n.º 20
0
Brn DeviceXml::ServiceVersion(const Brx& aServiceType) const
{
    const TUint kMaxDomainBytes = 64;
    const TUint kMaxTypeBytes = 64;
    
    Bws<kMaxDomainBytes> domain;
    Bws<kMaxTypeBytes> upnpType;
    
    Parser parser(aServiceType);
    
    TUint count = 0;
    
    while (!parser.Finished()) {
        upnpType.Replace(parser.Next('.'));
        count++;
    }

    parser.Restart();
        
    while (--count) {
        Brn element = parser.Next('.');
        
        if (domain.Bytes() > 0) {
            domain.Append('.');
        }
        
        domain.Append(element);
    }
    
    Bws<kMaxDomainBytes> upnpDomain;
    
    Ssdp::CanonicalDomainToUpnp(domain, upnpDomain);
    
    Brn serviceList = XmlParserBasic::Find("serviceList", iXml);
    
    for (;;) {
        Brn service = XmlParserBasic::Find("service", serviceList, serviceList);
        Brn type = XmlParserBasic::Find("serviceType", service);

        Parser parser(type);
        
        if (parser.Next(':') == Brn("urn")) {
            if (parser.Next(':') == upnpDomain) {
                if (parser.Next(':') == Brn("service")) {
                    if (parser.Next(':') == upnpType) {
                        return (parser.Remaining());
                    }
                }
            }
        }
    }
}
Ejemplo n.º 21
0
void SuiteFileStream::Test()
{
    const TUint kBytes = 256;
    Bws<kBytes> b;
    // Populate each position in the buffer with it's index.
    for (TUint i=0; i<kBytes; i++) {
        b.Append((TChar)i);
    }
    FileBrx f(b);
    FileStream stream;
    stream.SetFile(&f);
    TEST(stream.Bytes() == kBytes);

    // test basic reading
    Bws<kBytes> buf;
    stream.Read(buf);
    TEST(buf == b);
    TEST(stream.Tell() == kBytes);

    // test that reads on a full buffer and at the end of a file throw
    TEST_THROWS(stream.Read(buf), ReaderError);
    buf.SetBytes(0);
    TEST_THROWS(stream.Read(buf), ReaderError);

    // test seeking
    stream.Seek(0);
    TEST(stream.Tell() == 0);

    // test a stream can be (un)interrupted
    stream.ReadInterrupt();
    Bws<10> buf2;
    TEST_THROWS(stream.Read(buf2), ReaderError);
    stream.Interrupt(false);
    stream.Read(buf2);
    TEST(buf2.Bytes() == buf2.MaxBytes());
    for (TUint i=0; i<10; i++) {
        TEST(buf2[i] == b[i]);
    }
    
    // test that Read appends to a buffer
    buf.SetBytes(0);
    buf.Append(buf2);
    stream.Read(buf);
    TEST(buf.Bytes() == kBytes);
    TEST(buf == b);
}
Ejemplo n.º 22
0
void SuiteFileBrx::Test()
{
    const TUint kBytes = 256;
    Bws<kBytes> b;
    // Populate each position in the buffer with it's index.
    for (TUint i=0; i<kBytes; i++) {
        b.Append((TChar)i);
    }

    FileBrx f(b);
    Bws<kBytes> buff;

    f.Read(buff);       // Read full buffer
    TEST(buff == b);

    buff.SetBytes(0);
    TEST_THROWS(f.Read(buff), FileReadError); // Attempt full buffer from end

    f.Seek(0, eSeekFromStart);
    buff.SetBytes(0);
    f.Read(buff, 10);
    TEST(buff[0] == 0);
    TEST(buff[9] == 9);

    f.Seek(10, eSeekFromStart);
    buff.SetBytes(0);
    f.Read(buff, 10);
    TEST(buff[0] == 10);
    TEST(buff[9] == 19);
    
    f.Seek(10, eSeekFromCurrent);
    buff.SetBytes(0);
    f.Read(buff, 10);
    TEST(buff[0] == 30);
    TEST(buff[9] == 39);
}
Ejemplo n.º 23
0
ExampleMediaPlayer::ExampleMediaPlayer(HWND hwnd,
                                       Net::DvStack& aDvStack,
                                       const Brx& aUdn,
                                       const TChar* aRoom,
                                       const TChar* aProductName,
                                       const Brx& aUserAgent)
    : iSemShutdown("TMPS", 0)
    , iDisabled("test", 0)
    , iHwnd(hwnd)
    , iCpProxy(NULL)
    , iTxTimestamper(NULL)
    , iRxTimestamper(NULL)
    , iTxTsMapper(NULL)
    , iRxTsMapper(NULL)
    , iUserAgent(aUserAgent)
{
    iShell = new Shell(aDvStack.Env(), kShellPort);
    iShellDebug = new ShellCommandDebug(*iShell);

    Bws<256> friendlyName;
    friendlyName.Append(aRoom);
    friendlyName.Append(':');
    friendlyName.Append(aProductName);

    // create UPnP device
    iDevice = new DvDeviceStandard(aDvStack, aUdn, *this);
    iDevice->SetAttribute("Upnp.Domain", "av.openhome.org");
    iDevice->SetAttribute("Upnp.Type", "Source");
    iDevice->SetAttribute("Upnp.Version", "1");
    iDevice->SetAttribute("Upnp.FriendlyName", friendlyName.PtrZ());
    iDevice->SetAttribute("Upnp.Manufacturer", "OpenHome");
    iDevice->SetAttribute("Upnp.ModelName", "ExampleMediaPlayer");

    // create separate UPnP device for standard MediaRenderer
    Bws<256> buf(aUdn);
    buf.Append("-MediaRenderer");

    // The renderer name should be <room name>:<UPnP AV source name> to allow
    // our control point to match the renderer device to the upnp av source.
    Bws<256> rendererName(aRoom);
    rendererName.Append(":");
    rendererName.Append(SourceUpnpAv::kSourceName);
    iDeviceUpnpAv = new DvDeviceStandard(aDvStack, buf);
    iDeviceUpnpAv->SetAttribute("Upnp.Domain", "upnp.org");
    iDeviceUpnpAv->SetAttribute("Upnp.Type", "MediaRenderer");
    iDeviceUpnpAv->SetAttribute("Upnp.Version", "1");
    friendlyName.Append(":MediaRenderer");
    iDeviceUpnpAv->SetAttribute("Upnp.FriendlyName", rendererName.PtrZ());
    iDeviceUpnpAv->SetAttribute("Upnp.Manufacturer", "OpenHome");
    iDeviceUpnpAv->SetAttribute("Upnp.ModelName", "ExampleMediaPlayer");

    // create read/write store.  This creates a number of static (constant)
    // entries automatically
    iRamStore = new RamStore();

    // create a read/write store using the new config framework
    iConfigRegStore = new ConfigRegStore();

    iConfigRegStore->Write(Brn("Product.Room"), Brn(aRoom));
    iConfigRegStore->Write(Brn("Product.Name"), Brn(aProductName));

    // Volume Control
    VolumeProfile  volumeProfile;
    VolumeConsumer volumeInit;
    volumeInit.SetVolume(iVolume);
    volumeInit.SetBalance(iVolume);
    volumeInit.SetFade(iVolume);

    // Set pipeline thread priority just below the pipeline animator.
    iInitParams = PipelineInitParams::New();
    iInitParams->SetThreadPriorityMax(kPriorityHighest);
    iInitParams->SetStarvationMonitorMaxSize(Jiffies::kPerMs * 100);

    // create MediaPlayer
    iMediaPlayer = new MediaPlayer(aDvStack, *iDevice, *iShell, *iRamStore,
                                   *iConfigRegStore, iInitParams,
                                   volumeInit, volumeProfile, aUdn, Brn(aRoom),
                                   Brn(aProductName));

    iPipelineStateLogger = new LoggingPipelineObserver();
    iMediaPlayer->Pipeline().AddObserver(*iPipelineStateLogger);

    // Set up config app.
    static const TUint addr = 0;    // Bind to all addresses.
    static const TUint port = 0;    // Bind to whatever free port the OS
    // allocates to the framework server.

    iAppFramework = new WebAppFramework(aDvStack.Env(),
                                        addr,
                                        port,
                                        kMaxUiTabs,
                                        kUiSendQueueSize);
}
Ejemplo n.º 24
0
int CDECL main(int aArgc, char* aArgv[])
{
    OptionParser parser;
    OptionUint optionAdapter("-a", "--adapter", 0, "[adapter] index of network adapter to use");
    parser.AddOption(&optionAdapter);
    OptionString optionRoom("-r", "--room", Brx::Empty(), "Room containing the receiver to play/stop");
    parser.AddOption(&optionRoom);

    if (!parser.Parse(aArgc, aArgv)) {
        return 1;
    }

    gRoom.Replace(optionRoom.Value());

    InitialisationParams* initParams = InitialisationParams::Create();
	UpnpLibrary::Initialise(initParams);
    std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList();
    TIpAddress subnet = (*subnetList)[optionAdapter.Value()]->Subnet();
    UpnpLibrary::DestroySubnetList(subnetList);
    UpnpLibrary::Close();

    TUint channel = 0;
    TUint ttl = 4;
	TUint latency = 100;
    TBool multicast = false;
    TBool disabled = false;
    TUint preset = 99;

	THandle Songcast = SongcastCreate("av.openhome.org", subnet, channel, ttl, latency, multicast, !disabled, preset, loggerReceiver, 0, loggerSubnet, 0, loggerConfigurationChanged, 0, NULL, 0, "OpenHome", "http://www.openhome.org", "http://www.openhome.org", icon_png, icon_png_len, "image/png");

	if (Songcast == 0) {
		printf("Songcast error\n");
		return(1);
	}

	printf("preset = %d\n", preset);

    if (multicast) {
        printf("multicast\n");
    }
    else {
        printf("unicast\n");
    }

    if (disabled) {
        printf("disabled\n");
    }
    else {
        printf("enabled\n");
    }

	printf("q = quit, m = toggle multicast, e = toggle enabled\n");
	
    for (;;) {
    	int key = mygetch();
    	
    	if (key == 'q') {
    		break;
    	}

        if (key == 'm') {
            if (multicast) {
                multicast = false;
                SongcastSetMulticast(Songcast, false);
            }
            else {
                multicast = true;
                SongcastSetMulticast(Songcast, true);
            }
        }

        if (key == 'e') {
            if (disabled) {
                disabled = false;
                SongcastSetEnabled(Songcast, true);
            }
            else {
                disabled = true;
                SongcastSetEnabled(Songcast, false);
            }
        }

        if (key == 'a') {
            SongcastSetSubnet(Songcast, 43200); // 192.168.0.0
        }

        if (gRecv != 0)
        {
            if (key == 'p') {
                SongcastSetEnabled(Songcast, true);
                ReceiverPlay(gRecv);
            }

            if (key == 's') {
                ReceiverStop(gRecv);
                ReceiverStandby(gRecv);
                SongcastSetEnabled(Songcast, false);
            }
        }
	}
    
    if (gRecv != 0) {
        ReceiverRemoveRef(gRecv);
    }

	SongcastDestroy(Songcast);

	printf("\n");
	
    return (0);
}
Ejemplo n.º 25
0
Soundcard::Soundcard(TIpAddress /* aSubnet */, TUint aChannel, TUint aTtl, TBool aMulticast, TBool aEnabled, TUint aPreset, ReceiverCallback aReceiverCallback, void* aReceiverPtr)
	: iReceiverCallback(aReceiverCallback)
	, iReceiverPtr(aReceiverPtr)
{
	InitialisationParams* initParams = InitialisationParams::Create();

	UpnpLibrary::Initialise(initParams);

	std::vector<NetworkInterface*>* list = UpnpLibrary::SubnetList();

	ASSERT(list->size() > 0);

	NetworkInterface* iface = *list->begin();

	delete (list);

	UpnpLibrary::SetCurrentSubnet(*iface);

	printf("Using %x\n", iface->Address());
    
    UpnpLibrary::StartCombined();

	Bws<kMaxUdnBytes> computer;
	Bws<kMaxUdnBytes> udn;
	Bws<kMaxUdnBytes + 1> friendly;

	TUint bytes = computer.MaxBytes();

	if (!GetComputerName((LPSTR)computer.Ptr(), (LPDWORD)&bytes)) {
		THROW(SoundcardError);
	}

	computer.SetBytes(bytes);
	udn.Replace("ohSoundcard-");
	udn.Append(computer);
	friendly.Replace(udn);
	friendly.Append('\0');

	iDevice = new DvDeviceStandard(udn);
    
	iDevice->SetAttribute("Upnp.Domain", "av.openhome.org");
    iDevice->SetAttribute("Upnp.Type", "Soundcard");
    iDevice->SetAttribute("Upnp.Version", "1");
    iDevice->SetAttribute("Upnp.FriendlyName", (TChar*)friendly.Ptr());
    iDevice->SetAttribute("Upnp.Manufacturer", "Openhome");
    iDevice->SetAttribute("Upnp.ManufacturerUrl", "http://www.openhome.org");
    iDevice->SetAttribute("Upnp.ModelDescription", "OpenHome Soundcard");
    iDevice->SetAttribute("Upnp.ModelName", "ohSoundcard");
    iDevice->SetAttribute("Upnp.ModelNumber", "1");
    iDevice->SetAttribute("Upnp.ModelUrl", "http://www.openhome.org");
    iDevice->SetAttribute("Upnp.SerialNumber", "");
    iDevice->SetAttribute("Upnp.Upc", "");

    iDriver = new OhmSenderDriverWindows();
    
	Brn icon(icon_png, icon_png_len);

	iSender = new OhmSender(*iDevice, *iDriver, computer, aChannel, iface->Address(), aTtl, aMulticast, aEnabled, icon, Brn("image/png"), aPreset);
	
    iDevice->SetEnabled();

	iReceiverManager = new ReceiverManager3(*this, iSender->SenderUri(), iSender->SenderMetadata());
}
Ejemplo n.º 26
0
static void GetThreadName(Bws<5>& aThName)
{
    aThName.SetBytes(0);
    aThName.Append(Thread::CurrentThreadName());
    aThName.PtrZ();
}